Subversion Repositories DashDisplay

Rev

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