Subversion Repositories DashDisplay

Rev

Rev 22 | Rev 24 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 mjames 1
/**
16 mjames 2
  ******************************************************************************
3
  * File Name          : main.c
4
  * Description        : Main program body
5
  ******************************************************************************
6
  *
23 mjames 7
  * COPYRIGHT(c) 2017 STMicroelectronics
16 mjames 8
  *
9
  * Redistribution and use in source and binary forms, with or without modification,
10
  * are permitted provided that the following conditions are met:
11
  *   1. Redistributions of source code must retain the above copyright notice,
12
  *      this list of conditions and the following disclaimer.
13
  *   2. Redistributions in binary form must reproduce the above copyright notice,
14
  *      this list of conditions and the following disclaimer in the documentation
15
  *      and/or other materials provided with the distribution.
16
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
17
  *      may be used to endorse or promote products derived from this software
18
  *      without specific prior written permission.
19
  *
20
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
  *
31
  ******************************************************************************
32
  */
2 mjames 33
/* Includes ------------------------------------------------------------------*/
34
#include "stm32f1xx_hal.h"
35
 
36
/* USER CODE BEGIN Includes */
37
#include "ap_math.h"
38
#include "serial.h"
39
#include "SSD1306.h"
7 mjames 40
#include "Font.h"
2 mjames 41
#include "dials.h"
4 mjames 42
#include "switches.h"
2 mjames 43
#include <math.h>
4 mjames 44
#include "plx.h"
16 mjames 45
#include "eeprom.h"
20 mjames 46
#include "displayinfo.h"
2 mjames 47
 
48
/* USER CODE END Includes */
49
 
50
/* Private variables ---------------------------------------------------------*/
51
SPI_HandleTypeDef hspi1;
52
 
3 mjames 53
UART_HandleTypeDef huart1;
2 mjames 54
UART_HandleTypeDef huart2;
23 mjames 55
UART_HandleTypeDef huart3;
2 mjames 56
 
57
/* USER CODE BEGIN PV */
58
/* Private variables ---------------------------------------------------------*/
18 mjames 59
#define MAXRDG 32
2 mjames 60
 
7 mjames 61
int OldObservation[2] =
62
{ -1, -1 }; // illegal initial value
63
int OldObservationIndex[2] =
64
{ -1, -1 }; // if more than one sensor this will be printed
65
int16_t dial0[2] =
66
{ 0, 0 };
67
int16_t dial1[2] =
68
{ -1, -1 };
14 mjames 69
 
18 mjames 70
uint16_t dial_timer[2] =
71
{ 0, 0 };
72
 
73
static const int DialTimeout = 50; // about 20 seconds after twiddle, save the dial position.
74
 
16 mjames 75
/* Virtual address defined by the user: 0xFFFF value is prohibited */
17 mjames 76
uint16_t VirtAddVarTab[NumbOfVar] = {0x1111,0x2222 }  ;
14 mjames 77
 
7 mjames 78
union
79
{
80
        PLX_SensorInfo Sensor[MAXRDG];
81
        char Bytes[MAXRDG * sizeof(PLX_SensorInfo)];
82
} Data;
83
int Max[MAXRDG];
84
int Min[MAXRDG];
85
int PLXItems;
2 mjames 86
/* USER CODE END PV */
87
 
88
/* Private function prototypes -----------------------------------------------*/
16 mjames 89
void SystemClock_Config(void);
90
void Error_Handler(void);
91
static void MX_GPIO_Init(void);
92
static void MX_SPI1_Init(void);
93
static void MX_USART2_UART_Init(void);
94
static void MX_USART1_UART_Init(void);
23 mjames 95
static void MX_USART3_UART_Init(void);
2 mjames 96
 
97
/* USER CODE BEGIN PFP */
98
/* Private function prototypes -----------------------------------------------*/
99
 
100
/* USER CODE END PFP */
101
 
102
/* USER CODE BEGIN 0 */
103
/* dummy function */
7 mjames 104
void _init(void)
6 mjames 105
{
2 mjames 106
 
107
}
7 mjames 108
// the dial is the switch number we are using.
109
// suppress is the ItemIndex we wish to suppress on this display
110
int  DisplayCurrent(int dial,int suppress)
111
{
112
        char buff[10];
113
        int i;
18 mjames 114
        int rc;
7 mjames 115
        select_display(dial); // pick the display we are using
13 mjames 116
        int ItemIndex = dial_pos[dial]/4;
14 mjames 117
 
7 mjames 118
        // wrap around count if dial too far to the right
119
        if (ItemIndex >= PLXItems)
120
        {
121
                dial_pos[dial] = 0;
122
                ItemIndex = 0;
123
        }
124
        if (ItemIndex < 0)
125
        {
14 mjames 126
                ItemIndex = PLXItems-1;
127
                dial_pos[dial] = (PLXItems-1)*4;
7 mjames 128
        }
2 mjames 129
 
9 mjames 130
 
131
 
7 mjames 132
        // check for item suppression
133
        if(ItemIndex == suppress)
134
        {
135
                dial1[dial] = -1;
136
                OldObservation[dial] = -1;
137
                OldObservationIndex[dial] = -1;
2 mjames 138
 
8 mjames 139
                clearDisplay();
140
                display();
7 mjames 141
                return -1; // we suppressed this display
142
        }
143
        // do not try to convert if no items in buffer
144
        if (PLXItems > 0)
145
        {
146
                int DataVal = ConvPLX(Data.Sensor[ItemIndex].ReadingH,
147
                                Data.Sensor[ItemIndex].ReadingL); // data reading
148
                int Observation = ConvPLX(Data.Sensor[ItemIndex].AddrH,
149
                                Data.Sensor[ItemIndex].AddrL);
150
                int ObservationIndex = ConvPLX(0, Data.Sensor[ItemIndex].Instance);
151
                // now to convert the readings and format strings
152
                // find out limits
153
                char * msg;
154
                int len;
2 mjames 155
 
9 mjames 156
                // if the user presses the dial then reset min/max to current value
157
                if(push_pos[dial] == 1)
158
                {
159
                                Max[ItemIndex] = DataVal;
160
                                Min[ItemIndex] = DataVal; // 12 bit max value
161
                }
162
 
163
 
164
 
7 mjames 165
                if (Observation < PLX_MAX_OBS)
166
                {
167
                        if (Observation != OldObservation[dial]
168
                                        || ObservationIndex != OldObservationIndex[dial])
169
                        {
14 mjames 170
 
18 mjames 171
                dial_timer[dial] = DialTimeout;
14 mjames 172
 
7 mjames 173
                                dial1[dial] = -1;
174
                                clearDisplay();
175
                                dial_draw_scale(
13 mjames 176
                                                DisplayInfo[Observation].Low,
177
                                                DisplayInfo[Observation].High,
178
                                            12, 1,DisplayInfo[Observation].TickScale);
14 mjames 179
 
180
                                msg = DisplayInfo[Observation].name;
181
                                len = 7;
182
                                int len1  = ObservationIndex > 0 ? len-1: len;
183
                                for (i = 0; i < len1 && msg[i]; i++)
7 mjames 184
                                {
14 mjames 185
                                        buff[i] = msg[i];
7 mjames 186
                                }
14 mjames 187
                                if (ObservationIndex > 0 && i<len)
7 mjames 188
                                {
14 mjames 189
                                        buff[i++] = ObservationIndex + '1';
7 mjames 190
                                }
2 mjames 191
 
15 mjames 192
                                print_large_string(buff, 64-i*4, 48, i); // this prints spaces for \0 at end of string
14 mjames 193
 
7 mjames 194
                                OldObservation[dial] = Observation;
195
                                OldObservationIndex[dial] = ObservationIndex;
196
                                //
197
                                display();
2 mjames 198
 
7 mjames 199
                        }
18 mjames 200
                        else
201
                        {
202
                                // check for timer timeout on consistent timer
203
                                if(dial_timer[dial])
204
                                {
205
                                        dial_timer[dial]--;
2 mjames 206
 
18 mjames 207
                                        if(dial_timer[dial]==0  )
208
                                        {
209
                                                uint16_t curr_val = dial_pos[dial];
210
                                                rc = EE_ReadVariable(VirtAddVarTab[dial],&curr_val);
211
                                                if((rc !=0) || (curr_val != dial_pos[dial]))
212
                                                {
22 mjames 213
                                                        //__disable_irq();
21 mjames 214
                                                        HAL_FLASH_Unlock();
215
 
216
                                                        rc = EE_WriteVariable(VirtAddVarTab[dial],dial_pos[dial]);
217
                                                        HAL_FLASH_Lock();
22 mjames 218
                                                        //__enable_irq();
21 mjames 219
                                                }
18 mjames 220
                                        }
221
                                }
222
 
223
                        }
224
 
7 mjames 225
                        double max_rdg;
226
                        double min_rdg;
227
                        double cur_rdg;
228
                        int int_rdg;
9 mjames 229
                        int int_max;
230
                        int int_min;
2 mjames 231
 
7 mjames 232
                        max_rdg = ConveriMFDRaw2Data(Observation,
233
                                        DisplayInfo[Observation].Units, Max[ItemIndex]);
234
                        min_rdg = ConveriMFDRaw2Data(Observation,
235
                                        DisplayInfo[Observation].Units, Min[ItemIndex]);
236
                        cur_rdg = ConveriMFDRaw2Data(Observation,
237
                                        DisplayInfo[Observation].Units, DataVal);
2 mjames 238
 
7 mjames 239
                        int dp_pos;  // where to print the decimal place
19 mjames 240
                        float scale = 1.0;
7 mjames 241
                        switch (DisplayInfo[Observation].DP)
242
                        {
243
                        case 0:
19 mjames 244
                                scale = 1.0;
7 mjames 245
                                dp_pos = 100;
246
                                break;
247
                        case 1:
19 mjames 248
                                scale = 10.0;
249
                                dp_pos = 1;
7 mjames 250
                                break;
251
                        case 2:
19 mjames 252
                                scale = 100.0;
7 mjames 253
                                dp_pos = 2;
254
                                break;
255
                        }
19 mjames 256
                        int_rdg = (int) (cur_rdg * scale);
257
                        int_max = (int) (max_rdg * scale);
258
                        int_min = (int) (min_rdg * scale);
2 mjames 259
 
7 mjames 260
                        cur_rdg -= DisplayInfo[Observation].Low;
261
                        cur_rdg = 100 * cur_rdg
262
                                        / (DisplayInfo[Observation].High
263
                                                        - DisplayInfo[Observation].Low);
2 mjames 264
 
13 mjames 265
                        dial0[dial] = (int) cur_rdg  ;
2 mjames 266
 
7 mjames 267
                        /* old needle un-draw */
268
                        if (dial1[dial] >= 0)
269
                        {
270
                                dial_draw_needle(dial1[dial]);
271
                        }
272
                        dial_draw_needle(dial0[dial]);
273
                        // print value overlaid by needle
274
                        // this is actual reading
19 mjames 275
                        print_digits(30, 30, 5, dp_pos, int_rdg);
9 mjames 276
                        font_gotoxy(0,0);
15 mjames 277
                        font_digits(5,dp_pos,int_min);
278
 
9 mjames 279
                        font_gotoxy(0,1);
280
                        font_puts("Min");
2 mjames 281
 
15 mjames 282
                        font_gotoxy(15,0);
283
                        font_digits(5,dp_pos,int_max);
9 mjames 284
                        font_gotoxy(18,1);
285
                        font_puts("Max");
286
 
7 mjames 287
                        dial1[dial] = dial0[dial];
2 mjames 288
 
7 mjames 289
                        display();
2 mjames 290
 
7 mjames 291
                }
292
        }
293
        return ItemIndex;
294
}
295
/* USER CODE END 0 */
2 mjames 296
 
7 mjames 297
int main(void)
298
{
2 mjames 299
 
16 mjames 300
  /* USER CODE BEGIN 1 */
2 mjames 301
 
7 mjames 302
        GPIO_InitTypeDef GPIO_InitStruct;
2 mjames 303
 
23 mjames 304
        __HAL_RCC_SPI1_CLK_ENABLE();
305
        __HAL_RCC_USART1_CLK_ENABLE(); // PLX main port
306
        __HAL_RCC_USART2_CLK_ENABLE(); // debug port
307
        __HAL_RCC_USART3_CLK_ENABLE(); // Bluetooth port
308
 
16 mjames 309
  /* USER CODE END 1 */
2 mjames 310
 
16 mjames 311
  /* MCU Configuration----------------------------------------------------------*/
6 mjames 312
 
16 mjames 313
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
314
  HAL_Init();
2 mjames 315
 
16 mjames 316
  /* Configure the system clock */
317
  SystemClock_Config();
2 mjames 318
 
16 mjames 319
  /* Initialize all configured peripherals */
320
  MX_GPIO_Init();
321
  MX_SPI1_Init();
322
  MX_USART2_UART_Init();
323
  MX_USART1_UART_Init();
23 mjames 324
  MX_USART3_UART_Init();
2 mjames 325
 
16 mjames 326
  /* USER CODE BEGIN 2 */
2 mjames 327
 
4 mjames 328
 
2 mjames 329
 
7 mjames 330
        /* Turn on USART1 IRQ */
331
        HAL_NVIC_SetPriority(USART1_IRQn, 2, 0);
332
        HAL_NVIC_EnableIRQ(USART1_IRQn);
4 mjames 333
 
23 mjames 334
    /* Turn on USART2 IRQ  */
335
        HAL_NVIC_SetPriority(USART2_IRQn, 4, 0);
336
        HAL_NVIC_EnableIRQ(USART2_IRQn);
337
 
338
        /* turn on USART3 IRQ */
339
        HAL_NVIC_SetPriority(USART3_IRQn, 4, 0);
340
        HAL_NVIC_EnableIRQ(USART3_IRQn);
341
 
342
 
343
 
7 mjames 344
        /* setup the USART control blocks */
345
        init_usart_ctl(&uc1, huart1.Instance);
346
        init_usart_ctl(&uc2, huart2.Instance);
23 mjames 347
        init_usart_ctl(&uc3, huart3.Instance);
2 mjames 348
 
7 mjames 349
        EnableSerialRxInterrupt(&uc1);
350
        EnableSerialRxInterrupt(&uc2);
23 mjames 351
        EnableSerialRxInterrupt(&uc3);
352
 
18 mjames 353
        /* Unlock the Flash to enable the flash control register access *************/
354
        HAL_FLASH_Unlock();
7 mjames 355
 
22 mjames 356
        //__disable_irq();
16 mjames 357
        EE_Init();
22 mjames 358
        //__enable_irq();
16 mjames 359
 
21 mjames 360
    HAL_FLASH_Lock();
18 mjames 361
 
22 mjames 362
 
363
        InitSwitches();
364
 
17 mjames 365
        int i;
18 mjames 366
        uint16_t rc;
17 mjames 367
        for(i=0;i<2;i++)
368
        {
369
          uint16_t val;
370
 
18 mjames 371
          uint16_t rc =  EE_ReadVariable(VirtAddVarTab[i], &val);
17 mjames 372
 
373
          if (rc == 0)
374
          {
375
                  dial_pos[i] = val;
376
          }
18 mjames 377
          else
378
          {
379
                  break;
380
          }
17 mjames 381
        }
382
 
18 mjames 383
 
384
 
7 mjames 385
        ap_init(); // set up the approximate math library
386
 
387
        int disp;
388
 
389
        ssd1306_begin(1, 0);
10 mjames 390
        dial_origin(64, 60);
391
        dial_size(60);
392
 
393
 
17 mjames 394
        // sort out the switch positions
14 mjames 395
 
17 mjames 396
 
397
 
398
 
7 mjames 399
        for (disp = 0; disp < 2; disp++)
6 mjames 400
        {
7 mjames 401
                select_display(disp);
402
                clearDisplay();
403
                dim(0);
404
                //font_puts(
405
                //              "Hello world !!\rThis text is a test of the text rendering library in a 5*7 font");
4 mjames 406
 
13 mjames 407
                dial_draw_scale(0, 10, 12, 5,1);
10 mjames 408
                char  buffer[] = "Display  ";
409
                buffer[8] = disp+'1';
410
                print_large_string(buffer, 20,30, 9);
4 mjames 411
 
7 mjames 412
                display();
4 mjames 413
 
7 mjames 414
        }
10 mjames 415
 
416
 
4 mjames 417
 
16 mjames 418
  /* USER CODE END 2 */
7 mjames 419
 
16 mjames 420
  /* Infinite loop */
421
  /* USER CODE BEGIN WHILE */
7 mjames 422
        uint32_t Ticks = HAL_GetTick() + 100;
423
 
23 mjames 424
    uint32_t timeout = 0;  //
7 mjames 425
        // PLX decoder protocol
426
        char PLXPacket = 0;
427
        for (i = 0; i < MAXRDG; i++)
428
        {
429
                Max[i] = 0;
430
                Min[i] = 0xFFF; // 12 bit max value
431
        }
432
 
433
        int PLXPtr = 0;
434
 
435
        while (1)
436
        {
437
// poll switches
438
                HandleSwitches();
23 mjames 439
// Handle the bluetooth pairing function by pressing both buttons.
440
                if((push_pos[0] == 1) && (push_pos[1] == 1))
441
                {
442
                  HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, GPIO_PIN_SET);
443
                }
444
                else
445
                {
446
                  HAL_GPIO_WritePin(BT_BUTTON_GPIO_Port, BT_BUTTON_Pin, GPIO_PIN_RESET);
7 mjames 447
 
23 mjames 448
                }
9 mjames 449
 
23 mjames 450
 
7 mjames 451
                uint16_t cc = SerialCharsReceived(&uc1);
452
                int chr;
23 mjames 453
                if(cc==0)
454
                {
455
                        timeout++;
456
                        if (timeout % 1000 ==0)
457
                        {
458
                                PutCharSerial(&uc3,'+');
459
                        }
460
                        if(timeout > 60000)
461
                        {
462
                                // do turn off screen
463
                        }
464
 
465
                }
7 mjames 466
                for (chr = 0; chr < cc; chr++)
6 mjames 467
                {
7 mjames 468
                        char c = GetCharSerial(&uc1);
23 mjames 469
                        timeout = 0;
470
                        PutCharSerial(&uc3,c);
471
 
7 mjames 472
                        if (c == PLX_Start) // at any time if the start byte appears, reset the pointers
6 mjames 473
                        {
7 mjames 474
                                PLXPtr = 0;    // reset the pointer
475
                                PLXPacket = 1;
4 mjames 476
                        }
7 mjames 477
                        else if (c == PLX_Stop)
6 mjames 478
                        {
7 mjames 479
                                if (PLXPacket)
480
                                {
481
                                        // we can now decode the selected parameter
482
                                        PLXItems = PLXPtr / sizeof(PLX_SensorInfo); // total
483
                                        // saturate the rotary switch position
484
 
485
                                        int DataVal;
486
                                        // process min/max
487
                                        for (i = 0; i < PLXItems; i++)
488
                                        {
489
                                                DataVal = ConvPLX(Data.Sensor[i].ReadingH,
490
                                                                Data.Sensor[i].ReadingL);
491
                                                if (DataVal > Max[i])
492
                                                {
493
                                                        Max[i] = DataVal;
494
                                                }
495
                                                if (DataVal < Min[i])
496
                                                {
497
                                                        Min[i] = DataVal;
498
                                                }
499
                                        }
500
 
501
                                        // now to display the information
14 mjames 502
                                    int suppress = DisplayCurrent(0,-1);
503
                                        DisplayCurrent(1, suppress);
7 mjames 504
                                }
505
                                PLXPtr = 0;
506
                                PLXPacket = 0;
4 mjames 507
                        }
7 mjames 508
                        else if (c > PLX_Stop) // illegal char, restart reading
6 mjames 509
                        {
7 mjames 510
                                PLXPacket = 0;
511
                                PLXPtr = 0;
4 mjames 512
                        }
7 mjames 513
                        else if (PLXPtr < sizeof(Data.Bytes))
6 mjames 514
                        {
7 mjames 515
                                Data.Bytes[PLXPtr++] = c;
6 mjames 516
                        }
517
                }
4 mjames 518
 
7 mjames 519
                HAL_Delay(1);
6 mjames 520
        }
16 mjames 521
  /* USER CODE END WHILE */
2 mjames 522
 
16 mjames 523
  /* USER CODE BEGIN 3 */
6 mjames 524
 
16 mjames 525
 
526
  /* USER CODE END 3 */
527
 
2 mjames 528
}
529
 
530
/** System Clock Configuration
16 mjames 531
*/
7 mjames 532
void SystemClock_Config(void)
5 mjames 533
{
2 mjames 534
 
16 mjames 535
  RCC_OscInitTypeDef RCC_OscInitStruct;
536
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
2 mjames 537
 
16 mjames 538
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
539
  RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
540
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
541
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
542
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
543
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
544
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
545
  {
546
    Error_Handler();
547
  }
2 mjames 548
 
16 mjames 549
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
550
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
551
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
552
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
553
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
554
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
555
  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
556
  {
557
    Error_Handler();
558
  }
2 mjames 559
 
16 mjames 560
  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
2 mjames 561
 
16 mjames 562
  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
2 mjames 563
 
16 mjames 564
  /* SysTick_IRQn interrupt configuration */
565
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
2 mjames 566
}
567
 
568
/* SPI1 init function */
7 mjames 569
static void MX_SPI1_Init(void)
5 mjames 570
{
2 mjames 571
 
16 mjames 572
  hspi1.Instance = SPI1;
573
  hspi1.Init.Mode = SPI_MODE_MASTER;
574
  hspi1.Init.Direction = SPI_DIRECTION_1LINE;
575
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
576
  hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
577
  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
578
  hspi1.Init.NSS = SPI_NSS_SOFT;
579
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
580
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
581
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
582
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
583
  hspi1.Init.CRCPolynomial = 10;
584
  if (HAL_SPI_Init(&hspi1) != HAL_OK)
585
  {
586
    Error_Handler();
587
  }
2 mjames 588
 
589
}
590
 
3 mjames 591
/* USART1 init function */
7 mjames 592
static void MX_USART1_UART_Init(void)
5 mjames 593
{
3 mjames 594
 
16 mjames 595
  huart1.Instance = USART1;
596
  huart1.Init.BaudRate = 19200;
597
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
598
  huart1.Init.StopBits = UART_STOPBITS_1;
599
  huart1.Init.Parity = UART_PARITY_NONE;
600
  huart1.Init.Mode = UART_MODE_TX_RX;
601
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
602
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
603
  if (HAL_UART_Init(&huart1) != HAL_OK)
604
  {
605
    Error_Handler();
606
  }
3 mjames 607
 
608
}
609
 
2 mjames 610
/* USART2 init function */
7 mjames 611
static void MX_USART2_UART_Init(void)
5 mjames 612
{
2 mjames 613
 
16 mjames 614
  huart2.Instance = USART2;
615
  huart2.Init.BaudRate = 115200;
616
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
617
  huart2.Init.StopBits = UART_STOPBITS_1;
618
  huart2.Init.Parity = UART_PARITY_NONE;
619
  huart2.Init.Mode = UART_MODE_TX_RX;
620
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
621
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
622
  if (HAL_UART_Init(&huart2) != HAL_OK)
623
  {
624
    Error_Handler();
625
  }
2 mjames 626
 
627
}
628
 
23 mjames 629
/* USART3 init function */
630
static void MX_USART3_UART_Init(void)
631
{
632
 
633
  huart3.Instance = USART3;
634
  huart3.Init.BaudRate = 19200;
635
  huart3.Init.WordLength = UART_WORDLENGTH_8B;
636
  huart3.Init.StopBits = UART_STOPBITS_1;
637
  huart3.Init.Parity = UART_PARITY_NONE;
638
  huart3.Init.Mode = UART_MODE_TX_RX;
639
  huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
640
  huart3.Init.OverSampling = UART_OVERSAMPLING_16;
641
  if (HAL_UART_Init(&huart3) != HAL_OK)
642
  {
643
    Error_Handler();
644
  }
645
 
646
}
647
 
7 mjames 648
/** Configure pins as
16 mjames 649
        * Analog
650
        * Input
651
        * Output
652
        * EVENT_OUT
653
        * EXTI
654
*/
7 mjames 655
static void MX_GPIO_Init(void)
5 mjames 656
{
2 mjames 657
 
16 mjames 658
  GPIO_InitTypeDef GPIO_InitStruct;
2 mjames 659
 
16 mjames 660
  /* GPIO Ports Clock Enable */
661
  __HAL_RCC_GPIOD_CLK_ENABLE();
662
  __HAL_RCC_GPIOA_CLK_ENABLE();
663
  __HAL_RCC_GPIOC_CLK_ENABLE();
664
  __HAL_RCC_GPIOB_CLK_ENABLE();
2 mjames 665
 
16 mjames 666
  /*Configure GPIO pin Output Level */
667
  HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET);
2 mjames 668
 
16 mjames 669
  /*Configure GPIO pin Output Level */
23 mjames 670
  HAL_GPIO_WritePin(GPIOA, SPI1CD_Pin|BT_BUTTON_Pin, GPIO_PIN_RESET);
2 mjames 671
 
16 mjames 672
  /*Configure GPIO pin Output Level */
673
  HAL_GPIO_WritePin(GPIOC, SPI_RESET_Pin|USART3_INVERT_Pin|USB_PWR_Pin, GPIO_PIN_RESET);
2 mjames 674
 
16 mjames 675
  /*Configure GPIO pin Output Level */
676
  HAL_GPIO_WritePin(SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_SET);
2 mjames 677
 
23 mjames 678
  /*Configure GPIO pins : SPI_NSS1_Pin SPI1CD_Pin BT_BUTTON_Pin */
679
  GPIO_InitStruct.Pin = SPI_NSS1_Pin|SPI1CD_Pin|BT_BUTTON_Pin;
16 mjames 680
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
681
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
682
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
2 mjames 683
 
16 mjames 684
  /*Configure GPIO pins : SPI_RESET_Pin SPI_NSS2_Pin USART3_INVERT_Pin USB_PWR_Pin */
685
  GPIO_InitStruct.Pin = SPI_RESET_Pin|SPI_NSS2_Pin|USART3_INVERT_Pin|USB_PWR_Pin;
686
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
687
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
688
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
2 mjames 689
 
16 mjames 690
  /*Configure GPIO pins : SW1_PUSH_Pin SW1_I_Pin SW1_Q_Pin SW2_PUSH_Pin */
691
  GPIO_InitStruct.Pin = SW1_PUSH_Pin|SW1_I_Pin|SW1_Q_Pin|SW2_PUSH_Pin;
692
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
693
  GPIO_InitStruct.Pull = GPIO_PULLUP;
694
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
5 mjames 695
 
16 mjames 696
  /*Configure GPIO pins : SW2_I_Pin SW2_Q_Pin */
697
  GPIO_InitStruct.Pin = SW2_I_Pin|SW2_Q_Pin;
698
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
699
  GPIO_InitStruct.Pull = GPIO_PULLUP;
700
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
5 mjames 701
 
2 mjames 702
}
703
 
704
/* USER CODE BEGIN 4 */
705
 
706
/* USER CODE END 4 */
707
 
5 mjames 708
/**
16 mjames 709
  * @brief  This function is executed in case of error occurrence.
710
  * @param  None
711
  * @retval None
712
  */
7 mjames 713
void Error_Handler(void)
5 mjames 714
{
16 mjames 715
  /* USER CODE BEGIN Error_Handler */
7 mjames 716
/* User can add his own implementation to report the HAL error return state */
717
while (1)
718
{
5 mjames 719
}
16 mjames 720
  /* USER CODE END Error_Handler */
7 mjames 721
}
5 mjames 722
 
2 mjames 723
#ifdef USE_FULL_ASSERT
724
 
725
/**
16 mjames 726
   * @brief Reports the name of the source file and the source line number
727
   * where the assert_param error has occurred.
728
   * @param file: pointer to the source file name
729
   * @param line: assert_param error line source number
730
   * @retval None
731
   */
2 mjames 732
void assert_failed(uint8_t* file, uint32_t line)
7 mjames 733
{
16 mjames 734
  /* USER CODE BEGIN 6 */
7 mjames 735
/* User can add his own implementation to report the file name and line number,
736
 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
16 mjames 737
  /* USER CODE END 6 */
2 mjames 738
 
7 mjames 739
}
2 mjames 740
 
741
#endif
742
 
743
/**
16 mjames 744
  * @}
745
  */
2 mjames 746
 
747
/**
16 mjames 748
  * @}
749
*/
2 mjames 750
 
751
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/