]> mj.ucw.cz Git - home-hw.git/blobdiff - Src/main.c
Request/reply protocol
[home-hw.git] / Src / main.c
index de59f78369fc054eb53e7c83b568cc3ba3b56503..e77264bd3e58ad62ed54c3917417cb5fc73155f1 100644 (file)
@@ -45,6 +45,8 @@
 #include "usb.h"
 #include "app.h"
 
+#include <string.h>
+
 /* USER CODE END Includes */
 
 /* Private variables ---------------------------------------------------------*/
@@ -124,20 +126,41 @@ int main(void)
   display_init();
   usb_start(&usb);
 
+  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 */
   /* USER CODE BEGIN WHILE */
-  int cnt = 0;
   while (1)
   {
-    debug_printf("Counter = %d\n", cnt);
-    display_counter(cnt);
-    LL_GPIO_SetOutputPin(LED_GPIO_Port, LED_Pin);
-    LL_mDelay(500);
-    LL_GPIO_ResetOutputPin(LED_GPIO_Port, LED_Pin);
-    LL_mDelay(500);
-    cnt++;
+    if (rx_packet_state == 1 && !tx_packet_state)
+      {
+       display_buffer(rx_packet);
+       tx_packet_state = 1;
+       usb_ep_send(&usb, 0x82, tx_packet, 8);
+       rx_packet_state = 0;
+       usb_ep_receive(&usb, 0x01, rx_packet, 64);
+      }
+
+    // debug_printf("Counter = %d\n", cnt);
+    // display_counter(cnt);
+
+    static byte led_state;
+    if (led_state)
+      LL_GPIO_SetOutputPin(LED_GPIO_Port, LED_Pin);
+    else
+      LL_GPIO_ResetOutputPin(LED_GPIO_Port, LED_Pin);
+    led_state ^= 1;
+
+    __WFI();
 
   /* USER CODE END WHILE */