summaryrefslogtreecommitdiff
path: root/tinyusb/device
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-10-30 14:13:06 +0700
committerhathach <[email protected]>2013-10-30 14:13:06 +0700
commit3a37dd66cc06df4c326dd43257095c0069fff22e (patch)
tree72795f2e17c8e9af306fa2ab1045fa11b947c460 /tinyusb/device
parentb8a7ea6d46a49c1974e3f8d73aef19116927d0b2 (diff)
refractor hid device
add check dcd_pipe_open if endpoint is already used refractor usbd : parse and auto open class driver
Diffstat (limited to 'tinyusb/device')
-rw-r--r--tinyusb/device/dcd_lpc43xx.c11
-rw-r--r--tinyusb/device/usbd.c37
2 files changed, 29 insertions, 19 deletions
diff --git a/tinyusb/device/dcd_lpc43xx.c b/tinyusb/device/dcd_lpc43xx.c
index 6ef650b18..c60c60be8 100644
--- a/tinyusb/device/dcd_lpc43xx.c
+++ b/tinyusb/device/dcd_lpc43xx.c
@@ -328,6 +328,13 @@ endpoint_handle_t dcd_pipe_open(uint8_t coreid, tusb_descriptor_endpoint_t const
if (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS)
return null_handle; // TODO not support ISO yet
+ tusb_direction_t dir = (p_endpoint_desc->bEndpointAddress & TUSB_DIR_DEV_TO_HOST_MASK) ? TUSB_DIR_DEV_TO_HOST : TUSB_DIR_HOST_TO_DEV;
+
+ //------------- Endpoint Control Register -------------//
+ volatile uint32_t * reg_control = (&LPC_USB0->ENDPTCTRL0) + (p_endpoint_desc->bEndpointAddress & 0x0f);
+
+ ASSERT_FALSE( (*reg_control) & (ENDPTCTRL_MASK_ENABLE << (dir ? 16 : 0)), null_handle ); // endpoint must not be already enabled
+
//------------- Prepare Queue Head -------------//
uint8_t ep_idx = endpoint_addr2phy(p_endpoint_desc->bEndpointAddress);
dcd_qhd_t * p_qhd = &dcd_data.qhd[ep_idx];
@@ -338,9 +345,7 @@ endpoint_handle_t dcd_pipe_open(uint8_t coreid, tusb_descriptor_endpoint_t const
p_qhd->max_package_size = p_endpoint_desc->wMaxPacketSize.size;
p_qhd->qtd_overlay.next = QTD_INVALID;
- //------------- Endpoint Control Register -------------//
- volatile uint32_t * reg_control = (&LPC_USB0->ENDPTCTRL0) + (p_endpoint_desc->bEndpointAddress & 0x0f);
- (*reg_control) |= ((p_endpoint_desc->bmAttributes.xfer << 2) | ENDPTCTRL_MASK_ENABLE | ENDPTCTRL_MASK_TOGGLE_RESET) << ((p_endpoint_desc->bEndpointAddress & TUSB_DIR_DEV_TO_HOST_MASK) ? 16 : 0);
+ (*reg_control) |= ((p_endpoint_desc->bmAttributes.xfer << 2) | ENDPTCTRL_MASK_ENABLE | ENDPTCTRL_MASK_TOGGLE_RESET) << (dir ? 16 : 0);
return (endpoint_handle_t) { .coreid = coreid, .xfer_type = p_endpoint_desc->bmAttributes.xfer, .index = ep_idx };
}
diff --git a/tinyusb/device/usbd.c b/tinyusb/device/usbd.c
index 521e1f6b4..2a65b5037 100644
--- a/tinyusb/device/usbd.c
+++ b/tinyusb/device/usbd.c
@@ -124,27 +124,32 @@ tusb_error_t usbh_set_configure_received(uint8_t coreid, uint8_t config_number)
dcd_controller_set_configuration(coreid, config_number);
usbd_devices[coreid].state = TUSB_DEVICE_STATE_CONFIGURED;
- uint16_t length = 0;
+ //------------- parse configuration & open drivers -------------//
+ uint8_t* p_desc_configure = (uint8_t*) &app_tusb_desc_configuration;
+ uint8_t* p_desc = p_desc_configure + sizeof(tusb_descriptor_configuration_t);
- #if TUSB_CFG_DEVICE_HID_KEYBOARD
- tusb_descriptor_interface_t const * p_kbd_interface = &app_tusb_desc_configuration.keyboard_interface;
- usbd_devices[coreid].interface2class[p_kbd_interface->bInterfaceNumber] = p_kbd_interface->bInterfaceClass;
-
- if (usbd_class_drivers[p_kbd_interface->bInterfaceClass].open )
+ while( p_desc < p_desc_configure + ((tusb_descriptor_configuration_t*)p_desc_configure)->wTotalLength )
{
- usbd_class_drivers[p_kbd_interface->bInterfaceClass].open(coreid, p_kbd_interface, &length);
- }
- #endif
+ ASSERT( TUSB_DESC_TYPE_INTERFACE == p_desc[DESCRIPTOR_OFFSET_TYPE], TUSB_ERROR_NOT_SUPPORTED_YET );
- #if TUSB_CFG_DEVICE_HID_MOUSE
- tusb_descriptor_interface_t const * p_mouse_interface = &app_tusb_desc_configuration.mouse_interface;
- usbd_devices[coreid].interface2class[p_mouse_interface->bInterfaceNumber] = p_mouse_interface->bInterfaceClass;
+ uint8_t class_index;
+ tusb_descriptor_interface_t* p_desc_interface = (tusb_descriptor_interface_t*) p_desc;
- if (usbd_class_drivers[p_mouse_interface->bInterfaceClass].open )
- {
- usbd_class_drivers[p_mouse_interface->bInterfaceClass].open(coreid, p_mouse_interface, &length);
+ class_index = p_desc_interface->bInterfaceClass;
+
+ ASSERT( class_index != 0 && usbd_class_drivers[class_index].open != NULL, TUSB_ERROR_NOT_SUPPORTED_YET );
+ ASSERT( 0 == usbd_devices[coreid].interface2class[p_desc_interface->bInterfaceNumber], TUSB_ERROR_FAILED); // duplicate interface number TODO alternate setting
+
+ usbd_devices[coreid].interface2class[p_desc_interface->bInterfaceNumber] = class_index;
+
+ uint16_t length=0;
+ ASSERT_STATUS( usbd_class_drivers[class_index].open( coreid, p_desc_interface, &length ) );
+
+ ASSERT( length >= sizeof(tusb_descriptor_interface_t), TUSB_ERROR_FAILED );
+
+ // usbh_devices[new_addr].flag_supported_class |= BIT_(class_index);
+ p_desc += length;
}
- #endif
return TUSB_ERROR_NONE;
}