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