AudioRecord
Dependencies: STM32L4xx_HAL_Driver CMSIS_DSP_401
Main.c@3:ec7e3c37fe80, 2015-11-26 (annotated)
- Committer:
- EricLew
- Date:
- Thu Nov 26 22:32:56 2015 +0000
- Revision:
- 3:ec7e3c37fe80
- Parent:
- 1:1ae4b642c533
FFT is currently not working and commented out
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
EricLew | 0:d4e5ad7ad71c | 1 | #include "main.h" |
EricLew | 0:d4e5ad7ad71c | 2 | |
EricLew | 1:1ae4b642c533 | 3 | int32_t delay=0; |
EricLew | 0:d4e5ad7ad71c | 4 | uint32_t AppStatus = 0x00; |
EricLew | 0:d4e5ad7ad71c | 5 | FlagStatus AppLaunched = RESET; |
EricLew | 0:d4e5ad7ad71c | 6 | uint8_t DemoIndex = 0; |
EricLew | 0:d4e5ad7ad71c | 7 | |
EricLew | 0:d4e5ad7ad71c | 8 | /* initialization variable */ |
EricLew | 0:d4e5ad7ad71c | 9 | __IO FlagStatus KeyPressed = RESET; |
EricLew | 0:d4e5ad7ad71c | 10 | FlagStatus JoyInitialized = RESET; |
EricLew | 0:d4e5ad7ad71c | 11 | FlagStatus IddInitialized = RESET; |
EricLew | 0:d4e5ad7ad71c | 12 | FlagStatus LcdInitialized = RESET; |
EricLew | 0:d4e5ad7ad71c | 13 | FlagStatus LedInitialized = RESET; |
EricLew | 0:d4e5ad7ad71c | 14 | |
EricLew | 0:d4e5ad7ad71c | 15 | JOYState_TypeDef JoyState = JOY_NONE; |
EricLew | 0:d4e5ad7ad71c | 16 | |
EricLew | 0:d4e5ad7ad71c | 17 | __IO uint8_t NbLoop = 1; |
EricLew | 0:d4e5ad7ad71c | 18 | |
EricLew | 0:d4e5ad7ad71c | 19 | /* Volume of the audio playback */ |
EricLew | 0:d4e5ad7ad71c | 20 | /* Initial volume level (from 50% to 100% (Max)) */ |
EricLew | 0:d4e5ad7ad71c | 21 | __IO uint8_t Volume = 70; |
EricLew | 0:d4e5ad7ad71c | 22 | __IO uint8_t VolumeChange = 0; |
EricLew | 0:d4e5ad7ad71c | 23 | __IO uint8_t AudioPlaybackExit = 0; |
EricLew | 0:d4e5ad7ad71c | 24 | __IO uint8_t AudioRecordExit = 0; |
EricLew | 0:d4e5ad7ad71c | 25 | __IO uint8_t AudioRecordSampleRateSelected = 0; |
EricLew | 0:d4e5ad7ad71c | 26 | __IO uint8_t SampleRateIndex = 0; |
EricLew | 0:d4e5ad7ad71c | 27 | __IO uint8_t AudioRecordSampleRateChange = 0; |
EricLew | 0:d4e5ad7ad71c | 28 | |
EricLew | 0:d4e5ad7ad71c | 29 | extern __IO uint8_t bLCDGlass_KeyPressed; |
EricLew | 0:d4e5ad7ad71c | 30 | extern FlagStatus IddItOccurred; |
EricLew | 0:d4e5ad7ad71c | 31 | extern uint8_t IddIndex; |
EricLew | 0:d4e5ad7ad71c | 32 | |
EricLew | 0:d4e5ad7ad71c | 33 | |
EricLew | 0:d4e5ad7ad71c | 34 | |
EricLew | 0:d4e5ad7ad71c | 35 | typedef enum |
EricLew | 0:d4e5ad7ad71c | 36 | { |
EricLew | 0:d4e5ad7ad71c | 37 | DEMO_STATE_LED = 0x00, /*!< Led application launched */ |
EricLew | 0:d4e5ad7ad71c | 38 | DEMO_STATE_JOYSTICK, /*!< Joystick application launched */ |
EricLew | 0:d4e5ad7ad71c | 39 | DEMO_STATE_LCD , /*!< LCD application launched */ |
EricLew | 0:d4e5ad7ad71c | 40 | DEMO_STATE_AUDIO_RECORD, /*!< Audio record application launched */ |
EricLew | 0:d4e5ad7ad71c | 41 | DEMO_STATE_FIRST_STARTUP, /*!< Demo first Startup */ |
EricLew | 0:d4e5ad7ad71c | 42 | DEMO_STATE_IDLE, /*!< Demo in idle */ |
EricLew | 0:d4e5ad7ad71c | 43 | } Demo_StateTypeDef; |
EricLew | 0:d4e5ad7ad71c | 44 | |
EricLew | 0:d4e5ad7ad71c | 45 | /* Private function prototypes -----------------------------------------------*/ |
EricLew | 0:d4e5ad7ad71c | 46 | static void Display_DemoDescription(void); |
EricLew | 0:d4e5ad7ad71c | 47 | |
EricLew | 0:d4e5ad7ad71c | 48 | BSP_DemoTypedef BSP_examples[]= |
EricLew | 0:d4e5ad7ad71c | 49 | { |
EricLew | 0:d4e5ad7ad71c | 50 | {AudioRecord_demo, "AUDIO RECORD", DEMO_STATE_AUDIO_RECORD} |
EricLew | 0:d4e5ad7ad71c | 51 | }; |
EricLew | 0:d4e5ad7ad71c | 52 | |
EricLew | 0:d4e5ad7ad71c | 53 | int main(void) |
EricLew | 0:d4e5ad7ad71c | 54 | { |
EricLew | 0:d4e5ad7ad71c | 55 | uint8_t i = 0; |
EricLew | 0:d4e5ad7ad71c | 56 | uint8_t menudisplay[DEMO_NAME_CHAR_NB + 5] = {0}; |
EricLew | 0:d4e5ad7ad71c | 57 | |
EricLew | 0:d4e5ad7ad71c | 58 | /* STM32L4xx HAL library initialization: |
EricLew | 0:d4e5ad7ad71c | 59 | - Configure the Flash prefetch |
EricLew | 0:d4e5ad7ad71c | 60 | - Systick timer is configured by default as source of time base, but user |
EricLew | 0:d4e5ad7ad71c | 61 | can eventually implement his proper time base source (a general purpose |
EricLew | 0:d4e5ad7ad71c | 62 | timer for example or other time source), keeping in mind that Time base |
EricLew | 0:d4e5ad7ad71c | 63 | duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and |
EricLew | 0:d4e5ad7ad71c | 64 | handled in milliseconds basis. |
EricLew | 0:d4e5ad7ad71c | 65 | - Set NVIC Group Priority to 4 |
EricLew | 0:d4e5ad7ad71c | 66 | - Low Level Initialization |
EricLew | 0:d4e5ad7ad71c | 67 | */ |
EricLew | 0:d4e5ad7ad71c | 68 | HAL_Init(); |
EricLew | 0:d4e5ad7ad71c | 69 | |
EricLew | 0:d4e5ad7ad71c | 70 | /*##-1- Configure the system clock #########################################*/ |
EricLew | 0:d4e5ad7ad71c | 71 | /* */ |
EricLew | 0:d4e5ad7ad71c | 72 | SystemClock_Config(); |
EricLew | 0:d4e5ad7ad71c | 73 | |
EricLew | 0:d4e5ad7ad71c | 74 | /*##-2-Configure minimum hardware resources at boot ########################*/ |
EricLew | 0:d4e5ad7ad71c | 75 | SystemHardwareInit(); |
EricLew | 0:d4e5ad7ad71c | 76 | |
EricLew | 0:d4e5ad7ad71c | 77 | /* Display demo explaination on LCD Glass */ |
EricLew | 0:d4e5ad7ad71c | 78 | AppStatus = DEMO_STATE_FIRST_STARTUP; |
EricLew | 0:d4e5ad7ad71c | 79 | Display_DemoDescription(); |
EricLew | 0:d4e5ad7ad71c | 80 | |
EricLew | 0:d4e5ad7ad71c | 81 | /* Menu display first characters initialization */ |
EricLew | 0:d4e5ad7ad71c | 82 | for(i = 0; i < 5; i++) |
EricLew | 0:d4e5ad7ad71c | 83 | { |
EricLew | 0:d4e5ad7ad71c | 84 | menudisplay[i] = ' '; |
EricLew | 0:d4e5ad7ad71c | 85 | } |
EricLew | 0:d4e5ad7ad71c | 86 | |
EricLew | 0:d4e5ad7ad71c | 87 | |
EricLew | 0:d4e5ad7ad71c | 88 | /* Wait For User inputs */ |
EricLew | 0:d4e5ad7ad71c | 89 | while (1) |
EricLew | 0:d4e5ad7ad71c | 90 | { |
EricLew | 0:d4e5ad7ad71c | 91 | for(i = 0; i < DEMO_NAME_CHAR_NB; i++) |
EricLew | 0:d4e5ad7ad71c | 92 | { |
EricLew | 0:d4e5ad7ad71c | 93 | menudisplay[i+5] = BSP_examples[DemoIndex].DemoName[i]; |
EricLew | 0:d4e5ad7ad71c | 94 | } |
EricLew | 0:d4e5ad7ad71c | 95 | |
EricLew | 0:d4e5ad7ad71c | 96 | BSP_LCD_GLASS_ScrollSentence(menudisplay, 1, SCROLL_SPEED_HIGH); |
EricLew | 0:d4e5ad7ad71c | 97 | |
EricLew | 0:d4e5ad7ad71c | 98 | if(AppLaunched != RESET) |
EricLew | 0:d4e5ad7ad71c | 99 | { |
EricLew | 0:d4e5ad7ad71c | 100 | AppLaunched = RESET; |
EricLew | 0:d4e5ad7ad71c | 101 | KeyPressed = RESET; |
EricLew | 0:d4e5ad7ad71c | 102 | |
EricLew | 0:d4e5ad7ad71c | 103 | /* Clear screen */ |
EricLew | 0:d4e5ad7ad71c | 104 | BSP_LCD_GLASS_Clear(); |
EricLew | 0:d4e5ad7ad71c | 105 | |
EricLew | 0:d4e5ad7ad71c | 106 | /* Set Application status in case of specific joystick usage */ |
EricLew | 0:d4e5ad7ad71c | 107 | AppStatus = BSP_examples[DemoIndex].DemoIndex; |
EricLew | 0:d4e5ad7ad71c | 108 | |
EricLew | 0:d4e5ad7ad71c | 109 | /* launched application */ |
EricLew | 0:d4e5ad7ad71c | 110 | BSP_examples[DemoIndex].DemoFunc(); |
EricLew | 0:d4e5ad7ad71c | 111 | |
EricLew | 0:d4e5ad7ad71c | 112 | /* Set Application status to Idle */ |
EricLew | 0:d4e5ad7ad71c | 113 | AppStatus = DEMO_STATE_IDLE; |
EricLew | 0:d4e5ad7ad71c | 114 | |
EricLew | 0:d4e5ad7ad71c | 115 | /* Notify end of test and clear screen */ |
EricLew | 0:d4e5ad7ad71c | 116 | BSP_LCD_GLASS_ScrollSentence((uint8_t *)" END OF TEST", 1, SCROLL_SPEED_HIGH); |
EricLew | 0:d4e5ad7ad71c | 117 | BSP_LCD_GLASS_Clear(); |
EricLew | 0:d4e5ad7ad71c | 118 | } |
EricLew | 0:d4e5ad7ad71c | 119 | } |
EricLew | 0:d4e5ad7ad71c | 120 | } |
EricLew | 0:d4e5ad7ad71c | 121 | |
EricLew | 0:d4e5ad7ad71c | 122 | void SystemClock_Config(void) |
EricLew | 0:d4e5ad7ad71c | 123 | { |
EricLew | 0:d4e5ad7ad71c | 124 | /* oscillator and clocks configs */ |
EricLew | 0:d4e5ad7ad71c | 125 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
EricLew | 0:d4e5ad7ad71c | 126 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
EricLew | 0:d4e5ad7ad71c | 127 | |
EricLew | 0:d4e5ad7ad71c | 128 | /* The voltage scaling allows optimizing the power consumption when the device is |
EricLew | 0:d4e5ad7ad71c | 129 | clocked below the maximum system frequency, to update the voltage scaling value |
EricLew | 0:d4e5ad7ad71c | 130 | regarding system frequency refer to product datasheet. */ |
EricLew | 0:d4e5ad7ad71c | 131 | |
EricLew | 0:d4e5ad7ad71c | 132 | /* Enable Power Control clock */ |
EricLew | 0:d4e5ad7ad71c | 133 | __HAL_RCC_PWR_CLK_ENABLE(); |
EricLew | 0:d4e5ad7ad71c | 134 | |
EricLew | 0:d4e5ad7ad71c | 135 | if(HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK) |
EricLew | 0:d4e5ad7ad71c | 136 | { |
EricLew | 0:d4e5ad7ad71c | 137 | /* Initialization Error */ |
EricLew | 0:d4e5ad7ad71c | 138 | Error_Handler(); |
EricLew | 0:d4e5ad7ad71c | 139 | } |
EricLew | 0:d4e5ad7ad71c | 140 | |
EricLew | 0:d4e5ad7ad71c | 141 | /* Disable Power Control clock */ |
EricLew | 0:d4e5ad7ad71c | 142 | __HAL_RCC_PWR_CLK_DISABLE(); |
EricLew | 0:d4e5ad7ad71c | 143 | |
EricLew | 0:d4e5ad7ad71c | 144 | /* 80 Mhz from MSI 8Mhz */ |
EricLew | 0:d4e5ad7ad71c | 145 | /* MSI is enabled after System reset, activate PLL with MSI as source */ |
EricLew | 0:d4e5ad7ad71c | 146 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI; |
EricLew | 0:d4e5ad7ad71c | 147 | RCC_OscInitStruct.MSIState = RCC_MSI_ON; |
EricLew | 0:d4e5ad7ad71c | 148 | RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_7; |
EricLew | 0:d4e5ad7ad71c | 149 | RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT; |
EricLew | 0:d4e5ad7ad71c | 150 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
EricLew | 0:d4e5ad7ad71c | 151 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI; |
EricLew | 0:d4e5ad7ad71c | 152 | RCC_OscInitStruct.PLL.PLLM = 1; |
EricLew | 0:d4e5ad7ad71c | 153 | RCC_OscInitStruct.PLL.PLLN = 20; |
EricLew | 0:d4e5ad7ad71c | 154 | RCC_OscInitStruct.PLL.PLLR = 2; |
EricLew | 0:d4e5ad7ad71c | 155 | RCC_OscInitStruct.PLL.PLLP = 7; |
EricLew | 0:d4e5ad7ad71c | 156 | RCC_OscInitStruct.PLL.PLLQ = 4; |
EricLew | 0:d4e5ad7ad71c | 157 | |
EricLew | 0:d4e5ad7ad71c | 158 | if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
EricLew | 0:d4e5ad7ad71c | 159 | { |
EricLew | 0:d4e5ad7ad71c | 160 | /* Initialization Error */ |
EricLew | 0:d4e5ad7ad71c | 161 | Error_Handler(); |
EricLew | 0:d4e5ad7ad71c | 162 | } |
EricLew | 0:d4e5ad7ad71c | 163 | |
EricLew | 0:d4e5ad7ad71c | 164 | /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 |
EricLew | 0:d4e5ad7ad71c | 165 | clocks dividers */ |
EricLew | 0:d4e5ad7ad71c | 166 | RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); |
EricLew | 0:d4e5ad7ad71c | 167 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
EricLew | 0:d4e5ad7ad71c | 168 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
EricLew | 0:d4e5ad7ad71c | 169 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; |
EricLew | 0:d4e5ad7ad71c | 170 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
EricLew | 0:d4e5ad7ad71c | 171 | if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK) |
EricLew | 0:d4e5ad7ad71c | 172 | { |
EricLew | 0:d4e5ad7ad71c | 173 | /* Initialization Error */ |
EricLew | 0:d4e5ad7ad71c | 174 | Error_Handler(); |
EricLew | 0:d4e5ad7ad71c | 175 | } |
EricLew | 0:d4e5ad7ad71c | 176 | |
EricLew | 0:d4e5ad7ad71c | 177 | /* The voltage scaling allows optimizing the power consumption when the device is |
EricLew | 0:d4e5ad7ad71c | 178 | clocked below the maximum system frequency, to update the voltage scaling value |
EricLew | 0:d4e5ad7ad71c | 179 | regarding system frequency refer to product datasheet. */ |
EricLew | 0:d4e5ad7ad71c | 180 | |
EricLew | 0:d4e5ad7ad71c | 181 | /* Enable Power Control clock */ |
EricLew | 0:d4e5ad7ad71c | 182 | __HAL_RCC_PWR_CLK_ENABLE(); |
EricLew | 0:d4e5ad7ad71c | 183 | |
EricLew | 0:d4e5ad7ad71c | 184 | if(HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK) |
EricLew | 0:d4e5ad7ad71c | 185 | { |
EricLew | 0:d4e5ad7ad71c | 186 | /* Initialization Error */ |
EricLew | 0:d4e5ad7ad71c | 187 | Error_Handler(); |
EricLew | 0:d4e5ad7ad71c | 188 | } |
EricLew | 0:d4e5ad7ad71c | 189 | |
EricLew | 0:d4e5ad7ad71c | 190 | /* Disable Power Control clock */ |
EricLew | 0:d4e5ad7ad71c | 191 | __HAL_RCC_PWR_CLK_DISABLE(); |
EricLew | 0:d4e5ad7ad71c | 192 | } |
EricLew | 0:d4e5ad7ad71c | 193 | |
EricLew | 0:d4e5ad7ad71c | 194 | void SystemLowClock_Config(void) |
EricLew | 0:d4e5ad7ad71c | 195 | { |
EricLew | 0:d4e5ad7ad71c | 196 | /* oscillator and clocks configs */ |
EricLew | 0:d4e5ad7ad71c | 197 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
EricLew | 0:d4e5ad7ad71c | 198 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
EricLew | 0:d4e5ad7ad71c | 199 | uint32_t flatency = 0; |
EricLew | 0:d4e5ad7ad71c | 200 | |
EricLew | 0:d4e5ad7ad71c | 201 | /* Retrieve clock parameters */ |
EricLew | 0:d4e5ad7ad71c | 202 | HAL_RCC_GetClockConfig(&RCC_ClkInitStruct, &flatency ); |
EricLew | 0:d4e5ad7ad71c | 203 | |
EricLew | 0:d4e5ad7ad71c | 204 | /* switch SYSCLK to MSI in order to modify PLL divider */ |
EricLew | 0:d4e5ad7ad71c | 205 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK; |
EricLew | 0:d4e5ad7ad71c | 206 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI; |
EricLew | 0:d4e5ad7ad71c | 207 | if(HAL_RCC_ClockConfig(&RCC_ClkInitStruct, flatency) != HAL_OK) |
EricLew | 0:d4e5ad7ad71c | 208 | { |
EricLew | 0:d4e5ad7ad71c | 209 | /* Initialization Error */ |
EricLew | 0:d4e5ad7ad71c | 210 | Error_Handler(); |
EricLew | 0:d4e5ad7ad71c | 211 | } |
EricLew | 0:d4e5ad7ad71c | 212 | |
EricLew | 0:d4e5ad7ad71c | 213 | /* Retrieve oscillator parameters */ |
EricLew | 0:d4e5ad7ad71c | 214 | HAL_RCC_GetOscConfig(&RCC_OscInitStruct); |
EricLew | 0:d4e5ad7ad71c | 215 | |
EricLew | 0:d4e5ad7ad71c | 216 | /* turn off PLL */ |
EricLew | 0:d4e5ad7ad71c | 217 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_NONE; |
EricLew | 0:d4e5ad7ad71c | 218 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_OFF; |
EricLew | 0:d4e5ad7ad71c | 219 | if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
EricLew | 0:d4e5ad7ad71c | 220 | { |
EricLew | 0:d4e5ad7ad71c | 221 | /* Initialization Error */ |
EricLew | 0:d4e5ad7ad71c | 222 | Error_Handler(); |
EricLew | 0:d4e5ad7ad71c | 223 | } |
EricLew | 0:d4e5ad7ad71c | 224 | } |
EricLew | 0:d4e5ad7ad71c | 225 | |
EricLew | 0:d4e5ad7ad71c | 226 | /** |
EricLew | 0:d4e5ad7ad71c | 227 | * @brief System Power Configuration at Boot |
EricLew | 0:d4e5ad7ad71c | 228 | * @param None |
EricLew | 0:d4e5ad7ad71c | 229 | * @retval None |
EricLew | 0:d4e5ad7ad71c | 230 | */ |
EricLew | 0:d4e5ad7ad71c | 231 | void SystemHardwareInit(void) |
EricLew | 0:d4e5ad7ad71c | 232 | { |
EricLew | 0:d4e5ad7ad71c | 233 | /* Init LED4 and LED5 */ |
EricLew | 0:d4e5ad7ad71c | 234 | if(LedInitialized != SET) |
EricLew | 0:d4e5ad7ad71c | 235 | { |
EricLew | 0:d4e5ad7ad71c | 236 | BSP_LED_Init(LED_RED); |
EricLew | 0:d4e5ad7ad71c | 237 | BSP_LED_Init(LED_GREEN); |
EricLew | 0:d4e5ad7ad71c | 238 | LedInitialized = SET; |
EricLew | 0:d4e5ad7ad71c | 239 | } |
EricLew | 0:d4e5ad7ad71c | 240 | |
EricLew | 0:d4e5ad7ad71c | 241 | /* Init STM32L476G-Discovery joystick in interrupt mode */ |
EricLew | 0:d4e5ad7ad71c | 242 | if(JoyInitialized != SET) |
EricLew | 0:d4e5ad7ad71c | 243 | { |
EricLew | 0:d4e5ad7ad71c | 244 | BSP_JOY_Init(JOY_MODE_EXTI); |
EricLew | 0:d4e5ad7ad71c | 245 | JoyInitialized = SET; |
EricLew | 0:d4e5ad7ad71c | 246 | } |
EricLew | 0:d4e5ad7ad71c | 247 | |
EricLew | 0:d4e5ad7ad71c | 248 | /* Initialize the LCD */ |
EricLew | 0:d4e5ad7ad71c | 249 | if(LcdInitialized != SET) |
EricLew | 0:d4e5ad7ad71c | 250 | { |
EricLew | 0:d4e5ad7ad71c | 251 | BSP_LCD_GLASS_Init(); |
EricLew | 0:d4e5ad7ad71c | 252 | LcdInitialized = SET; |
EricLew | 0:d4e5ad7ad71c | 253 | } |
EricLew | 0:d4e5ad7ad71c | 254 | __HAL_RCC_I2C2_CLK_ENABLE(); |
EricLew | 0:d4e5ad7ad71c | 255 | } |
EricLew | 0:d4e5ad7ad71c | 256 | |
EricLew | 0:d4e5ad7ad71c | 257 | /** |
EricLew | 0:d4e5ad7ad71c | 258 | * @brief System Low Power Configuration |
EricLew | 0:d4e5ad7ad71c | 259 | * @param None |
EricLew | 0:d4e5ad7ad71c | 260 | * @retval None |
EricLew | 0:d4e5ad7ad71c | 261 | */ |
EricLew | 0:d4e5ad7ad71c | 262 | void SystemHardwareDeInit(void) |
EricLew | 0:d4e5ad7ad71c | 263 | { |
EricLew | 0:d4e5ad7ad71c | 264 | if(LedInitialized != RESET) |
EricLew | 0:d4e5ad7ad71c | 265 | { |
EricLew | 0:d4e5ad7ad71c | 266 | BSP_LED_DeInit(LED_RED); |
EricLew | 0:d4e5ad7ad71c | 267 | BSP_LED_DeInit(LED_GREEN); |
EricLew | 0:d4e5ad7ad71c | 268 | LedInitialized = RESET; |
EricLew | 0:d4e5ad7ad71c | 269 | } |
EricLew | 0:d4e5ad7ad71c | 270 | |
EricLew | 0:d4e5ad7ad71c | 271 | if(JoyInitialized != RESET) |
EricLew | 0:d4e5ad7ad71c | 272 | { |
EricLew | 0:d4e5ad7ad71c | 273 | BSP_JOY_DeInit(); |
EricLew | 0:d4e5ad7ad71c | 274 | JoyInitialized = RESET; |
EricLew | 0:d4e5ad7ad71c | 275 | } |
EricLew | 0:d4e5ad7ad71c | 276 | |
EricLew | 0:d4e5ad7ad71c | 277 | if(LcdInitialized != RESET) |
EricLew | 0:d4e5ad7ad71c | 278 | { |
EricLew | 0:d4e5ad7ad71c | 279 | BSP_LCD_GLASS_DeInit(); |
EricLew | 0:d4e5ad7ad71c | 280 | LcdInitialized = RESET; |
EricLew | 0:d4e5ad7ad71c | 281 | } |
EricLew | 0:d4e5ad7ad71c | 282 | |
EricLew | 0:d4e5ad7ad71c | 283 | /* Disable remaining clocks */ |
EricLew | 0:d4e5ad7ad71c | 284 | __HAL_RCC_PWR_CLK_DISABLE(); |
EricLew | 0:d4e5ad7ad71c | 285 | __HAL_RCC_FLASH_CLK_DISABLE(); |
EricLew | 0:d4e5ad7ad71c | 286 | __HAL_RCC_SYSCFG_CLK_DISABLE(); |
EricLew | 0:d4e5ad7ad71c | 287 | __HAL_RCC_GPIOA_CLK_DISABLE(); |
EricLew | 0:d4e5ad7ad71c | 288 | __HAL_RCC_GPIOB_CLK_DISABLE(); |
EricLew | 0:d4e5ad7ad71c | 289 | __HAL_RCC_GPIOC_CLK_DISABLE(); |
EricLew | 0:d4e5ad7ad71c | 290 | __HAL_RCC_GPIOD_CLK_DISABLE(); |
EricLew | 0:d4e5ad7ad71c | 291 | __HAL_RCC_GPIOE_CLK_DISABLE(); |
EricLew | 0:d4e5ad7ad71c | 292 | __HAL_RCC_I2C2_CLK_DISABLE(); |
EricLew | 0:d4e5ad7ad71c | 293 | RCC->AHB1SMENR = 0x0; |
EricLew | 0:d4e5ad7ad71c | 294 | RCC->AHB2SMENR = 0x0; |
EricLew | 0:d4e5ad7ad71c | 295 | RCC->AHB3SMENR = 0x0; |
EricLew | 0:d4e5ad7ad71c | 296 | RCC->APB1SMENR1 = 0x0; |
EricLew | 0:d4e5ad7ad71c | 297 | RCC->APB1SMENR2 = 0x0; |
EricLew | 0:d4e5ad7ad71c | 298 | RCC->APB2SMENR = 0x0; |
EricLew | 0:d4e5ad7ad71c | 299 | } |
EricLew | 0:d4e5ad7ad71c | 300 | |
EricLew | 0:d4e5ad7ad71c | 301 | static void Display_DemoDescription(void) |
EricLew | 0:d4e5ad7ad71c | 302 | { |
EricLew | 0:d4e5ad7ad71c | 303 | /* Clear the LCD */ |
EricLew | 0:d4e5ad7ad71c | 304 | BSP_LCD_GLASS_Clear(); |
EricLew | 0:d4e5ad7ad71c | 305 | |
EricLew | 0:d4e5ad7ad71c | 306 | /* Display LCD messages */ |
EricLew | 0:d4e5ad7ad71c | 307 | BSP_LCD_GLASS_ScrollSentence((uint8_t *)" STM32L476G-DISCO BSP DRIVER EXAMPLE", 1, SCROLL_SPEED_HIGH); |
EricLew | 0:d4e5ad7ad71c | 308 | BSP_LCD_GLASS_ScrollSentence((uint8_t *)" COPYRIGHT STMICROELECTRONICS 2015", 1, SCROLL_SPEED_HIGH); |
EricLew | 0:d4e5ad7ad71c | 309 | |
EricLew | 0:d4e5ad7ad71c | 310 | /* Introduce short delay before new message displayed */ |
EricLew | 0:d4e5ad7ad71c | 311 | HAL_Delay(50); |
EricLew | 0:d4e5ad7ad71c | 312 | |
EricLew | 0:d4e5ad7ad71c | 313 | BSP_LCD_GLASS_ScrollSentence((uint8_t *)" Press Joy Right to start ", 0xFFFF, SCROLL_SPEED_HIGH); |
EricLew | 0:d4e5ad7ad71c | 314 | |
EricLew | 0:d4e5ad7ad71c | 315 | /* Clear the LCD & reset Key pressed variable */ |
EricLew | 0:d4e5ad7ad71c | 316 | BSP_LCD_GLASS_Clear(); |
EricLew | 0:d4e5ad7ad71c | 317 | |
EricLew | 0:d4e5ad7ad71c | 318 | AppStatus = DEMO_STATE_IDLE; |
EricLew | 0:d4e5ad7ad71c | 319 | } |
EricLew | 0:d4e5ad7ad71c | 320 | |
EricLew | 0:d4e5ad7ad71c | 321 | uint8_t CheckForUserInput(void) |
EricLew | 0:d4e5ad7ad71c | 322 | { |
EricLew | 0:d4e5ad7ad71c | 323 | if(BSP_JOY_GetState() == JOY_SEL) |
EricLew | 0:d4e5ad7ad71c | 324 | { |
EricLew | 0:d4e5ad7ad71c | 325 | while (BSP_JOY_GetState() == JOY_SEL); |
EricLew | 0:d4e5ad7ad71c | 326 | return 1; |
EricLew | 0:d4e5ad7ad71c | 327 | } |
EricLew | 0:d4e5ad7ad71c | 328 | return 0; |
EricLew | 0:d4e5ad7ad71c | 329 | } |
EricLew | 0:d4e5ad7ad71c | 330 | |
EricLew | 0:d4e5ad7ad71c | 331 | /**lerais |
EricLew | 0:d4e5ad7ad71c | 332 | * @brief This function is executed in case of error occurrence. |
EricLew | 0:d4e5ad7ad71c | 333 | * @param None |
EricLew | 0:d4e5ad7ad71c | 334 | * @retval None |
EricLew | 0:d4e5ad7ad71c | 335 | */ |
EricLew | 0:d4e5ad7ad71c | 336 | void Error_Handler(void) |
EricLew | 0:d4e5ad7ad71c | 337 | { |
EricLew | 0:d4e5ad7ad71c | 338 | /* Turn LED RED on */ |
EricLew | 0:d4e5ad7ad71c | 339 | while(1) |
EricLew | 0:d4e5ad7ad71c | 340 | { |
EricLew | 0:d4e5ad7ad71c | 341 | BSP_LED_Toggle(LED_RED); |
EricLew | 0:d4e5ad7ad71c | 342 | HAL_Delay(40); |
EricLew | 0:d4e5ad7ad71c | 343 | } |
EricLew | 0:d4e5ad7ad71c | 344 | } |
EricLew | 0:d4e5ad7ad71c | 345 | |
EricLew | 0:d4e5ad7ad71c | 346 | |
EricLew | 0:d4e5ad7ad71c | 347 | void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) |
EricLew | 0:d4e5ad7ad71c | 348 | { |
EricLew | 0:d4e5ad7ad71c | 349 | if((GPIO_Pin & (DOWN_JOY_PIN | UP_JOY_PIN | SEL_JOY_PIN | RIGHT_JOY_PIN | LEFT_JOY_PIN)) |
EricLew | 0:d4e5ad7ad71c | 350 | != RESET) |
EricLew | 0:d4e5ad7ad71c | 351 | { |
EricLew | 0:d4e5ad7ad71c | 352 | KeyPressed = SET; |
EricLew | 0:d4e5ad7ad71c | 353 | |
EricLew | 0:d4e5ad7ad71c | 354 | switch(AppStatus) |
EricLew | 0:d4e5ad7ad71c | 355 | { |
EricLew | 0:d4e5ad7ad71c | 356 | case DEMO_STATE_FIRST_STARTUP: |
EricLew | 0:d4e5ad7ad71c | 357 | |
EricLew | 0:d4e5ad7ad71c | 358 | |
EricLew | 0:d4e5ad7ad71c | 359 | case DEMO_STATE_IDLE: |
EricLew | 0:d4e5ad7ad71c | 360 | bLCDGlass_KeyPressed = 0x01; |
EricLew | 0:d4e5ad7ad71c | 361 | switch(GPIO_Pin) |
EricLew | 0:d4e5ad7ad71c | 362 | { |
EricLew | 0:d4e5ad7ad71c | 363 | case DOWN_JOY_PIN : |
EricLew | 0:d4e5ad7ad71c | 364 | DemoIndex++; |
EricLew | 0:d4e5ad7ad71c | 365 | if(DemoIndex > COUNT_OF_EXAMPLE(BSP_examples)) |
EricLew | 0:d4e5ad7ad71c | 366 | { |
EricLew | 0:d4e5ad7ad71c | 367 | DemoIndex = 0; |
EricLew | 0:d4e5ad7ad71c | 368 | } |
EricLew | 0:d4e5ad7ad71c | 369 | break; |
EricLew | 0:d4e5ad7ad71c | 370 | case UP_JOY_PIN : |
EricLew | 0:d4e5ad7ad71c | 371 | DemoIndex--; |
EricLew | 0:d4e5ad7ad71c | 372 | if(DemoIndex > COUNT_OF_EXAMPLE(BSP_examples)) |
EricLew | 0:d4e5ad7ad71c | 373 | { |
EricLew | 0:d4e5ad7ad71c | 374 | DemoIndex = (COUNT_OF_EXAMPLE(BSP_examples) - 1); |
EricLew | 0:d4e5ad7ad71c | 375 | } |
EricLew | 0:d4e5ad7ad71c | 376 | break; |
EricLew | 0:d4e5ad7ad71c | 377 | case RIGHT_JOY_PIN : |
EricLew | 0:d4e5ad7ad71c | 378 | AppLaunched = SET; |
EricLew | 0:d4e5ad7ad71c | 379 | break; |
EricLew | 0:d4e5ad7ad71c | 380 | } |
EricLew | 0:d4e5ad7ad71c | 381 | break; |
EricLew | 0:d4e5ad7ad71c | 382 | |
EricLew | 0:d4e5ad7ad71c | 383 | case DEMO_STATE_LED: |
EricLew | 0:d4e5ad7ad71c | 384 | break; |
EricLew | 0:d4e5ad7ad71c | 385 | |
EricLew | 0:d4e5ad7ad71c | 386 | case DEMO_STATE_JOYSTICK: |
EricLew | 0:d4e5ad7ad71c | 387 | case DEMO_STATE_LCD: |
EricLew | 0:d4e5ad7ad71c | 388 | switch(GPIO_Pin) |
EricLew | 0:d4e5ad7ad71c | 389 | { |
EricLew | 0:d4e5ad7ad71c | 390 | case DOWN_JOY_PIN : |
EricLew | 0:d4e5ad7ad71c | 391 | JoyState = JOY_DOWN; |
EricLew | 0:d4e5ad7ad71c | 392 | break; |
EricLew | 0:d4e5ad7ad71c | 393 | case UP_JOY_PIN : |
EricLew | 0:d4e5ad7ad71c | 394 | JoyState = JOY_UP; |
EricLew | 0:d4e5ad7ad71c | 395 | break; |
EricLew | 0:d4e5ad7ad71c | 396 | case SEL_JOY_PIN : |
EricLew | 0:d4e5ad7ad71c | 397 | JoyState = JOY_SEL; |
EricLew | 0:d4e5ad7ad71c | 398 | break; |
EricLew | 0:d4e5ad7ad71c | 399 | case RIGHT_JOY_PIN : |
EricLew | 0:d4e5ad7ad71c | 400 | JoyState = JOY_RIGHT; |
EricLew | 0:d4e5ad7ad71c | 401 | break; |
EricLew | 0:d4e5ad7ad71c | 402 | case LEFT_JOY_PIN : |
EricLew | 0:d4e5ad7ad71c | 403 | JoyState = JOY_LEFT; |
EricLew | 0:d4e5ad7ad71c | 404 | break; |
EricLew | 0:d4e5ad7ad71c | 405 | } |
EricLew | 0:d4e5ad7ad71c | 406 | break; |
EricLew | 0:d4e5ad7ad71c | 407 | |
EricLew | 0:d4e5ad7ad71c | 408 | |
EricLew | 0:d4e5ad7ad71c | 409 | case DEMO_STATE_AUDIO_RECORD: |
EricLew | 0:d4e5ad7ad71c | 410 | switch(GPIO_Pin) |
EricLew | 0:d4e5ad7ad71c | 411 | { |
EricLew | 0:d4e5ad7ad71c | 412 | case RIGHT_JOY_PIN : |
EricLew | 0:d4e5ad7ad71c | 413 | /* SEL is used to confirm audio record sample rate and start audio recording */ |
EricLew | 0:d4e5ad7ad71c | 414 | AudioRecordSampleRateSelected = 1; |
EricLew | 0:d4e5ad7ad71c | 415 | break; |
EricLew | 0:d4e5ad7ad71c | 416 | } |
EricLew | 0:d4e5ad7ad71c | 417 | break; |
EricLew | 0:d4e5ad7ad71c | 418 | } |
EricLew | 0:d4e5ad7ad71c | 419 | } |
EricLew | 0:d4e5ad7ad71c | 420 | } |