This commit is contained in:
hathach 2018-12-10 05:15:49 +07:00
parent 6a6e7d0ecb
commit ac67e0ea3f
No known key found for this signature in database
GPG Key ID: 2FA891220FBFD581
3 changed files with 18 additions and 18 deletions

View File

@ -68,7 +68,7 @@ typedef struct {
uint8_t config_num; uint8_t config_num;
uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid) 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; }usbd_device_t;
@ -169,7 +169,7 @@ static osal_queue_t _usbd_q;
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Prototypes // 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_control_request(uint8_t rhport, tusb_control_request_t const * p_request);
static bool process_set_config(uint8_t rhport); static bool process_set_config(uint8_t rhport);
static void const* get_descriptor(tusb_control_request_t const * p_request, uint16_t* desc_len); 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 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,); 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); 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 itf = tu_u16_low(p_request->wIndex);
uint8_t const drvid = _usbd_dev.itf2drv[ itf ]; 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 ); 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_ERR( usbd_class_drivers[drv_id].open( rhport, desc_itf, &itf_len ), false );
TU_ASSERT( itf_len >= sizeof(tusb_desc_interface_t) ); 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 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 // 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; 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; 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); len += descriptor_len(p_desc);

View File

@ -139,7 +139,7 @@ CFG_TUSB_MEM_SECTION ATTR_ALIGNED(4) static uint8_t _usbh_ctrl_buf[CFG_TUSB_HOST
//------------- Helper Function Prototypes -------------// //------------- Helper Function Prototypes -------------//
static inline uint8_t get_new_address(void) ATTR_ALWAYS_INLINE; 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 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) // 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); dev->control.mutex_hdl = osal_mutex_create(&dev->control.mutex_def);
TU_ASSERT(dev->control.mutex_hdl != NULL); TU_ASSERT(dev->control.mutex_hdl != NULL);
memset(dev->itf2drv, -1, sizeof(dev->itf2drv)); // invalid mapping memset(dev->itf2drv, 0xff, sizeof(dev->itf2drv)); // invalid mapping
memset(dev->ep2drv , -1, sizeof(dev->ep2drv )); // invalid mapping memset(dev->ep2drv , 0xff, sizeof(dev->ep2drv )); // invalid mapping
} }
// Class drivers init // 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 else
{ {
int8_t drv_id = dev->ep2drv[edpt_number(pipe_hdl.ep_addr)][edpt_dir(pipe_hdl.ep_addr)]; uint8_t drv_id = dev->ep2drv[edpt_number(pipe_hdl.ep_addr)][edpt_dir(pipe_hdl.ep_addr)];
TU_ASSERT(drv_id >= 0, ); TU_ASSERT(drv_id < USBH_CLASS_DRIVER_COUNT, );
if (usbh_class_drivers[drv_id].isr) 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 // HCD must set this device's state to TUSB_DEVICE_STATE_UNPLUG when done
dev->state = TUSB_DEVICE_STATE_REMOVING; dev->state = TUSB_DEVICE_STATE_REMOVING;
memset(dev->itf2drv, -1, sizeof(dev->itf2drv)); // invalid mapping memset(dev->itf2drv, 0xff, sizeof(dev->itf2drv)); // invalid mapping
memset(dev->ep2drv , -1, sizeof(dev->ep2drv )); // invalid mapping memset(dev->ep2drv , 0xff, sizeof(dev->ep2drv )); // invalid mapping
usbh_pipe_control_close(dev_addr); usbh_pipe_control_close(dev_addr);
@ -599,7 +599,7 @@ bool enum_task(hcd_event_t* event)
else else
{ {
// Interface number must not be used already TODO alternate interface // 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; new_dev->itf2drv[desc_itf->bInterfaceNumber] = drv_id;
if (desc_itf->bInterfaceClass == TUSB_CLASS_HUB && new_dev->hub_addr != 0) 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 // Helper marking endpoint of interface belongs to class driver
// TODO merge with usbd // 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; uint16_t len = 0;

View File

@ -87,8 +87,8 @@ typedef struct {
osal_mutex_t mutex_hdl; // used to exclusively occupy control pipe osal_mutex_t mutex_hdl; // used to exclusively occupy control pipe
} control; } control;
int8_t itf2drv[16]; // map interface number to driver (negative is invalid) uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid)
int8_t ep2drv[8][2]; // map endpoint to driver ( negative is invalid ) uint8_t ep2drv[8][2]; // map endpoint to driver ( 0xff is invalid )
} usbh_device_t; } usbh_device_t;
extern usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1]; // including zero-address extern usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1]; // including zero-address