Subversion Repositories DashDisplay

Rev

Rev 3 | Rev 5 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3 Rev 4
Line 1... Line 1...
1
/**
1
/**
2
  ******************************************************************************
2
 ******************************************************************************
3
  * File Name          : main.c
3
 * File Name          : main.c
4
  * Description        : Main program body
4
 * Description        : Main program body
5
  ******************************************************************************
5
 ******************************************************************************
6
  *
6
 *
7
  * COPYRIGHT(c) 2016 STMicroelectronics
7
 * COPYRIGHT(c) 2016 STMicroelectronics
8
  *
8
 *
9
  * Redistribution and use in source and binary forms, with or without modification,
9
 * Redistribution and use in source and binary forms, with or without modification,
10
  * are permitted provided that the following conditions are met:
10
 * are permitted provided that the following conditions are met:
11
  *   1. Redistributions of source code must retain the above copyright notice,
11
 *   1. Redistributions of source code must retain the above copyright notice,
12
  *      this list of conditions and the following disclaimer.
12
 *      this list of conditions and the following disclaimer.
13
  *   2. Redistributions in binary form must reproduce the above copyright notice,
13
 *   2. Redistributions in binary form must reproduce the above copyright notice,
14
  *      this list of conditions and the following disclaimer in the documentation
14
 *      this list of conditions and the following disclaimer in the documentation
15
  *      and/or other materials provided with the distribution.
15
 *      and/or other materials provided with the distribution.
16
  *   3. Neither the name of STMicroelectronics nor the names of its contributors
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
17
 *      may be used to endorse or promote products derived from this software
18
  *      without specific prior written permission.
18
 *      without specific prior written permission.
19
  *
19
 *
20
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
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
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
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
23
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
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,
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
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.
29
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
  *
30
 *
31
  ******************************************************************************
31
 ******************************************************************************
32
  */
32
 */
33
/* Includes ------------------------------------------------------------------*/
33
/* Includes ------------------------------------------------------------------*/
34
#include "stm32f1xx_hal.h"
34
#include "stm32f1xx_hal.h"
35
 
35
 
36
/* USER CODE BEGIN Includes */
36
/* USER CODE BEGIN Includes */
37
#include "ap_math.h"
37
#include "ap_math.h"
38
#include "serial.h"
38
#include "serial.h"
39
#include "SSD1306.h"
39
#include "SSD1306.h"
40
#include "dials.h"
40
#include "dials.h"
-
 
41
#include "switches.h"
41
#include <math.h>
42
#include <math.h>
42
 
-
 
-
 
43
#include "plx.h"
43
 
44
 
44
/* USER CODE END Includes */
45
/* USER CODE END Includes */
45
 
46
 
46
/* Private variables ---------------------------------------------------------*/
47
/* Private variables ---------------------------------------------------------*/
47
ADC_HandleTypeDef hadc1;
48
ADC_HandleTypeDef hadc1;
Line 75... Line 76...
75
 
76
 
76
}
77
}
77
 
78
 
78
/* USER CODE END 0 */
79
/* USER CODE END 0 */
79
 
80
 
80
int main(void)
81
int main(void) {
81
{
-
 
82
 
82
 
83
  /* USER CODE BEGIN 1 */
83
        /* USER CODE BEGIN 1 */
84
 
84
 
85
        GPIO_InitTypeDef GPIO_InitStruct;
85
        GPIO_InitTypeDef GPIO_InitStruct;
86
 
86
 
87
        __HAL_RCC_SPI1_CLK_ENABLE()
87
        __HAL_RCC_SPI1_CLK_ENABLE()
88
        ;
88
        ;
89
        __HAL_RCC_USART1_CLK_ENABLE(); // PLX main port
89
        __HAL_RCC_USART1_CLK_ENABLE()
-
 
90
        ; // PLX main port
90
        __HAL_RCC_USART2_CLK_ENABLE(); // debug port
91
        __HAL_RCC_USART2_CLK_ENABLE()
-
 
92
        ; // debug port
91
  /* USER CODE END 1 */
93
        /* USER CODE END 1 */
92
 
94
 
93
  /* MCU Configuration----------------------------------------------------------*/
95
        /* MCU Configuration----------------------------------------------------------*/
94
 
96
 
95
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
97
        /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
96
  HAL_Init();
98
        HAL_Init();
97
 
99
 
98
  /* Configure the system clock */
100
        /* Configure the system clock */
99
  SystemClock_Config();
101
        SystemClock_Config();
100
 
102
 
101
  /* Initialize all configured peripherals */
103
        /* Initialize all configured peripherals */
102
  MX_GPIO_Init();
104
        MX_GPIO_Init();
103
  MX_ADC1_Init();
105
        MX_ADC1_Init();
104
  MX_SPI1_Init();
106
        MX_SPI1_Init();
105
  MX_USART2_UART_Init();
107
        MX_USART2_UART_Init();
106
  MX_USART1_UART_Init();
108
        MX_USART1_UART_Init();
107
 
109
 
108
  /* USER CODE BEGIN 2 */
110
        /* USER CODE BEGIN 2 */
109
        /* Need to set AF mode for output pins DURR. */
111
        /* Need to set AF mode for output pins DURR. */
110
        /* SPI bus AF pin selects */
112
        /* SPI bus AF pin selects */
111
        GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
113
        GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
112
 
114
 
113
        GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_7;
115
        GPIO_InitStruct.Pin = GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_7;
Line 129... Line 131...
129
 
131
 
130
        /* Turn on USART1 IRQ */
132
        /* Turn on USART1 IRQ */
131
        HAL_NVIC_SetPriority(USART1_IRQn, 2, 0);
133
        HAL_NVIC_SetPriority(USART1_IRQn, 2, 0);
132
        HAL_NVIC_EnableIRQ(USART1_IRQn);
134
        HAL_NVIC_EnableIRQ(USART1_IRQn);
133
 
135
 
134
 
-
 
135
        /* setup the USART control blocks */
136
        /* setup the USART control blocks */
136
        init_usart_ctl(&uc1, huart1.Instance);
137
        init_usart_ctl(&uc1, huart1.Instance);
137
        init_usart_ctl(&uc2, hirda2.Instance);
138
        init_usart_ctl(&uc2, huart2.Instance);
138
 
139
 
139
        EnableSerialRxInterrupt(&uc1);
140
        EnableSerialRxInterrupt(&uc1);
140
        EnableSerialRxInterrupt(&uc2);
141
        EnableSerialRxInterrupt(&uc2);
141
 
142
 
142
        ap_init(); // set up the approximate math library
143
        ap_init(); // set up the approximate math library
143
 
144
 
144
        ssd1306_begin(1, 0);
145
        ssd1306_begin(1, 0);
145
        clearDisplay();
146
        clearDisplay();
146
        dim(1);
147
        dim(0);
147
        //font_puts(
148
        //font_puts(
148
        //              "Hello world !!\rThis text is a test of the text rendering library in a 5*7 font");
149
        //              "Hello world !!\rThis text is a test of the text rendering library in a 5*7 font");
149
 
150
 
150
        static const xp = 128 - 42;
151
        static const xp = 128 - 42;
151
        dial_origin(xp, 40);
152
        dial_origin(xp, 40);
152
        dial_size(40);
153
        dial_size(40);
153
        dial_draw_scale(10, 20, 16 , 2);
154
        dial_draw_scale(10, 20, 16, 2);
154
 
155
 
155
        display();
156
        display();
156
 
157
 
157
  /* USER CODE END 2 */
158
        InitSwitches();
158
 
159
 
-
 
160
        /* USER CODE END 2 */
-
 
161
 
159
  /* Infinite loop */
162
        /* Infinite loop */
160
  /* USER CODE BEGIN WHILE */
163
        /* USER CODE BEGIN WHILE */
161
        uint32_t Ticks = HAL_GetTick()+100;
164
        uint32_t Ticks = HAL_GetTick() + 100;
162
        int16_t dial0 = 0;
165
        int16_t dial0 = 0;
163
        int16_t dial1 = -1;
166
        int16_t dial1 = -1;
164
 
167
 
165
        int c = 0;
168
        int c = 0;
166
        int i;
169
        int i;
167
        char buff[10];
170
        char buff[10];
168
 
171
 
-
 
172
        // PLX decoder protocol
-
 
173
#define MAXRDG 10
-
 
174
        char PLXPacket = 0;
-
 
175
        union {
-
 
176
                PLX_SensorInfo Sensor[MAXRDG];
-
 
177
                char Bytes[MAXRDG * sizeof(PLX_SensorInfo)];
-
 
178
 
-
 
179
        } Data;
-
 
180
        int Max[MAXRDG];
-
 
181
        int Min[MAXRDG];
-
 
182
        for (i = 0; i < MAXRDG; i++) {
-
 
183
                Max[i] = 0;
-
 
184
                Min[i] = 0xFFF; // 12 bit max value
-
 
185
        }
-
 
186
 
-
 
187
        int PLXPtr;
-
 
188
        int PLXItems;
169
 
189
 
-
 
190
        int OldObservation = -1; // illegal initial value
-
 
191
        int OldObservationIndex = -1; // if more than one sensor this will be printed
170
        while (1) {
192
        while (1) {
-
 
193
// poll switches
-
 
194
                HandleSwitches();
-
 
195
                int ItemIndex  = dial_pos[0];
-
 
196
 
-
 
197
                uint16_t cc = SerialCharsReceived(&uc1);
-
 
198
                for (i = 0; i < cc; i++) {
-
 
199
                        char c = GetCharSerial(&uc1);
-
 
200
                        if (c == PLX_Start) // at any time if the start byte appears, reset the pointers
-
 
201
                                        {
-
 
202
                                PLXPtr = 0;    // reset the pointer
-
 
203
                                PLXPacket = 1;
-
 
204
                                continue;
-
 
205
                        }
-
 
206
 
-
 
207
                        if (c == PLX_Stop) {
-
 
208
                                // we can now decode the selected parameter
-
 
209
                                PLXPacket = 0;
-
 
210
                                PLXItems = PLXPtr / sizeof(PLX_SensorInfo);
-
 
211
                                // saturate the rotary switch position
-
 
212
                if(ItemIndex > PLXItems)
-
 
213
                {
-
 
214
                        dial_pos[0]= PLXItems;
-
 
215
                        ItemIndex = PLXItems;
-
 
216
                }
-
 
217
 
-
 
218
                                int DataVal;
-
 
219
                                // process min/max
-
 
220
                                for (i = 0; i < PLXItems; i++) {
-
 
221
                                        DataVal = ConvPLX(Data.Sensor[i].ObsH, Data.Sensor[i].ObsL);
-
 
222
                                        if (DataVal > Max[i]) {
-
 
223
                                                Max[i] = DataVal;
-
 
224
                                        }
-
 
225
                                        if (DataVal < Min[i]) {
-
 
226
                                                Min[i] = DataVal;
-
 
227
                                        }
-
 
228
                                }
-
 
229
 
-
 
230
                                DataVal = ConvPLX(Data.Sensor[ItemIndex].ObsH,
-
 
231
                                                Data.Sensor[ItemIndex].ObsL);
-
 
232
                                int Observation = ConvPLX(Data.Sensor[ItemIndex].ObsH,
-
 
233
                                                Data.Sensor[ItemIndex].ObsL);
-
 
234
                                int ObservationIndex = ConvPLX(0, Data.Sensor[index].ObsIndex);
-
 
235
                                // now to convert the readings and format strings
-
 
236
                                // find out limits
-
 
237
                                if (Observation != OldObservation
-
 
238
                                                || ObservationIndex != OldObservationIndex) {
-
 
239
 
-
 
240
                                        dial_draw_scale(
-
 
241
                                                        DisplayInfo[Observation].Low
-
 
242
                                                                        / DisplayInfo[Observation].TickScale,
-
 
243
                                                        DisplayInfo[Observation].High
-
 
244
                                                                        / DisplayInfo[Observation].TickScale, 16,
-
 
245
                                                        1);
-
 
246
                                        int len;
-
 
247
                                        if (ObservationIndex > 0) {
-
 
248
                                                len=4;
-
 
249
                                                buff[5] = ObservationIndex + '1';
-
 
250
                                        } else {
-
 
251
                                                len=5;
-
 
252
                                        }
-
 
253
                                        for(i=0;i<len;i++)
-
 
254
                                        {
-
 
255
                                                buff[i] = DisplayInfo[Observation].name;
-
 
256
                                        }
-
 
257
                                        print_large_string(buff, 0, 0, 5); // this prints spaces for \0 at end of string
-
 
258
 
-
 
259
                                        OldObservation = Observation;
-
 
260
                                        OldObservationIndex = ObservationIndex;
-
 
261
                                }
-
 
262
                                //
-
 
263
 
-
 
264
                                double  max_rdg;
-
 
265
                                double  min_rdg;
-
 
266
                                double  cur_rdg;
-
 
267
 
-
 
268
                                max_rdg = ConveriMFDRaw2Data(Observation, DisplayInfo[Observation].Units, Max[ItemIndex]);
-
 
269
                                min_rdg = ConveriMFDRaw2Data(Observation, DisplayInfo[Observation].Units, Min[ItemIndex]);
-
 
270
                                cur_rdg = ConveriMFDRaw2Data(Observation, DisplayInfo[Observation].Units, DataVal);
-
 
271
 
-
 
272
 
-
 
273
 
-
 
274
 
-
 
275
 
-
 
276
                        }
-
 
277
                        if (c > PLX_Stop) // illegal char, restart reading
-
 
278
                                        {
-
 
279
                                PLXPacket = 0;
-
 
280
                        }
-
 
281
                        if (PLXPtr < sizeof(Data.Bytes)) {
-
 
282
                                Data.Bytes[PLXPtr++] = c;
-
 
283
                        }
-
 
284
                }
171
 
285
 
172
                uint16_t cc = SerialCharsReceived(&uc3);
-
 
173
                HAL_Delay(1);
286
                HAL_Delay(1);
174
                CDC_Poll_UART(); /* keep the traffic flowing */
-
 
175
 
287
 
-
 
288
 
176
                dial0 = (c * 2)% 100;
289
                /* now scale and decode the dial position etc .
-
 
290
                 *
-
 
291
                 */
177
                uint32_t CurrTicks = HAL_GetTick();
292
                uint32_t CurrTicks = HAL_GetTick();
178
                if (CurrTicks > Ticks) {
293
                if (CurrTicks > Ticks) {
-
 
294
                    /* Lookup the dial etc . */
-
 
295
 
-
 
296
 
179
                        Ticks = CurrTicks+100;
297
                        Ticks = CurrTicks + 100;
180
                        /* old needle un-draw */
298
                        /* old needle un-draw */
181
                        if (dial1 >= 0) {
299
                        if (dial1 >= 0) {
182
                                dial_draw_needle(dial1);
300
                                dial_draw_needle(dial1);
183
                        }
301
                        }
184
                        // print value overlaid by needle
302
                        // print value overlaid by needle
-
 
303
                        // this is actual reading
185
                        print_digits(xp-16, 48, 4, 3, c);
304
                        print_digits(xp - 16, 48, 4, 3, c);
186
 
-
 
187
 
-
 
188
 
305
 
189
                        dial_draw_needle(dial0);
306
                        dial_draw_needle(dial0);
190
                        dial1 = dial0;
307
                        dial1 = dial0;
191
 
308
 
192
 
-
 
193
 
-
 
194
                        c++;
309
                        c++;
195
                        for(i=0; i< 5; i++)
-
 
196
                        buff[i]=i+c;
-
 
197
                        print_large_string(buff,0,0,5);
-
 
198
                        //font_gotoxy(0, 2);
310
                        //font_gotoxy(0, 2);
199
                        //font_puts("baud\r\n");
311
                        //font_puts("baud\r\n");
200
                        //char buff[10];
312
                        //char buff[10];
201
                        //itoa(hirda3.Init.BaudRate, buff, 10);
313
                        //itoa(hirda3.Init.BaudRate, buff, 10);
202
                        //char l = 6 - strlen(buff);
314
                        //char l = 6 - strlen(buff);
203
                        /* pad with leading spaces */
315
                        /* pad with leading spaces */
204
                        //while (l > 0) {
316
                        //while (l > 0) {
205
                        //      font_putchar(' ');
317
                        //      font_putchar(' ');
206
                        //      l--;
318
                        //      l--;
207
                        //}
319
                        //}
208
 
-
 
209
                        //font_puts(itoa(hirda3.Init.BaudRate, buff, 10));
320
                        //font_puts(itoa(hirda3.Init.BaudRate, buff, 10));
210
 
-
 
211
                        display();
321
                        display();
212
                }
322
                }
213
  /* USER CODE END WHILE */
323
                /* USER CODE END WHILE */
214
 
324
 
215
  /* USER CODE BEGIN 3 */
325
                /* USER CODE BEGIN 3 */
216
 
326
 
217
        }
327
        }
218
  /* USER CODE END 3 */
328
        /* USER CODE END 3 */
219
 
329
 
220
}
330
}
221
 
331
 
222
/** System Clock Configuration
332
/** System Clock Configuration
223
*/
333
 */
224
void SystemClock_Config(void)
334
void SystemClock_Config(void) {
225
{
-
 
226
 
335
 
227
  RCC_OscInitTypeDef RCC_OscInitStruct;
336
        RCC_OscInitTypeDef RCC_OscInitStruct;
228
  RCC_ClkInitTypeDef RCC_ClkInitStruct;
337
        RCC_ClkInitTypeDef RCC_ClkInitStruct;
229
  RCC_PeriphCLKInitTypeDef PeriphClkInit;
338
        RCC_PeriphCLKInitTypeDef PeriphClkInit;
230
 
339
 
231
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
340
        RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
232
  RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
341
        RCC_OscInitStruct.HSEState = RCC_HSE_BYPASS;
233
  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
342
        RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
234
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
343
        RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
235
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
344
        RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
236
  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
345
        RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
237
  HAL_RCC_OscConfig(&RCC_OscInitStruct);
346
        HAL_RCC_OscConfig(&RCC_OscInitStruct);
238
 
347
 
239
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
348
        RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK
240
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
349
                        | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
241
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
350
        RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
242
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
351
        RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
243
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
352
        RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
244
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
353
        RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
245
  HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
354
        HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
246
 
355
 
247
  PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
356
        PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
248
  PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
357
        PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
249
  HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
358
        HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
250
 
359
 
251
  HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
360
        HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq() / 1000);
252
 
361
 
253
  HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
362
        HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
254
 
363
 
255
  /* SysTick_IRQn interrupt configuration */
364
        /* SysTick_IRQn interrupt configuration */
256
  HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
365
        HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
257
}
366
}
258
 
367
 
259
/* ADC1 init function */
368
/* ADC1 init function */
260
void MX_ADC1_Init(void)
369
void MX_ADC1_Init(void) {
261
{
-
 
262
 
370
 
263
  ADC_ChannelConfTypeDef sConfig;
371
        ADC_ChannelConfTypeDef sConfig;
264
 
372
 
265
    /**Common config
373
        /**Common config
266
    */
374
         */
267
  hadc1.Instance = ADC1;
375
        hadc1.Instance = ADC1;
268
  hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
376
        hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
269
  hadc1.Init.ContinuousConvMode = DISABLE;
377
        hadc1.Init.ContinuousConvMode = DISABLE;
270
  hadc1.Init.DiscontinuousConvMode = DISABLE;
378
        hadc1.Init.DiscontinuousConvMode = DISABLE;
271
  hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
379
        hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
272
  hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
380
        hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
273
  hadc1.Init.NbrOfConversion = 1;
381
        hadc1.Init.NbrOfConversion = 1;
274
  HAL_ADC_Init(&hadc1);
382
        HAL_ADC_Init(&hadc1);
275
 
383
 
276
    /**Configure Regular Channel
384
        /**Configure Regular Channel
277
    */
385
         */
278
  sConfig.Channel = ADC_CHANNEL_0;
386
        sConfig.Channel = ADC_CHANNEL_0;
279
  sConfig.Rank = 1;
387
        sConfig.Rank = 1;
280
  sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
388
        sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
281
  HAL_ADC_ConfigChannel(&hadc1, &sConfig);
389
        HAL_ADC_ConfigChannel(&hadc1, &sConfig);
282
 
390
 
283
}
391
}
284
 
392
 
285
/* SPI1 init function */
393
/* SPI1 init function */
286
void MX_SPI1_Init(void)
394
void MX_SPI1_Init(void) {
287
{
-
 
288
 
395
 
289
  hspi1.Instance = SPI1;
396
        hspi1.Instance = SPI1;
290
  hspi1.Init.Mode = SPI_MODE_MASTER;
397
        hspi1.Init.Mode = SPI_MODE_MASTER;
291
  hspi1.Init.Direction = SPI_DIRECTION_1LINE;
398
        hspi1.Init.Direction = SPI_DIRECTION_1LINE;
292
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
399
        hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
293
  hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
400
        hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
294
  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
401
        hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
295
  hspi1.Init.NSS = SPI_NSS_SOFT;
402
        hspi1.Init.NSS = SPI_NSS_SOFT;
296
  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
403
        hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8;
297
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
404
        hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
298
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
405
        hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
299
  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
406
        hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
300
  hspi1.Init.CRCPolynomial = 10;
407
        hspi1.Init.CRCPolynomial = 10;
301
  HAL_SPI_Init(&hspi1);
408
        HAL_SPI_Init(&hspi1);
302
 
409
 
303
}
410
}
304
 
411
 
305
/* USART1 init function */
412
/* USART1 init function */
306
void MX_USART1_UART_Init(void)
413
void MX_USART1_UART_Init(void) {
307
{
-
 
308
 
414
 
309
  huart1.Instance = USART1;
415
        huart1.Instance = USART1;
310
  huart1.Init.BaudRate = 115200;
416
        huart1.Init.BaudRate = 115200;
311
  huart1.Init.WordLength = UART_WORDLENGTH_8B;
417
        huart1.Init.WordLength = UART_WORDLENGTH_8B;
312
  huart1.Init.StopBits = UART_STOPBITS_1;
418
        huart1.Init.StopBits = UART_STOPBITS_1;
313
  huart1.Init.Parity = UART_PARITY_NONE;
419
        huart1.Init.Parity = UART_PARITY_NONE;
314
  huart1.Init.Mode = UART_MODE_TX_RX;
420
        huart1.Init.Mode = UART_MODE_TX_RX;
315
  huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
421
        huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
316
  huart1.Init.OverSampling = UART_OVERSAMPLING_16;
422
        huart1.Init.OverSampling = UART_OVERSAMPLING_16;
317
  HAL_UART_Init(&huart1);
423
        HAL_UART_Init(&huart1);
318
 
424
 
319
}
425
}
320
 
426
 
321
/* USART2 init function */
427
/* USART2 init function */
322
void MX_USART2_UART_Init(void)
428
void MX_USART2_UART_Init(void) {
323
{
-
 
324
 
429
 
325
  huart2.Instance = USART2;
430
        huart2.Instance = USART2;
326
  huart2.Init.BaudRate = 115200;
431
        huart2.Init.BaudRate = 115200;
327
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
432
        huart2.Init.WordLength = UART_WORDLENGTH_8B;
328
  huart2.Init.StopBits = UART_STOPBITS_1;
433
        huart2.Init.StopBits = UART_STOPBITS_1;
329
  huart2.Init.Parity = UART_PARITY_NONE;
434
        huart2.Init.Parity = UART_PARITY_NONE;
330
  huart2.Init.Mode = UART_MODE_TX_RX;
435
        huart2.Init.Mode = UART_MODE_TX_RX;
331
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
436
        huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
332
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
437
        huart2.Init.OverSampling = UART_OVERSAMPLING_16;
333
  HAL_UART_Init(&huart2);
438
        HAL_UART_Init(&huart2);
334
 
439
 
335
}
440
}
336
 
441
 
337
/** Configure pins as
442
/** Configure pins as
338
        * Analog
443
 * Analog
339
        * Input
444
 * Input
340
        * Output
445
 * Output
341
        * EVENT_OUT
446
 * EVENT_OUT
342
        * EXTI
447
 * EXTI
343
*/
448
 */
344
void MX_GPIO_Init(void)
449
void MX_GPIO_Init(void) {
-
 
450
 
-
 
451
        GPIO_InitTypeDef GPIO_InitStruct;
345
{
452
 
-
 
453
        /* GPIO Ports Clock Enable */
-
 
454
        __HAL_RCC_GPIOD_CLK_ENABLE()
-
 
455
        ;
-
 
456
        __HAL_RCC_GPIOA_CLK_ENABLE()
-
 
457
        ;
-
 
458
        __HAL_RCC_GPIOC_CLK_ENABLE()
-
 
459
        ;
-
 
460
        __HAL_RCC_GPIOB_CLK_ENABLE()
-
 
461
        ;
346
 
462
 
-
 
463
        /*Configure GPIO pin Output Level */
-
 
464
        HAL_GPIO_WritePin(GPIOA, SPI1_NSS1_Pin | SPI1CD_Pin, GPIO_PIN_RESET);
-
 
465
 
-
 
466
        /*Configure GPIO pin Output Level */
-
 
467
        HAL_GPIO_WritePin(GPIOC,
-
 
468
                        SPI_RESET_Pin | SPI_NSS2_Pin | USART3_INVERT_Pin | USB_PWR_Pin,
-
 
469
                        GPIO_PIN_RESET);
-
 
470
 
-
 
471
        /*Configure GPIO pins : SPI1_NSS1_Pin SPI1CD_Pin */
-
 
472
        GPIO_InitStruct.Pin = SPI1_NSS1_Pin | SPI1CD_Pin;
-
 
473
        GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
-
 
474
        GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
347
  GPIO_InitTypeDef GPIO_InitStruct;
475
        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
348
 
476
 
349
  /* GPIO Ports Clock Enable */
-
 
350
  __HAL_RCC_GPIOD_CLK_ENABLE();
-
 
351
  __HAL_RCC_GPIOA_CLK_ENABLE();
-
 
352
  __HAL_RCC_GPIOC_CLK_ENABLE();
-
 
353
  __HAL_RCC_GPIOB_CLK_ENABLE();
-
 
354
 
-
 
355
  /*Configure GPIO pin Output Level */
-
 
356
  HAL_GPIO_WritePin(GPIOA, SPI1_NSS1_Pin|SPI1CD_Pin, GPIO_PIN_RESET);
-
 
357
 
-
 
358
  /*Configure GPIO pin Output Level */
-
 
359
  HAL_GPIO_WritePin(GPIOC, SPI_RESET_Pin|SPI_NSS2_Pin|USART3_INVERT_Pin|USB_PWR_Pin, GPIO_PIN_RESET);
-
 
360
 
-
 
361
  /*Configure GPIO pins : SPI1_NSS1_Pin SPI1CD_Pin */
-
 
362
  GPIO_InitStruct.Pin = SPI1_NSS1_Pin|SPI1CD_Pin;
-
 
363
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
-
 
364
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
-
 
365
  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
-
 
366
 
-
 
367
  /*Configure GPIO pins : SPI_RESET_Pin SPI_NSS2_Pin USART3_INVERT_Pin USB_PWR_Pin */
477
        /*Configure GPIO pins : SPI_RESET_Pin SPI_NSS2_Pin USART3_INVERT_Pin USB_PWR_Pin */
368
  GPIO_InitStruct.Pin = SPI_RESET_Pin|SPI_NSS2_Pin|USART3_INVERT_Pin|USB_PWR_Pin;
478
        GPIO_InitStruct.Pin = SPI_RESET_Pin | SPI_NSS2_Pin | USART3_INVERT_Pin
-
 
479
                        | USB_PWR_Pin;
369
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
480
        GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
370
  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
481
        GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
371
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
482
        HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
372
 
483
 
373
  /*Configure GPIO pins : SW1_PUSH_Pin SW1_I_Pin SW1_Q_Pin SW2_PUSH_Pin */
484
        /*Configure GPIO pins : SW1_PUSH_Pin SW1_I_Pin SW1_Q_Pin SW2_PUSH_Pin */
374
  GPIO_InitStruct.Pin = SW1_PUSH_Pin|SW1_I_Pin|SW1_Q_Pin|SW2_PUSH_Pin;
485
        GPIO_InitStruct.Pin = SW1_PUSH_Pin | SW1_I_Pin | SW1_Q_Pin | SW2_PUSH_Pin;
375
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
486
        GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
376
  GPIO_InitStruct.Pull = GPIO_PULLUP;
487
        GPIO_InitStruct.Pull = GPIO_PULLUP;
377
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
488
        HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
378
 
489
 
379
  /*Configure GPIO pins : SW2_I_Pin SW2_Q_Pin */
490
        /*Configure GPIO pins : SW2_I_Pin SW2_Q_Pin */
380
  GPIO_InitStruct.Pin = SW2_I_Pin|SW2_Q_Pin;
491
        GPIO_InitStruct.Pin = SW2_I_Pin | SW2_Q_Pin;
381
  GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
492
        GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
382
  GPIO_InitStruct.Pull = GPIO_PULLUP;
493
        GPIO_InitStruct.Pull = GPIO_PULLUP;
383
  HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
494
        HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
384
 
495
 
385
}
496
}
386
 
497
 
387
/* USER CODE BEGIN 4 */
498
/* USER CODE BEGIN 4 */
388
 
499
 
389
/* USER CODE END 4 */
500
/* USER CODE END 4 */
390
 
501
 
391
#ifdef USE_FULL_ASSERT
502
#ifdef USE_FULL_ASSERT
392
 
503
 
393
/**
504
/**
394
   * @brief Reports the name of the source file and the source line number
505
 * @brief Reports the name of the source file and the source line number
395
   * where the assert_param error has occurred.
506
 * where the assert_param error has occurred.
396
   * @param file: pointer to the source file name
507
 * @param file: pointer to the source file name
397
   * @param line: assert_param error line source number
508
 * @param line: assert_param error line source number
398
   * @retval None
509
 * @retval None
399
   */
510
 */
400
void assert_failed(uint8_t* file, uint32_t line)
511
void assert_failed(uint8_t* file, uint32_t line)
401
{
512
{
402
  /* USER CODE BEGIN 6 */
513
        /* USER CODE BEGIN 6 */
403
        /* User can add his own implementation to report the file name and line number,
514
        /* User can add his own implementation to report the file name and line number,
404
         ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
515
         ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
405
  /* USER CODE END 6 */
516
        /* USER CODE END 6 */
406
 
517
 
407
}
518
}
408
 
519
 
409
#endif
520
#endif
410
 
521
 
411
/**
522
/**
412
  * @}
523
 * @}
413
  */
524
 */
414
 
525
 
415
/**
526
/**
416
  * @}
527
 * @}
417
*/
528
 */
418
 
529
 
419
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
530
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/