]> mj.ucw.cz Git - home-hw.git/blobdiff - Src/usbdev.c
Request/reply protocol
[home-hw.git] / Src / usbdev.c
index 9713bc8093f9452b01da53131e7ef3ddde60a321..4834592fbfd1b5c3c8b2897fa2978fef6bf5987c 100644 (file)
@@ -91,8 +91,9 @@ static const byte desc_languages[] = {
 
 /*** Callbacks ***/
 
-static byte usb_rx_buf[64];
-static byte usb_tx_buf[64];
+byte rx_packet[64];
+byte tx_packet[64];
+volatile byte rx_packet_state, tx_packet_state;
 
 void usb_dev_reset(struct usb *usb)
 {
@@ -110,7 +111,7 @@ void usb_dev_configure(struct usb *usb)
 {
   usb_ep_open(usb, 0x01, USB_EP_TYPE_BULK, 64);
   usb_ep_open(usb, 0x82, USB_EP_TYPE_BULK, 64);
-  usb_ep_receive(usb, 0x01, usb_rx_buf, 64);
+  usb_ep_receive(usb, 0x01, rx_packet, 64);
 }
 
 void usb_dev_unconfigure(struct usb *usb)
@@ -136,21 +137,15 @@ void usb_dev_recv_done(struct usb *usb, byte epnum)
 {
   if (epnum == 0x01)
     {
-      // 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);
+      if (len >= 8 && !rx_packet_state)
+       rx_packet_state = 1;
+      else
+       usb_ep_receive(usb, 0x01, rx_packet, 64);
     }
 }
 
 void usb_dev_send_done(struct usb *usb, byte epnum)
 {
-  // usb_ep_receive(usb, 0x01, usb_rx_buf, 64);
+  tx_packet_state = 0;
 }