| Index: emcore/trunk/usb/usb.h |
| — | — | @@ -4,21 +4,21 @@ |
| 5 | 5 | #include "../global.h" |
| 6 | 6 | |
| 7 | 7 | #ifndef IN_APPLICATION_CODE |
| 8 | | -#if USB_ENDPOINTS & 0b00000000000000000000000000000010 |
| | 8 | +#if USB_ENDPOINTS & 0b00000000000000000000000000000010 |
| 9 | 9 | #define USBDEBUG_ENDPOINT_OUT 1 |
| 10 | | -#elif USB_ENDPOINTS & 0b00000000000000000000000000000010 |
| | 10 | +#elif USB_ENDPOINTS & 0b00000000000000000000000000000100 |
| 11 | 11 | #define USBDEBUG_ENDPOINT_OUT 2 |
| 12 | | -#elif USB_ENDPOINTS & 0b00000000000000000000000000000100 |
| | 12 | +#elif USB_ENDPOINTS & 0b00000000000000000000000000001000 |
| 13 | 13 | #define USBDEBUG_ENDPOINT_OUT 3 |
| 14 | | -#elif USB_ENDPOINTS & 0b00000000000000000000000000001000 |
| | 14 | +#elif USB_ENDPOINTS & 0b00000000000000000000000000010000 |
| 15 | 15 | #define USBDEBUG_ENDPOINT_OUT 4 |
| 16 | | -#elif USB_ENDPOINTS & 0b00000000000000000000000000010000 |
| | 16 | +#elif USB_ENDPOINTS & 0b00000000000000000000000000100000 |
| 17 | 17 | #define USBDEBUG_ENDPOINT_OUT 5 |
| 18 | | -#elif USB_ENDPOINTS & 0b00000000000000000000000000100000 |
| | 18 | +#elif USB_ENDPOINTS & 0b00000000000000000000000001000000 |
| 19 | 19 | #define USBDEBUG_ENDPOINT_OUT 6 |
| 20 | | -#elif USB_ENDPOINTS & 0b00000000000000000000000001000000 |
| | 20 | +#elif USB_ENDPOINTS & 0b00000000000000000000000010000000 |
| 21 | 21 | #define USBDEBUG_ENDPOINT_OUT 7 |
| 22 | | -#elif USB_ENDPOINTS & 0b00000000000000000000000010000000 |
| | 22 | +#elif USB_ENDPOINTS & 0b00000000000000000000000100000000 |
| 23 | 23 | #define USBDEBUG_ENDPOINT_OUT 8 |
| 24 | 24 | #elif USB_ENDPOINTS & 0b00000000000000000000001000000000 |
| 25 | 25 | #define USBDEBUG_ENDPOINT_OUT 9 |
| — | — | @@ -37,21 +37,21 @@ |
| 38 | 38 | #else |
| 39 | 39 | #error USBDEBUG: No OUT endpoints available! |
| 40 | 40 | #endif |
| 41 | | -#if USB_ENDPOINTS & 0b00000000000000100000000000000000 |
| | 41 | +#if USB_ENDPOINTS & 0b00000000000000100000000000000000 |
| 42 | 42 | #define USBDEBUG_ENDPOINT_IN 1 |
| 43 | | -#elif USB_ENDPOINTS & 0b00000000000000100000000000000000 |
| | 43 | +#elif USB_ENDPOINTS & 0b00000000000001000000000000000000 |
| 44 | 44 | #define USBDEBUG_ENDPOINT_IN 2 |
| 45 | | -#elif USB_ENDPOINTS & 0b00000000000001000000000000000000 |
| | 45 | +#elif USB_ENDPOINTS & 0b00000000000010000000000000000000 |
| 46 | 46 | #define USBDEBUG_ENDPOINT_IN 3 |
| 47 | | -#elif USB_ENDPOINTS & 0b00000000000010000000000000000000 |
| | 47 | +#elif USB_ENDPOINTS & 0b00000000000100000000000000000000 |
| 48 | 48 | #define USBDEBUG_ENDPOINT_IN 4 |
| 49 | | -#elif USB_ENDPOINTS & 0b00000000000100000000000000000000 |
| | 49 | +#elif USB_ENDPOINTS & 0b00000000001000000000000000000000 |
| 50 | 50 | #define USBDEBUG_ENDPOINT_IN 5 |
| 51 | | -#elif USB_ENDPOINTS & 0b00000000001000000000000000000000 |
| | 51 | +#elif USB_ENDPOINTS & 0b00000000010000000000000000000000 |
| 52 | 52 | #define USBDEBUG_ENDPOINT_IN 6 |
| 53 | | -#elif USB_ENDPOINTS & 0b00000000010000000000000000000000 |
| | 53 | +#elif USB_ENDPOINTS & 0b00000000100000000000000000000000 |
| 54 | 54 | #define USBDEBUG_ENDPOINT_IN 7 |
| 55 | | -#elif USB_ENDPOINTS & 0b00000000100000000000000000000000 |
| | 55 | +#elif USB_ENDPOINTS & 0b00000001000000000000000000000000 |
| 56 | 56 | #define USBDEBUG_ENDPOINT_IN 8 |
| 57 | 57 | #elif USB_ENDPOINTS & 0b00000010000000000000000000000000 |
| 58 | 58 | #define USBDEBUG_ENDPOINT_IN 9 |
| Index: emcore/trunk/usb/usbdebug.c |
| — | — | @@ -117,7 +117,7 @@ |
| 118 | 118 | dbgstate = DBGSTATE_IDLE;
|
| 119 | 119 | }
|
| 120 | 120 |
|
| 121 | | -void usbdebug_bus_reset(const struct usb_instance* data, int highspeed)
|
| | 121 | +void usbdebug_bus_reset(const struct usb_instance* data, int configuration, int interface, int highspeed)
|
| 122 | 122 | {
|
| 123 | 123 | maxpacket = highspeed ? 512 : 64;
|
| 124 | 124 | }
|
| — | — | @@ -150,13 +150,13 @@ |
| 151 | 151 | {
|
| 152 | 152 | union usb_endpoint_number ep = { .number = USBDEBUG_ENDPOINT_IN, .direction = USB_ENDPOINT_DIRECTION_IN };
|
| 153 | 153 | size = MIN(state->size, maxpacket * usb_get_max_transfer_size(data, ep));
|
| 154 | | - usb_start_rx(data, ep, state->addr, size);
|
| | 154 | + usb_start_tx(data, ep, state->addr, size);
|
| 155 | 155 | }
|
| 156 | 156 | else
|
| 157 | 157 | {
|
| 158 | 158 | union usb_endpoint_number ep = { .number = USBDEBUG_ENDPOINT_OUT, .direction = USB_ENDPOINT_DIRECTION_OUT };
|
| 159 | 159 | size = MIN(state->size, maxpacket * usb_get_max_transfer_size(data, ep));
|
| 160 | | - usb_start_tx(data, ep, state->addr, size);
|
| | 160 | + usb_start_rx(data, ep, state->addr, size);
|
| 161 | 161 | }
|
| 162 | 162 | state->addr += size;
|
| 163 | 163 | state->size -= size;
|
| — | — | @@ -166,7 +166,6 @@ |
| 167 | 167 | bool usbdebug_bulk_handle_data(const struct usb_instance* data, union usb_endpoint_number epnum, int bytesleft)
|
| 168 | 168 | {
|
| 169 | 169 | uint32_t* buf = (uint32_t*)data->buffer->raw;
|
| 170 | | - int len = 64 - bytesleft;
|
| 171 | 170 | union usb_endpoint_number ep0out = { .number = 0, .direction = USB_ENDPOINT_DIRECTION_OUT };
|
| 172 | 171 | union usb_endpoint_number ep0in = { .number = 0, .direction = USB_ENDPOINT_DIRECTION_IN };
|
| 173 | 172 | usb_ep0_start_rx(data, false, 0, NULL);
|
| — | — | @@ -173,8 +172,6 @@ |
| 174 | 173 | switch (buf[0])
|
| 175 | 174 | {
|
| 176 | 175 | case 1: // START MEMORY TRANSFER
|
| 177 | | - if (len == 12)
|
| 178 | | - {
|
| 179 | 176 | bulk_state[bulk_ctrlreq_ep].addr = (void*)buf[1];
|
| 180 | 177 | bulk_state[bulk_ctrlreq_ep].size = buf[2];
|
| 181 | 178 | usbdebug_bulk_xfer_complete(data, 0, bulk_ctrlreq_ep, 0); // Convenient way to start a transfer.
|
| — | — | @@ -181,7 +178,6 @@ |
| 182 | 179 | usb_set_stall(data, ep0out, true);
|
| 183 | 180 | usb_ep0_start_tx(data, NULL, 0, NULL);
|
| 184 | 181 | break;
|
| 185 | | - }
|
| 186 | 182 | default:
|
| 187 | 183 | usb_set_stall(data, ep0out, true);
|
| 188 | 184 | usb_set_stall(data, ep0in, true);
|
| — | — | @@ -206,8 +202,7 @@ |
| 207 | 203 | bulk_ctrlreq_ep = endpoint;
|
| 208 | 204 | usb_ep0_start_rx(data, true, 64, usbdebug_bulk_handle_data);
|
| 209 | 205 | return -3;
|
| 210 | | - case USB_SETUP_BMREQUESTTYPE_DIRECTION_IN:
|
| 211 | | - return -2;
|
| | 206 | + default: break;
|
| 212 | 207 | }
|
| 213 | 208 | break;
|
| 214 | 209 | default: break;
|
| Index: emcore/trunk/usb/usbdebug.h |
| — | — | @@ -36,7 +36,7 @@ |
| 37 | 37 | extern int usbdebug_handle_setup(const struct usb_instance* data, int interface, union usb_ep0_buffer* request, const void** response);
|
| 38 | 38 | extern void usbdebug_bulk_xfer_complete(const struct usb_instance* data, int interface, int endpoint, int bytesleft);
|
| 39 | 39 | extern int usbdebug_bulk_ctrl_request(const struct usb_instance* data, int interface, int endpoint, union usb_ep0_buffer* request, const void** response);
|
| 40 | | -extern void usbdebug_bus_reset(const struct usb_instance* data, int highspeed);
|
| | 40 | +extern void usbdebug_bus_reset(const struct usb_instance* data, int configuration, int interface, int highspeed);
|
| 41 | 41 | extern void dbgconsole_putc(char string) ICODE_ATTR;
|
| 42 | 42 | extern void dbgconsole_puts(const char* string) ICODE_ATTR;
|
| 43 | 43 | extern void dbgconsole_write(const char* string, size_t length) ICODE_ATTR;
|
| Index: emcore/trunk/usb/usb.c |
| — | — | @@ -277,50 +277,50 @@ |
| 278 | 278 | default: break; |
| 279 | 279 | } |
| 280 | 280 | break; |
| 281 | | - default: break; |
| | 281 | + default: break; |
| 282 | 282 | } |
| 283 | 283 | break; |
| 284 | | - case USB_SETUP_BMREQUESTTYPE_RECIPIENT_ENDPOINT: |
| | 284 | + } |
| | 285 | + case USB_SETUP_BMREQUESTTYPE_RECIPIENT_ENDPOINT: |
| | 286 | + { |
| | 287 | + if (!data->state->current_configuration) break; |
| | 288 | + union usb_endpoint_number ep = { .byte = buffer->setup.wIndex }; |
| | 289 | + int intfid; |
| | 290 | + int epid; |
| | 291 | + const struct usb_endpoint* endpoint = usb_find_endpoint(data, ep, &intfid, &epid); |
| | 292 | + if (!endpoint) break; |
| | 293 | + if (endpoint->ctrl_request) size = endpoint->ctrl_request(data, intfid, epid, buffer, &addr); |
| | 294 | + if (size != -1) break; |
| | 295 | + switch (buffer->setup.bmRequestType.type) |
| 285 | 296 | { |
| 286 | | - if (!data->state->current_configuration) break; |
| 287 | | - union usb_endpoint_number ep = { .byte = buffer->setup.wIndex }; |
| 288 | | - int intfid; |
| 289 | | - int epid; |
| 290 | | - const struct usb_endpoint* endpoint = usb_find_endpoint(data, ep, &intfid, &epid); |
| 291 | | - if (!endpoint) break; |
| 292 | | - if (endpoint->ctrl_request) size = endpoint->ctrl_request(data, intfid, epid, buffer, &addr); |
| 293 | | - if (size != -1) break; |
| 294 | | - switch (buffer->setup.bmRequestType.type) |
| | 297 | + case USB_SETUP_BMREQUESTTYPE_TYPE_STANDARD: |
| | 298 | + switch (buffer->setup.bRequest.req) |
| 295 | 299 | { |
| 296 | | - case USB_SETUP_BMREQUESTTYPE_TYPE_STANDARD: |
| 297 | | - switch (buffer->setup.bRequest.req) |
| 298 | | - { |
| 299 | | - case USB_SETUP_BREQUEST_GET_STATUS: |
| 300 | | - if (buffer->setup.wLength != 2 || buffer->setup.wValue) break; |
| 301 | | - data->buffer->raw[0] = 0; |
| 302 | | - data->buffer->raw[1] = data->driver->get_stall(data, ep); |
| 303 | | - addr = data->buffer; |
| 304 | | - size = 2; |
| 305 | | - break; |
| 306 | | - case USB_SETUP_BREQUEST_CLEAR_FEATURE: |
| 307 | | - if (buffer->setup.wLength || buffer->setup.wValue) break; |
| 308 | | - usb_set_stall(data, ep, false); |
| 309 | | - size = 0; |
| 310 | | - break; |
| 311 | | - case USB_SETUP_BREQUEST_SET_FEATURE: |
| 312 | | - if (buffer->setup.wLength || buffer->setup.wValue) break; |
| 313 | | - usb_set_stall(data, ep, true); |
| 314 | | - size = 0; |
| 315 | | - break; |
| 316 | | - default: break; |
| 317 | | - } |
| | 300 | + case USB_SETUP_BREQUEST_GET_STATUS: |
| | 301 | + if (buffer->setup.wLength != 2 || buffer->setup.wValue) break; |
| | 302 | + data->buffer->raw[0] = 0; |
| | 303 | + data->buffer->raw[1] = data->driver->get_stall(data, ep); |
| | 304 | + addr = data->buffer; |
| | 305 | + size = 2; |
| 318 | 306 | break; |
| 319 | | - default: break; |
| | 307 | + case USB_SETUP_BREQUEST_CLEAR_FEATURE: |
| | 308 | + if (buffer->setup.wLength || buffer->setup.wValue) break; |
| | 309 | + usb_set_stall(data, ep, false); |
| | 310 | + size = 0; |
| | 311 | + break; |
| | 312 | + case USB_SETUP_BREQUEST_SET_FEATURE: |
| | 313 | + if (buffer->setup.wLength || buffer->setup.wValue) break; |
| | 314 | + usb_set_stall(data, ep, true); |
| | 315 | + size = 0; |
| | 316 | + break; |
| | 317 | + default: break; |
| 320 | 318 | } |
| 321 | 319 | break; |
| | 320 | + default: break; |
| 322 | 321 | } |
| 323 | | - default: break; |
| | 322 | + break; |
| 324 | 323 | } |
| | 324 | + default: break; |
| 325 | 325 | } |
| 326 | 326 | union usb_endpoint_number ep0in = { .number = 0, .direction = USB_ENDPOINT_DIRECTION_IN }; |
| 327 | 327 | union usb_endpoint_number ep0out = { .number = 0, .direction = USB_ENDPOINT_DIRECTION_OUT }; |