diff --git a/src/device/dcd.h b/src/device/dcd.h index 8dafef66d..63f923faa 100644 --- a/src/device/dcd.h +++ b/src/device/dcd.h @@ -48,6 +48,7 @@ typedef enum DCD_EVENT_SETUP_RECEIVED, DCD_EVENT_XFER_COMPLETE, + // Not an DCD event, just a convenient way to defer ISR function USBD_EVENT_FUNC_CALL } dcd_eventid_t; diff --git a/src/device/usbd.c b/src/device/usbd.c index 4089cf72c..c2b463e70 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -40,13 +40,14 @@ // Device Data //--------------------------------------------------------------------+ typedef struct { - volatile uint8_t config_num; - struct ATTR_PACKED { - volatile uint8_t connected : 1; - volatile uint8_t suspended : 1; - uint8_t remote_wakeup_en : 1; + volatile uint8_t connected : 1; + volatile uint8_t configured : 1; + volatile uint8_t suspended : 1; + + uint8_t remote_wakeup_en : 1; + uint8_t self_powered : 1; }; // uint8_t ep_busy_mask[2]; // bit mask for busy endpoint @@ -177,7 +178,7 @@ void usbd_control_set_complete_callback( bool (*fp) (uint8_t, tusb_control_reque //--------------------------------------------------------------------+ bool tud_mounted(void) { - return _usbd_dev.config_num > 0; + return _usbd_dev.configured; } bool tud_remote_wakeup(void) @@ -359,6 +360,9 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const void* data_buf = NULL; uint16_t data_len = 0; + uint8_t cfgnum_tmp; + (void) cfgnum_tmp; // only used for GET_CONFIGURATION + switch ( p_request->bRequest ) { case TUSB_REQ_SET_ADDRESS: @@ -369,16 +373,18 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const break; case TUSB_REQ_GET_CONFIGURATION: - data_buf = (uint8_t*) &_usbd_dev.config_num; + cfgnum_tmp = _usbd_dev.configured ? 1 : 0; + + data_buf = &cfgnum_tmp; data_len = 1; break; case TUSB_REQ_SET_CONFIGURATION: { - uint8_t const config = (uint8_t) p_request->wValue; + uint8_t const cfg_num = (uint8_t) p_request->wValue; - dcd_set_config(rhport, config); - _usbd_dev.config_num = config; + dcd_set_config(rhport, cfg_num); + _usbd_dev.configured = cfg_num ? 1 : 0; TU_ASSERT( process_set_config(rhport) ); } @@ -405,6 +411,10 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const } break; + case TUSB_REQ_GET_STATUS: + + break; + // Unknown/Unsupported request default: TU_BREAKPOINT(); return false; } @@ -608,7 +618,7 @@ void dcd_event_handler(dcd_event_t const * event, bool in_isr) case DCD_EVENT_UNPLUGGED: _usbd_dev.connected = 0; - _usbd_dev.config_num = 0; + _usbd_dev.configured = 0; osal_queue_send(_usbd_q, event, in_isr); break; diff --git a/src/device/usbd_auto_desc.c b/src/device/usbd_auto_desc.c index c4213edba..8272ea5a8 100644 --- a/src/device/usbd_auto_desc.c +++ b/src/device/usbd_auto_desc.c @@ -254,7 +254,7 @@ tusb_desc_device_t const _desc_auto_device = .iProduct = 0x02, .iSerialNumber = 0x03, - .bNumConfigurations = 0x01 // TODO multiple configurations + .bNumConfigurations = 0x01 };