]> mj.ucw.cz Git - home-hw.git/blobdiff - ssr/Src/main.c
SSR: Cleanup
[home-hw.git] / ssr / Src / main.c
index e934fa9ce2ffd911f87a278c2e714fa4e340f977..dc015c0ad0ab1b5e1694cdefb7be22a87fccfa13 100644 (file)
@@ -62,10 +62,9 @@ struct usb usb;
 /* Private function prototypes -----------------------------------------------*/
 void SystemClock_Config(void);
 static void MX_GPIO_Init(void);
-static void MX_I2C1_Init(void);
-static void MX_I2C2_Init(void);
 static void MX_USB_PCD_Init(void);
 static void MX_TIM4_Init(void);
+static void MX_USART1_UART_Init(void);
 
 /* USER CODE BEGIN PFP */
 /* Private function prototypes -----------------------------------------------*/
@@ -118,24 +117,16 @@ int main(void)
   LL_GPIO_ResetOutputPin(GPIOA, LL_GPIO_PIN_13);
   LL_mDelay(1000);
 
-  MX_I2C1_Init();
-  MX_I2C2_Init();
   MX_USB_PCD_Init();
   MX_TIM4_Init();
+  MX_USART1_UART_Init();
   /* USER CODE BEGIN 2 */
-  display_init();
   usb_start(&usb);
-  bmp_init();
 
   LL_TIM_EnableCounter(TIM4);
   LL_TIM_EnableIT_UPDATE(TIM4);
   LL_TIM_GenerateEvent_UPDATE(TIM4);
 
-  {
-    byte buf[5] = { 0xff, 0xff, 10, 0xff, 0xff };
-    display_buffer(buf);
-  }
-
   /* USER CODE END 2 */
 
   /* Infinite loop */
@@ -151,21 +142,14 @@ int main(void)
          LL_GPIO_ResetOutputPin(LED_GPIO_Port, LED_Pin);
        led_state ^= 1;
 
-       display_buffer(rx_packet);
        tx_packet_state = 1;
-       put_u32_be(tx_packet, adjusted_temp);
-       put_u32_be(tx_packet + 4, adjusted_press);
-       put_u32_be(tx_packet + 8, bmp_counter);
+       put_u32_be(tx_packet, 42);
        usb_ep_send(&usb, 0x82, tx_packet, 12);
        rx_packet_state = 0;
        usb_ep_receive(&usb, 0x01, rx_packet, 64);
-       bmp_request = 1;
       }
 
-    bmp_step();
-
     // debug_printf("Counter = %d\n", cnt);
-    // display_counter(cnt);
 
     __WFI();
 
@@ -232,92 +216,6 @@ void SystemClock_Config(void)
   NVIC_SetPriority(SysTick_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
 }
 
-/* I2C1 init function */
-static void MX_I2C1_Init(void)
-{
-
-  LL_I2C_InitTypeDef I2C_InitStruct;
-
-  LL_GPIO_InitTypeDef GPIO_InitStruct;
-
-  /**I2C1 GPIO Configuration  
-  PB6   ------> I2C1_SCL
-  PB7   ------> I2C1_SDA 
-  */
-  GPIO_InitStruct.Pin = LL_GPIO_PIN_6|LL_GPIO_PIN_7;
-  GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
-  GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
-  GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
-  LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
-  /* Peripheral clock enable */
-  LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C1);
-
-  /* I2C1 interrupt Init */
-  NVIC_SetPriority(I2C1_EV_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(),0, 0));
-  NVIC_EnableIRQ(I2C1_EV_IRQn);
-
-    /**I2C Initialization 
-    */
-  I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C;
-  I2C_InitStruct.ClockSpeed = 400000;
-  I2C_InitStruct.DutyCycle = LL_I2C_DUTYCYCLE_2;
-  I2C_InitStruct.OwnAddress1 = 0;
-  I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK;
-  I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT;
-  LL_I2C_Init(I2C1, &I2C_InitStruct);
-
-  LL_I2C_SetOwnAddress2(I2C1, 0);
-
-  LL_I2C_DisableOwnAddress2(I2C1);
-
-  LL_I2C_DisableGeneralCall(I2C1);
-
-  LL_I2C_EnableClockStretching(I2C1);
-
-}
-
-/* I2C2 init function */
-static void MX_I2C2_Init(void)
-{
-
-  LL_I2C_InitTypeDef I2C_InitStruct;
-
-  LL_GPIO_InitTypeDef GPIO_InitStruct;
-
-  /**I2C2 GPIO Configuration  
-  PB10   ------> I2C2_SCL
-  PB11   ------> I2C2_SDA 
-  */
-  GPIO_InitStruct.Pin = LL_GPIO_PIN_10|LL_GPIO_PIN_11;
-  GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
-  GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
-  GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_OPENDRAIN;
-  LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
-
-  /* Peripheral clock enable */
-  LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_I2C2);
-
-    /**I2C Initialization 
-    */
-  I2C_InitStruct.PeripheralMode = LL_I2C_MODE_I2C;
-  I2C_InitStruct.ClockSpeed = 400000;
-  I2C_InitStruct.DutyCycle = LL_I2C_DUTYCYCLE_2;
-  I2C_InitStruct.OwnAddress1 = 0;
-  I2C_InitStruct.TypeAcknowledge = LL_I2C_ACK;
-  I2C_InitStruct.OwnAddrSize = LL_I2C_OWNADDRESS1_7BIT;
-  LL_I2C_Init(I2C2, &I2C_InitStruct);
-
-  LL_I2C_SetOwnAddress2(I2C2, 0);
-
-  LL_I2C_DisableOwnAddress2(I2C2);
-
-  LL_I2C_DisableGeneralCall(I2C2);
-
-  LL_I2C_EnableClockStretching(I2C2);
-
-}
-
 /* TIM4 init function */
 static void MX_TIM4_Init(void)
 {
@@ -357,6 +255,45 @@ static void MX_TIM4_Init(void)
 
 }
 
+/* USART1 init function */
+static void MX_USART1_UART_Init(void)
+{
+
+  LL_USART_InitTypeDef USART_InitStruct;
+
+  LL_GPIO_InitTypeDef GPIO_InitStruct;
+
+  /* Peripheral clock enable */
+  LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_USART1);
+  
+  /**USART1 GPIO Configuration  
+  PA9   ------> USART1_TX
+  PA10   ------> USART1_RX 
+  */
+  GPIO_InitStruct.Pin = LL_GPIO_PIN_9;
+  GPIO_InitStruct.Mode = LL_GPIO_MODE_ALTERNATE;
+  GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
+  GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
+  LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+
+  GPIO_InitStruct.Pin = LL_GPIO_PIN_10;
+  GPIO_InitStruct.Mode = LL_GPIO_MODE_FLOATING;
+  LL_GPIO_Init(GPIOA, &GPIO_InitStruct);
+
+  USART_InitStruct.BaudRate = 115200;
+  USART_InitStruct.DataWidth = LL_USART_DATAWIDTH_8B;
+  USART_InitStruct.StopBits = LL_USART_STOPBITS_1;
+  USART_InitStruct.Parity = LL_USART_PARITY_NONE;
+  USART_InitStruct.TransferDirection = LL_USART_DIRECTION_TX_RX;
+  USART_InitStruct.HardwareFlowControl = LL_USART_HWCONTROL_NONE;
+  LL_USART_Init(USART1, &USART_InitStruct);
+
+  LL_USART_ConfigAsyncMode(USART1);
+
+  LL_USART_Enable(USART1);
+
+}
+
 /* USB init function */
 static void MX_USB_PCD_Init(void)
 {
@@ -396,6 +333,9 @@ static void MX_GPIO_Init(void)
   /**/
   LL_GPIO_ResetOutputPin(LED_GPIO_Port, LED_Pin);
 
+  /**/
+  LL_GPIO_ResetOutputPin(GPIOB, SSR3_Pin|SSR4_Pin|SSR1_Pin|SSR2_Pin);
+
   /**/
   GPIO_InitStruct.Pin = LED_Pin;
   GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
@@ -404,9 +344,11 @@ static void MX_GPIO_Init(void)
   LL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);
 
   /**/
-  GPIO_InitStruct.Pin = BMP_DONE_Pin;
-  GPIO_InitStruct.Mode = LL_GPIO_MODE_FLOATING;
-  LL_GPIO_Init(BMP_DONE_GPIO_Port, &GPIO_InitStruct);
+  GPIO_InitStruct.Pin = SSR3_Pin|SSR4_Pin|SSR1_Pin|SSR2_Pin;
+  GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
+  GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_LOW;
+  GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
+  LL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
 }