From 2529ce991e6eda9f8235084ed1b7a7e408c86866 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Mon, 2 Apr 2012 20:24:45 +0200 Subject: Added SET_CONFIGURATION. --- main.cpp | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index 591d99b..9337c20 100644 --- a/main.cpp +++ b/main.cpp @@ -52,16 +52,23 @@ void usb_write(uint32_t* bufp, uint32_t len) { } } -uint32_t dev_desc[] = {0x02000112, 0x400000ff, 0x56781234, 0x00000000, 0x0100}; -uint32_t conf_desc[] = {0x00090209, 0xc0000100, 0x00}; +uint8_t dev_desc[] = { + 0x12, 0x01, 0x00, 0x02, 0xff, 0x00, 0x00, 0x40, 0x34, 0x12, 0x78, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, +}; + +uint8_t conf_desc[] = { + 0x09, 0x02, 0x19, 0x00, 0x01, 0x01, 0x00, 0xc0, 0x00, + 0x09, 0x04, 0x00, 0x00, 0x01, 0xff, 0x00, 0x00, 0x00, + 0x07, 0x05, 0x81, 0x02, 0x40, 0x00, 0x00, +}; bool get_descriptor(uint16_t wValue, uint16_t wIndex, uint16_t wLength) { switch(wValue) { case 0x100: - usb_write(dev_desc, wLength); + usb_write((uint32_t*)dev_desc, wLength > sizeof(dev_desc) ? sizeof(dev_desc) : wLength); return true; case 0x200: - usb_write(conf_desc, wLength); + usb_write((uint32_t*)conf_desc, wLength > sizeof(conf_desc) ? sizeof(conf_desc) : wLength); return true; default: return false; @@ -74,6 +81,15 @@ bool set_address(uint16_t wValue, uint16_t wIndex, uint16_t wLength) { return true; } +bool set_configuration(uint16_t wValue, uint16_t wIndex, uint16_t wLength) { + if(wValue > 1) { + return false; + } + + usb_write(0, 0); + return true; +} + bool jtag_shift(uint16_t wValue, uint16_t wIndex, uint16_t wLength) { if(wLength > 16) { return false; @@ -122,6 +138,13 @@ void handle_setup(const uint32_t* bufp) { } } + // SET_CONFIGURATION + if(bmRequestType == 0x00 && bRequest == 0x09) { + if(set_configuration(wValue, wIndex, wLength)) { + return; + } + } + // I2C_READ if(bmRequestType == 0xc0 && bRequest == 0xf0) { if(i2c_read(wValue, wIndex, wLength)) { -- cgit v1.2.3