Subversion Repositories DashDisplay

Rev

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