From d2e7c6170752b085bbfed155308511790984ccab Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Thu, 20 Sep 2012 21:19:29 +0200 Subject: Improved USB driver. --- usb/generic.h | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'usb/generic.h') diff --git a/usb/generic.h b/usb/generic.h index 60c89c4..d5c12ff 100644 --- a/usb/generic.h +++ b/usb/generic.h @@ -3,12 +3,17 @@ #include +#include + +RBLog<256, 2> usb_rblog; + struct desc_t { uint32_t size; void* data; }; enum SetupStatus {Unhandled, Ok, Stall}; +enum EPType {Control, Bulk, Interrupt, Isochronous}; class USB_class_driver { friend class USB_generic; @@ -36,7 +41,7 @@ class USB_generic { virtual void write(uint32_t ep, uint32_t* bufp, uint32_t len) = 0; virtual uint32_t read(uint32_t ep, uint32_t* bufp, uint32_t len) = 0; virtual void hw_set_address(uint8_t addr) = 0; - virtual void hw_conf_ep(uint8_t ep, uint32_t conf) = 0; + virtual void hw_conf_ep(uint8_t ep, EPType type, uint32_t size) = 0; virtual void hw_set_stall(uint8_t ep) = 0; bool register_control_handler(USB_class_driver* control_handler) { @@ -101,11 +106,11 @@ class USB_generic { bool set_configuration(uint16_t wValue, uint16_t wIndex, uint16_t wLength) { switch(wValue) { case 0: - hw_conf_ep(1, 0); break; case 1: - hw_conf_ep(1, (1 << 22) | (2 << 18) | (1 << 15) | 64); + hw_conf_ep(0x01, Bulk, 64); + hw_conf_ep(0x81, Bulk, 64); break; default: @@ -117,7 +122,7 @@ class USB_generic { } void handle_reset() { - + hw_conf_ep(0, Control, 64); } void handle_setup(const uint32_t* bufp) { @@ -127,6 +132,10 @@ class USB_generic { uint16_t wIndex = bufp[1] & 0xffff; uint16_t wLength = (bufp[1] >> 16) & 0xffff; + usb_rblog.log("handle_setup, bmRequestType=%02x, bRequest=%02x", bmRequestType, bRequest); + + out_handlers[0] = nullptr; + // GET_DESCRIPTOR if(bmRequestType == 0x80 && bRequest == 0x06) { if(get_descriptor(wValue, wIndex, wLength)) { @@ -154,6 +163,10 @@ class USB_generic { if(handler) { res = handler->handle_setup(bmRequestType, bRequest, wValue, wIndex, wLength); + if(res == SetupStatus::Ok) { + out_handlers[0] = handler; + } + if(res != SetupStatus::Unhandled) { break; } @@ -168,6 +181,8 @@ class USB_generic { } void handle_out(uint8_t ep, uint32_t len) { + usb_rblog.log("handle_out, ep=%02x, len=%d", ep, len); + if(out_handlers[ep]) { out_handlers[ep]->handle_out(ep, len); } -- cgit v1.2.3