]> mj.ucw.cz Git - home-hw.git/blobdiff - Src/usbdev.c
Time display through USB
[home-hw.git] / Src / usbdev.c
index 3e6e76a3bec050b4b4c03265def7d3a73c22c21d..9713bc8093f9452b01da53131e7ef3ddde60a321 100644 (file)
@@ -3,6 +3,9 @@
 
 #include "util.h"
 #include "usb.h"
 
 #include "util.h"
 #include "usb.h"
+#include "app.h"
+
+#include <string.h>
 
 /*** Descriptors ***/
 
 
 /*** Descriptors ***/
 
@@ -65,7 +68,7 @@ static const byte desc_config[] = {
   // End-point descriptor
   7,                           // bLength
   USB_DESC_TYPE_ENDPOINT,      // bDescriptorType
   // End-point descriptor
   7,                           // bLength
   USB_DESC_TYPE_ENDPOINT,      // bDescriptorType
-  0x81,                                // bEndpointAddress
+  0x82,                                // bEndpointAddress
   USB_EP_TYPE_BULK,            // bmAttributes
   0x40, 0x00,                  // wMaxPacketSize
   0x00,                                // bInterval: unused
   USB_EP_TYPE_BULK,            // bmAttributes
   0x40, 0x00,                  // wMaxPacketSize
   0x00,                                // bInterval: unused
@@ -88,6 +91,9 @@ static const byte desc_languages[] = {
 
 /*** Callbacks ***/
 
 
 /*** Callbacks ***/
 
+static byte usb_rx_buf[64];
+static byte usb_tx_buf[64];
+
 void usb_dev_reset(struct usb *usb)
 {
   usb->desc_device = desc_device;
 void usb_dev_reset(struct usb *usb)
 {
   usb->desc_device = desc_device;
@@ -102,10 +108,15 @@ void usb_dev_reset(struct usb *usb)
 
 void usb_dev_configure(struct usb *usb)
 {
 
 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);
 }
 
 void usb_dev_unconfigure(struct usb *usb)
 {
 }
 
 void usb_dev_unconfigure(struct usb *usb)
 {
+  usb_ep_close(usb, 0x01);
+  usb_ep_close(usb, 0x82);
 }
 
 bool usb_dev_setup_hook(struct usb *usb, struct setup_request *setup)
 }
 
 bool usb_dev_setup_hook(struct usb *usb, struct setup_request *setup)
@@ -123,8 +134,23 @@ void usb_dev_ctl_send_done(struct usb *usb)
 
 void usb_dev_recv_done(struct usb *usb, byte epnum)
 {
 
 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);
+    }
 }
 
 void usb_dev_send_done(struct usb *usb, byte epnum)
 {
 }
 
 void usb_dev_send_done(struct usb *usb, byte epnum)
 {
+  // usb_ep_receive(usb, 0x01, usb_rx_buf, 64);
 }
 }