Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 50 | mjames | 1 | /* USER CODE BEGIN Header */ |
| 2 | mjames | 2 | /** |
| 52 | mjames | 3 | ****************************************************************************** |
| 4 | * @file : main.c |
||
| 5 | * @brief : Main program body |
||
| 6 | ****************************************************************************** |
||
| 7 | * @attention |
||
| 8 | * |
||
| 9 | * <h2><center>© Copyright (c) 2020 STMicroelectronics. |
||
| 10 | * All rights reserved.</center></h2> |
||
| 11 | * |
||
| 12 | * This software component is licensed by ST under BSD 3-Clause license, |
||
| 13 | * the "License"; You may not use this file except in compliance with the |
||
| 14 | * License. You may obtain a copy of the License at: |
||
| 15 | * opensource.org/licenses/BSD-3-Clause |
||
| 16 | * |
||
| 17 | ****************************************************************************** |
||
| 18 | */ |
||
| 50 | mjames | 19 | /* USER CODE END Header */ |
| 2 | mjames | 20 | /* Includes ------------------------------------------------------------------*/ |
| 50 | mjames | 21 | #include "main.h" |
| 2 | mjames | 22 | |
| 50 | mjames | 23 | /* Private includes ----------------------------------------------------------*/ |
| 2 | mjames | 24 | /* USER CODE BEGIN Includes */ |
| 50 | mjames | 25 | |
| 26 | #include "libPLX/plx.h" |
||
| 27 | #include "libSerial/serial.H" |
||
| 28 | #include "libSmallPrintf/small_printf.h" |
||
| 58 | mjames | 29 | #include "libNMEA/nmea.h" |
| 4 | mjames | 30 | #include "switches.h" |
| 62 | mjames | 31 | #include<string.h> |
| 2 | mjames | 32 | |
| 33 | /* USER CODE END Includes */ |
||
| 34 | |||
| 50 | mjames | 35 | /* Private typedef -----------------------------------------------------------*/ |
| 36 | /* USER CODE BEGIN PTD */ |
||
| 37 | |||
| 38 | /* USER CODE END PTD */ |
||
| 39 | |||
| 40 | /* Private define ------------------------------------------------------------*/ |
||
| 41 | /* USER CODE BEGIN PD */ |
||
| 42 | /* USER CODE END PD */ |
||
| 43 | |||
| 44 | /* Private macro -------------------------------------------------------------*/ |
||
| 45 | /* USER CODE BEGIN PM */ |
||
| 46 | |||
| 47 | /* USER CODE END PM */ |
||
| 48 | |||
| 2 | mjames | 49 | /* Private variables ---------------------------------------------------------*/ |
| 62 | mjames | 50 | SPI_HandleTypeDef hspi1; |
| 2 | mjames | 51 | |
| 50 | mjames | 52 | TIM_HandleTypeDef htim2; |
| 44 | mjames | 53 | TIM_HandleTypeDef htim3; |
| 54 | TIM_HandleTypeDef htim9; |
||
| 55 | |||
| 60 | mjames | 56 | UART_HandleTypeDef huart4; |
| 3 | mjames | 57 | UART_HandleTypeDef huart1; |
| 2 | mjames | 58 | UART_HandleTypeDef huart2; |
| 23 | mjames | 59 | UART_HandleTypeDef huart3; |
| 2 | mjames | 60 | |
| 61 | /* USER CODE BEGIN PV */ |
||
| 62 | /* Private variables ---------------------------------------------------------*/ |
||
| 63 | |||
| 50 | mjames | 64 | context_t contexts[MAX_DISPLAYS]; |
| 65 | |||
| 24 | mjames | 66 | /* timeout when the ignition is switched off */ |
| 67 | #define IGNITION_OFF_TIMEOUT 30000UL |
||
| 68 | |||
| 62 | mjames | 69 | // 500mS per logger period. |
| 52 | mjames | 70 | #define LOGGER_INTERVAL 500UL |
| 14 | mjames | 71 | |
| 57 | mjames | 72 | const int DialTimeout = 10000; // about 10 seconds after twiddle, save the dial position. |
| 18 | mjames | 73 | |
| 56 | mjames | 74 | nvram_info_t dial_nvram[MAX_DISPLAYS] __attribute__((section(".NVRAM_Data"))); |
| 14 | mjames | 75 | |
| 56 | mjames | 76 | info_t Info[MAXRDG]; |
| 77 | |||
| 78 | /// \brief storage for incoming data |
||
| 50 | mjames | 79 | data_t Data; |
| 56 | mjames | 80 | |
| 7 | mjames | 81 | int PLXItems; |
| 24 | mjames | 82 | |
| 27 | mjames | 83 | uint32_t Latch_Timer = IGNITION_OFF_TIMEOUT; |
| 24 | mjames | 84 | |
| 58 | mjames | 85 | // location for GPS data |
| 86 | Location loc; |
||
| 87 | |||
| 2 | mjames | 88 | /* USER CODE END PV */ |
| 89 | |||
| 90 | /* Private function prototypes -----------------------------------------------*/ |
||
| 58 | mjames | 91 | void SystemClock_Config(void); |
| 92 | static void MX_GPIO_Init(void); |
||
| 93 | static void MX_SPI1_Init(void); |
||
| 94 | static void MX_USART1_UART_Init(void); |
||
| 95 | static void MX_USART2_UART_Init(void); |
||
| 96 | static void MX_USART3_UART_Init(void); |
||
| 97 | static void MX_TIM3_Init(void); |
||
| 98 | static void MX_TIM9_Init(void); |
||
| 99 | static void MX_TIM2_Init(void); |
||
| 60 | mjames | 100 | static void MX_UART4_Init(void); |
| 2 | mjames | 101 | /* USER CODE BEGIN PFP */ |
| 102 | |||
| 7 | mjames | 103 | // the dial is the switch number we are using. |
| 104 | // suppress is the ItemIndex we wish to suppress on this display |
||
| 60 | mjames | 105 | int DisplayCurrent(int dial, int suppress) |
| 7 | mjames | 106 | { |
| 57 | mjames | 107 | if (contexts[dial].knobPos < 0) |
| 50 | mjames | 108 | return -1; |
| 60 | mjames | 109 | return cc_display(dial, suppress); |
| 50 | mjames | 110 | } |
| 30 | mjames | 111 | |
| 56 | mjames | 112 | /// \note this code doesnt work so it leaves speed as 9600. |
| 113 | /// \brief Setup Bluetooth module |
||
| 60 | mjames | 114 | void initModule(usart_ctl *ctl, uint32_t baudRate) |
| 53 | mjames | 115 | { |
| 116 | char initBuf[30]; |
||
| 117 | // switch to command mode |
||
| 60 | mjames | 118 | HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, GPIO_PIN_RESET); |
| 119 | HAL_Delay(500); |
||
| 62 | mjames | 120 | int initLen = small_sprintf(initBuf, "AT+UART=%lu,1,2\n", baudRate); |
| 60 | mjames | 121 | setBaud(ctl, 38400); |
| 122 | sendString(ctl, initBuf, initLen); |
||
| 123 | TxWaitEmpty(ctl); |
||
| 53 | mjames | 124 | // switch back to normal comms at new baud rate |
| 125 | |||
| 60 | mjames | 126 | HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, GPIO_PIN_SET); |
| 127 | setBaud(ctl, baudRate); |
||
| 128 | HAL_Delay(100); |
||
| 129 | } |
||
| 53 | mjames | 130 | |
| 60 | mjames | 131 | // workspace for RMC data read from GPS module. |
| 132 | uint8_t rmc_buff[80]; |
||
| 62 | mjames | 133 | volatile uint16_t rmc_length; |
| 60 | mjames | 134 | |
| 135 | uint8_t rmc_callback(uint8_t *data, uint16_t length) |
||
| 136 | { |
||
| 62 | mjames | 137 | rmc_length = length < sizeof(rmc_buff) ? length : sizeof(rmc_buff); |
| 60 | mjames | 138 | memcpy(rmc_buff, data, length); |
| 62 | mjames | 139 | return 0; |
| 53 | mjames | 140 | } |
| 141 | |||
| 50 | mjames | 142 | /* USER CODE END PFP */ |
| 14 | mjames | 143 | |
| 50 | mjames | 144 | /* Private user code ---------------------------------------------------------*/ |
| 145 | /* USER CODE BEGIN 0 */ |
||
| 14 | mjames | 146 | |
| 7 | mjames | 147 | /* USER CODE END 0 */ |
| 2 | mjames | 148 | |
| 50 | mjames | 149 | /** |
| 62 | mjames | 150 | * @brief The application entry point. |
| 151 | * @retval int |
||
| 152 | */ |
||
| 58 | mjames | 153 | int main(void) |
| 7 | mjames | 154 | { |
| 16 | mjames | 155 | /* USER CODE BEGIN 1 */ |
| 60 | mjames | 156 | __HAL_RCC_SPI1_CLK_ENABLE(); |
| 157 | __HAL_RCC_USART1_CLK_ENABLE(); // PLX main port |
||
| 158 | __HAL_RCC_USART2_CLK_ENABLE(); // debug port |
||
| 159 | __HAL_RCC_USART3_CLK_ENABLE(); // Bluetooth port |
||
| 61 | mjames | 160 | __HAL_RCC_UART4_CLK_ENABLE(); // NMEA0183 port |
| 2 | mjames | 161 | |
| 50 | mjames | 162 | __HAL_RCC_TIM3_CLK_ENABLE(); |
| 2 | mjames | 163 | |
| 50 | mjames | 164 | __HAL_RCC_TIM9_CLK_ENABLE(); |
| 23 | mjames | 165 | |
| 16 | mjames | 166 | /* USER CODE END 1 */ |
| 2 | mjames | 167 | |
| 50 | mjames | 168 | /* MCU Configuration--------------------------------------------------------*/ |
| 6 | mjames | 169 | |
| 16 | mjames | 170 | /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ |
| 58 | mjames | 171 | HAL_Init(); |
| 2 | mjames | 172 | |
| 50 | mjames | 173 | /* USER CODE BEGIN Init */ |
| 174 | |||
| 175 | /* USER CODE END Init */ |
||
| 176 | |||
| 16 | mjames | 177 | /* Configure the system clock */ |
| 58 | mjames | 178 | SystemClock_Config(); |
| 2 | mjames | 179 | |
| 50 | mjames | 180 | /* USER CODE BEGIN SysInit */ |
| 59 | mjames | 181 | // Switch handler called on sysTick interrupt. |
| 60 | mjames | 182 | InitSwitches(); |
| 50 | mjames | 183 | |
| 184 | /* USER CODE END SysInit */ |
||
| 185 | |||
| 16 | mjames | 186 | /* Initialize all configured peripherals */ |
| 58 | mjames | 187 | MX_GPIO_Init(); |
| 188 | MX_SPI1_Init(); |
||
| 189 | MX_USART1_UART_Init(); |
||
| 190 | MX_USART2_UART_Init(); |
||
| 191 | MX_USART3_UART_Init(); |
||
| 192 | MX_TIM3_Init(); |
||
| 193 | MX_TIM9_Init(); |
||
| 194 | MX_TIM2_Init(); |
||
| 60 | mjames | 195 | MX_UART4_Init(); |
| 16 | mjames | 196 | /* USER CODE BEGIN 2 */ |
| 2 | mjames | 197 | |
| 50 | mjames | 198 | /* Turn on USART1 IRQ */ |
| 60 | mjames | 199 | HAL_NVIC_SetPriority(USART1_IRQn, 2, 0); |
| 200 | HAL_NVIC_EnableIRQ(USART1_IRQn); |
||
| 4 | mjames | 201 | |
| 50 | mjames | 202 | /* Turn on USART2 IRQ */ |
| 60 | mjames | 203 | HAL_NVIC_SetPriority(USART2_IRQn, 4, 0); |
| 204 | HAL_NVIC_EnableIRQ(USART2_IRQn); |
||
| 2 | mjames | 205 | |
| 50 | mjames | 206 | /* turn on USART3 IRQ */ |
| 60 | mjames | 207 | HAL_NVIC_SetPriority(USART3_IRQn, 4, 0); |
| 208 | HAL_NVIC_EnableIRQ(USART3_IRQn); |
||
| 4 | mjames | 209 | |
| 60 | mjames | 210 | /* turn on UART4 IRQ */ |
| 211 | HAL_NVIC_SetPriority(UART4_IRQn, 4, 0); |
||
| 212 | HAL_NVIC_EnableIRQ(UART4_IRQn); |
||
| 213 | |||
| 50 | mjames | 214 | /* setup the USART control blocks */ |
| 60 | mjames | 215 | init_usart_ctl(&uc1, &huart1); |
| 216 | init_usart_ctl(&uc2, &huart2); |
||
| 217 | init_usart_ctl(&uc3, &huart3); |
||
| 218 | init_usart_ctl(&uc4, &huart4); |
||
| 23 | mjames | 219 | |
| 60 | mjames | 220 | EnableSerialRxInterrupt(&uc1); |
| 221 | EnableSerialRxInterrupt(&uc2); |
||
| 222 | EnableSerialRxInterrupt(&uc3); |
||
| 223 | EnableSerialRxInterrupt(&uc4); |
||
| 23 | mjames | 224 | |
| 60 | mjames | 225 | HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_ALL); |
| 23 | mjames | 226 | |
| 60 | mjames | 227 | HAL_TIM_Encoder_Start(&htim9, TIM_CHANNEL_ALL); |
| 44 | mjames | 228 | |
| 60 | mjames | 229 | initModule(&uc3, 9600); |
| 2 | mjames | 230 | |
| 58 | mjames | 231 | // Initialise UART for 4800 baud NMEA |
| 60 | mjames | 232 | setBaud(&uc2, 4800); |
| 58 | mjames | 233 | |
| 60 | mjames | 234 | // Initialuse UART4 for 4800 baud NMEA. |
| 235 | setBaud(&uc4, 4800); |
||
| 23 | mjames | 236 | |
| 60 | mjames | 237 | cc_init(); |
| 238 | |||
| 50 | mjames | 239 | int i; |
| 240 | for (i = 0; i < 2; i++) |
||
| 60 | mjames | 241 | { |
| 242 | dial_pos[i] = 0; // default to items 0 and 1 |
||
| 243 | contexts[i].knobPos = -1; |
||
| 244 | } |
||
| 7 | mjames | 245 | |
| 50 | mjames | 246 | /* reset the display timeout, latch on power from accessories */ |
| 247 | Latch_Timer = IGNITION_OFF_TIMEOUT; |
||
| 60 | mjames | 248 | HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port, POWER_LATCH_Pin, GPIO_PIN_RESET); |
| 16 | mjames | 249 | |
| 60 | mjames | 250 | setRmcCallback(&rmc_callback); |
| 251 | |||
| 16 | mjames | 252 | /* USER CODE END 2 */ |
| 7 | mjames | 253 | |
| 16 | mjames | 254 | /* Infinite loop */ |
| 255 | /* USER CODE BEGIN WHILE */ |
||
| 52 | mjames | 256 | while (1) |
| 60 | mjames | 257 | { |
| 258 | |||
| 259 | /* while ignition is on, keep resetting power latch timer */ |
||
| 260 | if (HAL_GPIO_ReadPin(IGNITION_GPIO_Port, IGNITION_Pin) == GPIO_PIN_RESET) |
||
| 52 | mjames | 261 | { |
| 60 | mjames | 262 | Latch_Timer = HAL_GetTick() + IGNITION_OFF_TIMEOUT; |
| 263 | } |
||
| 264 | else |
||
| 265 | { |
||
| 266 | /* if the ignition has been off for a while, then turn off power */ |
||
| 267 | if (HAL_GetTick() > Latch_Timer) |
||
| 268 | { |
||
| 269 | HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port, POWER_LATCH_Pin, |
||
| 270 | GPIO_PIN_RESET); |
||
| 271 | } |
||
| 272 | } |
||
| 7 | mjames | 273 | |
| 60 | mjames | 274 | uint32_t timeout = 0; // |
| 58 | mjames | 275 | |
| 62 | mjames | 276 | uint32_t nextTick = 0; |
| 60 | mjames | 277 | uint8_t log = 0; |
| 62 | mjames | 278 | uint8_t logCount = 1000 / LOGGER_INTERVAL; |
| 60 | mjames | 279 | // PLX decoder protocols |
| 280 | char PLXPacket = 0; |
||
| 281 | for (i = 0; i < MAXRDG; i++) |
||
| 282 | { |
||
| 283 | Info[i].Max = 0; |
||
| 284 | Info[i].Min = 0xFFF; // 12 bit max value |
||
| 62 | mjames | 285 | Info[i].sum = 0; // |
| 286 | Info[i].count=0; |
||
| 60 | mjames | 287 | } |
| 58 | mjames | 288 | |
| 60 | mjames | 289 | int PLXPtr = 0; |
| 290 | |||
| 291 | while (1) |
||
| 292 | { |
||
| 293 | |||
| 294 | // poll GPS Position/time on UART4 |
||
| 62 | mjames | 295 | (void)updateLocation(&loc, &uc4); |
| 58 | mjames | 296 | if (loc.valid == 'V') |
| 60 | mjames | 297 | memset(loc.time, '-', 6); |
| 58 | mjames | 298 | |
| 62 | mjames | 299 | // if permitted, log data from RMC packet |
| 300 | if (rmc_length && HAL_GPIO_ReadPin(BT_STATE_GPIO_Port, BT_STATE_Pin) == GPIO_PIN_SET) |
||
| 301 | { |
||
| 302 | sendString(&uc3, rmc_buff, rmc_length); |
||
| 303 | rmc_length = 0; |
||
| 304 | nextTick = HAL_GetTick() + LOGGER_INTERVAL; |
||
| 305 | logCount = 0; |
||
| 306 | log = 1; |
||
| 307 | } |
||
| 308 | |||
| 309 | // time several counted logger intervals after RMC recieved, enable logger each timeout. |
||
| 310 | if (logCount < ((1000 / LOGGER_INTERVAL)-1) && HAL_GetTick() > nextTick) |
||
| 311 | { |
||
| 312 | nextTick = HAL_GetTick() + LOGGER_INTERVAL; |
||
| 313 | ++logCount; |
||
| 314 | log = 1; |
||
| 315 | } |
||
| 316 | |||
| 60 | mjames | 317 | // Handle the bluetooth pairing / reset function by pressing both buttons. |
| 318 | if ((push_pos[0] == 1) && (push_pos[1] == 1)) |
||
| 319 | { |
||
| 320 | HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, |
||
| 321 | GPIO_PIN_RESET); |
||
| 322 | } |
||
| 52 | mjames | 323 | else |
| 60 | mjames | 324 | { |
| 325 | HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, |
||
| 326 | GPIO_PIN_SET); |
||
| 327 | } |
||
| 27 | mjames | 328 | |
| 60 | mjames | 329 | uint16_t cc = SerialCharsReceived(&uc1); |
| 330 | int chr; |
||
| 331 | if (cc == 0) |
||
| 332 | { |
||
| 333 | timeout++; |
||
| 334 | if (timeout % 1000 == 0) |
||
| 335 | { |
||
| 336 | const char msg[] = "Timeout\r\n"; |
||
| 337 | sendString(&uc3, msg, sizeof(msg)); |
||
| 338 | } |
||
| 27 | mjames | 339 | |
| 60 | mjames | 340 | if (timeout > 60000) |
| 341 | { |
||
| 27 | mjames | 342 | |
| 60 | mjames | 343 | // do turn off screen |
| 344 | } |
||
| 345 | } |
||
| 62 | mjames | 346 | |
| 347 | |||
| 60 | mjames | 348 | for (chr = 0; chr < cc; chr++) |
| 349 | { |
||
| 350 | char c = GetCharSerial(&uc1); |
||
| 24 | mjames | 351 | |
| 60 | mjames | 352 | if (c == PLX_Start) // at any time if the start byte appears, reset the pointers |
| 353 | { |
||
| 354 | PLXPtr = 0; // reset the pointer |
||
| 355 | PLXPacket = 1; |
||
| 356 | timeout = 0; // Reset the timer |
||
| 357 | } |
||
| 358 | else if (c == PLX_Stop) |
||
| 359 | { |
||
| 360 | if (PLXPacket) |
||
| 361 | { |
||
| 362 | // we can now decode the selected parameter |
||
| 363 | PLXItems = PLXPtr / sizeof(PLX_SensorInfo); // total |
||
| 364 | // saturate the rotary switch position |
||
| 7 | mjames | 365 | |
| 60 | mjames | 366 | // process min/max |
| 367 | for (i = 0; i < PLXItems; i++) |
||
| 368 | { |
||
| 369 | Info[i].observation = ConvPLX(Data.Sensor[i].AddrH, |
||
| 370 | Data.Sensor[i].AddrL); |
||
| 371 | Info[i].instance = Data.Sensor[i].Instance; |
||
| 372 | Info[i].data = ConvPLX(Data.Sensor[i].ReadingH, |
||
| 373 | Data.Sensor[i].ReadingL); |
||
| 374 | if (Info[i].data > Info[i].Max) |
||
| 375 | { |
||
| 376 | Info[i].Max = Info[i].data; |
||
| 377 | } |
||
| 378 | if (Info[i].data < Info[i].Min) |
||
| 379 | { |
||
| 380 | Info[i].Min = Info[i].data; |
||
| 381 | } |
||
| 62 | mjames | 382 | // take an avarage |
| 383 | Info[i].sum += Info[i].data; |
||
| 384 | Info[i].count ++; |
||
| 38 | mjames | 385 | |
| 62 | mjames | 386 | // Send items to BT if it is in connected state |
| 387 | if (log && HAL_GPIO_ReadPin(BT_STATE_GPIO_Port, BT_STATE_Pin) == GPIO_PIN_SET) |
||
| 60 | mjames | 388 | { |
| 38 | mjames | 389 | |
| 62 | mjames | 390 | char outbuff[100]; |
| 7 | mjames | 391 | |
| 62 | mjames | 392 | int cnt = small_sprintf(outbuff, |
| 393 | "$PLLOG,%d,%d,%d,%ld", |
||
| 394 | logCount, |
||
| 395 | Info[i].observation, |
||
| 396 | Info[i].instance, |
||
| 397 | Info[i].count==0? 0: Info[i].sum/Info[i].count); |
||
| 27 | mjames | 398 | |
| 62 | mjames | 399 | // NMEA style checksum |
| 400 | int ck; |
||
| 401 | int sum = 0; |
||
| 402 | for (ck = 1; ck < cnt; ck++) |
||
| 403 | sum += outbuff[ck]; |
||
| 404 | cnt += small_sprintf(outbuff + cnt, "*%02X\n", |
||
| 405 | sum & 0xFF); |
||
| 406 | sendString(&uc3, outbuff, cnt); |
||
| 60 | mjames | 407 | } |
| 408 | } |
||
| 62 | mjames | 409 | log = 0; |
| 410 | // now to display the information |
||
| 60 | mjames | 411 | int suppress = DisplayCurrent(0, -1); |
| 412 | DisplayCurrent(1, suppress); |
||
| 413 | } |
||
| 414 | PLXPtr = 0; |
||
| 415 | PLXPacket = 0; |
||
| 416 | } |
||
| 417 | else if (c > PLX_Stop) // illegal char, restart reading |
||
| 418 | { |
||
| 419 | PLXPacket = 0; |
||
| 420 | PLXPtr = 0; |
||
| 421 | } |
||
| 422 | else if (PLXPacket && PLXPtr < sizeof(Data.Bytes)) |
||
| 423 | { |
||
| 424 | Data.Bytes[PLXPtr++] = c; |
||
| 425 | } |
||
| 426 | } |
||
| 23 | mjames | 427 | |
| 60 | mjames | 428 | HAL_Delay(1); |
| 56 | mjames | 429 | |
| 60 | mjames | 430 | for (i = 0; i < MAX_DISPLAYS; i++) |
| 431 | { |
||
| 432 | if (dial_pos[i] < 0) |
||
| 433 | dial_pos[i] = PLXItems - 1; |
||
| 434 | if (dial_pos[i] >= PLXItems) |
||
| 435 | dial_pos[i] = 0; |
||
| 56 | mjames | 436 | |
| 60 | mjames | 437 | int prevPos = contexts[i].knobPos; |
| 438 | if (contexts[i].knobPos >= 0) |
||
| 439 | contexts[i].knobPos = dial_pos[i]; |
||
| 440 | // if the dial position was changed then reset timer |
||
| 441 | if (prevPos != contexts[i].knobPos) |
||
| 442 | contexts[i].dial_timer = DialTimeout; |
||
| 30 | mjames | 443 | |
| 60 | mjames | 444 | cc_check_nvram(i); |
| 445 | if (contexts[i].knobPos >= 0) |
||
| 446 | dial_pos[i] = contexts[i].knobPos; |
||
| 447 | } |
||
| 448 | } |
||
| 58 | mjames | 449 | /* USER CODE END WHILE */ |
| 52 | mjames | 450 | |
| 58 | mjames | 451 | /* USER CODE BEGIN 3 */ |
| 60 | mjames | 452 | } |
| 16 | mjames | 453 | /* USER CODE END 3 */ |
| 2 | mjames | 454 | } |
| 455 | |||
| 50 | mjames | 456 | /** |
| 62 | mjames | 457 | * @brief System Clock Configuration |
| 458 | * @retval None |
||
| 459 | */ |
||
| 58 | mjames | 460 | void SystemClock_Config(void) |
| 5 | mjames | 461 | { |
| 58 | mjames | 462 | RCC_OscInitTypeDef RCC_OscInitStruct = {0}; |
| 463 | RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; |
||
| 2 | mjames | 464 | |
| 50 | mjames | 465 | /** Configure the main internal regulator output voltage |
| 62 | mjames | 466 | */ |
| 29 | mjames | 467 | __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); |
| 61 | mjames | 468 | |
| 50 | mjames | 469 | /** Initializes the RCC Oscillators according to the specified parameters |
| 62 | mjames | 470 | * in the RCC_OscInitTypeDef structure. |
| 471 | */ |
||
| 44 | mjames | 472 | RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; |
| 59 | mjames | 473 | RCC_OscInitStruct.HSEState = RCC_HSE_ON; |
| 16 | mjames | 474 | RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; |
| 44 | mjames | 475 | RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; |
| 476 | RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12; |
||
| 29 | mjames | 477 | RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3; |
| 58 | mjames | 478 | if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) |
| 479 | { |
||
| 480 | Error_Handler(); |
||
| 481 | } |
||
| 61 | mjames | 482 | |
| 50 | mjames | 483 | /** Initializes the CPU, AHB and APB buses clocks |
| 62 | mjames | 484 | */ |
| 485 | RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; |
||
| 16 | mjames | 486 | RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; |
| 487 | RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; |
||
| 29 | mjames | 488 | RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; |
| 16 | mjames | 489 | RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; |
| 50 | mjames | 490 | |
| 58 | mjames | 491 | if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) |
| 492 | { |
||
| 493 | Error_Handler(); |
||
| 494 | } |
||
| 2 | mjames | 495 | } |
| 496 | |||
| 50 | mjames | 497 | /** |
| 62 | mjames | 498 | * @brief SPI1 Initialization Function |
| 499 | * @param None |
||
| 500 | * @retval None |
||
| 501 | */ |
||
| 58 | mjames | 502 | static void MX_SPI1_Init(void) |
| 5 | mjames | 503 | { |
| 2 | mjames | 504 | |
| 50 | mjames | 505 | /* USER CODE BEGIN SPI1_Init 0 */ |
| 506 | |||
| 507 | /* USER CODE END SPI1_Init 0 */ |
||
| 508 | |||
| 509 | /* USER CODE BEGIN SPI1_Init 1 */ |
||
| 510 | |||
| 511 | /* USER CODE END SPI1_Init 1 */ |
||
| 512 | /* SPI1 parameter configuration*/ |
||
| 16 | mjames | 513 | hspi1.Instance = SPI1; |
| 514 | hspi1.Init.Mode = SPI_MODE_MASTER; |
||
| 515 | hspi1.Init.Direction = SPI_DIRECTION_1LINE; |
||
| 516 | hspi1.Init.DataSize = SPI_DATASIZE_8BIT; |
||
| 517 | hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH; |
||
| 518 | hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; |
||
| 519 | hspi1.Init.NSS = SPI_NSS_SOFT; |
||
| 50 | mjames | 520 | hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; |
| 16 | mjames | 521 | hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; |
| 522 | hspi1.Init.TIMode = SPI_TIMODE_DISABLE; |
||
| 523 | hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; |
||
| 524 | hspi1.Init.CRCPolynomial = 10; |
||
| 58 | mjames | 525 | if (HAL_SPI_Init(&hspi1) != HAL_OK) |
| 526 | { |
||
| 527 | Error_Handler(); |
||
| 528 | } |
||
| 50 | mjames | 529 | /* USER CODE BEGIN SPI1_Init 2 */ |
| 2 | mjames | 530 | |
| 50 | mjames | 531 | /* USER CODE END SPI1_Init 2 */ |
| 2 | mjames | 532 | } |
| 533 | |||
| 50 | mjames | 534 | /** |
| 62 | mjames | 535 | * @brief TIM2 Initialization Function |
| 536 | * @param None |
||
| 537 | * @retval None |
||
| 538 | */ |
||
| 58 | mjames | 539 | static void MX_TIM2_Init(void) |
| 50 | mjames | 540 | { |
| 541 | |||
| 542 | /* USER CODE BEGIN TIM2_Init 0 */ |
||
| 543 | |||
| 544 | /* USER CODE END TIM2_Init 0 */ |
||
| 545 | |||
| 58 | mjames | 546 | TIM_ClockConfigTypeDef sClockSourceConfig = {0}; |
| 547 | TIM_MasterConfigTypeDef sMasterConfig = {0}; |
||
| 50 | mjames | 548 | |
| 549 | /* USER CODE BEGIN TIM2_Init 1 */ |
||
| 550 | |||
| 551 | /* USER CODE END TIM2_Init 1 */ |
||
| 552 | htim2.Instance = TIM2; |
||
| 553 | htim2.Init.Prescaler = 0; |
||
| 554 | htim2.Init.CounterMode = TIM_COUNTERMODE_UP; |
||
| 555 | htim2.Init.Period = 65535; |
||
| 556 | htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
||
| 557 | htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
||
| 58 | mjames | 558 | if (HAL_TIM_Base_Init(&htim2) != HAL_OK) |
| 559 | { |
||
| 560 | Error_Handler(); |
||
| 561 | } |
||
| 50 | mjames | 562 | sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; |
| 58 | mjames | 563 | if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) |
| 564 | { |
||
| 565 | Error_Handler(); |
||
| 566 | } |
||
| 50 | mjames | 567 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; |
| 568 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
||
| 58 | mjames | 569 | if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK) |
| 570 | { |
||
| 571 | Error_Handler(); |
||
| 572 | } |
||
| 50 | mjames | 573 | /* USER CODE BEGIN TIM2_Init 2 */ |
| 574 | |||
| 575 | /* USER CODE END TIM2_Init 2 */ |
||
| 576 | } |
||
| 577 | |||
| 578 | /** |
||
| 62 | mjames | 579 | * @brief TIM3 Initialization Function |
| 580 | * @param None |
||
| 581 | * @retval None |
||
| 582 | */ |
||
| 58 | mjames | 583 | static void MX_TIM3_Init(void) |
| 44 | mjames | 584 | { |
| 585 | |||
| 50 | mjames | 586 | /* USER CODE BEGIN TIM3_Init 0 */ |
| 44 | mjames | 587 | |
| 50 | mjames | 588 | /* USER CODE END TIM3_Init 0 */ |
| 589 | |||
| 58 | mjames | 590 | TIM_Encoder_InitTypeDef sConfig = {0}; |
| 591 | TIM_MasterConfigTypeDef sMasterConfig = {0}; |
||
| 50 | mjames | 592 | |
| 593 | /* USER CODE BEGIN TIM3_Init 1 */ |
||
| 594 | |||
| 595 | /* USER CODE END TIM3_Init 1 */ |
||
| 44 | mjames | 596 | htim3.Instance = TIM3; |
| 597 | htim3.Init.Prescaler = 0; |
||
| 598 | htim3.Init.CounterMode = TIM_COUNTERMODE_UP; |
||
| 50 | mjames | 599 | htim3.Init.Period = 65535; |
| 600 | htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
||
| 601 | htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
||
| 44 | mjames | 602 | sConfig.EncoderMode = TIM_ENCODERMODE_TI1; |
| 50 | mjames | 603 | sConfig.IC1Polarity = TIM_ICPOLARITY_RISING; |
| 44 | mjames | 604 | sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI; |
| 605 | sConfig.IC1Prescaler = TIM_ICPSC_DIV1; |
||
| 606 | sConfig.IC1Filter = 15; |
||
| 50 | mjames | 607 | sConfig.IC2Polarity = TIM_ICPOLARITY_RISING; |
| 44 | mjames | 608 | sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI; |
| 609 | sConfig.IC2Prescaler = TIM_ICPSC_DIV1; |
||
| 610 | sConfig.IC2Filter = 15; |
||
| 58 | mjames | 611 | if (HAL_TIM_Encoder_Init(&htim3, &sConfig) != HAL_OK) |
| 612 | { |
||
| 613 | Error_Handler(); |
||
| 614 | } |
||
| 44 | mjames | 615 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; |
| 616 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
||
| 58 | mjames | 617 | if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK) |
| 618 | { |
||
| 619 | Error_Handler(); |
||
| 620 | } |
||
| 50 | mjames | 621 | /* USER CODE BEGIN TIM3_Init 2 */ |
| 44 | mjames | 622 | |
| 50 | mjames | 623 | /* USER CODE END TIM3_Init 2 */ |
| 44 | mjames | 624 | } |
| 625 | |||
| 50 | mjames | 626 | /** |
| 62 | mjames | 627 | * @brief TIM9 Initialization Function |
| 628 | * @param None |
||
| 629 | * @retval None |
||
| 630 | */ |
||
| 58 | mjames | 631 | static void MX_TIM9_Init(void) |
| 44 | mjames | 632 | { |
| 633 | |||
| 50 | mjames | 634 | /* USER CODE BEGIN TIM9_Init 0 */ |
| 44 | mjames | 635 | |
| 50 | mjames | 636 | /* USER CODE END TIM9_Init 0 */ |
| 637 | |||
| 58 | mjames | 638 | TIM_Encoder_InitTypeDef sConfig = {0}; |
| 639 | TIM_MasterConfigTypeDef sMasterConfig = {0}; |
||
| 50 | mjames | 640 | |
| 641 | /* USER CODE BEGIN TIM9_Init 1 */ |
||
| 642 | |||
| 643 | /* USER CODE END TIM9_Init 1 */ |
||
| 44 | mjames | 644 | htim9.Instance = TIM9; |
| 645 | htim9.Init.Prescaler = 0; |
||
| 646 | htim9.Init.CounterMode = TIM_COUNTERMODE_UP; |
||
| 50 | mjames | 647 | htim9.Init.Period = 65535; |
| 648 | htim9.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; |
||
| 649 | htim9.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; |
||
| 44 | mjames | 650 | sConfig.EncoderMode = TIM_ENCODERMODE_TI1; |
| 50 | mjames | 651 | sConfig.IC1Polarity = TIM_ICPOLARITY_RISING; |
| 44 | mjames | 652 | sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI; |
| 653 | sConfig.IC1Prescaler = TIM_ICPSC_DIV1; |
||
| 654 | sConfig.IC1Filter = 15; |
||
| 50 | mjames | 655 | sConfig.IC2Polarity = TIM_ICPOLARITY_RISING; |
| 44 | mjames | 656 | sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI; |
| 657 | sConfig.IC2Prescaler = TIM_ICPSC_DIV1; |
||
| 50 | mjames | 658 | sConfig.IC2Filter = 0; |
| 58 | mjames | 659 | if (HAL_TIM_Encoder_Init(&htim9, &sConfig) != HAL_OK) |
| 660 | { |
||
| 661 | Error_Handler(); |
||
| 662 | } |
||
| 44 | mjames | 663 | sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; |
| 664 | sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; |
||
| 58 | mjames | 665 | if (HAL_TIMEx_MasterConfigSynchronization(&htim9, &sMasterConfig) != HAL_OK) |
| 666 | { |
||
| 667 | Error_Handler(); |
||
| 668 | } |
||
| 50 | mjames | 669 | /* USER CODE BEGIN TIM9_Init 2 */ |
| 44 | mjames | 670 | |
| 50 | mjames | 671 | /* USER CODE END TIM9_Init 2 */ |
| 60 | mjames | 672 | } |
| 50 | mjames | 673 | |
| 60 | mjames | 674 | /** |
| 62 | mjames | 675 | * @brief UART4 Initialization Function |
| 676 | * @param None |
||
| 677 | * @retval None |
||
| 678 | */ |
||
| 60 | mjames | 679 | static void MX_UART4_Init(void) |
| 680 | { |
||
| 681 | |||
| 682 | /* USER CODE BEGIN UART4_Init 0 */ |
||
| 683 | |||
| 684 | /* USER CODE END UART4_Init 0 */ |
||
| 685 | |||
| 686 | /* USER CODE BEGIN UART4_Init 1 */ |
||
| 687 | |||
| 688 | /* USER CODE END UART4_Init 1 */ |
||
| 689 | huart4.Instance = UART4; |
||
| 690 | huart4.Init.BaudRate = 4800; |
||
| 691 | huart4.Init.WordLength = UART_WORDLENGTH_8B; |
||
| 692 | huart4.Init.StopBits = UART_STOPBITS_1; |
||
| 693 | huart4.Init.Parity = UART_PARITY_NONE; |
||
| 694 | huart4.Init.Mode = UART_MODE_TX_RX; |
||
| 695 | huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
||
| 696 | huart4.Init.OverSampling = UART_OVERSAMPLING_16; |
||
| 697 | if (HAL_UART_Init(&huart4) != HAL_OK) |
||
| 698 | { |
||
| 699 | Error_Handler(); |
||
| 700 | } |
||
| 701 | /* USER CODE BEGIN UART4_Init 2 */ |
||
| 702 | |||
| 703 | /* USER CODE END UART4_Init 2 */ |
||
| 44 | mjames | 704 | } |
| 705 | |||
| 50 | mjames | 706 | /** |
| 62 | mjames | 707 | * @brief USART1 Initialization Function |
| 708 | * @param None |
||
| 709 | * @retval None |
||
| 710 | */ |
||
| 58 | mjames | 711 | static void MX_USART1_UART_Init(void) |
| 5 | mjames | 712 | { |
| 3 | mjames | 713 | |
| 50 | mjames | 714 | /* USER CODE BEGIN USART1_Init 0 */ |
| 715 | |||
| 716 | /* USER CODE END USART1_Init 0 */ |
||
| 717 | |||
| 718 | /* USER CODE BEGIN USART1_Init 1 */ |
||
| 719 | |||
| 720 | /* USER CODE END USART1_Init 1 */ |
||
| 16 | mjames | 721 | huart1.Instance = USART1; |
| 722 | huart1.Init.BaudRate = 19200; |
||
| 723 | huart1.Init.WordLength = UART_WORDLENGTH_8B; |
||
| 44 | mjames | 724 | huart1.Init.StopBits = UART_STOPBITS_1; |
| 16 | mjames | 725 | huart1.Init.Parity = UART_PARITY_NONE; |
| 726 | huart1.Init.Mode = UART_MODE_TX_RX; |
||
| 727 | huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
||
| 728 | huart1.Init.OverSampling = UART_OVERSAMPLING_16; |
||
| 58 | mjames | 729 | if (HAL_UART_Init(&huart1) != HAL_OK) |
| 730 | { |
||
| 731 | Error_Handler(); |
||
| 732 | } |
||
| 50 | mjames | 733 | /* USER CODE BEGIN USART1_Init 2 */ |
| 3 | mjames | 734 | |
| 50 | mjames | 735 | /* USER CODE END USART1_Init 2 */ |
| 3 | mjames | 736 | } |
| 737 | |||
| 50 | mjames | 738 | /** |
| 62 | mjames | 739 | * @brief USART2 Initialization Function |
| 740 | * @param None |
||
| 741 | * @retval None |
||
| 742 | */ |
||
| 58 | mjames | 743 | static void MX_USART2_UART_Init(void) |
| 5 | mjames | 744 | { |
| 2 | mjames | 745 | |
| 50 | mjames | 746 | /* USER CODE BEGIN USART2_Init 0 */ |
| 747 | |||
| 748 | /* USER CODE END USART2_Init 0 */ |
||
| 749 | |||
| 750 | /* USER CODE BEGIN USART2_Init 1 */ |
||
| 751 | |||
| 752 | /* USER CODE END USART2_Init 1 */ |
||
| 16 | mjames | 753 | huart2.Instance = USART2; |
| 754 | huart2.Init.BaudRate = 115200; |
||
| 755 | huart2.Init.WordLength = UART_WORDLENGTH_8B; |
||
| 756 | huart2.Init.StopBits = UART_STOPBITS_1; |
||
| 757 | huart2.Init.Parity = UART_PARITY_NONE; |
||
| 758 | huart2.Init.Mode = UART_MODE_TX_RX; |
||
| 759 | huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
||
| 760 | huart2.Init.OverSampling = UART_OVERSAMPLING_16; |
||
| 58 | mjames | 761 | if (HAL_UART_Init(&huart2) != HAL_OK) |
| 762 | { |
||
| 763 | Error_Handler(); |
||
| 764 | } |
||
| 50 | mjames | 765 | /* USER CODE BEGIN USART2_Init 2 */ |
| 2 | mjames | 766 | |
| 50 | mjames | 767 | /* USER CODE END USART2_Init 2 */ |
| 2 | mjames | 768 | } |
| 769 | |||
| 50 | mjames | 770 | /** |
| 62 | mjames | 771 | * @brief USART3 Initialization Function |
| 772 | * @param None |
||
| 773 | * @retval None |
||
| 774 | */ |
||
| 58 | mjames | 775 | static void MX_USART3_UART_Init(void) |
| 23 | mjames | 776 | { |
| 777 | |||
| 50 | mjames | 778 | /* USER CODE BEGIN USART3_Init 0 */ |
| 779 | |||
| 780 | /* USER CODE END USART3_Init 0 */ |
||
| 781 | |||
| 782 | /* USER CODE BEGIN USART3_Init 1 */ |
||
| 783 | |||
| 784 | /* USER CODE END USART3_Init 1 */ |
||
| 23 | mjames | 785 | huart3.Instance = USART3; |
| 58 | mjames | 786 | huart3.Init.BaudRate = 19200; |
| 23 | mjames | 787 | huart3.Init.WordLength = UART_WORDLENGTH_8B; |
| 50 | mjames | 788 | huart3.Init.StopBits = UART_STOPBITS_1; |
| 44 | mjames | 789 | huart3.Init.Parity = UART_PARITY_NONE; |
| 23 | mjames | 790 | huart3.Init.Mode = UART_MODE_TX_RX; |
| 791 | huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE; |
||
| 792 | huart3.Init.OverSampling = UART_OVERSAMPLING_16; |
||
| 58 | mjames | 793 | if (HAL_UART_Init(&huart3) != HAL_OK) |
| 794 | { |
||
| 795 | Error_Handler(); |
||
| 796 | } |
||
| 50 | mjames | 797 | /* USER CODE BEGIN USART3_Init 2 */ |
| 23 | mjames | 798 | |
| 50 | mjames | 799 | /* USER CODE END USART3_Init 2 */ |
| 23 | mjames | 800 | } |
| 801 | |||
| 50 | mjames | 802 | /** |
| 62 | mjames | 803 | * @brief GPIO Initialization Function |
| 804 | * @param None |
||
| 805 | * @retval None |
||
| 806 | */ |
||
| 58 | mjames | 807 | static void MX_GPIO_Init(void) |
| 5 | mjames | 808 | { |
| 58 | mjames | 809 | GPIO_InitTypeDef GPIO_InitStruct = {0}; |
| 2 | mjames | 810 | |
| 16 | mjames | 811 | /* GPIO Ports Clock Enable */ |
| 29 | mjames | 812 | __HAL_RCC_GPIOH_CLK_ENABLE(); |
| 813 | __HAL_RCC_GPIOA_CLK_ENABLE(); |
||
| 814 | __HAL_RCC_GPIOC_CLK_ENABLE(); |
||
| 815 | __HAL_RCC_GPIOB_CLK_ENABLE(); |
||
| 2 | mjames | 816 | |
| 16 | mjames | 817 | /*Configure GPIO pin Output Level */ |
| 58 | mjames | 818 | HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET); |
| 2 | mjames | 819 | |
| 16 | mjames | 820 | /*Configure GPIO pin Output Level */ |
| 62 | mjames | 821 | HAL_GPIO_WritePin(GPIOA, SPI_CD_Pin | BT_BUTTON_Pin, GPIO_PIN_RESET); |
| 2 | mjames | 822 | |
| 50 | mjames | 823 | /*Configure GPIO pin Output Level */ |
| 62 | mjames | 824 | HAL_GPIO_WritePin(GPIOC, SPI_RESET_Pin | POWER_LATCH_Pin | USB_PWR_Pin, GPIO_PIN_RESET); |
| 50 | mjames | 825 | |
| 826 | /*Configure GPIO pin Output Level */ |
||
| 58 | mjames | 827 | HAL_GPIO_WritePin(SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_SET); |
| 50 | mjames | 828 | |
| 829 | /*Configure GPIO pins : SPI_NSS1_Pin SPI_CD_Pin */ |
||
| 62 | mjames | 830 | GPIO_InitStruct.Pin = SPI_NSS1_Pin | SPI_CD_Pin; |
| 16 | mjames | 831 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| 29 | mjames | 832 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 16 | mjames | 833 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
| 58 | mjames | 834 | HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); |
| 2 | mjames | 835 | |
| 24 | mjames | 836 | /*Configure GPIO pins : SPI_RESET_Pin SPI_NSS2_Pin POWER_LATCH_Pin USB_PWR_Pin */ |
| 62 | mjames | 837 | GPIO_InitStruct.Pin = SPI_RESET_Pin | SPI_NSS2_Pin | POWER_LATCH_Pin | USB_PWR_Pin; |
| 16 | mjames | 838 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
| 29 | mjames | 839 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
| 16 | mjames | 840 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
| 58 | mjames | 841 | HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); |
| 2 | mjames | 842 | |
| 61 | mjames | 843 | /*Configure GPIO pins : BT_STATE_Pin SW1_PUSH_Pin SW2_PUSH_Pin */ |
| 62 | mjames | 844 | GPIO_InitStruct.Pin = BT_STATE_Pin | SW1_PUSH_Pin | SW2_PUSH_Pin; |
| 16 | mjames | 845 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
| 32 | mjames | 846 | GPIO_InitStruct.Pull = GPIO_PULLUP; |
| 58 | mjames | 847 | HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); |
| 5 | mjames | 848 | |
| 32 | mjames | 849 | /*Configure GPIO pin : IGNITION_Pin */ |
| 850 | GPIO_InitStruct.Pin = IGNITION_Pin; |
||
| 851 | GPIO_InitStruct.Mode = GPIO_MODE_INPUT; |
||
| 852 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
| 58 | mjames | 853 | HAL_GPIO_Init(IGNITION_GPIO_Port, &GPIO_InitStruct); |
| 32 | mjames | 854 | |
| 37 | mjames | 855 | /*Configure GPIO pin : BT_BUTTON_Pin */ |
| 856 | GPIO_InitStruct.Pin = BT_BUTTON_Pin; |
||
| 857 | GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; |
||
| 858 | GPIO_InitStruct.Pull = GPIO_NOPULL; |
||
| 859 | GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
||
| 58 | mjames | 860 | HAL_GPIO_Init(BT_BUTTON_GPIO_Port, &GPIO_InitStruct); |
| 2 | mjames | 861 | } |
| 862 | |||
| 863 | /* USER CODE BEGIN 4 */ |
||
| 864 | |||
| 865 | /* USER CODE END 4 */ |
||
| 866 | |||
| 5 | mjames | 867 | /** |
| 62 | mjames | 868 | * @brief This function is executed in case of error occurrence. |
| 869 | * @retval None |
||
| 870 | */ |
||
| 58 | mjames | 871 | void Error_Handler(void) |
| 5 | mjames | 872 | { |
| 50 | mjames | 873 | /* USER CODE BEGIN Error_Handler_Debug */ |
| 874 | /* User can add his own implementation to report the HAL error return state */ |
||
| 875 | |||
| 876 | /* USER CODE END Error_Handler_Debug */ |
||
| 30 | mjames | 877 | } |
| 5 | mjames | 878 | |
| 62 | mjames | 879 | #ifdef USE_FULL_ASSERT |
| 2 | mjames | 880 | /** |
| 62 | mjames | 881 | * @brief Reports the name of the source file and the source line number |
| 882 | * where the assert_param error has occurred. |
||
| 883 | * @param file: pointer to the source file name |
||
| 884 | * @param line: assert_param error line source number |
||
| 885 | * @retval None |
||
| 886 | */ |
||
| 50 | mjames | 887 | void assert_failed(uint8_t *file, uint32_t line) |
| 29 | mjames | 888 | { |
| 889 | /* USER CODE BEGIN 6 */ |
||
| 50 | mjames | 890 | /* User can add his own implementation to report the file name and line number, |
| 891 | tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ |
||
| 29 | mjames | 892 | /* USER CODE END 6 */ |
| 893 | } |
||
| 50 | mjames | 894 | #endif /* USE_FULL_ASSERT */ |