diff options
| author | hathach <[email protected]> | 2019-07-26 20:14:56 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2019-07-26 20:14:56 +0700 |
| commit | cdaf455461c5ac5867f5eba2eb8874d1a32f0e82 (patch) | |
| tree | 17a17253e472aeb0bfd77fef3cffb5285f365b22 | |
| parent | 4ed1a96311f0a6d97c381b020c4c60dcc49cccbf (diff) | |
fix stall response with SET_INTERFACE/GET_INTERFACE
webusb work with linux & macos
| -rw-r--r-- | examples/device/webusb/src/main.c | 44 | ||||
| -rw-r--r-- | src/device/usbd.c | 30 |
2 files changed, 49 insertions, 25 deletions
diff --git a/examples/device/webusb/src/main.c b/examples/device/webusb/src/main.c index e6bfe3802..f844e9506 100644 --- a/examples/device/webusb/src/main.c +++ b/examples/device/webusb/src/main.c @@ -86,6 +86,28 @@ int main(void) return 0; } +// send characters to both CDC and WebUSB +void echo_all(uint8_t buf[], uint32_t count) +{ + // echo to web serial + if ( web_serial_connected ) + { + tud_vendor_write(buf, count); + } + + // echo to cdc + if ( tud_cdc_connected() ) + { + for(uint32_t i=0; i<count; i++) + { + tud_cdc_write_char(buf[i]); + + if ( buf[i] == '\r' ) tud_cdc_write_char('\n'); + } + tud_cdc_write_flush(); + } +} + //--------------------------------------------------------------------+ // Device callbacks //--------------------------------------------------------------------+ @@ -117,28 +139,6 @@ void tud_resume_cb(void) blink_interval_ms = BLINK_MOUNTED; } -// send characters to both CDC and WebUSB -void echo_all(uint8_t buf[], uint32_t count) -{ - // echo to web serial - if ( web_serial_connected ) - { - tud_vendor_write(buf, count); - } - - // echo to cdc - if ( tud_cdc_connected() ) - { - for(uint32_t i=0; i<count; i++) - { - tud_cdc_write_char(buf[i]); - - if ( buf[i] == '\r' ) tud_cdc_write_char('\n'); - } - tud_cdc_write_flush(); - } -} - //--------------------------------------------------------------------+ // WebUSB use vendor class //--------------------------------------------------------------------+ diff --git a/src/device/usbd.c b/src/device/usbd.c index f737f5d36..a6eda79de 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -439,10 +439,34 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const TU_VERIFY(drvid < USBD_CLASS_DRIVER_COUNT);
- usbd_control_set_complete_callback(usbd_class_drivers[drvid].control_complete);
+ switch ( p_request->bRequest )
+ {
+ case TUSB_REQ_GET_INTERFACE:
+ {
+ // TODO not support alternate interface yet
+ uint8_t alternate = 0;
+ tud_control_xfer(rhport, p_request, &alternate, 1);
+ }
+ break;
+
+ case TUSB_REQ_SET_INTERFACE:
+ {
+ uint8_t alternate = (uint8_t) p_request->wValue;
- // stall control endpoint if driver return false
- return usbd_class_drivers[drvid].control_request(rhport, p_request);
+ // TODO not support alternate interface yet
+ TU_ASSERT(alternate == 0);
+
+ tud_control_status(rhport, p_request);
+ }
+ break;
+
+ default:
+ // forward to class driver
+ // stall control endpoint if driver return false
+ usbd_control_set_complete_callback(usbd_class_drivers[drvid].control_complete);
+ TU_ASSERT(usbd_class_drivers[drvid].control_request(rhport, p_request));
+ break;
+ }
}
break;
|
