From 95cd6c3a2f01ec418de6bf7534c519dd53943503 Mon Sep 17 00:00:00 2001 From: hathach Date: Wed, 14 Nov 2018 23:39:58 +0700 Subject: [PATCH] remove control from class driver array --- src/device/control.c | 3 --- src/device/control.h | 2 -- src/device/usbd.c | 26 +++++++++++--------------- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/src/device/control.c b/src/device/control.c index 26dd8fb3..35ae536e 100644 --- a/src/device/control.c +++ b/src/device/control.c @@ -54,9 +54,6 @@ void controld_reset(uint8_t rhport) { control_state.current_stage = CONTROL_STAGE_SETUP; } -void controld_init(void) { -} - // Helper to send STATUS (zero length) packet // Note dir is value of direction bit in setup packet (i.e DATA stage direction) static inline bool dcd_control_status(uint8_t rhport, uint8_t dir) diff --git a/src/device/control.h b/src/device/control.h index 633ccb60..e8dcf76f 100644 --- a/src/device/control.h +++ b/src/device/control.h @@ -76,8 +76,6 @@ tusb_error_t tud_control_interface_control_cb(uint8_t rhport, uint8_t interface, //--------------------------------------------------------------------+ // INTERNAL API //--------------------------------------------------------------------+ - -void controld_init(void); tusb_error_t controld_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length); // This tracks the state of a control request. diff --git a/src/device/usbd.c b/src/device/usbd.c index 45149463..13cc7f33 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -104,16 +104,6 @@ typedef struct { static usbd_class_driver_t const usbd_class_drivers[] = { - { - .class_code = TUSB_CLASS_UNSPECIFIED, - .init = controld_init, - .open = NULL, - .control_request = NULL, - .control_request_complete = NULL, - .xfer_cb = controld_xfer_cb, - .sof = NULL, - .reset = controld_reset - }, #if CFG_TUD_CDC { .class_code = TUSB_CLASS_CDC, @@ -223,9 +213,8 @@ static void usbd_reset(uint8_t rhport) tu_varclr(&_usbd_dev); memset(_usbd_dev.itf2drv, 0xff, sizeof(_usbd_dev.itf2drv)); // invalid mapping memset(_usbd_dev.ep2drv , 0xff, sizeof(_usbd_dev.ep2drv )); // invalid mapping - // Always map the 0th endpoint to the control driver. - _usbd_dev.ep2drv[TUSB_DIR_IN][0] = 0; - _usbd_dev.ep2drv[TUSB_DIR_OUT][0] = 0; + + controld_reset(rhport); for (uint8_t i = 0; i < USBD_CLASS_DRIVER_COUNT; i++) { @@ -253,10 +242,17 @@ static void usbd_task_body(void) { // Invoke the class callback associated with the endpoint address uint8_t const ep_addr = event.xfer_complete.ep_addr; - uint8_t const drv_id = _usbd_dev.ep2drv[edpt_dir(ep_addr)][edpt_number(ep_addr)]; - if ( drv_id < USBD_CLASS_DRIVER_COUNT ) + if ( 0 == edpt_number(ep_addr) ) { + // control transfer + controld_xfer_cb(event.rhport, ep_addr, event.xfer_complete.result, event.xfer_complete.len); + } + else + { + uint8_t const drv_id = _usbd_dev.ep2drv[edpt_dir(ep_addr)][edpt_number(ep_addr)]; + TU_ASSERT(drv_id < USBD_CLASS_DRIVER_COUNT,); + usbd_class_drivers[drv_id].xfer_cb(event.rhport, ep_addr, event.xfer_complete.result, event.xfer_complete.len); } }