Subversion Repositories DashDisplay

Rev

Rev 14 | Rev 16 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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