Subversion Repositories DashDisplay

Rev

Rev 72 | Rev 74 | Go to most recent revision | Details | Compare with Previous | 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>&copy; 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"
65 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 ---------------------------------------------------------*/
65 mjames 50
I2C_HandleTypeDef hi2c1;
51
 
62 mjames 52
SPI_HandleTypeDef hspi1;
2 mjames 53
 
50 mjames 54
TIM_HandleTypeDef htim2;
44 mjames 55
TIM_HandleTypeDef htim3;
56
TIM_HandleTypeDef htim9;
57
 
60 mjames 58
UART_HandleTypeDef huart4;
3 mjames 59
UART_HandleTypeDef huart1;
2 mjames 60
UART_HandleTypeDef huart2;
23 mjames 61
UART_HandleTypeDef huart3;
2 mjames 62
 
63
/* USER CODE BEGIN PV */
64
/* Private variables ---------------------------------------------------------*/
65
 
50 mjames 66
context_t contexts[MAX_DISPLAYS];
67
 
70 mjames 68
///@brief  timeout when the ignition is switched off
24 mjames 69
#define IGNITION_OFF_TIMEOUT 30000UL
70
 
70 mjames 71
/// @brief 1000mS per logger period, print average per period
73 mjames 72
#define LOGGER_INTERVAL 500UL
14 mjames 73
 
70 mjames 74
/// @brief  about 10 seconds after twiddle, save the dial position.
75
const int DialTimeout = 100;
18 mjames 76
 
70 mjames 77
/// @brief Data storage for readings
56 mjames 78
info_t Info[MAXRDG];
79
 
70 mjames 80
/// @brief Define a null item
81
const info_t nullInfo = {.Max = 0,
82
                         .Min = 0xFFF,
83
                         .sum = 0,
84
                         .count = 0,
85
                         .updated = 0,
86
                         .lastUpdated = 0,
87
                         .observation = PLX_MAX_OBS,
88
                         .instance = PLX_MAX_INST};
89
 
56 mjames 90
/// \brief storage for incoming data
50 mjames 91
data_t Data;
56 mjames 92
 
27 mjames 93
uint32_t Latch_Timer = IGNITION_OFF_TIMEOUT;
24 mjames 94
 
58 mjames 95
// location for GPS data
96
Location loc;
97
 
2 mjames 98
/* USER CODE END PV */
99
 
100
/* Private function prototypes -----------------------------------------------*/
58 mjames 101
void SystemClock_Config(void);
102
static void MX_GPIO_Init(void);
103
static void MX_SPI1_Init(void);
104
static void MX_USART1_UART_Init(void);
105
static void MX_USART2_UART_Init(void);
106
static void MX_USART3_UART_Init(void);
107
static void MX_TIM3_Init(void);
108
static void MX_TIM9_Init(void);
109
static void MX_TIM2_Init(void);
60 mjames 110
static void MX_UART4_Init(void);
65 mjames 111
static void MX_I2C1_Init(void);
2 mjames 112
/* USER CODE BEGIN PFP */
113
 
7 mjames 114
// the dial is the switch number we are using.
115
// suppress is the ItemIndex we wish to suppress on this display
60 mjames 116
int DisplayCurrent(int dial, int suppress)
7 mjames 117
{
60 mjames 118
  return cc_display(dial, suppress);
50 mjames 119
}
30 mjames 120
 
70 mjames 121
/// \note  HC-05 only accepts : 9600,19200,38400,57600,115200,230400,460800 baud
56 mjames 122
/// \brief Setup Bluetooth module
60 mjames 123
void initModule(usart_ctl *ctl, uint32_t baudRate)
53 mjames 124
{
73 mjames 125
  char initBuf[60];
53 mjames 126
  // switch to command mode
73 mjames 127
  HAL_GPIO_WritePin(BT_RESET_GPIO_Port, BT_RESET_Pin, GPIO_PIN_SET);
128
  HAL_Delay(500);
129
  // clear the button press
70 mjames 130
  HAL_GPIO_WritePin(BT_RESET_GPIO_Port, BT_RESET_Pin, GPIO_PIN_RESET);
60 mjames 131
  HAL_Delay(500);
132
  setBaud(ctl, 38400);
73 mjames 133
  int initLen = small_sprintf(initBuf, "AT\nAT+UART?\nAT+UART=%ld,0,0\n", baudRate);
70 mjames 134
  const char buf[] = "AT+RESET\n";
60 mjames 135
  sendString(ctl, initBuf, initLen);
70 mjames 136
  HAL_Delay(500);
137
  initLen = small_sprintf(initBuf, buf);
138
  sendString(ctl, initBuf, initLen);
139
 
60 mjames 140
  TxWaitEmpty(ctl);
70 mjames 141
 
53 mjames 142
  // switch back to normal comms at new baud rate
60 mjames 143
  setBaud(ctl, baudRate);
144
  HAL_Delay(100);
145
}
53 mjames 146
 
60 mjames 147
// workspace for RMC data read from GPS module.
148
uint8_t rmc_buff[80];
62 mjames 149
volatile uint16_t rmc_length;
60 mjames 150
 
151
uint8_t rmc_callback(uint8_t *data, uint16_t length)
152
{
62 mjames 153
  rmc_length = length < sizeof(rmc_buff) ? length : sizeof(rmc_buff);
60 mjames 154
  memcpy(rmc_buff, data, length);
62 mjames 155
  return 0;
53 mjames 156
}
157
 
63 mjames 158
// check if bluetooth connected
159
uint8_t btConnected()
160
{
65 mjames 161
  return HAL_GPIO_ReadPin(BT_STATE_GPIO_Port, BT_STATE_Pin) == GPIO_PIN_SET;
63 mjames 162
}
163
 
70 mjames 164
/// @brief return true if this slot is unused
165
/// @param ptr pointer to the slot to
166
uint8_t isUnused(int index)
167
{
168
  if (index < 0 || index > MAXRDG)
169
    return false;
170
 
171
  return Info[index].instance == PLX_MAX_INST && Info[index].observation == PLX_MAX_OBS;
172
}
173
 
174
/// @brief Determine if an entry is currently valid
175
/// @param index the number of the array entry to display
176
/// @return true if the entry contains data which is fresh
177
uint8_t isValid(int index)
178
{
179
  if (index < 0 || index > MAXRDG)
180
    return false;
181
  if (isUnused(index))
182
    return false;
183
 
184
  uint32_t age = HAL_GetTick() - Info[index].lastUpdated;
185
 
186
  if (age > 300)
187
    return false;
188
 
189
  return true;
190
}
191
 
50 mjames 192
/* USER CODE END PFP */
14 mjames 193
 
50 mjames 194
/* Private user code ---------------------------------------------------------*/
195
/* USER CODE BEGIN 0 */
14 mjames 196
 
7 mjames 197
/* USER CODE END 0 */
2 mjames 198
 
50 mjames 199
/**
62 mjames 200
 * @brief  The application entry point.
201
 * @retval int
202
 */
58 mjames 203
int main(void)
7 mjames 204
{
16 mjames 205
  /* USER CODE BEGIN 1 */
60 mjames 206
  __HAL_RCC_SPI1_CLK_ENABLE();
207
  __HAL_RCC_USART1_CLK_ENABLE(); // PLX main port
208
  __HAL_RCC_USART2_CLK_ENABLE(); // debug port
209
  __HAL_RCC_USART3_CLK_ENABLE(); // Bluetooth port
61 mjames 210
  __HAL_RCC_UART4_CLK_ENABLE();  // NMEA0183 port
2 mjames 211
 
50 mjames 212
  __HAL_RCC_TIM3_CLK_ENABLE();
2 mjames 213
 
50 mjames 214
  __HAL_RCC_TIM9_CLK_ENABLE();
23 mjames 215
 
16 mjames 216
  /* USER CODE END 1 */
2 mjames 217
 
50 mjames 218
  /* MCU Configuration--------------------------------------------------------*/
6 mjames 219
 
16 mjames 220
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
58 mjames 221
  HAL_Init();
2 mjames 222
 
50 mjames 223
  /* USER CODE BEGIN Init */
224
 
225
  /* USER CODE END Init */
226
 
16 mjames 227
  /* Configure the system clock */
58 mjames 228
  SystemClock_Config();
2 mjames 229
 
50 mjames 230
  /* USER CODE BEGIN SysInit */
59 mjames 231
  // Switch handler called on sysTick interrupt.
60 mjames 232
  InitSwitches();
50 mjames 233
 
234
  /* USER CODE END SysInit */
235
 
16 mjames 236
  /* Initialize all configured peripherals */
58 mjames 237
  MX_GPIO_Init();
238
  MX_SPI1_Init();
239
  MX_USART1_UART_Init();
240
  MX_USART2_UART_Init();
241
  MX_USART3_UART_Init();
242
  MX_TIM3_Init();
243
  MX_TIM9_Init();
244
  MX_TIM2_Init();
60 mjames 245
  MX_UART4_Init();
65 mjames 246
  MX_I2C1_Init();
16 mjames 247
  /* USER CODE BEGIN 2 */
2 mjames 248
 
50 mjames 249
  /* Turn on USART1 IRQ */
60 mjames 250
  HAL_NVIC_SetPriority(USART1_IRQn, 2, 0);
251
  HAL_NVIC_EnableIRQ(USART1_IRQn);
4 mjames 252
 
50 mjames 253
  /* Turn on USART2 IRQ  */
60 mjames 254
  HAL_NVIC_SetPriority(USART2_IRQn, 4, 0);
255
  HAL_NVIC_EnableIRQ(USART2_IRQn);
2 mjames 256
 
50 mjames 257
  /* turn on USART3 IRQ */
60 mjames 258
  HAL_NVIC_SetPriority(USART3_IRQn, 4, 0);
259
  HAL_NVIC_EnableIRQ(USART3_IRQn);
4 mjames 260
 
60 mjames 261
  /* turn on UART4 IRQ */
262
  HAL_NVIC_SetPriority(UART4_IRQn, 4, 0);
263
  HAL_NVIC_EnableIRQ(UART4_IRQn);
264
 
50 mjames 265
  /* setup the USART control blocks */
60 mjames 266
  init_usart_ctl(&uc1, &huart1);
267
  init_usart_ctl(&uc2, &huart2);
268
  init_usart_ctl(&uc3, &huart3);
269
  init_usart_ctl(&uc4, &huart4);
23 mjames 270
 
60 mjames 271
  EnableSerialRxInterrupt(&uc1);
272
  EnableSerialRxInterrupt(&uc2);
273
  EnableSerialRxInterrupt(&uc3);
274
  EnableSerialRxInterrupt(&uc4);
23 mjames 275
 
60 mjames 276
  HAL_TIM_Encoder_Start(&htim3, TIM_CHANNEL_ALL);
23 mjames 277
 
60 mjames 278
  HAL_TIM_Encoder_Start(&htim9, TIM_CHANNEL_ALL);
44 mjames 279
 
70 mjames 280
  initModule(&uc3, 38400);
2 mjames 281
 
58 mjames 282
  // Initialise UART for 4800 baud NMEA
60 mjames 283
  setBaud(&uc2, 4800);
58 mjames 284
 
60 mjames 285
  // Initialuse UART4 for 4800 baud NMEA.
286
  setBaud(&uc4, 4800);
23 mjames 287
 
60 mjames 288
  cc_init();
289
 
50 mjames 290
  int i;
291
  for (i = 0; i < 2; i++)
60 mjames 292
  {
73 mjames 293
    contexts[i].knobPos = -1; // set the knob position
60 mjames 294
  }
7 mjames 295
 
50 mjames 296
  /* reset the display timeout, latch on power from accessories */
297
  Latch_Timer = IGNITION_OFF_TIMEOUT;
60 mjames 298
  HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port, POWER_LATCH_Pin, GPIO_PIN_RESET);
16 mjames 299
 
60 mjames 300
  setRmcCallback(&rmc_callback);
301
 
66 mjames 302
  // data timeout
303
  uint32_t timeout = 0; //
304
 
73 mjames 305
  // used in NMEA style logging
306
  uint32_t nextTick = 0;    ///< time to send next
307
  uint32_t offsetTicks = 0; ///< time to print as offset in mS for each loop
308
  //
66 mjames 309
  uint8_t log = 0;
310
  // PLX decoder protocols
311
  char PLXPacket = 0;
70 mjames 312
 
66 mjames 313
  for (i = 0; i < MAXRDG; i++)
314
  {
70 mjames 315
    Info[i] = nullInfo;
66 mjames 316
  }
317
 
318
  int PLXPtr = 0;
319
 
73 mjames 320
  uint32_t resetCounter = 0; // record time at which both reset buttons were first pressed.
70 mjames 321
 
16 mjames 322
  /* USER CODE END 2 */
7 mjames 323
 
16 mjames 324
  /* Infinite loop */
325
  /* USER CODE BEGIN WHILE */
52 mjames 326
  while (1)
60 mjames 327
  {
328
 
329
    /* while ignition is on, keep resetting power latch timer */
330
    if (HAL_GPIO_ReadPin(IGNITION_GPIO_Port, IGNITION_Pin) == GPIO_PIN_RESET)
52 mjames 331
    {
60 mjames 332
      Latch_Timer = HAL_GetTick() + IGNITION_OFF_TIMEOUT;
333
    }
334
    else
335
    {
336
      /* if the ignition has been off for a while, then turn off power */
337
      if (HAL_GetTick() > Latch_Timer)
338
      {
339
        HAL_GPIO_WritePin(POWER_LATCH_GPIO_Port, POWER_LATCH_Pin,
340
                          GPIO_PIN_RESET);
341
      }
342
    }
7 mjames 343
 
66 mjames 344
    // Handle the bluetooth pairing / reset function by pressing both buttons.
345
    if ((push_pos[0] == 1) && (push_pos[1] == 1))
60 mjames 346
    {
66 mjames 347
      HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin,
348
                        GPIO_PIN_RESET);
70 mjames 349
      if (resetCounter == 0)
350
        resetCounter = HAL_GetTick();
60 mjames 351
    }
66 mjames 352
    else
353
    {
354
      HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin,
355
                        GPIO_PIN_SET);
70 mjames 356
 
357
      if (resetCounter != 0)
358
      {
359
        // Held down reset button for 10 seconds, clear NVRAM.
360
        if ((HAL_GetTick() - resetCounter) > 10000)
361
        {
362
          for (i = 0; i < 2; i++)
363
          {
364
            contexts[i].knobPos = -1;   // set the knob position
365
            contexts[i].dial_timer = 1; // timeout immediately when decremented
366
          }
367
          erase_nvram();
368
        }
369
        resetCounter = 0;
370
      }
66 mjames 371
    }
58 mjames 372
 
66 mjames 373
    // poll GPS Position/time on UART4
374
    (void)updateLocation(&loc, &uc4);
375
    if (loc.valid == 'V')
376
      memset(loc.time, '-', 6);
60 mjames 377
 
66 mjames 378
    // if permitted, log data from RMC packet
379
    if (btConnected())
60 mjames 380
    {
66 mjames 381
      // Any RMC data, send it, reset the logger timeout
382
      if (rmc_length)
62 mjames 383
      {
66 mjames 384
        sendString(&uc3, (const char *)rmc_buff, rmc_length);
62 mjames 385
        rmc_length = 0;
73 mjames 386
        offsetTicks = 0;
62 mjames 387
        nextTick = HAL_GetTick() + LOGGER_INTERVAL;
73 mjames 388
        log = 1;
62 mjames 389
      }
65 mjames 390
 
66 mjames 391
      // Timeout for data logging regularly
392
      if (HAL_GetTick() > nextTick)
62 mjames 393
      {
73 mjames 394
        offsetTicks += LOGGER_INTERVAL;
62 mjames 395
        nextTick = HAL_GetTick() + LOGGER_INTERVAL;
73 mjames 396
        if (offsetTicks < (1000))
397
          log = 1;
62 mjames 398
      }
399
 
66 mjames 400
      if (log)
60 mjames 401
      {
66 mjames 402
        log = 0;
403
        // Send items  to BT if it is in connected state
73 mjames 404
 
405
        char linebuff[20];
406
        strftime(linebuff, sizeof(linebuff), "%H%M%S", &loc.tv);
71 mjames 407
        for (int i = 0; i < MAXRDG; ++i)
66 mjames 408
        {
71 mjames 409
          if (!isValid(i))
410
            continue;
66 mjames 411
          char outbuff[100];
412
 
413
          int cnt = small_sprintf(outbuff,
73 mjames 414
                                  "$PLLOG,%s.%03lu,%d,%d,%ld",
415
                                  linebuff,
416
                                  offsetTicks,
66 mjames 417
                                  Info[i].observation,
418
                                  Info[i].instance,
419
                                  Info[i].count == 0 ? 0 : Info[i].sum / Info[i].count);
420
 
421
          // NMEA style checksum
422
          int ck;
423
          int sum = 0;
424
          for (ck = 1; ck < cnt; ck++)
425
            sum += outbuff[ck];
426
          cnt += small_sprintf(outbuff + cnt, "*%02X\n",
427
                               sum & 0xFF);
428
          sendString(&uc3, outbuff, cnt);
429
        }
60 mjames 430
      }
66 mjames 431
    }
432
 
433
    // determine if we are getting any data from the interface
434
    uint16_t cc = SerialCharsReceived(&uc1);
435
    int chr;
436
    if (cc == 0)
437
    {
438
      timeout++;
439
      if (btConnected() && (timeout % 1000 == 0))
60 mjames 440
      {
66 mjames 441
        const char msg[] = "Timeout\r\n";
442
        sendString(&uc3, msg, sizeof(msg));
60 mjames 443
      }
27 mjames 444
 
66 mjames 445
      if (timeout > 60000)
60 mjames 446
      {
27 mjames 447
 
66 mjames 448
        // do turn off screen
60 mjames 449
      }
66 mjames 450
      // wait for a bit if nothing came in.
451
      HAL_Delay(10);
452
    }
62 mjames 453
 
66 mjames 454
    /// process the observation list
455
    for (chr = 0; chr < cc; chr++)
456
    {
68 mjames 457
      char c = GetCharSerial(&uc1);
66 mjames 458
 
459
      if (c == PLX_Start) // at any time if the start byte appears, reset the pointers
60 mjames 460
      {
66 mjames 461
        PLXPtr = 0; // reset the pointer
462
        PLXPacket = 1;
463
        timeout = 0; // Reset the timer
67 mjames 464
        continue;
66 mjames 465
      }
67 mjames 466
      if (c == PLX_Stop)
66 mjames 467
      {
468
        if (PLXPacket)
469
        {
470
          // we can now decode the selected parameter
70 mjames 471
          int PLXNewItems = PLXPtr / sizeof(PLX_SensorInfo); // total items in last reading batch
24 mjames 472
 
70 mjames 473
          // process items
474
          for (i = 0; i < PLXNewItems; i++)
60 mjames 475
          {
70 mjames 476
            // search to see if the item already has a slot in the Info[] array
477
            // match the observation and instance: if found, update entry
478
            enum PLX_Observations observation = ConvPLX(Data.Sensor[i].AddrH,
479
                                                        Data.Sensor[i].AddrL);
7 mjames 480
 
70 mjames 481
            char instance = Data.Sensor[i].Instance;
482
 
483
            // validate the current item, discard out of range
484
 
485
            if ((instance > PLX_MAX_INST) || (observation > PLX_MAX_OBS))
486
              continue;
487
 
488
            // search for the item in the list
489
            int j;
490
            for (j = 0; j < MAXRDG; ++j)
60 mjames 491
            {
70 mjames 492
              if ((Info[j].observation == observation) && (Info[j].instance == instance))
493
                break;
60 mjames 494
            }
70 mjames 495
            // fallen off the end of the list of existing items without a match, so j points at next new item
496
            //
497
            // Find an unused slot
498
 
499
            if (j == MAXRDG)
66 mjames 500
            {
70 mjames 501
              int k;
502
              {
503
                for (k = 0; k < MAXRDG; ++k)
504
                  if (!isValid(k))
505
                  {
506
                    j = k; // found a spare slot
507
                    break;
508
                  }
509
              }
510
              if (k == MAXRDG)
511
                continue; // abandon this iteration
66 mjames 512
            }
70 mjames 513
 
514
            // give up if we are going to fall off the end of the array
515
            if (j > MAXRDG)
516
              break;
517
 
518
            Info[j].observation = observation;
519
 
520
            Info[j].instance = instance;
521
            Info[j].data = ConvPLX(Data.Sensor[j].ReadingH,
522
                                   Data.Sensor[j].ReadingL);
523
            if (Info[j].data > Info[j].Max)
524
            {
525
              Info[j].Max = Info[j].data;
526
            }
527
            if (Info[j].data < Info[j].Min)
528
            {
529
              Info[j].Min = Info[j].data;
530
            }
66 mjames 531
            // take an average
70 mjames 532
            Info[j].sum += Info[j].data;
533
            Info[j].count++;
66 mjames 534
            // note the last update time
70 mjames 535
            Info[j].lastUpdated = HAL_GetTick();
536
            Info[j].updated = 1; // it has been updated
60 mjames 537
          }
538
          PLXPtr = 0;
539
          PLXPacket = 0;
70 mjames 540
 
541
          // scan through and invalidate all old items
542
          for (int i = 0; i < MAXRDG; ++i)
543
          {
544
            if (!isValid(i))
545
              Info[i] = nullInfo;
546
          }
547
 
548
          break; // something to process
60 mjames 549
        }
550
      }
67 mjames 551
      if (c > PLX_Stop) // illegal char, restart reading
552
      {
553
        PLXPacket = 0;
554
        PLXPtr = 0;
555
        continue;
556
      }
557
      if (PLXPacket && PLXPtr < sizeof(Data.Bytes))
558
      {
559
        Data.Bytes[PLXPtr++] = c;
560
      }
561
    }
71 mjames 562
 
563
    // handle switch rotation
564
    for (i = 0; i < MAX_DIALS; ++i)
565
    {
566
      int delta = get_dial_diff(i);
567
      int pos = contexts[i].knobPos;
73 mjames 568
      if (pos < 0)
569
        break; // dont process until we have read NVRAM for the first time .
71 mjames 570
      int start = pos;
571
      // move in positive direction
572
      while (delta > 0)
573
      {
574
        // skip invalid items, dont count
73 mjames 575
        if (pos < MAXRDG - 1)
71 mjames 576
          pos++;
577
        else
73 mjames 578
          pos = 0;
71 mjames 579
 
580
        if (isValid(pos))
73 mjames 581
          delta--; // count a valid item
582
 
71 mjames 583
        // wrap
584
        if (pos == start)
585
          break;
586
      }
587
 
588
      // move in negative direction
589
      while (delta < 0)
73 mjames 590
 
71 mjames 591
      {
592
        // skip invalid items, dont count
73 mjames 593
        if (pos > 0)
71 mjames 594
          pos--;
595
        else
73 mjames 596
          pos = MAXRDG - 1;
71 mjames 597
 
598
        if (isValid(pos))
73 mjames 599
          delta++; // count a valid item
600
 
71 mjames 601
        // wrap
602
        if (pos == start)
603
          break;
73 mjames 604
      }
605
 
71 mjames 606
      contexts[i].knobPos = pos;
607
      if (pos != start)
608
        contexts[i].dial_timer = DialTimeout;
609
    }
610
 
67 mjames 611
    int suppress = -1;
612
    for (i = 0; i < MAX_DISPLAYS; i++)
613
    { // now to display the information
614
      suppress = DisplayCurrent(i, suppress);
23 mjames 615
 
67 mjames 616
      cc_check_nvram(i);
60 mjames 617
    }
73 mjames 618
    /* USER CODE END WHILE */
66 mjames 619
  }
73 mjames 620
  /* USER CODE BEGIN 3 */
621
 
622
  /* USER CODE END 3 */
71 mjames 623
}
52 mjames 624
 
50 mjames 625
/**
62 mjames 626
 * @brief System Clock Configuration
627
 * @retval None
628
 */
58 mjames 629
void SystemClock_Config(void)
5 mjames 630
{
58 mjames 631
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
632
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
2 mjames 633
 
50 mjames 634
  /** Configure the main internal regulator output voltage
62 mjames 635
   */
29 mjames 636
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
61 mjames 637
 
50 mjames 638
  /** Initializes the RCC Oscillators according to the specified parameters
62 mjames 639
   * in the RCC_OscInitTypeDef structure.
640
   */
44 mjames 641
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
59 mjames 642
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
16 mjames 643
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
44 mjames 644
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
645
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL12;
29 mjames 646
  RCC_OscInitStruct.PLL.PLLDIV = RCC_PLL_DIV3;
58 mjames 647
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
648
  {
649
    Error_Handler();
650
  }
61 mjames 651
 
50 mjames 652
  /** Initializes the CPU, AHB and APB buses clocks
62 mjames 653
   */
654
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
16 mjames 655
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
656
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
29 mjames 657
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
16 mjames 658
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
50 mjames 659
 
58 mjames 660
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
661
  {
662
    Error_Handler();
663
  }
2 mjames 664
}
665
 
50 mjames 666
/**
65 mjames 667
 * @brief I2C1 Initialization Function
668
 * @param None
669
 * @retval None
670
 */
671
static void MX_I2C1_Init(void)
672
{
673
 
674
  /* USER CODE BEGIN I2C1_Init 0 */
675
 
676
  /* USER CODE END I2C1_Init 0 */
677
 
678
  /* USER CODE BEGIN I2C1_Init 1 */
679
 
680
  /* USER CODE END I2C1_Init 1 */
681
  hi2c1.Instance = I2C1;
682
  hi2c1.Init.ClockSpeed = 100000;
683
  hi2c1.Init.DutyCycle = I2C_DUTYCYCLE_2;
684
  hi2c1.Init.OwnAddress1 = 0;
685
  hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
686
  hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
687
  hi2c1.Init.OwnAddress2 = 0;
688
  hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
689
  hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
690
  if (HAL_I2C_Init(&hi2c1) != HAL_OK)
691
  {
692
    Error_Handler();
693
  }
694
  /* USER CODE BEGIN I2C1_Init 2 */
695
 
696
  /* USER CODE END I2C1_Init 2 */
697
}
698
 
699
/**
62 mjames 700
 * @brief SPI1 Initialization Function
701
 * @param None
702
 * @retval None
703
 */
58 mjames 704
static void MX_SPI1_Init(void)
5 mjames 705
{
2 mjames 706
 
50 mjames 707
  /* USER CODE BEGIN SPI1_Init 0 */
708
 
709
  /* USER CODE END SPI1_Init 0 */
710
 
711
  /* USER CODE BEGIN SPI1_Init 1 */
712
 
713
  /* USER CODE END SPI1_Init 1 */
714
  /* SPI1 parameter configuration*/
16 mjames 715
  hspi1.Instance = SPI1;
716
  hspi1.Init.Mode = SPI_MODE_MASTER;
717
  hspi1.Init.Direction = SPI_DIRECTION_1LINE;
718
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
719
  hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
720
  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
721
  hspi1.Init.NSS = SPI_NSS_SOFT;
50 mjames 722
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
16 mjames 723
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
724
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
725
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
726
  hspi1.Init.CRCPolynomial = 10;
58 mjames 727
  if (HAL_SPI_Init(&hspi1) != HAL_OK)
728
  {
729
    Error_Handler();
730
  }
50 mjames 731
  /* USER CODE BEGIN SPI1_Init 2 */
2 mjames 732
 
50 mjames 733
  /* USER CODE END SPI1_Init 2 */
2 mjames 734
}
735
 
50 mjames 736
/**
62 mjames 737
 * @brief TIM2 Initialization Function
738
 * @param None
739
 * @retval None
740
 */
58 mjames 741
static void MX_TIM2_Init(void)
50 mjames 742
{
743
 
744
  /* USER CODE BEGIN TIM2_Init 0 */
745
 
746
  /* USER CODE END TIM2_Init 0 */
747
 
58 mjames 748
  TIM_ClockConfigTypeDef sClockSourceConfig = {0};
749
  TIM_MasterConfigTypeDef sMasterConfig = {0};
50 mjames 750
 
751
  /* USER CODE BEGIN TIM2_Init 1 */
752
 
753
  /* USER CODE END TIM2_Init 1 */
754
  htim2.Instance = TIM2;
755
  htim2.Init.Prescaler = 0;
756
  htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
757
  htim2.Init.Period = 65535;
758
  htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
759
  htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
58 mjames 760
  if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
761
  {
762
    Error_Handler();
763
  }
50 mjames 764
  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
58 mjames 765
  if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
766
  {
767
    Error_Handler();
768
  }
50 mjames 769
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
770
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
58 mjames 771
  if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
772
  {
773
    Error_Handler();
774
  }
50 mjames 775
  /* USER CODE BEGIN TIM2_Init 2 */
776
 
777
  /* USER CODE END TIM2_Init 2 */
778
}
779
 
780
/**
62 mjames 781
 * @brief TIM3 Initialization Function
782
 * @param None
783
 * @retval None
784
 */
58 mjames 785
static void MX_TIM3_Init(void)
44 mjames 786
{
787
 
50 mjames 788
  /* USER CODE BEGIN TIM3_Init 0 */
44 mjames 789
 
50 mjames 790
  /* USER CODE END TIM3_Init 0 */
791
 
58 mjames 792
  TIM_Encoder_InitTypeDef sConfig = {0};
793
  TIM_MasterConfigTypeDef sMasterConfig = {0};
50 mjames 794
 
795
  /* USER CODE BEGIN TIM3_Init 1 */
796
 
797
  /* USER CODE END TIM3_Init 1 */
44 mjames 798
  htim3.Instance = TIM3;
799
  htim3.Init.Prescaler = 0;
800
  htim3.Init.CounterMode = TIM_COUNTERMODE_UP;
50 mjames 801
  htim3.Init.Period = 65535;
802
  htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
803
  htim3.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
44 mjames 804
  sConfig.EncoderMode = TIM_ENCODERMODE_TI1;
50 mjames 805
  sConfig.IC1Polarity = TIM_ICPOLARITY_RISING;
44 mjames 806
  sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI;
807
  sConfig.IC1Prescaler = TIM_ICPSC_DIV1;
808
  sConfig.IC1Filter = 15;
50 mjames 809
  sConfig.IC2Polarity = TIM_ICPOLARITY_RISING;
44 mjames 810
  sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI;
811
  sConfig.IC2Prescaler = TIM_ICPSC_DIV1;
812
  sConfig.IC2Filter = 15;
58 mjames 813
  if (HAL_TIM_Encoder_Init(&htim3, &sConfig) != HAL_OK)
814
  {
815
    Error_Handler();
816
  }
44 mjames 817
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
818
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
58 mjames 819
  if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK)
820
  {
821
    Error_Handler();
822
  }
50 mjames 823
  /* USER CODE BEGIN TIM3_Init 2 */
44 mjames 824
 
50 mjames 825
  /* USER CODE END TIM3_Init 2 */
44 mjames 826
}
827
 
50 mjames 828
/**
62 mjames 829
 * @brief TIM9 Initialization Function
830
 * @param None
831
 * @retval None
832
 */
58 mjames 833
static void MX_TIM9_Init(void)
44 mjames 834
{
835
 
50 mjames 836
  /* USER CODE BEGIN TIM9_Init 0 */
44 mjames 837
 
50 mjames 838
  /* USER CODE END TIM9_Init 0 */
839
 
58 mjames 840
  TIM_Encoder_InitTypeDef sConfig = {0};
841
  TIM_MasterConfigTypeDef sMasterConfig = {0};
50 mjames 842
 
843
  /* USER CODE BEGIN TIM9_Init 1 */
844
 
845
  /* USER CODE END TIM9_Init 1 */
44 mjames 846
  htim9.Instance = TIM9;
847
  htim9.Init.Prescaler = 0;
848
  htim9.Init.CounterMode = TIM_COUNTERMODE_UP;
50 mjames 849
  htim9.Init.Period = 65535;
850
  htim9.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
851
  htim9.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
44 mjames 852
  sConfig.EncoderMode = TIM_ENCODERMODE_TI1;
50 mjames 853
  sConfig.IC1Polarity = TIM_ICPOLARITY_RISING;
44 mjames 854
  sConfig.IC1Selection = TIM_ICSELECTION_DIRECTTI;
855
  sConfig.IC1Prescaler = TIM_ICPSC_DIV1;
856
  sConfig.IC1Filter = 15;
50 mjames 857
  sConfig.IC2Polarity = TIM_ICPOLARITY_RISING;
44 mjames 858
  sConfig.IC2Selection = TIM_ICSELECTION_DIRECTTI;
859
  sConfig.IC2Prescaler = TIM_ICPSC_DIV1;
50 mjames 860
  sConfig.IC2Filter = 0;
58 mjames 861
  if (HAL_TIM_Encoder_Init(&htim9, &sConfig) != HAL_OK)
862
  {
863
    Error_Handler();
864
  }
44 mjames 865
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
866
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
58 mjames 867
  if (HAL_TIMEx_MasterConfigSynchronization(&htim9, &sMasterConfig) != HAL_OK)
868
  {
869
    Error_Handler();
870
  }
50 mjames 871
  /* USER CODE BEGIN TIM9_Init 2 */
44 mjames 872
 
50 mjames 873
  /* USER CODE END TIM9_Init 2 */
60 mjames 874
}
50 mjames 875
 
60 mjames 876
/**
62 mjames 877
 * @brief UART4 Initialization Function
878
 * @param None
879
 * @retval None
880
 */
60 mjames 881
static void MX_UART4_Init(void)
882
{
883
 
884
  /* USER CODE BEGIN UART4_Init 0 */
885
 
886
  /* USER CODE END UART4_Init 0 */
887
 
888
  /* USER CODE BEGIN UART4_Init 1 */
889
 
890
  /* USER CODE END UART4_Init 1 */
891
  huart4.Instance = UART4;
892
  huart4.Init.BaudRate = 4800;
893
  huart4.Init.WordLength = UART_WORDLENGTH_8B;
894
  huart4.Init.StopBits = UART_STOPBITS_1;
895
  huart4.Init.Parity = UART_PARITY_NONE;
896
  huart4.Init.Mode = UART_MODE_TX_RX;
897
  huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE;
898
  huart4.Init.OverSampling = UART_OVERSAMPLING_16;
899
  if (HAL_UART_Init(&huart4) != HAL_OK)
900
  {
901
    Error_Handler();
902
  }
903
  /* USER CODE BEGIN UART4_Init 2 */
904
 
905
  /* USER CODE END UART4_Init 2 */
44 mjames 906
}
907
 
50 mjames 908
/**
62 mjames 909
 * @brief USART1 Initialization Function
910
 * @param None
911
 * @retval None
912
 */
58 mjames 913
static void MX_USART1_UART_Init(void)
5 mjames 914
{
3 mjames 915
 
50 mjames 916
  /* USER CODE BEGIN USART1_Init 0 */
917
 
918
  /* USER CODE END USART1_Init 0 */
919
 
920
  /* USER CODE BEGIN USART1_Init 1 */
921
 
922
  /* USER CODE END USART1_Init 1 */
16 mjames 923
  huart1.Instance = USART1;
924
  huart1.Init.BaudRate = 19200;
925
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
44 mjames 926
  huart1.Init.StopBits = UART_STOPBITS_1;
16 mjames 927
  huart1.Init.Parity = UART_PARITY_NONE;
928
  huart1.Init.Mode = UART_MODE_TX_RX;
929
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
930
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
58 mjames 931
  if (HAL_UART_Init(&huart1) != HAL_OK)
932
  {
933
    Error_Handler();
934
  }
50 mjames 935
  /* USER CODE BEGIN USART1_Init 2 */
3 mjames 936
 
50 mjames 937
  /* USER CODE END USART1_Init 2 */
3 mjames 938
}
939
 
50 mjames 940
/**
62 mjames 941
 * @brief USART2 Initialization Function
942
 * @param None
943
 * @retval None
944
 */
58 mjames 945
static void MX_USART2_UART_Init(void)
5 mjames 946
{
2 mjames 947
 
50 mjames 948
  /* USER CODE BEGIN USART2_Init 0 */
949
 
950
  /* USER CODE END USART2_Init 0 */
951
 
952
  /* USER CODE BEGIN USART2_Init 1 */
953
 
954
  /* USER CODE END USART2_Init 1 */
16 mjames 955
  huart2.Instance = USART2;
956
  huart2.Init.BaudRate = 115200;
957
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
958
  huart2.Init.StopBits = UART_STOPBITS_1;
959
  huart2.Init.Parity = UART_PARITY_NONE;
960
  huart2.Init.Mode = UART_MODE_TX_RX;
961
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
962
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
58 mjames 963
  if (HAL_UART_Init(&huart2) != HAL_OK)
964
  {
965
    Error_Handler();
966
  }
50 mjames 967
  /* USER CODE BEGIN USART2_Init 2 */
2 mjames 968
 
50 mjames 969
  /* USER CODE END USART2_Init 2 */
2 mjames 970
}
971
 
50 mjames 972
/**
62 mjames 973
 * @brief USART3 Initialization Function
974
 * @param None
975
 * @retval None
976
 */
58 mjames 977
static void MX_USART3_UART_Init(void)
23 mjames 978
{
979
 
50 mjames 980
  /* USER CODE BEGIN USART3_Init 0 */
981
 
982
  /* USER CODE END USART3_Init 0 */
983
 
984
  /* USER CODE BEGIN USART3_Init 1 */
985
 
986
  /* USER CODE END USART3_Init 1 */
23 mjames 987
  huart3.Instance = USART3;
58 mjames 988
  huart3.Init.BaudRate = 19200;
23 mjames 989
  huart3.Init.WordLength = UART_WORDLENGTH_8B;
50 mjames 990
  huart3.Init.StopBits = UART_STOPBITS_1;
44 mjames 991
  huart3.Init.Parity = UART_PARITY_NONE;
23 mjames 992
  huart3.Init.Mode = UART_MODE_TX_RX;
993
  huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
994
  huart3.Init.OverSampling = UART_OVERSAMPLING_16;
58 mjames 995
  if (HAL_UART_Init(&huart3) != HAL_OK)
996
  {
997
    Error_Handler();
998
  }
50 mjames 999
  /* USER CODE BEGIN USART3_Init 2 */
23 mjames 1000
 
50 mjames 1001
  /* USER CODE END USART3_Init 2 */
23 mjames 1002
}
1003
 
50 mjames 1004
/**
62 mjames 1005
 * @brief GPIO Initialization Function
1006
 * @param None
1007
 * @retval None
1008
 */
58 mjames 1009
static void MX_GPIO_Init(void)
5 mjames 1010
{
58 mjames 1011
  GPIO_InitTypeDef GPIO_InitStruct = {0};
2 mjames 1012
 
16 mjames 1013
  /* GPIO Ports Clock Enable */
29 mjames 1014
  __HAL_RCC_GPIOH_CLK_ENABLE();
1015
  __HAL_RCC_GPIOA_CLK_ENABLE();
1016
  __HAL_RCC_GPIOC_CLK_ENABLE();
1017
  __HAL_RCC_GPIOB_CLK_ENABLE();
2 mjames 1018
 
16 mjames 1019
  /*Configure GPIO pin Output Level */
73 mjames 1020
  HAL_GPIO_WritePin(GPIOA, SPI_NSS1_Pin | BT_BUTTON_Pin | BT_RESET_Pin, GPIO_PIN_SET);
2 mjames 1021
 
16 mjames 1022
  /*Configure GPIO pin Output Level */
73 mjames 1023
  HAL_GPIO_WritePin(SPI_CD_GPIO_Port, SPI_CD_Pin, GPIO_PIN_RESET);
2 mjames 1024
 
50 mjames 1025
  /*Configure GPIO pin Output Level */
62 mjames 1026
  HAL_GPIO_WritePin(GPIOC, SPI_RESET_Pin | POWER_LATCH_Pin | USB_PWR_Pin, GPIO_PIN_RESET);
50 mjames 1027
 
1028
  /*Configure GPIO pin Output Level */
58 mjames 1029
  HAL_GPIO_WritePin(SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_SET);
50 mjames 1030
 
1031
  /*Configure GPIO pins : SPI_NSS1_Pin SPI_CD_Pin */
62 mjames 1032
  GPIO_InitStruct.Pin = SPI_NSS1_Pin | SPI_CD_Pin;
16 mjames 1033
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
29 mjames 1034
  GPIO_InitStruct.Pull = GPIO_NOPULL;
16 mjames 1035
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
58 mjames 1036
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
2 mjames 1037
 
24 mjames 1038
  /*Configure GPIO pins : SPI_RESET_Pin SPI_NSS2_Pin POWER_LATCH_Pin USB_PWR_Pin */
62 mjames 1039
  GPIO_InitStruct.Pin = SPI_RESET_Pin | SPI_NSS2_Pin | POWER_LATCH_Pin | USB_PWR_Pin;
16 mjames 1040
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
29 mjames 1041
  GPIO_InitStruct.Pull = GPIO_NOPULL;
16 mjames 1042
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
58 mjames 1043
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
2 mjames 1044
 
61 mjames 1045
  /*Configure GPIO pins : BT_STATE_Pin SW1_PUSH_Pin SW2_PUSH_Pin */
62 mjames 1046
  GPIO_InitStruct.Pin = BT_STATE_Pin | SW1_PUSH_Pin | SW2_PUSH_Pin;
16 mjames 1047
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
32 mjames 1048
  GPIO_InitStruct.Pull = GPIO_PULLUP;
58 mjames 1049
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
5 mjames 1050
 
32 mjames 1051
  /*Configure GPIO pin : IGNITION_Pin */
1052
  GPIO_InitStruct.Pin = IGNITION_Pin;
1053
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
1054
  GPIO_InitStruct.Pull = GPIO_NOPULL;
58 mjames 1055
  HAL_GPIO_Init(IGNITION_GPIO_Port, &GPIO_InitStruct);
32 mjames 1056
 
73 mjames 1057
  /*Configure GPIO pin : BT_BUTTON_Pin */
1058
  GPIO_InitStruct.Pin = BT_BUTTON_Pin;
37 mjames 1059
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
73 mjames 1060
  GPIO_InitStruct.Pull = GPIO_PULLUP;
1061
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
1062
  HAL_GPIO_Init(BT_BUTTON_GPIO_Port, &GPIO_InitStruct);
1063
 
1064
  /*Configure GPIO pin : BT_RESET_Pin */
1065
  GPIO_InitStruct.Pin = BT_RESET_Pin;
1066
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
37 mjames 1067
  GPIO_InitStruct.Pull = GPIO_NOPULL;
73 mjames 1068
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
1069
  HAL_GPIO_Init(BT_RESET_GPIO_Port, &GPIO_InitStruct);
2 mjames 1070
}
1071
 
1072
/* USER CODE BEGIN 4 */
1073
 
1074
/* USER CODE END 4 */
1075
 
5 mjames 1076
/**
62 mjames 1077
 * @brief  This function is executed in case of error occurrence.
1078
 * @retval None
1079
 */
58 mjames 1080
void Error_Handler(void)
5 mjames 1081
{
50 mjames 1082
  /* USER CODE BEGIN Error_Handler_Debug */
1083
  /* User can add his own implementation to report the HAL error return state */
1084
 
1085
  /* USER CODE END Error_Handler_Debug */
30 mjames 1086
}
5 mjames 1087
 
62 mjames 1088
#ifdef USE_FULL_ASSERT
2 mjames 1089
/**
62 mjames 1090
 * @brief  Reports the name of the source file and the source line number
1091
 *         where the assert_param error has occurred.
1092
 * @param  file: pointer to the source file name
1093
 * @param  line: assert_param error line source number
1094
 * @retval None
1095
 */
50 mjames 1096
void assert_failed(uint8_t *file, uint32_t line)
29 mjames 1097
{
1098
  /* USER CODE BEGIN 6 */
50 mjames 1099
  /* User can add his own implementation to report the file name and line number,
1100
     tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
29 mjames 1101
  /* USER CODE END 6 */
1102
}
50 mjames 1103
#endif /* USE_FULL_ASSERT */