Subversion Repositories DashDisplay

Rev

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

Rev Author Line No. Line
2 mjames 1
/**
6 mjames 2
 ******************************************************************************
3
 * File Name          : main.c
4
 * Description        : Main program body
5
 ******************************************************************************
6
 *
7
 * COPYRIGHT(c) 2016 STMicroelectronics
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"
2 mjames 45
 
46
/* USER CODE END Includes */
47
 
48
/* Private variables ---------------------------------------------------------*/
49
SPI_HandleTypeDef hspi1;
50
 
3 mjames 51
UART_HandleTypeDef huart1;
2 mjames 52
UART_HandleTypeDef huart2;
53
 
54
/* USER CODE BEGIN PV */
55
/* Private variables ---------------------------------------------------------*/
7 mjames 56
#define MAXRDG 10
2 mjames 57
 
7 mjames 58
int OldObservation[2] =
59
{ -1, -1 }; // illegal initial value
60
int OldObservationIndex[2] =
61
{ -1, -1 }; // if more than one sensor this will be printed
62
int16_t dial0[2] =
63
{ 0, 0 };
64
int16_t dial1[2] =
65
{ -1, -1 };
66
union
67
{
68
        PLX_SensorInfo Sensor[MAXRDG];
69
        char Bytes[MAXRDG * sizeof(PLX_SensorInfo)];
70
} Data;
71
int Max[MAXRDG];
72
int Min[MAXRDG];
73
int PLXItems;
2 mjames 74
/* USER CODE END PV */
75
 
76
/* Private function prototypes -----------------------------------------------*/
6 mjames 77
void
7 mjames 78
SystemClock_Config(void);
6 mjames 79
void
7 mjames 80
Error_Handler(void);
6 mjames 81
static void
7 mjames 82
MX_GPIO_Init(void);
6 mjames 83
static void
7 mjames 84
MX_SPI1_Init(void);
6 mjames 85
static void
7 mjames 86
MX_USART2_UART_Init(void);
6 mjames 87
static void
7 mjames 88
MX_USART1_UART_Init(void);
2 mjames 89
 
90
/* USER CODE BEGIN PFP */
91
/* Private function prototypes -----------------------------------------------*/
92
 
93
/* USER CODE END PFP */
94
 
95
/* USER CODE BEGIN 0 */
96
/* dummy function */
7 mjames 97
void _init(void)
6 mjames 98
{
2 mjames 99
 
100
}
7 mjames 101
// the dial is the switch number we are using.
102
// suppress is the ItemIndex we wish to suppress on this display
103
int  DisplayCurrent(int dial,int suppress)
104
{
105
        char buff[10];
106
        int i;
107
        select_display(dial); // pick the display we are using
108
        int ItemIndex = dial_pos[dial];
109
        // wrap around count if dial too far to the right
110
        if (ItemIndex >= PLXItems)
111
        {
112
                dial_pos[dial] = 0;
113
                ItemIndex = 0;
114
        }
115
        if (ItemIndex < 0)
116
        {
117
                ItemIndex = 0;
118
                dial_pos[dial] = 0;
119
        }
2 mjames 120
 
7 mjames 121
        // check for item suppression
122
        if(ItemIndex == suppress)
123
        {
124
                dial1[dial] = -1;
125
                OldObservation[dial] = -1;
126
                OldObservationIndex[dial] = -1;
2 mjames 127
 
8 mjames 128
                clearDisplay();
129
                display();
7 mjames 130
                return -1; // we suppressed this display
131
        }
132
        // do not try to convert if no items in buffer
133
        if (PLXItems > 0)
134
        {
135
                int DataVal = ConvPLX(Data.Sensor[ItemIndex].ReadingH,
136
                                Data.Sensor[ItemIndex].ReadingL); // data reading
137
                int Observation = ConvPLX(Data.Sensor[ItemIndex].AddrH,
138
                                Data.Sensor[ItemIndex].AddrL);
139
                int ObservationIndex = ConvPLX(0, Data.Sensor[ItemIndex].Instance);
140
                // now to convert the readings and format strings
141
                // find out limits
142
                char * msg;
143
                int len;
2 mjames 144
 
7 mjames 145
                if (Observation < PLX_MAX_OBS)
146
                {
147
                        if (Observation != OldObservation[dial]
148
                                        || ObservationIndex != OldObservationIndex[dial])
149
                        {
150
                                dial1[dial] = -1;
151
                                clearDisplay();
152
                                dial_draw_scale(
153
                                                DisplayInfo[Observation].Low
154
                                                                / DisplayInfo[Observation].TickScale,
155
                                                DisplayInfo[Observation].High
156
                                                                / DisplayInfo[Observation].TickScale, 16, 1);
157
                                if (ObservationIndex > 0)
158
                                {
159
                                        len = 5;
160
                                        buff[6] = ObservationIndex + '1';
161
                                }
162
                                else
163
                                {
164
                                        len = 6;
165
                                }
166
                                {
167
                                        msg = DisplayInfo[Observation].name;
168
                                }
169
                                for (i = 0; i < len; i++)
170
                                {
171
                                        buff[i] = msg[i];
172
                                }
173
                                print_large_string(buff, 32, 48, 6); // this prints spaces for \0 at end of string
2 mjames 174
 
7 mjames 175
                                OldObservation[dial] = Observation;
176
                                OldObservationIndex[dial] = ObservationIndex;
177
                                //
178
                                display();
2 mjames 179
 
7 mjames 180
                        }
2 mjames 181
 
7 mjames 182
                        double max_rdg;
183
                        double min_rdg;
184
                        double cur_rdg;
185
                        int int_rdg;
2 mjames 186
 
7 mjames 187
                        max_rdg = ConveriMFDRaw2Data(Observation,
188
                                        DisplayInfo[Observation].Units, Max[ItemIndex]);
189
                        min_rdg = ConveriMFDRaw2Data(Observation,
190
                                        DisplayInfo[Observation].Units, Min[ItemIndex]);
191
                        cur_rdg = ConveriMFDRaw2Data(Observation,
192
                                        DisplayInfo[Observation].Units, DataVal);
2 mjames 193
 
7 mjames 194
                        cur_rdg /= DisplayInfo[Observation].TickScale;
195
                        int dp_pos;  // where to print the decimal place
196
                        switch (DisplayInfo[Observation].DP)
197
                        {
198
                        case 0:
199
                                int_rdg = (int) (cur_rdg);
200
                                dp_pos = 100;
201
                                break;
202
                        case 1:
203
                                int_rdg = (int) (cur_rdg * 10.0);
204
                                dp_pos = 3;
205
                                break;
206
                        case 2:
207
                                int_rdg = (int) (cur_rdg * 100.0);
208
                                dp_pos = 2;
209
                                break;
210
                        }
2 mjames 211
 
7 mjames 212
                        cur_rdg -= DisplayInfo[Observation].Low;
213
                        cur_rdg = 100 * cur_rdg
214
                                        / (DisplayInfo[Observation].High
215
                                                        - DisplayInfo[Observation].Low);
2 mjames 216
 
7 mjames 217
                        dial0[dial] = (int) cur_rdg;
2 mjames 218
 
7 mjames 219
                        /* old needle un-draw */
220
                        if (dial1[dial] >= 0)
221
                        {
222
                                dial_draw_needle(dial1[dial]);
223
                        }
224
                        dial_draw_needle(dial0[dial]);
225
                        // print value overlaid by needle
226
                        // this is actual reading
227
                        print_digits(64 - 16, 30, 4, dp_pos, int_rdg);
2 mjames 228
 
7 mjames 229
                        dial1[dial] = dial0[dial];
2 mjames 230
 
7 mjames 231
                        display();
2 mjames 232
 
7 mjames 233
                }
234
        }
235
        return ItemIndex;
236
}
237
/* USER CODE END 0 */
2 mjames 238
 
7 mjames 239
int main(void)
240
{
2 mjames 241
 
7 mjames 242
        /* USER CODE BEGIN 1 */
2 mjames 243
 
7 mjames 244
        GPIO_InitTypeDef GPIO_InitStruct;
2 mjames 245
 
7 mjames 246
        __HAL_RCC_SPI1_CLK_ENABLE()
247
        ;
248
        __HAL_RCC_USART1_CLK_ENABLE()
249
        ; // PLX main port
250
        __HAL_RCC_USART2_CLK_ENABLE()
251
        ; // debug port
252
        /* USER CODE END 1 */
2 mjames 253
 
7 mjames 254
        /* MCU Configuration----------------------------------------------------------*/
6 mjames 255
 
7 mjames 256
        /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
257
        HAL_Init();
2 mjames 258
 
7 mjames 259
        /* Configure the system clock */
260
        SystemClock_Config();
2 mjames 261
 
7 mjames 262
        /* Initialize all configured peripherals */
263
        MX_GPIO_Init();
264
        MX_SPI1_Init();
265
        MX_USART2_UART_Init();
266
        MX_USART1_UART_Init();
2 mjames 267
 
7 mjames 268
        /* USER CODE BEGIN 2 */
269
        /* Need to set AF mode for output pins DURR. */
270
        /* SPI bus AF pin selects */
271
        GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
2 mjames 272
 
8 mjames 273
        GPIO_InitStruct.Pin =  GPIO_PIN_5 | GPIO_PIN_7;
7 mjames 274
        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
275
        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
4 mjames 276
 
7 mjames 277
        /* USART2 AF pin selects */
278
        GPIO_InitStruct.Pin = GPIO_PIN_2;
279
        GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
280
        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
2 mjames 281
 
7 mjames 282
        /* USART1 AF pin selects */
283
        GPIO_InitStruct.Pin = GPIO_PIN_9;
284
        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
2 mjames 285
 
7 mjames 286
        /* Turn on USART2 IRQ  */
287
        HAL_NVIC_SetPriority(USART2_IRQn, 4, 0);
288
        HAL_NVIC_EnableIRQ(USART2_IRQn);
2 mjames 289
 
7 mjames 290
        /* Turn on USART1 IRQ */
291
        HAL_NVIC_SetPriority(USART1_IRQn, 2, 0);
292
        HAL_NVIC_EnableIRQ(USART1_IRQn);
4 mjames 293
 
7 mjames 294
        /* setup the USART control blocks */
295
        init_usart_ctl(&uc1, huart1.Instance);
296
        init_usart_ctl(&uc2, huart2.Instance);
2 mjames 297
 
7 mjames 298
        EnableSerialRxInterrupt(&uc1);
299
        EnableSerialRxInterrupt(&uc2);
300
 
301
        ap_init(); // set up the approximate math library
302
 
303
        int disp;
304
 
305
        ssd1306_begin(1, 0);
306
// static const int xp = 128 - 42;
307
        for (disp = 0; disp < 2; disp++)
6 mjames 308
        {
7 mjames 309
                select_display(disp);
310
                clearDisplay();
311
                dim(0);
312
                //font_puts(
313
                //              "Hello world !!\rThis text is a test of the text rendering library in a 5*7 font");
4 mjames 314
 
7 mjames 315
                dial_origin(64, 60);
316
                dial_size(60);
317
                dial_draw_scale(0, 10, 16, 5);
4 mjames 318
 
7 mjames 319
                display();
4 mjames 320
 
7 mjames 321
        }
322
        InitSwitches();
4 mjames 323
 
7 mjames 324
        /* USER CODE END 2 */
325
 
326
        /* Infinite loop */
327
        /* USER CODE BEGIN WHILE */
328
        uint32_t Ticks = HAL_GetTick() + 100;
329
 
330
        int i;
331
 
332
        // PLX decoder protocol
333
        char PLXPacket = 0;
334
        for (i = 0; i < MAXRDG; i++)
335
        {
336
                Max[i] = 0;
337
                Min[i] = 0xFFF; // 12 bit max value
338
        }
339
 
340
        int PLXPtr = 0;
341
 
342
        while (1)
343
        {
344
// poll switches
345
                HandleSwitches();
346
 
347
                uint16_t cc = SerialCharsReceived(&uc1);
348
                int chr;
349
                for (chr = 0; chr < cc; chr++)
6 mjames 350
                {
7 mjames 351
                        char c = GetCharSerial(&uc1);
352
                        if (c == PLX_Start) // at any time if the start byte appears, reset the pointers
6 mjames 353
                        {
7 mjames 354
                                PLXPtr = 0;    // reset the pointer
355
                                PLXPacket = 1;
4 mjames 356
                        }
7 mjames 357
                        else if (c == PLX_Stop)
6 mjames 358
                        {
7 mjames 359
                                if (PLXPacket)
360
                                {
361
                                        // we can now decode the selected parameter
362
                                        PLXItems = PLXPtr / sizeof(PLX_SensorInfo); // total
363
                                        // saturate the rotary switch position
364
 
365
                                        int DataVal;
366
                                        // process min/max
367
                                        for (i = 0; i < PLXItems; i++)
368
                                        {
369
                                                DataVal = ConvPLX(Data.Sensor[i].ReadingH,
370
                                                                Data.Sensor[i].ReadingL);
371
                                                if (DataVal > Max[i])
372
                                                {
373
                                                        Max[i] = DataVal;
374
                                                }
375
                                                if (DataVal < Min[i])
376
                                                {
377
                                                        Min[i] = DataVal;
378
                                                }
379
                                        }
380
 
381
                                        // now to display the information
382
                                        int suppress = DisplayCurrent(0,-1);
383
                                        DisplayCurrent(1,suppress);
384
                                }
385
                                PLXPtr = 0;
386
                                PLXPacket = 0;
4 mjames 387
                        }
7 mjames 388
                        else if (c > PLX_Stop) // illegal char, restart reading
6 mjames 389
                        {
7 mjames 390
                                PLXPacket = 0;
391
                                PLXPtr = 0;
4 mjames 392
                        }
7 mjames 393
                        else if (PLXPtr < sizeof(Data.Bytes))
6 mjames 394
                        {
7 mjames 395
                                Data.Bytes[PLXPtr++] = c;
6 mjames 396
                        }
397
                }
4 mjames 398
 
7 mjames 399
                HAL_Delay(1);
6 mjames 400
        }
7 mjames 401
        /* USER CODE END WHILE */
2 mjames 402
 
7 mjames 403
        /* USER CODE BEGIN 3 */
6 mjames 404
 
2 mjames 405
}
7 mjames 406
/* USER CODE END 3 */
2 mjames 407
 
408
/** System Clock Configuration
6 mjames 409
 */
7 mjames 410
void SystemClock_Config(void)
5 mjames 411
{
2 mjames 412
 
7 mjames 413
RCC_OscInitTypeDef RCC_OscInitStruct;
414
RCC_ClkInitTypeDef RCC_ClkInitStruct;
2 mjames 415
 
7 mjames 416
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
417
RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
418
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
419
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
420
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
421
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
422
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
423
{
424
        Error_Handler();
2 mjames 425
}
426
 
7 mjames 427
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
428
                | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
429
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
430
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
431
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
432
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
433
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
5 mjames 434
{
7 mjames 435
        Error_Handler();
436
}
2 mjames 437
 
7 mjames 438
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000);
2 mjames 439
 
7 mjames 440
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
2 mjames 441
 
7 mjames 442
/* SysTick_IRQn interrupt configuration */
443
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
2 mjames 444
}
445
 
446
/* SPI1 init function */
7 mjames 447
static void MX_SPI1_Init(void)
5 mjames 448
{
2 mjames 449
 
7 mjames 450
hspi1.Instance = SPI1;
451
hspi1.Init.Mode = SPI_MODE_MASTER;
452
hspi1.Init.Direction = SPI_DIRECTION_1LINE;
453
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
454
hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
455
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
456
hspi1.Init.NSS = SPI_NSS_SOFT;
457
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
458
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
459
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
460
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
461
hspi1.Init.CRCPolynomial = 10;
462
if (HAL_SPI_Init(&hspi1) != HAL_OK)
463
{
464
        Error_Handler();
465
}
2 mjames 466
 
467
}
468
 
3 mjames 469
/* USART1 init function */
7 mjames 470
static void MX_USART1_UART_Init(void)
5 mjames 471
{
3 mjames 472
 
7 mjames 473
huart1.Instance = USART1;
474
huart1.Init.BaudRate = 19200;
475
huart1.Init.WordLength = UART_WORDLENGTH_8B;
476
huart1.Init.StopBits = UART_STOPBITS_1;
477
huart1.Init.Parity = UART_PARITY_NONE;
478
huart1.Init.Mode = UART_MODE_TX_RX;
479
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
480
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
481
if (HAL_UART_Init(&huart1) != HAL_OK)
482
{
483
        Error_Handler();
484
}
3 mjames 485
 
486
}
487
 
2 mjames 488
/* USART2 init function */
7 mjames 489
static void MX_USART2_UART_Init(void)
5 mjames 490
{
2 mjames 491
 
7 mjames 492
huart2.Instance = USART2;
493
huart2.Init.BaudRate = 115200;
494
huart2.Init.WordLength = UART_WORDLENGTH_8B;
495
huart2.Init.StopBits = UART_STOPBITS_1;
496
huart2.Init.Parity = UART_PARITY_NONE;
497
huart2.Init.Mode = UART_MODE_TX_RX;
498
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
499
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
500
if (HAL_UART_Init(&huart2) != HAL_OK)
501
{
502
        Error_Handler();
503
}
2 mjames 504
 
505
}
506
 
7 mjames 507
/** Configure pins as
6 mjames 508
 * Analog
509
 * Input
510
 * Output
511
 * EVENT_OUT
512
 * EXTI
513
 */
7 mjames 514
static void MX_GPIO_Init(void)
5 mjames 515
{
2 mjames 516
 
7 mjames 517
GPIO_InitTypeDef GPIO_InitStruct;
2 mjames 518
 
7 mjames 519
/* GPIO Ports Clock Enable */
520
__HAL_RCC_GPIOD_CLK_ENABLE()
521
;
522
__HAL_RCC_GPIOA_CLK_ENABLE()
523
;
524
__HAL_RCC_GPIOC_CLK_ENABLE()
525
;
526
__HAL_RCC_GPIOB_CLK_ENABLE()
527
;
2 mjames 528
 
7 mjames 529
/*Configure GPIO pin Output Level */
530
HAL_GPIO_WritePin(SPI_NSS1_GPIO_Port, SPI_NSS1_Pin, GPIO_PIN_SET);
2 mjames 531
 
7 mjames 532
/*Configure GPIO pin Output Level */
533
HAL_GPIO_WritePin(SPI1CD_GPIO_Port, SPI1CD_Pin, GPIO_PIN_RESET);
2 mjames 534
 
7 mjames 535
/*Configure GPIO pin Output Level */
536
HAL_GPIO_WritePin(GPIOC,
537
SPI_RESET_Pin | USART3_INVERT_Pin | USB_PWR_Pin, GPIO_PIN_RESET);
2 mjames 538
 
7 mjames 539
/*Configure GPIO pin Output Level */
540
HAL_GPIO_WritePin(SPI_NSS2_GPIO_Port, SPI_NSS2_Pin, GPIO_PIN_SET);
2 mjames 541
 
7 mjames 542
/*Configure GPIO pins : SPI_NSS1_Pin SPI1CD_Pin */
543
GPIO_InitStruct.Pin = SPI_NSS1_Pin | SPI1CD_Pin;
544
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
545
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
546
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
2 mjames 547
 
7 mjames 548
/*Configure GPIO pins : SPI_RESET_Pin SPI_NSS2_Pin USART3_INVERT_Pin USB_PWR_Pin */
549
GPIO_InitStruct.Pin = SPI_RESET_Pin | SPI_NSS2_Pin | USART3_INVERT_Pin
550
                | USB_PWR_Pin;
551
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
552
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
553
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
2 mjames 554
 
7 mjames 555
/*Configure GPIO pins : SW1_PUSH_Pin SW1_I_Pin SW1_Q_Pin SW2_PUSH_Pin */
556
GPIO_InitStruct.Pin = SW1_PUSH_Pin | SW1_I_Pin | SW1_Q_Pin | SW2_PUSH_Pin;
557
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
558
GPIO_InitStruct.Pull = GPIO_PULLUP;
559
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
5 mjames 560
 
7 mjames 561
/*Configure GPIO pins : SW2_I_Pin SW2_Q_Pin */
562
GPIO_InitStruct.Pin = SW2_I_Pin | SW2_Q_Pin;
563
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
564
GPIO_InitStruct.Pull = GPIO_PULLUP;
565
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
5 mjames 566
 
2 mjames 567
}
568
 
569
/* USER CODE BEGIN 4 */
570
 
571
/* USER CODE END 4 */
572
 
5 mjames 573
/**
6 mjames 574
 * @brief  This function is executed in case of error occurrence.
575
 * @param  None
576
 * @retval None
577
 */
7 mjames 578
void Error_Handler(void)
5 mjames 579
{
7 mjames 580
/* USER CODE BEGIN Error_Handler */
581
/* User can add his own implementation to report the HAL error return state */
582
while (1)
583
{
5 mjames 584
}
7 mjames 585
/* USER CODE END Error_Handler */
586
}
5 mjames 587
 
2 mjames 588
#ifdef USE_FULL_ASSERT
589
 
590
/**
6 mjames 591
 * @brief Reports the name of the source file and the source line number
592
 * where the assert_param error has occurred.
593
 * @param file: pointer to the source file name
594
 * @param line: assert_param error line source number
595
 * @retval None
596
 */
2 mjames 597
void assert_failed(uint8_t* file, uint32_t line)
7 mjames 598
{
599
/* USER CODE BEGIN 6 */
600
/* User can add his own implementation to report the file name and line number,
601
 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
602
/* USER CODE END 6 */
2 mjames 603
 
7 mjames 604
}
2 mjames 605
 
606
#endif
607
 
608
/**
6 mjames 609
 * @}
610
 */
2 mjames 611
 
612
/**
6 mjames 613
 * @}
614
 */
2 mjames 615
 
616
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/