]> mj.ucw.cz Git - home-hw.git/commitdiff
Time display through USB
authorMartin Mares <mj@ucw.cz>
Tue, 26 Jun 2018 13:37:32 +0000 (15:37 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 26 Jun 2018 13:37:32 +0000 (15:37 +0200)
Inc/app.h
Src/display.c
Src/main.c
Src/stm32f1xx_it.c
Src/usbdev.c
host/test.c

index bd81ad08a567b270adb177126c7d5e6c55966681..d975287ef502c59fb2fba75fcaba135a79be3695 100644 (file)
--- a/Inc/app.h
+++ b/Inc/app.h
@@ -1,4 +1,10 @@
+// main.c
+
+extern byte rx_display[8];
+extern volatile byte rx_display_ready;
+
 // display.c
 
 void display_init(void);
 void display_counter(uint cnt);
+void display_buffer(byte *buf);
index a8aecf3db468c6def128af853b2000f74e65f020..2af6ad1e6bea0a423b34c2f4837741421620e631 100644 (file)
@@ -157,3 +157,35 @@ void display_counter(uint cnt)
       display_data_end();
     }
 }
+
+void display_buffer(byte *buf)
+{
+  for (uint p=0; p<4; p++)
+    {
+      display_cmd(SSD1306_SETSTARTPAGE + p);
+      display_cmd(SSD1306_SETHIGHCOLUMN);
+      display_cmd(SSD1306_SETLOWCOLUMN);
+      display_data_start();
+      for (uint i=0; i<5; i++)
+       {
+         uint ch = buf[i];
+         if (ch <= 10)
+           {
+             for (uint j=0; j<23; j++)
+               {
+                 byte x = Gentium23x32[(23*4+1)*ch + 1 + 4*j + p];
+                 display_data(x);
+               }
+           }
+         else
+           {
+             for (uint j=0; j<23; j++)
+               display_data(0);
+           }
+         display_data(0);
+         display_data(0);
+         display_data(0);
+       }
+      display_data_end();
+    }
+}
index 57349e4521dd5e5ef16e148492eb2daa2b8bc153..bb225b2362046e2cdaf17476e555569404db85cf 100644 (file)
@@ -45,6 +45,8 @@
 #include "usb.h"
 #include "app.h"
 
+#include <string.h>
+
 /* USER CODE END Includes */
 
 /* Private variables ---------------------------------------------------------*/
@@ -71,6 +73,8 @@ static void MX_TIM4_Init(void);
 /* USER CODE END PFP */
 
 /* USER CODE BEGIN 0 */
+byte rx_display[8];
+volatile byte rx_display_ready;
 
 /* USER CODE END 0 */
 
@@ -128,17 +132,40 @@ int main(void)
   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_mDelay(1000);
-    cnt++;
+    __disable_irq();
+    if (rx_display_ready)
+      {
+       byte rx[8];
+       rx_display_ready = 0;
+       memcpy(rx, rx_display, 8);
+       __enable_irq();
+       display_buffer(rx);
+      }
+    else
+      __enable_irq();
+
+    // 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 */
 
index 67ae5fe53330627f035d347aeaa3b70df8749ca9..1754251c6d162f6b33ff88692dd65c2ff7ebdd83 100644 (file)
@@ -230,12 +230,7 @@ void TIM4_IRQHandler(void)
   /* USER CODE BEGIN TIM4_IRQn 0 */
   if (LL_TIM_IsActiveFlag_UPDATE(TIM4))
     {
-      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;
+      // FIXME
       LL_TIM_ClearFlag_UPDATE(TIM4);
     }
 
index ca98cd32faea940bbe09daec2b96bd756a1a4e2c..9713bc8093f9452b01da53131e7ef3ddde60a321 100644 (file)
@@ -3,6 +3,9 @@
 
 #include "util.h"
 #include "usb.h"
+#include "app.h"
+
+#include <string.h>
 
 /*** Descriptors ***/
 
@@ -135,6 +138,14 @@ void usb_dev_recv_done(struct usb *usb, byte epnum)
     {
       // usb_tx_buf[0]++;
       // usb_ep_send(usb, 0x82, usb_tx_buf, 33);
+
+      u32 len = usb_ep_received_size(usb, 0x01);
+      if (len >= 8)
+       {
+         memcpy(rx_display, usb_rx_buf, 8);
+         rx_display_ready = 1;
+       }
+
       usb_ep_receive(usb, 0x01, usb_rx_buf, 64);
     }
 }
index 81d428e69b8c46cae77e9466932d97948839379e..07b804e4d3a0fb2f274cec710ad2fa7396ff78fb 100644 (file)
@@ -1,5 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
+#include <time.h>
 #include <libusb-1.0/libusb.h>
 
 struct libusb_context *usb_ctxt;
@@ -61,16 +63,25 @@ int main(void)
 
   for (;;)
     {
-      unsigned char req[64] = { 1, 2, 3, 4 };
+      time_t t = time(NULL);
+      struct tm *tm = localtime(&t);
+
+      unsigned char req[8] = {
+       tm->tm_hour / 10,
+       tm->tm_hour % 10,
+       (tm->tm_sec % 2 ? 10 : 0xff),
+       tm->tm_min / 10,
+       tm->tm_min % 10,
+      };
       int transferred;
-      if (err = libusb_bulk_transfer(devh, 0x01, req, 32, &transferred, 2000))
+      if (err = libusb_bulk_transfer(devh, 0x01, req, 8, &transferred, 2000))
        {
          fprintf(stderr, "Transfer failed: error %d\n", err);
          exit(1);
        }
       printf("Transferred %d bytes\n", transferred);
 
-#if 1
+#if 0
       unsigned char resp[1000];
       int received;
       if (err = libusb_bulk_transfer(devh, 0x82, resp, 1000, &received, 2000))
@@ -80,6 +91,8 @@ int main(void)
        }
       printf("Received %d bytes [%02x]\n", received, resp[0]);
 #endif
+
+      sleep(1);
     }
 
   return 0;