From ac67e0ea3fdb7e3121b82335268a00133bd4b660 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 10 Dec 2018 05:15:49 +0700 Subject: [PATCH] clean up --- src/device/usbd.c | 14 +++++++------- src/host/usbh.c | 18 +++++++++--------- src/host/usbh_hcd.h | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/device/usbd.c b/src/device/usbd.c index 44bd641d..5262d6c7 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -68,7 +68,7 @@ typedef struct { uint8_t config_num; uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid) - uint8_t ep2drv[2][8]; // map endpoint to driver ( 0xff is invalid ) + uint8_t ep2drv[8][2]; // map endpoint to driver ( 0xff is invalid ) }usbd_device_t; @@ -169,7 +169,7 @@ static osal_queue_t _usbd_q; //--------------------------------------------------------------------+ // Prototypes //--------------------------------------------------------------------+ -static void mark_interface_endpoint(uint8_t const* p_desc, uint16_t desc_len, uint8_t driver_id); +static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc, uint16_t desc_len, uint8_t driver_id); static bool process_control_request(uint8_t rhport, tusb_control_request_t const * p_request); static bool process_set_config(uint8_t rhport); static void const* get_descriptor(tusb_control_request_t const * p_request, uint16_t* desc_len); @@ -253,7 +253,7 @@ static void usbd_task_body(void) } else { - uint8_t const drv_id = _usbd_dev.ep2drv[edpt_dir(ep_addr)][edpt_number(ep_addr)]; + uint8_t const drv_id = _usbd_dev.ep2drv[edpt_number(ep_addr)][edpt_dir(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); @@ -375,7 +375,7 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const uint8_t const itf = tu_u16_low(p_request->wIndex); uint8_t const drvid = _usbd_dev.itf2drv[ itf ]; - TU_VERIFY (drvid < USBD_CLASS_DRIVER_COUNT ); + TU_VERIFY(drvid < USBD_CLASS_DRIVER_COUNT); usbd_control_set_complete_callback(usbd_class_drivers[drvid].control_request_complete ); @@ -460,7 +460,7 @@ static bool process_set_config(uint8_t rhport) TU_ASSERT_ERR( usbd_class_drivers[drv_id].open( rhport, desc_itf, &itf_len ), false ); TU_ASSERT( itf_len >= sizeof(tusb_desc_interface_t) ); - mark_interface_endpoint(p_desc, itf_len, drv_id); + mark_interface_endpoint(_usbd_dev.ep2drv, p_desc, itf_len, drv_id); p_desc += itf_len; // next interface } @@ -473,7 +473,7 @@ static bool process_set_config(uint8_t rhport) } // Helper marking endpoint of interface belongs to class driver -static void mark_interface_endpoint(uint8_t const* p_desc, uint16_t desc_len, uint8_t driver_id) +static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc, uint16_t desc_len, uint8_t driver_id) { uint16_t len = 0; @@ -483,7 +483,7 @@ static void mark_interface_endpoint(uint8_t const* p_desc, uint16_t desc_len, ui { uint8_t const ep_addr = ((tusb_desc_endpoint_t const*) p_desc)->bEndpointAddress; - _usbd_dev.ep2drv[ edpt_dir(ep_addr) ][ edpt_number(ep_addr) ] = driver_id; + ep2drv[edpt_number(ep_addr)][edpt_dir(ep_addr)] = driver_id; } len += descriptor_len(p_desc); diff --git a/src/host/usbh.c b/src/host/usbh.c index 73bcc2e9..7be0376c 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -139,7 +139,7 @@ CFG_TUSB_MEM_SECTION ATTR_ALIGNED(4) static uint8_t _usbh_ctrl_buf[CFG_TUSB_HOST //------------- Helper Function Prototypes -------------// static inline uint8_t get_new_address(void) ATTR_ALWAYS_INLINE; static inline uint8_t get_configure_number_for_device(tusb_desc_device_t* dev_desc) ATTR_ALWAYS_INLINE; -static void mark_interface_endpoint(int8_t ep2drv[8][2], uint8_t const* p_desc, uint16_t desc_len, uint8_t driver_id); +static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc, uint16_t desc_len, uint8_t driver_id); //--------------------------------------------------------------------+ // PUBLIC API (Parameter Verification is required) @@ -174,8 +174,8 @@ bool usbh_init(void) dev->control.mutex_hdl = osal_mutex_create(&dev->control.mutex_def); TU_ASSERT(dev->control.mutex_hdl != NULL); - memset(dev->itf2drv, -1, sizeof(dev->itf2drv)); // invalid mapping - memset(dev->ep2drv , -1, sizeof(dev->ep2drv )); // invalid mapping + memset(dev->itf2drv, 0xff, sizeof(dev->itf2drv)); // invalid mapping + memset(dev->ep2drv , 0xff, sizeof(dev->ep2drv )); // invalid mapping } // Class drivers init @@ -268,8 +268,8 @@ void usbh_xfer_isr(pipe_handle_t pipe_hdl, uint8_t class_code, xfer_result_t eve } else { - int8_t drv_id = dev->ep2drv[edpt_number(pipe_hdl.ep_addr)][edpt_dir(pipe_hdl.ep_addr)]; - TU_ASSERT(drv_id >= 0, ); + uint8_t drv_id = dev->ep2drv[edpt_number(pipe_hdl.ep_addr)][edpt_dir(pipe_hdl.ep_addr)]; + TU_ASSERT(drv_id < USBH_CLASS_DRIVER_COUNT, ); if (usbh_class_drivers[drv_id].isr) { @@ -345,8 +345,8 @@ static void usbh_device_unplugged(uint8_t hostid, uint8_t hub_addr, uint8_t hub_ // HCD must set this device's state to TUSB_DEVICE_STATE_UNPLUG when done dev->state = TUSB_DEVICE_STATE_REMOVING; - memset(dev->itf2drv, -1, sizeof(dev->itf2drv)); // invalid mapping - memset(dev->ep2drv , -1, sizeof(dev->ep2drv )); // invalid mapping + memset(dev->itf2drv, 0xff, sizeof(dev->itf2drv)); // invalid mapping + memset(dev->ep2drv , 0xff, sizeof(dev->ep2drv )); // invalid mapping usbh_pipe_control_close(dev_addr); @@ -599,7 +599,7 @@ bool enum_task(hcd_event_t* event) else { // Interface number must not be used already TODO alternate interface - TU_ASSERT( new_dev->itf2drv[desc_itf->bInterfaceNumber] < 0 ); + TU_ASSERT( new_dev->itf2drv[desc_itf->bInterfaceNumber] == 0xff ); new_dev->itf2drv[desc_itf->bInterfaceNumber] = drv_id; if (desc_itf->bInterfaceClass == TUSB_CLASS_HUB && new_dev->hub_addr != 0) @@ -696,7 +696,7 @@ static inline uint8_t get_configure_number_for_device(tusb_desc_device_t* dev_de // Helper marking endpoint of interface belongs to class driver // TODO merge with usbd -static void mark_interface_endpoint(int8_t ep2drv[8][2], uint8_t const* p_desc, uint16_t desc_len, uint8_t driver_id) +static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc, uint16_t desc_len, uint8_t driver_id) { uint16_t len = 0; diff --git a/src/host/usbh_hcd.h b/src/host/usbh_hcd.h index 398c6111..8af454b1 100644 --- a/src/host/usbh_hcd.h +++ b/src/host/usbh_hcd.h @@ -87,8 +87,8 @@ typedef struct { osal_mutex_t mutex_hdl; // used to exclusively occupy control pipe } control; - int8_t itf2drv[16]; // map interface number to driver (negative is invalid) - int8_t ep2drv[8][2]; // map endpoint to driver ( negative is invalid ) + uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid) + uint8_t ep2drv[8][2]; // map endpoint to driver ( 0xff is invalid ) } usbh_device_t; extern usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1]; // including zero-address