Subversion Repositories DashDisplay

Rev

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