AudioRecord and FFT/MSE comparison. Call AudioRecord_demo for control record and AudioSample for subsequent recordings.
Dependencies: CMSIS_DSP_401 STM32L4xx_HAL_Driver
Fork of OneHopeOnePrayer by
stm32l4xx_nucleo.c@5:f6afbd3fc47a, 2015-12-05 (annotated)
- Committer:
- EricLew
- Date:
- Sat Dec 05 16:17:25 2015 +0000
- Revision:
- 5:f6afbd3fc47a
Ported to Nucleo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
EricLew | 5:f6afbd3fc47a | 1 | /** |
EricLew | 5:f6afbd3fc47a | 2 | ****************************************************************************** |
EricLew | 5:f6afbd3fc47a | 3 | * @file stm32l4xx_nucleo.c |
EricLew | 5:f6afbd3fc47a | 4 | * @author MCD Application Team |
EricLew | 5:f6afbd3fc47a | 5 | * @version V2.0.0 |
EricLew | 5:f6afbd3fc47a | 6 | * @date 16-September-2015 |
EricLew | 5:f6afbd3fc47a | 7 | * @brief This file provides set of firmware functions to manage: |
EricLew | 5:f6afbd3fc47a | 8 | * - LEDs and push-button available on STM32L4XX-Nucleo Kit |
EricLew | 5:f6afbd3fc47a | 9 | * from STMicroelectronics |
EricLew | 5:f6afbd3fc47a | 10 | * - LCD, joystick and microSD available on Adafruit 1.8" TFT LCD |
EricLew | 5:f6afbd3fc47a | 11 | * shield (reference ID 802) |
EricLew | 5:f6afbd3fc47a | 12 | ****************************************************************************** |
EricLew | 5:f6afbd3fc47a | 13 | * @attention |
EricLew | 5:f6afbd3fc47a | 14 | * |
EricLew | 5:f6afbd3fc47a | 15 | * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> |
EricLew | 5:f6afbd3fc47a | 16 | * |
EricLew | 5:f6afbd3fc47a | 17 | * Redistribution and use in source and binary forms, with or without modification, |
EricLew | 5:f6afbd3fc47a | 18 | * are permitted provided that the following conditions are met: |
EricLew | 5:f6afbd3fc47a | 19 | * 1. Redistributions of source code must retain the above copyright notice, |
EricLew | 5:f6afbd3fc47a | 20 | * this list of conditions and the following disclaimer. |
EricLew | 5:f6afbd3fc47a | 21 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
EricLew | 5:f6afbd3fc47a | 22 | * this list of conditions and the following disclaimer in the documentation |
EricLew | 5:f6afbd3fc47a | 23 | * and/or other materials provided with the distribution. |
EricLew | 5:f6afbd3fc47a | 24 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
EricLew | 5:f6afbd3fc47a | 25 | * may be used to endorse or promote products derived from this software |
EricLew | 5:f6afbd3fc47a | 26 | * without specific prior written permission. |
EricLew | 5:f6afbd3fc47a | 27 | * |
EricLew | 5:f6afbd3fc47a | 28 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
EricLew | 5:f6afbd3fc47a | 29 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
EricLew | 5:f6afbd3fc47a | 30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
EricLew | 5:f6afbd3fc47a | 31 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
EricLew | 5:f6afbd3fc47a | 32 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
EricLew | 5:f6afbd3fc47a | 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
EricLew | 5:f6afbd3fc47a | 34 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
EricLew | 5:f6afbd3fc47a | 35 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
EricLew | 5:f6afbd3fc47a | 36 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
EricLew | 5:f6afbd3fc47a | 37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
EricLew | 5:f6afbd3fc47a | 38 | * |
EricLew | 5:f6afbd3fc47a | 39 | ****************************************************************************** |
EricLew | 5:f6afbd3fc47a | 40 | */ |
EricLew | 5:f6afbd3fc47a | 41 | |
EricLew | 5:f6afbd3fc47a | 42 | /* Includes ------------------------------------------------------------------*/ |
EricLew | 5:f6afbd3fc47a | 43 | #include "stm32l4xx_nucleo.h" |
EricLew | 5:f6afbd3fc47a | 44 | |
EricLew | 5:f6afbd3fc47a | 45 | /** @addtogroup BSP |
EricLew | 5:f6afbd3fc47a | 46 | * @{ |
EricLew | 5:f6afbd3fc47a | 47 | */ |
EricLew | 5:f6afbd3fc47a | 48 | |
EricLew | 5:f6afbd3fc47a | 49 | /** @defgroup STM32L4XX_NUCLEO STM32L476RG-Nucleo |
EricLew | 5:f6afbd3fc47a | 50 | * @brief This file provides set of firmware functions to manage Leds and push-button |
EricLew | 5:f6afbd3fc47a | 51 | * available on STM32L4XX-Nucleo Kit from STMicroelectronics. |
EricLew | 5:f6afbd3fc47a | 52 | * It provides also LCD, joystick and uSD functions to communicate with |
EricLew | 5:f6afbd3fc47a | 53 | * Adafruit 1.8" TFT LCD shield (reference ID 802) |
EricLew | 5:f6afbd3fc47a | 54 | * @{ |
EricLew | 5:f6afbd3fc47a | 55 | */ |
EricLew | 5:f6afbd3fc47a | 56 | |
EricLew | 5:f6afbd3fc47a | 57 | |
EricLew | 5:f6afbd3fc47a | 58 | /** @defgroup STM32L4XX_NUCLEO_Private_Defines Private Defines |
EricLew | 5:f6afbd3fc47a | 59 | * @{ |
EricLew | 5:f6afbd3fc47a | 60 | */ |
EricLew | 5:f6afbd3fc47a | 61 | |
EricLew | 5:f6afbd3fc47a | 62 | /** |
EricLew | 5:f6afbd3fc47a | 63 | * @brief STM32L476RG NUCLEO BSP Driver version V2.0.0 |
EricLew | 5:f6afbd3fc47a | 64 | */ |
EricLew | 5:f6afbd3fc47a | 65 | #define __STM32L4XX_NUCLEO_BSP_VERSION_MAIN (0x02) /*!< [31:24] main version */ |
EricLew | 5:f6afbd3fc47a | 66 | #define __STM32L4XX_NUCLEO_BSP_VERSION_SUB1 (0x00) /*!< [23:16] sub1 version */ |
EricLew | 5:f6afbd3fc47a | 67 | #define __STM32L4XX_NUCLEO_BSP_VERSION_SUB2 (0x00) /*!< [15:8] sub2 version */ |
EricLew | 5:f6afbd3fc47a | 68 | #define __STM32L4XX_NUCLEO_BSP_VERSION_RC (0x00) /*!< [7:0] release candidate */ |
EricLew | 5:f6afbd3fc47a | 69 | #define __STM32L4XX_NUCLEO_BSP_VERSION ((__STM32L4XX_NUCLEO_BSP_VERSION_MAIN << 24)\ |
EricLew | 5:f6afbd3fc47a | 70 | |(__STM32L4XX_NUCLEO_BSP_VERSION_SUB1 << 16)\ |
EricLew | 5:f6afbd3fc47a | 71 | |(__STM32L4XX_NUCLEO_BSP_VERSION_SUB2 << 8 )\ |
EricLew | 5:f6afbd3fc47a | 72 | |(__STM32L4XX_NUCLEO_BSP_VERSION_RC)) |
EricLew | 5:f6afbd3fc47a | 73 | |
EricLew | 5:f6afbd3fc47a | 74 | /** |
EricLew | 5:f6afbd3fc47a | 75 | * @brief LINK SD Card |
EricLew | 5:f6afbd3fc47a | 76 | */ |
EricLew | 5:f6afbd3fc47a | 77 | #define SD_DUMMY_BYTE 0xFF |
EricLew | 5:f6afbd3fc47a | 78 | #define SD_NO_RESPONSE_EXPECTED 0x80 |
EricLew | 5:f6afbd3fc47a | 79 | |
EricLew | 5:f6afbd3fc47a | 80 | /** |
EricLew | 5:f6afbd3fc47a | 81 | * @} |
EricLew | 5:f6afbd3fc47a | 82 | */ |
EricLew | 5:f6afbd3fc47a | 83 | |
EricLew | 5:f6afbd3fc47a | 84 | |
EricLew | 5:f6afbd3fc47a | 85 | /** @defgroup STM32L4XX_NUCLEO_Private_Variables Exported Variables |
EricLew | 5:f6afbd3fc47a | 86 | * @{ |
EricLew | 5:f6afbd3fc47a | 87 | */ |
EricLew | 5:f6afbd3fc47a | 88 | GPIO_TypeDef* GPIO_PORT[LEDn] = {LED2_GPIO_PORT}; |
EricLew | 5:f6afbd3fc47a | 89 | |
EricLew | 5:f6afbd3fc47a | 90 | const uint16_t GPIO_PIN[LEDn] = {LED2_PIN}; |
EricLew | 5:f6afbd3fc47a | 91 | |
EricLew | 5:f6afbd3fc47a | 92 | GPIO_TypeDef* BUTTON_PORT[BUTTONn] = {USER_BUTTON_GPIO_PORT}; |
EricLew | 5:f6afbd3fc47a | 93 | const uint16_t BUTTON_PIN[BUTTONn] = {USER_BUTTON_PIN}; |
EricLew | 5:f6afbd3fc47a | 94 | const uint16_t BUTTON_IRQn[BUTTONn] = {USER_BUTTON_EXTI_IRQn}; |
EricLew | 5:f6afbd3fc47a | 95 | |
EricLew | 5:f6afbd3fc47a | 96 | /** |
EricLew | 5:f6afbd3fc47a | 97 | * @brief BUS variables |
EricLew | 5:f6afbd3fc47a | 98 | */ |
EricLew | 5:f6afbd3fc47a | 99 | |
EricLew | 5:f6afbd3fc47a | 100 | #ifdef HAL_SPI_MODULE_ENABLED |
EricLew | 5:f6afbd3fc47a | 101 | uint32_t hnucleo_SpixTimeout = NUCLEO_SPIx_TIMEOUT_MAX; /*<! Value of Timeout when SPI communication fails */ |
EricLew | 5:f6afbd3fc47a | 102 | static SPI_HandleTypeDef hnucleo_Spi; |
EricLew | 5:f6afbd3fc47a | 103 | #endif /* HAL_SPI_MODULE_ENABLED */ |
EricLew | 5:f6afbd3fc47a | 104 | |
EricLew | 5:f6afbd3fc47a | 105 | #ifdef HAL_ADC_MODULE_ENABLED |
EricLew | 5:f6afbd3fc47a | 106 | static ADC_HandleTypeDef hnucleo_Adc; |
EricLew | 5:f6afbd3fc47a | 107 | /* ADC channel configuration structure declaration */ |
EricLew | 5:f6afbd3fc47a | 108 | static ADC_ChannelConfTypeDef hnucleo_AdcChannelConfig; |
EricLew | 5:f6afbd3fc47a | 109 | #endif /* HAL_ADC_MODULE_ENABLED */ |
EricLew | 5:f6afbd3fc47a | 110 | |
EricLew | 5:f6afbd3fc47a | 111 | /** |
EricLew | 5:f6afbd3fc47a | 112 | * @} |
EricLew | 5:f6afbd3fc47a | 113 | */ |
EricLew | 5:f6afbd3fc47a | 114 | |
EricLew | 5:f6afbd3fc47a | 115 | /** @defgroup STM32L4XX_NUCLEO_Private_Functions Private Functions |
EricLew | 5:f6afbd3fc47a | 116 | * @{ |
EricLew | 5:f6afbd3fc47a | 117 | */ |
EricLew | 5:f6afbd3fc47a | 118 | #ifdef HAL_SPI_MODULE_ENABLED |
EricLew | 5:f6afbd3fc47a | 119 | static void SPIx_Init(void); |
EricLew | 5:f6afbd3fc47a | 120 | static void SPIx_Write(uint8_t Value); |
EricLew | 5:f6afbd3fc47a | 121 | static void SPIx_Error (void); |
EricLew | 5:f6afbd3fc47a | 122 | static void SPIx_MspInit(void); |
EricLew | 5:f6afbd3fc47a | 123 | #endif /* HAL_SPI_MODULE_ENABLED */ |
EricLew | 5:f6afbd3fc47a | 124 | |
EricLew | 5:f6afbd3fc47a | 125 | #ifdef HAL_ADC_MODULE_ENABLED |
EricLew | 5:f6afbd3fc47a | 126 | static HAL_StatusTypeDef ADCx_Init(void); |
EricLew | 5:f6afbd3fc47a | 127 | static void ADCx_MspInit(ADC_HandleTypeDef *hadc); |
EricLew | 5:f6afbd3fc47a | 128 | #endif /* HAL_ADC_MODULE_ENABLED */ |
EricLew | 5:f6afbd3fc47a | 129 | |
EricLew | 5:f6afbd3fc47a | 130 | #ifdef HAL_SPI_MODULE_ENABLED |
EricLew | 5:f6afbd3fc47a | 131 | /* SD IO functions */ |
EricLew | 5:f6afbd3fc47a | 132 | void SD_IO_Init(void); |
EricLew | 5:f6afbd3fc47a | 133 | void SD_IO_CSState(uint8_t state); |
EricLew | 5:f6afbd3fc47a | 134 | void SD_IO_WriteReadData(const uint8_t *DataIn, uint8_t *DataOut, uint16_t DataLength); |
EricLew | 5:f6afbd3fc47a | 135 | uint8_t SD_IO_WriteByte(uint8_t Data); |
EricLew | 5:f6afbd3fc47a | 136 | |
EricLew | 5:f6afbd3fc47a | 137 | /* LCD IO functions */ |
EricLew | 5:f6afbd3fc47a | 138 | void LCD_IO_Init(void); |
EricLew | 5:f6afbd3fc47a | 139 | void LCD_IO_WriteMultipleData(uint8_t *pData, uint32_t Size); |
EricLew | 5:f6afbd3fc47a | 140 | void LCD_IO_WriteReg(uint8_t LCDReg); |
EricLew | 5:f6afbd3fc47a | 141 | void LCD_Delay(uint32_t delay); |
EricLew | 5:f6afbd3fc47a | 142 | #endif /* HAL_SPI_MODULE_ENABLED */ |
EricLew | 5:f6afbd3fc47a | 143 | /** |
EricLew | 5:f6afbd3fc47a | 144 | * @} |
EricLew | 5:f6afbd3fc47a | 145 | */ |
EricLew | 5:f6afbd3fc47a | 146 | |
EricLew | 5:f6afbd3fc47a | 147 | /** @defgroup STM32L4XX_NUCLEO_Exported_Functions Exported Functions |
EricLew | 5:f6afbd3fc47a | 148 | * @{ |
EricLew | 5:f6afbd3fc47a | 149 | */ |
EricLew | 5:f6afbd3fc47a | 150 | |
EricLew | 5:f6afbd3fc47a | 151 | /** |
EricLew | 5:f6afbd3fc47a | 152 | * @brief This method returns the STM32L4XX NUCLEO BSP Driver revision |
EricLew | 5:f6afbd3fc47a | 153 | * @retval version : 0xXYZR (8bits for each decimal, R for RC) |
EricLew | 5:f6afbd3fc47a | 154 | */ |
EricLew | 5:f6afbd3fc47a | 155 | uint32_t BSP_GetVersion(void) |
EricLew | 5:f6afbd3fc47a | 156 | { |
EricLew | 5:f6afbd3fc47a | 157 | return __STM32L4XX_NUCLEO_BSP_VERSION; |
EricLew | 5:f6afbd3fc47a | 158 | } |
EricLew | 5:f6afbd3fc47a | 159 | |
EricLew | 5:f6afbd3fc47a | 160 | /** @defgroup STM32L4XX_NUCLEO_LED_Functions LED Functions |
EricLew | 5:f6afbd3fc47a | 161 | * @{ |
EricLew | 5:f6afbd3fc47a | 162 | */ |
EricLew | 5:f6afbd3fc47a | 163 | |
EricLew | 5:f6afbd3fc47a | 164 | /** |
EricLew | 5:f6afbd3fc47a | 165 | * @brief Configures LED GPIO. |
EricLew | 5:f6afbd3fc47a | 166 | * @param Led: LED to be configured. |
EricLew | 5:f6afbd3fc47a | 167 | * This parameter can be one of the following values: |
EricLew | 5:f6afbd3fc47a | 168 | * @arg LED2 |
EricLew | 5:f6afbd3fc47a | 169 | * @retval None |
EricLew | 5:f6afbd3fc47a | 170 | */ |
EricLew | 5:f6afbd3fc47a | 171 | void BSP_LED_Init(Led_TypeDef Led) |
EricLew | 5:f6afbd3fc47a | 172 | { |
EricLew | 5:f6afbd3fc47a | 173 | GPIO_InitTypeDef gpioinitstruct = {0}; |
EricLew | 5:f6afbd3fc47a | 174 | |
EricLew | 5:f6afbd3fc47a | 175 | /* Enable the GPIO_LED Clock */ |
EricLew | 5:f6afbd3fc47a | 176 | LEDx_GPIO_CLK_ENABLE(Led); |
EricLew | 5:f6afbd3fc47a | 177 | |
EricLew | 5:f6afbd3fc47a | 178 | /* Configure the GPIO_LED pin */ |
EricLew | 5:f6afbd3fc47a | 179 | gpioinitstruct.Pin = GPIO_PIN[Led]; |
EricLew | 5:f6afbd3fc47a | 180 | gpioinitstruct.Mode = GPIO_MODE_OUTPUT_PP; |
EricLew | 5:f6afbd3fc47a | 181 | gpioinitstruct.Pull = GPIO_NOPULL; |
EricLew | 5:f6afbd3fc47a | 182 | gpioinitstruct.Speed = GPIO_SPEED_FREQ_HIGH; |
EricLew | 5:f6afbd3fc47a | 183 | HAL_GPIO_Init(GPIO_PORT[Led], &gpioinitstruct); |
EricLew | 5:f6afbd3fc47a | 184 | } |
EricLew | 5:f6afbd3fc47a | 185 | |
EricLew | 5:f6afbd3fc47a | 186 | /** |
EricLew | 5:f6afbd3fc47a | 187 | * @brief Turns selected LED On. |
EricLew | 5:f6afbd3fc47a | 188 | * @param Led: Specifies the Led to be set on. |
EricLew | 5:f6afbd3fc47a | 189 | * This parameter can be one of following parameters: |
EricLew | 5:f6afbd3fc47a | 190 | * @arg LED2 |
EricLew | 5:f6afbd3fc47a | 191 | * @retval None |
EricLew | 5:f6afbd3fc47a | 192 | */ |
EricLew | 5:f6afbd3fc47a | 193 | void BSP_LED_On(Led_TypeDef Led) |
EricLew | 5:f6afbd3fc47a | 194 | { |
EricLew | 5:f6afbd3fc47a | 195 | HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_SET); |
EricLew | 5:f6afbd3fc47a | 196 | } |
EricLew | 5:f6afbd3fc47a | 197 | |
EricLew | 5:f6afbd3fc47a | 198 | /** |
EricLew | 5:f6afbd3fc47a | 199 | * @brief Turns selected LED Off. |
EricLew | 5:f6afbd3fc47a | 200 | * @param Led: Specifies the Led to be set off. |
EricLew | 5:f6afbd3fc47a | 201 | * This parameter can be one of following parameters: |
EricLew | 5:f6afbd3fc47a | 202 | * @arg LED2 |
EricLew | 5:f6afbd3fc47a | 203 | * @retval None |
EricLew | 5:f6afbd3fc47a | 204 | */ |
EricLew | 5:f6afbd3fc47a | 205 | void BSP_LED_Off(Led_TypeDef Led) |
EricLew | 5:f6afbd3fc47a | 206 | { |
EricLew | 5:f6afbd3fc47a | 207 | HAL_GPIO_WritePin(GPIO_PORT[Led], GPIO_PIN[Led], GPIO_PIN_RESET); |
EricLew | 5:f6afbd3fc47a | 208 | } |
EricLew | 5:f6afbd3fc47a | 209 | |
EricLew | 5:f6afbd3fc47a | 210 | /** |
EricLew | 5:f6afbd3fc47a | 211 | * @brief Toggles the selected LED. |
EricLew | 5:f6afbd3fc47a | 212 | * @param Led: Specifies the Led to be toggled. |
EricLew | 5:f6afbd3fc47a | 213 | * This parameter can be one of following parameters: |
EricLew | 5:f6afbd3fc47a | 214 | * @arg LED2 |
EricLew | 5:f6afbd3fc47a | 215 | * @retval None |
EricLew | 5:f6afbd3fc47a | 216 | */ |
EricLew | 5:f6afbd3fc47a | 217 | void BSP_LED_Toggle(Led_TypeDef Led) |
EricLew | 5:f6afbd3fc47a | 218 | { |
EricLew | 5:f6afbd3fc47a | 219 | HAL_GPIO_TogglePin(GPIO_PORT[Led], GPIO_PIN[Led]); |
EricLew | 5:f6afbd3fc47a | 220 | } |
EricLew | 5:f6afbd3fc47a | 221 | |
EricLew | 5:f6afbd3fc47a | 222 | /** |
EricLew | 5:f6afbd3fc47a | 223 | * @} |
EricLew | 5:f6afbd3fc47a | 224 | */ |
EricLew | 5:f6afbd3fc47a | 225 | |
EricLew | 5:f6afbd3fc47a | 226 | /** @defgroup STM32L4XX_NUCLEO_BUTTON_Functions BUTTON Functions |
EricLew | 5:f6afbd3fc47a | 227 | * @{ |
EricLew | 5:f6afbd3fc47a | 228 | */ |
EricLew | 5:f6afbd3fc47a | 229 | |
EricLew | 5:f6afbd3fc47a | 230 | /** |
EricLew | 5:f6afbd3fc47a | 231 | * @brief Configures Button GPIO and EXTI Line. |
EricLew | 5:f6afbd3fc47a | 232 | * @param Button: Specifies the Button to be configured. |
EricLew | 5:f6afbd3fc47a | 233 | * This parameter should be: BUTTON_USER |
EricLew | 5:f6afbd3fc47a | 234 | * @param ButtonMode: Specifies Button mode. |
EricLew | 5:f6afbd3fc47a | 235 | * This parameter can be one of following parameters: |
EricLew | 5:f6afbd3fc47a | 236 | * @arg BUTTON_MODE_GPIO: Button will be used as simple IO |
EricLew | 5:f6afbd3fc47a | 237 | * @arg BUTTON_MODE_EXTI: Button will be connected to EXTI line with interrupt |
EricLew | 5:f6afbd3fc47a | 238 | * generation capability |
EricLew | 5:f6afbd3fc47a | 239 | * @retval None |
EricLew | 5:f6afbd3fc47a | 240 | */ |
EricLew | 5:f6afbd3fc47a | 241 | void BSP_PB_Init(Button_TypeDef Button, ButtonMode_TypeDef ButtonMode) |
EricLew | 5:f6afbd3fc47a | 242 | { |
EricLew | 5:f6afbd3fc47a | 243 | GPIO_InitTypeDef gpioinitstruct = {0}; |
EricLew | 5:f6afbd3fc47a | 244 | |
EricLew | 5:f6afbd3fc47a | 245 | /* Enable the BUTTON Clock */ |
EricLew | 5:f6afbd3fc47a | 246 | BUTTONx_GPIO_CLK_ENABLE(Button); |
EricLew | 5:f6afbd3fc47a | 247 | |
EricLew | 5:f6afbd3fc47a | 248 | if (ButtonMode == BUTTON_MODE_GPIO) { |
EricLew | 5:f6afbd3fc47a | 249 | /* Configure Button pin as input */ |
EricLew | 5:f6afbd3fc47a | 250 | gpioinitstruct.Pin = BUTTON_PIN[Button]; |
EricLew | 5:f6afbd3fc47a | 251 | gpioinitstruct.Mode = GPIO_MODE_INPUT; |
EricLew | 5:f6afbd3fc47a | 252 | gpioinitstruct.Pull = GPIO_NOPULL; |
EricLew | 5:f6afbd3fc47a | 253 | gpioinitstruct.Speed = GPIO_SPEED_FREQ_HIGH; |
EricLew | 5:f6afbd3fc47a | 254 | |
EricLew | 5:f6afbd3fc47a | 255 | HAL_GPIO_Init(BUTTON_PORT[Button], &gpioinitstruct); |
EricLew | 5:f6afbd3fc47a | 256 | } else if(ButtonMode == BUTTON_MODE_EXTI) { |
EricLew | 5:f6afbd3fc47a | 257 | /* Configure Button pin as input with External interrupt */ |
EricLew | 5:f6afbd3fc47a | 258 | gpioinitstruct.Pin = BUTTON_PIN[Button]; |
EricLew | 5:f6afbd3fc47a | 259 | gpioinitstruct.Mode = GPIO_MODE_IT_FALLING; |
EricLew | 5:f6afbd3fc47a | 260 | gpioinitstruct.Pull = GPIO_NOPULL; |
EricLew | 5:f6afbd3fc47a | 261 | gpioinitstruct.Speed = GPIO_SPEED_FREQ_HIGH; |
EricLew | 5:f6afbd3fc47a | 262 | HAL_GPIO_Init(BUTTON_PORT[Button], &gpioinitstruct); |
EricLew | 5:f6afbd3fc47a | 263 | |
EricLew | 5:f6afbd3fc47a | 264 | /* Enable and set Button EXTI Interrupt to the lowest priority */ |
EricLew | 5:f6afbd3fc47a | 265 | HAL_NVIC_SetPriority((IRQn_Type)(BUTTON_IRQn[Button]), 0x0F, 0); |
EricLew | 5:f6afbd3fc47a | 266 | HAL_NVIC_EnableIRQ((IRQn_Type)(BUTTON_IRQn[Button])); |
EricLew | 5:f6afbd3fc47a | 267 | } |
EricLew | 5:f6afbd3fc47a | 268 | } |
EricLew | 5:f6afbd3fc47a | 269 | |
EricLew | 5:f6afbd3fc47a | 270 | /** |
EricLew | 5:f6afbd3fc47a | 271 | * @brief Returns the selected Button state. |
EricLew | 5:f6afbd3fc47a | 272 | * @param Button: Specifies the Button to be checked. |
EricLew | 5:f6afbd3fc47a | 273 | * This parameter should be: BUTTON_USER |
EricLew | 5:f6afbd3fc47a | 274 | * @retval Button state. |
EricLew | 5:f6afbd3fc47a | 275 | */ |
EricLew | 5:f6afbd3fc47a | 276 | uint32_t BSP_PB_GetState(Button_TypeDef Button) |
EricLew | 5:f6afbd3fc47a | 277 | { |
EricLew | 5:f6afbd3fc47a | 278 | return HAL_GPIO_ReadPin(BUTTON_PORT[Button], BUTTON_PIN[Button]); |
EricLew | 5:f6afbd3fc47a | 279 | } |
EricLew | 5:f6afbd3fc47a | 280 | |
EricLew | 5:f6afbd3fc47a | 281 | #ifdef HAL_ADC_MODULE_ENABLED |
EricLew | 5:f6afbd3fc47a | 282 | /** |
EricLew | 5:f6afbd3fc47a | 283 | * @brief Configures joystick available on adafruit 1.8" TFT shield |
EricLew | 5:f6afbd3fc47a | 284 | * managed through ADC to detect motion. |
EricLew | 5:f6afbd3fc47a | 285 | * @retval Joystickstatus (0=> success, 1=> fail) |
EricLew | 5:f6afbd3fc47a | 286 | */ |
EricLew | 5:f6afbd3fc47a | 287 | uint8_t BSP_JOY_Init(void) |
EricLew | 5:f6afbd3fc47a | 288 | { |
EricLew | 5:f6afbd3fc47a | 289 | if (ADCx_Init() != HAL_OK) { |
EricLew | 5:f6afbd3fc47a | 290 | return (uint8_t) HAL_ERROR; |
EricLew | 5:f6afbd3fc47a | 291 | } |
EricLew | 5:f6afbd3fc47a | 292 | |
EricLew | 5:f6afbd3fc47a | 293 | /* Select Channel 15 to be converted */ |
EricLew | 5:f6afbd3fc47a | 294 | hnucleo_AdcChannelConfig.Channel = ADC_CHANNEL_15; |
EricLew | 5:f6afbd3fc47a | 295 | hnucleo_AdcChannelConfig.SamplingTime = ADC_SAMPLETIME_24CYCLES_5; |
EricLew | 5:f6afbd3fc47a | 296 | hnucleo_AdcChannelConfig.Rank = 1; |
EricLew | 5:f6afbd3fc47a | 297 | hnucleo_AdcChannelConfig.SingleDiff = ADC_SINGLE_ENDED; |
EricLew | 5:f6afbd3fc47a | 298 | hnucleo_AdcChannelConfig.OffsetNumber = ADC_OFFSET_NONE; |
EricLew | 5:f6afbd3fc47a | 299 | |
EricLew | 5:f6afbd3fc47a | 300 | /* Return Joystick initialization status */ |
EricLew | 5:f6afbd3fc47a | 301 | return (uint8_t) HAL_ADC_ConfigChannel(&hnucleo_Adc, &hnucleo_AdcChannelConfig); |
EricLew | 5:f6afbd3fc47a | 302 | } |
EricLew | 5:f6afbd3fc47a | 303 | |
EricLew | 5:f6afbd3fc47a | 304 | /** |
EricLew | 5:f6afbd3fc47a | 305 | * @brief Returns the Joystick key pressed. |
EricLew | 5:f6afbd3fc47a | 306 | * @note To know which Joystick key is pressed we need to detect the voltage |
EricLew | 5:f6afbd3fc47a | 307 | * level on each key output |
EricLew | 5:f6afbd3fc47a | 308 | * - None : 3.3 V / 4095 |
EricLew | 5:f6afbd3fc47a | 309 | * - SEL : 1.055 V / 1308 |
EricLew | 5:f6afbd3fc47a | 310 | * - DOWN : 0.71 V / 88 |
EricLew | 5:f6afbd3fc47a | 311 | * - LEFT : 3.0 V / 3720 |
EricLew | 5:f6afbd3fc47a | 312 | * - RIGHT : 0.595 V / 737 |
EricLew | 5:f6afbd3fc47a | 313 | * - UP : 1.65 V / 2046 |
EricLew | 5:f6afbd3fc47a | 314 | * @retval JOYState_TypeDef: Code of the Joystick key pressed. |
EricLew | 5:f6afbd3fc47a | 315 | */ |
EricLew | 5:f6afbd3fc47a | 316 | JOYState_TypeDef BSP_JOY_GetState(void) |
EricLew | 5:f6afbd3fc47a | 317 | { |
EricLew | 5:f6afbd3fc47a | 318 | JOYState_TypeDef state = JOY_NONE; |
EricLew | 5:f6afbd3fc47a | 319 | uint16_t keyconvertedvalue = 0; |
EricLew | 5:f6afbd3fc47a | 320 | |
EricLew | 5:f6afbd3fc47a | 321 | /* Start the conversion process */ |
EricLew | 5:f6afbd3fc47a | 322 | HAL_ADC_Start(&hnucleo_Adc); |
EricLew | 5:f6afbd3fc47a | 323 | |
EricLew | 5:f6afbd3fc47a | 324 | /* Wait for the end of conversion */ |
EricLew | 5:f6afbd3fc47a | 325 | HAL_ADC_PollForConversion(&hnucleo_Adc, 10); |
EricLew | 5:f6afbd3fc47a | 326 | |
EricLew | 5:f6afbd3fc47a | 327 | /* Check if the continous conversion of regular channel is finished */ |
EricLew | 5:f6afbd3fc47a | 328 | if(HAL_ADC_GetState(&hnucleo_Adc) & HAL_ADC_STATE_REG_EOC) { |
EricLew | 5:f6afbd3fc47a | 329 | /* Get the converted value of regular channel */ |
EricLew | 5:f6afbd3fc47a | 330 | keyconvertedvalue = HAL_ADC_GetValue(&hnucleo_Adc); |
EricLew | 5:f6afbd3fc47a | 331 | } |
EricLew | 5:f6afbd3fc47a | 332 | |
EricLew | 5:f6afbd3fc47a | 333 | if((keyconvertedvalue > 1980) && (keyconvertedvalue < 2120)) { |
EricLew | 5:f6afbd3fc47a | 334 | state = JOY_UP; |
EricLew | 5:f6afbd3fc47a | 335 | } else if((keyconvertedvalue > 630) && (keyconvertedvalue < 830)) { |
EricLew | 5:f6afbd3fc47a | 336 | state = JOY_RIGHT; |
EricLew | 5:f6afbd3fc47a | 337 | } else if((keyconvertedvalue > 1210) && (keyconvertedvalue < 1410)) { |
EricLew | 5:f6afbd3fc47a | 338 | state = JOY_SEL; |
EricLew | 5:f6afbd3fc47a | 339 | } else if((keyconvertedvalue > 20) && (keyconvertedvalue < 160)) { |
EricLew | 5:f6afbd3fc47a | 340 | state = JOY_DOWN; |
EricLew | 5:f6afbd3fc47a | 341 | } else if((keyconvertedvalue > 3620) && (keyconvertedvalue < 3820)) { |
EricLew | 5:f6afbd3fc47a | 342 | state = JOY_LEFT; |
EricLew | 5:f6afbd3fc47a | 343 | } else { |
EricLew | 5:f6afbd3fc47a | 344 | state = JOY_NONE; |
EricLew | 5:f6afbd3fc47a | 345 | } |
EricLew | 5:f6afbd3fc47a | 346 | |
EricLew | 5:f6afbd3fc47a | 347 | /* Return the code of the Joystick key pressed*/ |
EricLew | 5:f6afbd3fc47a | 348 | return state; |
EricLew | 5:f6afbd3fc47a | 349 | } |
EricLew | 5:f6afbd3fc47a | 350 | |
EricLew | 5:f6afbd3fc47a | 351 | #endif /* HAL_ADC_MODULE_ENABLED */ |
EricLew | 5:f6afbd3fc47a | 352 | |
EricLew | 5:f6afbd3fc47a | 353 | /** |
EricLew | 5:f6afbd3fc47a | 354 | * @} |
EricLew | 5:f6afbd3fc47a | 355 | */ |
EricLew | 5:f6afbd3fc47a | 356 | |
EricLew | 5:f6afbd3fc47a | 357 | /** |
EricLew | 5:f6afbd3fc47a | 358 | * @} |
EricLew | 5:f6afbd3fc47a | 359 | */ |
EricLew | 5:f6afbd3fc47a | 360 | |
EricLew | 5:f6afbd3fc47a | 361 | /** @addtogroup STM32L4XX_NUCLEO_Private_Functions |
EricLew | 5:f6afbd3fc47a | 362 | * @{ |
EricLew | 5:f6afbd3fc47a | 363 | */ |
EricLew | 5:f6afbd3fc47a | 364 | |
EricLew | 5:f6afbd3fc47a | 365 | #ifdef HAL_SPI_MODULE_ENABLED |
EricLew | 5:f6afbd3fc47a | 366 | /****************************************************************************** |
EricLew | 5:f6afbd3fc47a | 367 | BUS OPERATIONS |
EricLew | 5:f6afbd3fc47a | 368 | *******************************************************************************/ |
EricLew | 5:f6afbd3fc47a | 369 | /** |
EricLew | 5:f6afbd3fc47a | 370 | * @brief Initialize SPI MSP. |
EricLew | 5:f6afbd3fc47a | 371 | * @retval None |
EricLew | 5:f6afbd3fc47a | 372 | */ |
EricLew | 5:f6afbd3fc47a | 373 | static void SPIx_MspInit(void) |
EricLew | 5:f6afbd3fc47a | 374 | { |
EricLew | 5:f6afbd3fc47a | 375 | GPIO_InitTypeDef gpioinitstruct = {0}; |
EricLew | 5:f6afbd3fc47a | 376 | |
EricLew | 5:f6afbd3fc47a | 377 | /*** Configure the GPIOs ***/ |
EricLew | 5:f6afbd3fc47a | 378 | /* Enable GPIO clock */ |
EricLew | 5:f6afbd3fc47a | 379 | NUCLEO_SPIx_SCK_GPIO_CLK_ENABLE(); |
EricLew | 5:f6afbd3fc47a | 380 | NUCLEO_SPIx_MISO_MOSI_GPIO_CLK_ENABLE(); |
EricLew | 5:f6afbd3fc47a | 381 | |
EricLew | 5:f6afbd3fc47a | 382 | /* Configure SPI SCK */ |
EricLew | 5:f6afbd3fc47a | 383 | gpioinitstruct.Pin = NUCLEO_SPIx_SCK_PIN; |
EricLew | 5:f6afbd3fc47a | 384 | gpioinitstruct.Mode = GPIO_MODE_AF_PP; |
EricLew | 5:f6afbd3fc47a | 385 | gpioinitstruct.Pull = GPIO_PULLUP; |
EricLew | 5:f6afbd3fc47a | 386 | gpioinitstruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
EricLew | 5:f6afbd3fc47a | 387 | gpioinitstruct.Alternate = NUCLEO_SPIx_SCK_AF; |
EricLew | 5:f6afbd3fc47a | 388 | HAL_GPIO_Init(NUCLEO_SPIx_SCK_GPIO_PORT, &gpioinitstruct); |
EricLew | 5:f6afbd3fc47a | 389 | |
EricLew | 5:f6afbd3fc47a | 390 | /* Configure SPI MISO and MOSI */ |
EricLew | 5:f6afbd3fc47a | 391 | gpioinitstruct.Pin = NUCLEO_SPIx_MOSI_PIN; |
EricLew | 5:f6afbd3fc47a | 392 | gpioinitstruct.Alternate = NUCLEO_SPIx_MISO_MOSI_AF; |
EricLew | 5:f6afbd3fc47a | 393 | gpioinitstruct.Pull = GPIO_PULLDOWN; |
EricLew | 5:f6afbd3fc47a | 394 | HAL_GPIO_Init(NUCLEO_SPIx_MISO_MOSI_GPIO_PORT, &gpioinitstruct); |
EricLew | 5:f6afbd3fc47a | 395 | |
EricLew | 5:f6afbd3fc47a | 396 | gpioinitstruct.Pin = NUCLEO_SPIx_MISO_PIN; |
EricLew | 5:f6afbd3fc47a | 397 | HAL_GPIO_Init(NUCLEO_SPIx_MISO_MOSI_GPIO_PORT, &gpioinitstruct); |
EricLew | 5:f6afbd3fc47a | 398 | |
EricLew | 5:f6afbd3fc47a | 399 | /*** Configure the SPI peripheral ***/ |
EricLew | 5:f6afbd3fc47a | 400 | /* Enable SPI clock */ |
EricLew | 5:f6afbd3fc47a | 401 | NUCLEO_SPIx_CLK_ENABLE(); |
EricLew | 5:f6afbd3fc47a | 402 | } |
EricLew | 5:f6afbd3fc47a | 403 | |
EricLew | 5:f6afbd3fc47a | 404 | /** |
EricLew | 5:f6afbd3fc47a | 405 | * @brief Initialize SPI HAL. |
EricLew | 5:f6afbd3fc47a | 406 | * @retval None |
EricLew | 5:f6afbd3fc47a | 407 | */ |
EricLew | 5:f6afbd3fc47a | 408 | static void SPIx_Init(void) |
EricLew | 5:f6afbd3fc47a | 409 | { |
EricLew | 5:f6afbd3fc47a | 410 | if(HAL_SPI_GetState(&hnucleo_Spi) == HAL_SPI_STATE_RESET) { |
EricLew | 5:f6afbd3fc47a | 411 | /* SPI Config */ |
EricLew | 5:f6afbd3fc47a | 412 | hnucleo_Spi.Instance = NUCLEO_SPIx; |
EricLew | 5:f6afbd3fc47a | 413 | /* SPI baudrate is set to 8 MHz maximum (PCLK2/SPI_BaudRatePrescaler = 32/4 = 8 MHz) |
EricLew | 5:f6afbd3fc47a | 414 | to verify these constraints: |
EricLew | 5:f6afbd3fc47a | 415 | - ST7735 LCD SPI interface max baudrate is 15MHz for write and 6.66MHz for read |
EricLew | 5:f6afbd3fc47a | 416 | Since the provided driver doesn't use read capability from LCD, only constraint |
EricLew | 5:f6afbd3fc47a | 417 | on write baudrate is considered. |
EricLew | 5:f6afbd3fc47a | 418 | - SD card SPI interface max baudrate is 25MHz for write/read |
EricLew | 5:f6afbd3fc47a | 419 | - PCLK2 max frequency is 32 MHz |
EricLew | 5:f6afbd3fc47a | 420 | */ |
EricLew | 5:f6afbd3fc47a | 421 | hnucleo_Spi.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4; |
EricLew | 5:f6afbd3fc47a | 422 | hnucleo_Spi.Init.Direction = SPI_DIRECTION_2LINES; |
EricLew | 5:f6afbd3fc47a | 423 | hnucleo_Spi.Init.CLKPhase = SPI_PHASE_2EDGE; |
EricLew | 5:f6afbd3fc47a | 424 | hnucleo_Spi.Init.CLKPolarity = SPI_POLARITY_HIGH; |
EricLew | 5:f6afbd3fc47a | 425 | hnucleo_Spi.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; |
EricLew | 5:f6afbd3fc47a | 426 | hnucleo_Spi.Init.CRCPolynomial = 7; |
EricLew | 5:f6afbd3fc47a | 427 | hnucleo_Spi.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; |
EricLew | 5:f6afbd3fc47a | 428 | hnucleo_Spi.Init.DataSize = SPI_DATASIZE_8BIT; |
EricLew | 5:f6afbd3fc47a | 429 | hnucleo_Spi.Init.FirstBit = SPI_FIRSTBIT_MSB; |
EricLew | 5:f6afbd3fc47a | 430 | hnucleo_Spi.Init.NSS = SPI_NSS_SOFT; |
EricLew | 5:f6afbd3fc47a | 431 | hnucleo_Spi.Init.NSSPMode = SPI_NSS_PULSE_DISABLE; |
EricLew | 5:f6afbd3fc47a | 432 | hnucleo_Spi.Init.TIMode = SPI_TIMODE_DISABLE; |
EricLew | 5:f6afbd3fc47a | 433 | hnucleo_Spi.Init.Mode = SPI_MODE_MASTER; |
EricLew | 5:f6afbd3fc47a | 434 | |
EricLew | 5:f6afbd3fc47a | 435 | SPIx_MspInit(); |
EricLew | 5:f6afbd3fc47a | 436 | HAL_SPI_Init(&hnucleo_Spi); |
EricLew | 5:f6afbd3fc47a | 437 | } |
EricLew | 5:f6afbd3fc47a | 438 | } |
EricLew | 5:f6afbd3fc47a | 439 | |
EricLew | 5:f6afbd3fc47a | 440 | /** |
EricLew | 5:f6afbd3fc47a | 441 | * @brief SPI Write byte(s) to device |
EricLew | 5:f6afbd3fc47a | 442 | * @param DataIn: Pointer to data buffer to write |
EricLew | 5:f6afbd3fc47a | 443 | * @param DataOut: Pointer to data buffer for read data |
EricLew | 5:f6afbd3fc47a | 444 | * @param DataLength: number of bytes to write |
EricLew | 5:f6afbd3fc47a | 445 | * @retval None |
EricLew | 5:f6afbd3fc47a | 446 | */ |
EricLew | 5:f6afbd3fc47a | 447 | static void SPIx_WriteReadData(const uint8_t *DataIn, uint8_t *DataOut, uint16_t DataLength) |
EricLew | 5:f6afbd3fc47a | 448 | { |
EricLew | 5:f6afbd3fc47a | 449 | HAL_StatusTypeDef status = HAL_OK; |
EricLew | 5:f6afbd3fc47a | 450 | status = HAL_SPI_TransmitReceive(&hnucleo_Spi, (uint8_t*) DataIn, DataOut, DataLength, hnucleo_SpixTimeout); |
EricLew | 5:f6afbd3fc47a | 451 | |
EricLew | 5:f6afbd3fc47a | 452 | /* Check the communication status */ |
EricLew | 5:f6afbd3fc47a | 453 | if(status != HAL_OK) { |
EricLew | 5:f6afbd3fc47a | 454 | /* Execute user timeout callback */ |
EricLew | 5:f6afbd3fc47a | 455 | SPIx_Error(); |
EricLew | 5:f6afbd3fc47a | 456 | } |
EricLew | 5:f6afbd3fc47a | 457 | } |
EricLew | 5:f6afbd3fc47a | 458 | |
EricLew | 5:f6afbd3fc47a | 459 | /** |
EricLew | 5:f6afbd3fc47a | 460 | * @brief SPI Write a byte to device |
EricLew | 5:f6afbd3fc47a | 461 | * @param Value: value to be written |
EricLew | 5:f6afbd3fc47a | 462 | * @retval None |
EricLew | 5:f6afbd3fc47a | 463 | */ |
EricLew | 5:f6afbd3fc47a | 464 | static void SPIx_Write(uint8_t Value) |
EricLew | 5:f6afbd3fc47a | 465 | { |
EricLew | 5:f6afbd3fc47a | 466 | HAL_StatusTypeDef status = HAL_OK; |
EricLew | 5:f6afbd3fc47a | 467 | uint8_t data; |
EricLew | 5:f6afbd3fc47a | 468 | |
EricLew | 5:f6afbd3fc47a | 469 | status = HAL_SPI_TransmitReceive(&hnucleo_Spi, (uint8_t*) &Value, &data, 1, hnucleo_SpixTimeout); |
EricLew | 5:f6afbd3fc47a | 470 | |
EricLew | 5:f6afbd3fc47a | 471 | /* Check the communication status */ |
EricLew | 5:f6afbd3fc47a | 472 | if(status != HAL_OK) { |
EricLew | 5:f6afbd3fc47a | 473 | /* Execute user timeout callback */ |
EricLew | 5:f6afbd3fc47a | 474 | SPIx_Error(); |
EricLew | 5:f6afbd3fc47a | 475 | } |
EricLew | 5:f6afbd3fc47a | 476 | } |
EricLew | 5:f6afbd3fc47a | 477 | |
EricLew | 5:f6afbd3fc47a | 478 | /** |
EricLew | 5:f6afbd3fc47a | 479 | * @brief SPI error treatment function |
EricLew | 5:f6afbd3fc47a | 480 | * @retval None |
EricLew | 5:f6afbd3fc47a | 481 | */ |
EricLew | 5:f6afbd3fc47a | 482 | static void SPIx_Error (void) |
EricLew | 5:f6afbd3fc47a | 483 | { |
EricLew | 5:f6afbd3fc47a | 484 | /* De-initialize the SPI communication BUS */ |
EricLew | 5:f6afbd3fc47a | 485 | HAL_SPI_DeInit(&hnucleo_Spi); |
EricLew | 5:f6afbd3fc47a | 486 | |
EricLew | 5:f6afbd3fc47a | 487 | /* Re-Initiaize the SPI communication BUS */ |
EricLew | 5:f6afbd3fc47a | 488 | SPIx_Init(); |
EricLew | 5:f6afbd3fc47a | 489 | } |
EricLew | 5:f6afbd3fc47a | 490 | |
EricLew | 5:f6afbd3fc47a | 491 | /****************************************************************************** |
EricLew | 5:f6afbd3fc47a | 492 | LINK OPERATIONS |
EricLew | 5:f6afbd3fc47a | 493 | *******************************************************************************/ |
EricLew | 5:f6afbd3fc47a | 494 | |
EricLew | 5:f6afbd3fc47a | 495 | /********************************* LINK SD ************************************/ |
EricLew | 5:f6afbd3fc47a | 496 | /** |
EricLew | 5:f6afbd3fc47a | 497 | * @brief Initialize the SD Card and put it into StandBy State (Ready for |
EricLew | 5:f6afbd3fc47a | 498 | * data transfer). |
EricLew | 5:f6afbd3fc47a | 499 | * @retval None |
EricLew | 5:f6afbd3fc47a | 500 | */ |
EricLew | 5:f6afbd3fc47a | 501 | void SD_IO_Init(void) |
EricLew | 5:f6afbd3fc47a | 502 | { |
EricLew | 5:f6afbd3fc47a | 503 | GPIO_InitTypeDef gpioinitstruct = {0}; |
EricLew | 5:f6afbd3fc47a | 504 | uint8_t counter = 0; |
EricLew | 5:f6afbd3fc47a | 505 | |
EricLew | 5:f6afbd3fc47a | 506 | /* SD_CS_GPIO Periph clock enable */ |
EricLew | 5:f6afbd3fc47a | 507 | SD_CS_GPIO_CLK_ENABLE(); |
EricLew | 5:f6afbd3fc47a | 508 | |
EricLew | 5:f6afbd3fc47a | 509 | /* Configure SD_CS_PIN pin: SD Card CS pin */ |
EricLew | 5:f6afbd3fc47a | 510 | gpioinitstruct.Pin = SD_CS_PIN; |
EricLew | 5:f6afbd3fc47a | 511 | gpioinitstruct.Mode = GPIO_MODE_OUTPUT_PP; |
EricLew | 5:f6afbd3fc47a | 512 | gpioinitstruct.Pull = GPIO_PULLUP; |
EricLew | 5:f6afbd3fc47a | 513 | gpioinitstruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
EricLew | 5:f6afbd3fc47a | 514 | HAL_GPIO_Init(SD_CS_GPIO_PORT, &gpioinitstruct); |
EricLew | 5:f6afbd3fc47a | 515 | |
EricLew | 5:f6afbd3fc47a | 516 | /* Configure LCD_CS_PIN pin: LCD Card CS pin */ |
EricLew | 5:f6afbd3fc47a | 517 | gpioinitstruct.Pin = LCD_CS_PIN; |
EricLew | 5:f6afbd3fc47a | 518 | gpioinitstruct.Mode = GPIO_MODE_OUTPUT_PP; |
EricLew | 5:f6afbd3fc47a | 519 | gpioinitstruct.Pull = GPIO_NOPULL; |
EricLew | 5:f6afbd3fc47a | 520 | gpioinitstruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
EricLew | 5:f6afbd3fc47a | 521 | HAL_GPIO_Init(SD_CS_GPIO_PORT, &gpioinitstruct); |
EricLew | 5:f6afbd3fc47a | 522 | LCD_CS_HIGH(); |
EricLew | 5:f6afbd3fc47a | 523 | |
EricLew | 5:f6afbd3fc47a | 524 | /*------------Put SD in SPI mode--------------*/ |
EricLew | 5:f6afbd3fc47a | 525 | /* SD SPI Config */ |
EricLew | 5:f6afbd3fc47a | 526 | SPIx_Init(); |
EricLew | 5:f6afbd3fc47a | 527 | |
EricLew | 5:f6afbd3fc47a | 528 | /* SD chip select high */ |
EricLew | 5:f6afbd3fc47a | 529 | SD_CS_HIGH(); |
EricLew | 5:f6afbd3fc47a | 530 | |
EricLew | 5:f6afbd3fc47a | 531 | /* Send dummy byte 0xFF, 10 times with CS high */ |
EricLew | 5:f6afbd3fc47a | 532 | /* Rise CS and MOSI for 80 clocks cycles */ |
EricLew | 5:f6afbd3fc47a | 533 | for (counter = 0; counter <= 9; counter++) { |
EricLew | 5:f6afbd3fc47a | 534 | /* Send dummy byte 0xFF */ |
EricLew | 5:f6afbd3fc47a | 535 | SD_IO_WriteByte(SD_DUMMY_BYTE); |
EricLew | 5:f6afbd3fc47a | 536 | } |
EricLew | 5:f6afbd3fc47a | 537 | } |
EricLew | 5:f6afbd3fc47a | 538 | |
EricLew | 5:f6afbd3fc47a | 539 | /** |
EricLew | 5:f6afbd3fc47a | 540 | * @brief Set SD interface Chip Select state |
EricLew | 5:f6afbd3fc47a | 541 | * @param val: 0 (low) or 1 (high) state |
EricLew | 5:f6afbd3fc47a | 542 | * @retval None |
EricLew | 5:f6afbd3fc47a | 543 | */ |
EricLew | 5:f6afbd3fc47a | 544 | void SD_IO_CSState(uint8_t val) |
EricLew | 5:f6afbd3fc47a | 545 | { |
EricLew | 5:f6afbd3fc47a | 546 | if(val == 1) { |
EricLew | 5:f6afbd3fc47a | 547 | SD_CS_HIGH(); |
EricLew | 5:f6afbd3fc47a | 548 | } else { |
EricLew | 5:f6afbd3fc47a | 549 | SD_CS_LOW(); |
EricLew | 5:f6afbd3fc47a | 550 | } |
EricLew | 5:f6afbd3fc47a | 551 | } |
EricLew | 5:f6afbd3fc47a | 552 | |
EricLew | 5:f6afbd3fc47a | 553 | /** |
EricLew | 5:f6afbd3fc47a | 554 | * @brief Write byte(s) on the SD |
EricLew | 5:f6afbd3fc47a | 555 | * @param DataIn: Pointer to data buffer to write |
EricLew | 5:f6afbd3fc47a | 556 | * @param DataOut: Pointer to data buffer for read data |
EricLew | 5:f6afbd3fc47a | 557 | * @param DataLength: number of bytes to write |
EricLew | 5:f6afbd3fc47a | 558 | * @retval None |
EricLew | 5:f6afbd3fc47a | 559 | */ |
EricLew | 5:f6afbd3fc47a | 560 | void SD_IO_WriteReadData(const uint8_t *DataIn, uint8_t *DataOut, uint16_t DataLength) |
EricLew | 5:f6afbd3fc47a | 561 | { |
EricLew | 5:f6afbd3fc47a | 562 | /* Send the byte */ |
EricLew | 5:f6afbd3fc47a | 563 | SPIx_WriteReadData(DataIn, DataOut, DataLength); |
EricLew | 5:f6afbd3fc47a | 564 | } |
EricLew | 5:f6afbd3fc47a | 565 | |
EricLew | 5:f6afbd3fc47a | 566 | /** |
EricLew | 5:f6afbd3fc47a | 567 | * @brief Write a byte on the SD. |
EricLew | 5:f6afbd3fc47a | 568 | * @param Data: byte to send. |
EricLew | 5:f6afbd3fc47a | 569 | * @retval Data written |
EricLew | 5:f6afbd3fc47a | 570 | */ |
EricLew | 5:f6afbd3fc47a | 571 | uint8_t SD_IO_WriteByte(uint8_t Data) |
EricLew | 5:f6afbd3fc47a | 572 | { |
EricLew | 5:f6afbd3fc47a | 573 | uint8_t tmp; |
EricLew | 5:f6afbd3fc47a | 574 | |
EricLew | 5:f6afbd3fc47a | 575 | /* Send the byte */ |
EricLew | 5:f6afbd3fc47a | 576 | SPIx_WriteReadData(&Data,&tmp,1); |
EricLew | 5:f6afbd3fc47a | 577 | return tmp; |
EricLew | 5:f6afbd3fc47a | 578 | } |
EricLew | 5:f6afbd3fc47a | 579 | |
EricLew | 5:f6afbd3fc47a | 580 | /********************************* LINK LCD ***********************************/ |
EricLew | 5:f6afbd3fc47a | 581 | /** |
EricLew | 5:f6afbd3fc47a | 582 | * @brief Initialize the LCD |
EricLew | 5:f6afbd3fc47a | 583 | * @retval None |
EricLew | 5:f6afbd3fc47a | 584 | */ |
EricLew | 5:f6afbd3fc47a | 585 | void LCD_IO_Init(void) |
EricLew | 5:f6afbd3fc47a | 586 | { |
EricLew | 5:f6afbd3fc47a | 587 | GPIO_InitTypeDef gpioinitstruct = {0}; |
EricLew | 5:f6afbd3fc47a | 588 | |
EricLew | 5:f6afbd3fc47a | 589 | /* LCD_CS_GPIO and LCD_DC_GPIO Periph clock enable */ |
EricLew | 5:f6afbd3fc47a | 590 | LCD_CS_GPIO_CLK_ENABLE(); |
EricLew | 5:f6afbd3fc47a | 591 | LCD_DC_GPIO_CLK_ENABLE(); |
EricLew | 5:f6afbd3fc47a | 592 | |
EricLew | 5:f6afbd3fc47a | 593 | /* Configure LCD_CS_PIN pin: LCD Card CS pin */ |
EricLew | 5:f6afbd3fc47a | 594 | gpioinitstruct.Pin = LCD_CS_PIN; |
EricLew | 5:f6afbd3fc47a | 595 | gpioinitstruct.Mode = GPIO_MODE_OUTPUT_PP; |
EricLew | 5:f6afbd3fc47a | 596 | gpioinitstruct.Pull = GPIO_NOPULL; |
EricLew | 5:f6afbd3fc47a | 597 | gpioinitstruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; |
EricLew | 5:f6afbd3fc47a | 598 | HAL_GPIO_Init(SD_CS_GPIO_PORT, &gpioinitstruct); |
EricLew | 5:f6afbd3fc47a | 599 | |
EricLew | 5:f6afbd3fc47a | 600 | /* Configure LCD_DC_PIN pin: LCD Card DC pin */ |
EricLew | 5:f6afbd3fc47a | 601 | gpioinitstruct.Pin = LCD_DC_PIN; |
EricLew | 5:f6afbd3fc47a | 602 | HAL_GPIO_Init(LCD_DC_GPIO_PORT, &gpioinitstruct); |
EricLew | 5:f6afbd3fc47a | 603 | |
EricLew | 5:f6afbd3fc47a | 604 | /* LCD chip select high */ |
EricLew | 5:f6afbd3fc47a | 605 | LCD_CS_HIGH(); |
EricLew | 5:f6afbd3fc47a | 606 | |
EricLew | 5:f6afbd3fc47a | 607 | /* LCD SPI Config */ |
EricLew | 5:f6afbd3fc47a | 608 | SPIx_Init(); |
EricLew | 5:f6afbd3fc47a | 609 | } |
EricLew | 5:f6afbd3fc47a | 610 | |
EricLew | 5:f6afbd3fc47a | 611 | /** |
EricLew | 5:f6afbd3fc47a | 612 | * @brief Write command to select the LCD register. |
EricLew | 5:f6afbd3fc47a | 613 | * @param LCDReg: Address of the selected register. |
EricLew | 5:f6afbd3fc47a | 614 | * @retval None |
EricLew | 5:f6afbd3fc47a | 615 | */ |
EricLew | 5:f6afbd3fc47a | 616 | void LCD_IO_WriteReg(uint8_t LCDReg) |
EricLew | 5:f6afbd3fc47a | 617 | { |
EricLew | 5:f6afbd3fc47a | 618 | /* Reset LCD control line CS */ |
EricLew | 5:f6afbd3fc47a | 619 | LCD_CS_LOW(); |
EricLew | 5:f6afbd3fc47a | 620 | |
EricLew | 5:f6afbd3fc47a | 621 | /* Set LCD data/command line DC to Low */ |
EricLew | 5:f6afbd3fc47a | 622 | LCD_DC_LOW(); |
EricLew | 5:f6afbd3fc47a | 623 | |
EricLew | 5:f6afbd3fc47a | 624 | /* Send Command */ |
EricLew | 5:f6afbd3fc47a | 625 | SPIx_Write(LCDReg); |
EricLew | 5:f6afbd3fc47a | 626 | |
EricLew | 5:f6afbd3fc47a | 627 | /* Deselect : Chip Select high */ |
EricLew | 5:f6afbd3fc47a | 628 | LCD_CS_HIGH(); |
EricLew | 5:f6afbd3fc47a | 629 | } |
EricLew | 5:f6afbd3fc47a | 630 | |
EricLew | 5:f6afbd3fc47a | 631 | /** |
EricLew | 5:f6afbd3fc47a | 632 | * @brief Write register value. |
EricLew | 5:f6afbd3fc47a | 633 | * @param pData Pointer on the register value |
EricLew | 5:f6afbd3fc47a | 634 | * @param Size Size of byte to transmit to the register |
EricLew | 5:f6afbd3fc47a | 635 | * @retval None |
EricLew | 5:f6afbd3fc47a | 636 | */ |
EricLew | 5:f6afbd3fc47a | 637 | void LCD_IO_WriteMultipleData(uint8_t *pData, uint32_t Size) |
EricLew | 5:f6afbd3fc47a | 638 | { |
EricLew | 5:f6afbd3fc47a | 639 | uint32_t counter = 0; |
EricLew | 5:f6afbd3fc47a | 640 | __IO uint32_t data = 0; |
EricLew | 5:f6afbd3fc47a | 641 | |
EricLew | 5:f6afbd3fc47a | 642 | /* Reset LCD control line CS */ |
EricLew | 5:f6afbd3fc47a | 643 | LCD_CS_LOW(); |
EricLew | 5:f6afbd3fc47a | 644 | |
EricLew | 5:f6afbd3fc47a | 645 | /* Set LCD data/command line DC to High */ |
EricLew | 5:f6afbd3fc47a | 646 | LCD_DC_HIGH(); |
EricLew | 5:f6afbd3fc47a | 647 | |
EricLew | 5:f6afbd3fc47a | 648 | if (Size == 1) { |
EricLew | 5:f6afbd3fc47a | 649 | /* Only 1 byte to be sent to LCD - general interface can be used */ |
EricLew | 5:f6afbd3fc47a | 650 | /* Send Data */ |
EricLew | 5:f6afbd3fc47a | 651 | SPIx_Write(*pData); |
EricLew | 5:f6afbd3fc47a | 652 | } else { |
EricLew | 5:f6afbd3fc47a | 653 | /* Several data should be sent in a raw */ |
EricLew | 5:f6afbd3fc47a | 654 | /* Direct SPI accesses for optimization */ |
EricLew | 5:f6afbd3fc47a | 655 | for (counter = Size; counter != 0; counter--) { |
EricLew | 5:f6afbd3fc47a | 656 | while(((hnucleo_Spi.Instance->SR) & SPI_FLAG_TXE) != SPI_FLAG_TXE) { |
EricLew | 5:f6afbd3fc47a | 657 | } |
EricLew | 5:f6afbd3fc47a | 658 | /* Need to invert bytes for LCD*/ |
EricLew | 5:f6afbd3fc47a | 659 | *((__IO uint8_t*)&hnucleo_Spi.Instance->DR) = *(pData+1); |
EricLew | 5:f6afbd3fc47a | 660 | |
EricLew | 5:f6afbd3fc47a | 661 | while(((hnucleo_Spi.Instance->SR) & SPI_FLAG_TXE) != SPI_FLAG_TXE) { |
EricLew | 5:f6afbd3fc47a | 662 | } |
EricLew | 5:f6afbd3fc47a | 663 | *((__IO uint8_t*)&hnucleo_Spi.Instance->DR) = *pData; |
EricLew | 5:f6afbd3fc47a | 664 | counter--; |
EricLew | 5:f6afbd3fc47a | 665 | pData += 2; |
EricLew | 5:f6afbd3fc47a | 666 | } |
EricLew | 5:f6afbd3fc47a | 667 | |
EricLew | 5:f6afbd3fc47a | 668 | /* Wait until the bus is ready before releasing Chip select */ |
EricLew | 5:f6afbd3fc47a | 669 | while(((hnucleo_Spi.Instance->SR) & SPI_FLAG_BSY) != RESET) { |
EricLew | 5:f6afbd3fc47a | 670 | } |
EricLew | 5:f6afbd3fc47a | 671 | } |
EricLew | 5:f6afbd3fc47a | 672 | |
EricLew | 5:f6afbd3fc47a | 673 | /* Empty the Rx fifo */ |
EricLew | 5:f6afbd3fc47a | 674 | data = *(&hnucleo_Spi.Instance->DR); |
EricLew | 5:f6afbd3fc47a | 675 | UNUSED(data); /* Remove GNU warning */ |
EricLew | 5:f6afbd3fc47a | 676 | |
EricLew | 5:f6afbd3fc47a | 677 | /* Deselect : Chip Select high */ |
EricLew | 5:f6afbd3fc47a | 678 | LCD_CS_HIGH(); |
EricLew | 5:f6afbd3fc47a | 679 | } |
EricLew | 5:f6afbd3fc47a | 680 | |
EricLew | 5:f6afbd3fc47a | 681 | /** |
EricLew | 5:f6afbd3fc47a | 682 | * @brief Wait for loop in ms. |
EricLew | 5:f6afbd3fc47a | 683 | * @param Delay in ms. |
EricLew | 5:f6afbd3fc47a | 684 | * @retval None |
EricLew | 5:f6afbd3fc47a | 685 | */ |
EricLew | 5:f6afbd3fc47a | 686 | void LCD_Delay(uint32_t Delay) |
EricLew | 5:f6afbd3fc47a | 687 | { |
EricLew | 5:f6afbd3fc47a | 688 | HAL_Delay(Delay); |
EricLew | 5:f6afbd3fc47a | 689 | } |
EricLew | 5:f6afbd3fc47a | 690 | |
EricLew | 5:f6afbd3fc47a | 691 | #endif /* HAL_SPI_MODULE_ENABLED */ |
EricLew | 5:f6afbd3fc47a | 692 | |
EricLew | 5:f6afbd3fc47a | 693 | #ifdef HAL_ADC_MODULE_ENABLED |
EricLew | 5:f6afbd3fc47a | 694 | /******************************* LINK JOYSTICK ********************************/ |
EricLew | 5:f6afbd3fc47a | 695 | /** |
EricLew | 5:f6afbd3fc47a | 696 | * @brief Initialize ADC MSP. |
EricLew | 5:f6afbd3fc47a | 697 | * @retval None |
EricLew | 5:f6afbd3fc47a | 698 | */ |
EricLew | 5:f6afbd3fc47a | 699 | static void ADCx_MspInit(ADC_HandleTypeDef *hadc) |
EricLew | 5:f6afbd3fc47a | 700 | { |
EricLew | 5:f6afbd3fc47a | 701 | GPIO_InitTypeDef gpioinitstruct = {0}; |
EricLew | 5:f6afbd3fc47a | 702 | RCC_PeriphCLKInitTypeDef RCC_PeriphCLKInitStruct; |
EricLew | 5:f6afbd3fc47a | 703 | |
EricLew | 5:f6afbd3fc47a | 704 | /*** Configure the GPIOs ***/ |
EricLew | 5:f6afbd3fc47a | 705 | /* Enable GPIO clock */ |
EricLew | 5:f6afbd3fc47a | 706 | NUCLEO_ADCx_GPIO_CLK_ENABLE(); |
EricLew | 5:f6afbd3fc47a | 707 | |
EricLew | 5:f6afbd3fc47a | 708 | /* Configure ADC1 Channel8 as analog input */ |
EricLew | 5:f6afbd3fc47a | 709 | gpioinitstruct.Pin = NUCLEO_ADCx_GPIO_PIN ; |
EricLew | 5:f6afbd3fc47a | 710 | gpioinitstruct.Mode = GPIO_MODE_ANALOG_ADC_CONTROL; |
EricLew | 5:f6afbd3fc47a | 711 | gpioinitstruct.Pull = GPIO_NOPULL; |
EricLew | 5:f6afbd3fc47a | 712 | gpioinitstruct.Speed = GPIO_SPEED_FREQ_HIGH; |
EricLew | 5:f6afbd3fc47a | 713 | HAL_GPIO_Init(NUCLEO_ADCx_GPIO_PORT, &gpioinitstruct); |
EricLew | 5:f6afbd3fc47a | 714 | |
EricLew | 5:f6afbd3fc47a | 715 | /*** Configure the ADC peripheral ***/ |
EricLew | 5:f6afbd3fc47a | 716 | /* Enable ADC clock */ |
EricLew | 5:f6afbd3fc47a | 717 | NUCLEO_ADCx_CLK_ENABLE(); |
EricLew | 5:f6afbd3fc47a | 718 | |
EricLew | 5:f6afbd3fc47a | 719 | /* Configure SYSCLK as source clock for ADC */ |
EricLew | 5:f6afbd3fc47a | 720 | RCC_PeriphCLKInitStruct.PeriphClockSelection = RCC_PERIPHCLK_ADC; |
EricLew | 5:f6afbd3fc47a | 721 | RCC_PeriphCLKInitStruct.AdcClockSelection = RCC_ADCCLKSOURCE_SYSCLK; |
EricLew | 5:f6afbd3fc47a | 722 | HAL_RCCEx_PeriphCLKConfig(&RCC_PeriphCLKInitStruct); |
EricLew | 5:f6afbd3fc47a | 723 | } |
EricLew | 5:f6afbd3fc47a | 724 | |
EricLew | 5:f6afbd3fc47a | 725 | /** |
EricLew | 5:f6afbd3fc47a | 726 | * @brief Initializes ADC HAL. |
EricLew | 5:f6afbd3fc47a | 727 | * @retval None |
EricLew | 5:f6afbd3fc47a | 728 | */ |
EricLew | 5:f6afbd3fc47a | 729 | static HAL_StatusTypeDef ADCx_Init(void) |
EricLew | 5:f6afbd3fc47a | 730 | { |
EricLew | 5:f6afbd3fc47a | 731 | if(HAL_ADC_GetState(&hnucleo_Adc) == HAL_ADC_STATE_RESET) { |
EricLew | 5:f6afbd3fc47a | 732 | /* ADC Config */ |
EricLew | 5:f6afbd3fc47a | 733 | hnucleo_Adc.Instance = NUCLEO_ADCx; |
EricLew | 5:f6afbd3fc47a | 734 | hnucleo_Adc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV8; /* (must not exceed 16MHz) */ |
EricLew | 5:f6afbd3fc47a | 735 | hnucleo_Adc.Init.Resolution = ADC_RESOLUTION_12B; |
EricLew | 5:f6afbd3fc47a | 736 | hnucleo_Adc.Init.DataAlign = ADC_DATAALIGN_RIGHT; |
EricLew | 5:f6afbd3fc47a | 737 | hnucleo_Adc.Init.ScanConvMode = DISABLE; |
EricLew | 5:f6afbd3fc47a | 738 | hnucleo_Adc.Init.EOCSelection = ADC_EOC_SINGLE_CONV; |
EricLew | 5:f6afbd3fc47a | 739 | hnucleo_Adc.Init.LowPowerAutoWait = ENABLE; |
EricLew | 5:f6afbd3fc47a | 740 | hnucleo_Adc.Init.ContinuousConvMode = DISABLE; |
EricLew | 5:f6afbd3fc47a | 741 | hnucleo_Adc.Init.NbrOfConversion = 1; |
EricLew | 5:f6afbd3fc47a | 742 | hnucleo_Adc.Init.DiscontinuousConvMode = DISABLE; |
EricLew | 5:f6afbd3fc47a | 743 | hnucleo_Adc.Init.NbrOfDiscConversion = 1; |
EricLew | 5:f6afbd3fc47a | 744 | hnucleo_Adc.Init.ExternalTrigConv = ADC_SOFTWARE_START; |
EricLew | 5:f6afbd3fc47a | 745 | hnucleo_Adc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; |
EricLew | 5:f6afbd3fc47a | 746 | hnucleo_Adc.Init.DMAContinuousRequests = DISABLE; |
EricLew | 5:f6afbd3fc47a | 747 | hnucleo_Adc.Init.Overrun = ADC_OVR_DATA_PRESERVED; |
EricLew | 5:f6afbd3fc47a | 748 | hnucleo_Adc.Init.OversamplingMode = DISABLE; |
EricLew | 5:f6afbd3fc47a | 749 | |
EricLew | 5:f6afbd3fc47a | 750 | ADCx_MspInit(&hnucleo_Adc); |
EricLew | 5:f6afbd3fc47a | 751 | if (HAL_ADC_Init(&hnucleo_Adc) != HAL_OK) { |
EricLew | 5:f6afbd3fc47a | 752 | return HAL_ERROR; |
EricLew | 5:f6afbd3fc47a | 753 | } |
EricLew | 5:f6afbd3fc47a | 754 | |
EricLew | 5:f6afbd3fc47a | 755 | if (HAL_ADCEx_Calibration_Start(&hnucleo_Adc,ADC_SINGLE_ENDED) != HAL_OK) { |
EricLew | 5:f6afbd3fc47a | 756 | return HAL_ERROR; |
EricLew | 5:f6afbd3fc47a | 757 | } |
EricLew | 5:f6afbd3fc47a | 758 | } |
EricLew | 5:f6afbd3fc47a | 759 | |
EricLew | 5:f6afbd3fc47a | 760 | return HAL_OK; |
EricLew | 5:f6afbd3fc47a | 761 | } |
EricLew | 5:f6afbd3fc47a | 762 | |
EricLew | 5:f6afbd3fc47a | 763 | #endif /* HAL_ADC_MODULE_ENABLED */ |
EricLew | 5:f6afbd3fc47a | 764 | |
EricLew | 5:f6afbd3fc47a | 765 | /** |
EricLew | 5:f6afbd3fc47a | 766 | * @} |
EricLew | 5:f6afbd3fc47a | 767 | */ |
EricLew | 5:f6afbd3fc47a | 768 | |
EricLew | 5:f6afbd3fc47a | 769 | /** |
EricLew | 5:f6afbd3fc47a | 770 | * @} |
EricLew | 5:f6afbd3fc47a | 771 | */ |
EricLew | 5:f6afbd3fc47a | 772 | |
EricLew | 5:f6afbd3fc47a | 773 | /** |
EricLew | 5:f6afbd3fc47a | 774 | * @} |
EricLew | 5:f6afbd3fc47a | 775 | */ |
EricLew | 5:f6afbd3fc47a | 776 | |
EricLew | 5:f6afbd3fc47a | 777 | /** |
EricLew | 5:f6afbd3fc47a | 778 | * @} |
EricLew | 5:f6afbd3fc47a | 779 | */ |
EricLew | 5:f6afbd3fc47a | 780 | |
EricLew | 5:f6afbd3fc47a | 781 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |
EricLew | 5:f6afbd3fc47a | 782 |