Subversion Repositories DashDisplay

Rev

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