summaryrefslogtreecommitdiff
path: root/tinyusb
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-02-06 18:12:26 +0700
committerhathach <[email protected]>2013-02-06 18:12:26 +0700
commite6ed1729b252acaf2f4cd551586f942b8ab7549b (patch)
tree079578615d314b1519fb6b615e17ab631012f76f /tinyusb
parent060c4b3b302f349d15db1d521e97e9b08e889c93 (diff)
update enumeration up to get full configuration descriptor
Diffstat (limited to 'tinyusb')
-rw-r--r--tinyusb/common/common.h14
-rw-r--r--tinyusb/common/errors.h1
-rw-r--r--tinyusb/host/usbh.c63
-rw-r--r--tinyusb/host/usbh.h2
-rw-r--r--tinyusb/osal/osal.h4
5 files changed, 67 insertions, 17 deletions
diff --git a/tinyusb/common/common.h b/tinyusb/common/common.h
index a3c8cfef5..6859b0e01 100644
--- a/tinyusb/common/common.h
+++ b/tinyusb/common/common.h
@@ -109,15 +109,21 @@ static inline uint32_t u32_from_u8(uint8_t b1, uint8_t b2, uint8_t b3, uint8_t b
}
/// min value
-static inline uint32_t min_of(uint32_t x, uint32_t y) ATTR_ALWAYS_INLINE ATTR_CONST;
-static inline uint32_t min_of(uint32_t x, uint32_t y)
+static inline uint8_t min8_of(uint8_t x, uint8_t y) ATTR_ALWAYS_INLINE ATTR_CONST;
+static inline uint8_t min8_of(uint8_t x, uint8_t y)
+{
+ return (x < y) ? x : y;
+}
+
+static inline uint32_t min32_of(uint32_t x, uint32_t y) ATTR_ALWAYS_INLINE ATTR_CONST;
+static inline uint32_t min32_of(uint32_t x, uint32_t y)
{
return (x < y) ? x : y;
}
/// max value
-static inline uint32_t max_of(uint32_t x, uint32_t y) ATTR_ALWAYS_INLINE ATTR_CONST;
-static inline uint32_t max_of(uint32_t x, uint32_t y)
+static inline uint32_t max32_of(uint32_t x, uint32_t y) ATTR_ALWAYS_INLINE ATTR_CONST;
+static inline uint32_t max32_of(uint32_t x, uint32_t y)
{
return (x > y) ? x : y;
}
diff --git a/tinyusb/common/errors.h b/tinyusb/common/errors.h
index 57de5cea4..42855ffed 100644
--- a/tinyusb/common/errors.h
+++ b/tinyusb/common/errors.h
@@ -67,6 +67,7 @@
ENTRY(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE)\
ENTRY(TUSB_ERROR_HCD_FAILED)\
ENTRY(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND)\
+ ENTRY(TUSB_ERROR_USBH_MOUNT_CONFIG_DESC_TOO_LONG)\
ENTRY(TUSB_ERROR_OSAL_TIMEOUT)\
ENTRY(TUSB_ERROR_OSAL_TASK_FAILED)\
ENTRY(TUSB_ERROR_OSAL_QUEUE_FAILED)\
diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c
index 17bcc2027..18b2d5dc3 100644
--- a/tinyusb/host/usbh.c
+++ b/tinyusb/host/usbh.c
@@ -121,7 +121,7 @@ void usbh_enumeration_task(void)
.wValue = new_addr
};
- hcd_pipe_control_xfer(0, &request_set_address, NULL);
+ (void) hcd_pipe_control_xfer(0, &request_set_address, NULL);
osal_semaphore_wait(usbh_device_info_pool[0].sem_hdl, OSAL_TIMEOUT_NORMAL, &error); // careful of local variable without static
TASK_ASSERT_STATUS_HANDLER(error, tusbh_device_mount_failed_cb(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL) );
}
@@ -133,19 +133,58 @@ void usbh_enumeration_task(void)
usbh_device_info_pool[new_addr].speed = enum_entry.speed;
usbh_device_info_pool[new_addr].status = TUSB_DEVICE_STATUS_ADDRESSED;
-// usbh_device_info_pool[new_addr].pipe_control = hcd_pipe_control_open(new_addr, ((tusb_descriptor_device_t*) enum_data_buffer)->bMaxPacketSize0 );
+ TASK_ASSERT_STATUS ( hcd_pipe_control_open(new_addr, ((tusb_descriptor_device_t*) enum_data_buffer)->bMaxPacketSize0 ) );
{ // Get full device descriptor
- // tusb_std_request_t request_device_desc = {
- // .bmRequestType = { .direction = TUSB_DIR_DEV_TO_HOST, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE },
- // .bRequest = TUSB_REQUEST_GET_DESCRIPTOR,
- // .wValue = (TUSB_DESC_DEVICE << 8),
- // .wLength = 18
- // };
- //
- // hcd_pipe_control_xfer(device_addr0.pipe_hdl, &request_device_desc, enum_data_buffer);
- // osal_semaphore_wait(usbh_device_info_pool[0].sem_hdl, OSAL_TIMEOUT_NORMAL, &error); // careful of local variable without static
- // TASK_ASSERT_STATUS_HANDLER(error, tusbh_device_mount_failed_cb(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL) );
+ tusb_std_request_t request_full_device_desc = {
+ .bmRequestType = { .direction = TUSB_DIR_DEV_TO_HOST, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE },
+ .bRequest = TUSB_REQUEST_GET_DESCRIPTOR,
+ .wValue = (TUSB_DESC_DEVICE << 8),
+ .wLength = 18
+ };
+
+ (void) hcd_pipe_control_xfer(new_addr, &request_full_device_desc, enum_data_buffer);
+ osal_semaphore_wait(usbh_device_info_pool[new_addr].sem_hdl, OSAL_TIMEOUT_NORMAL, &error); // careful of local variable without static
+ TASK_ASSERT_STATUS_HANDLER(error, tusbh_device_mount_failed_cb(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL) );
+ }
+
+ usbh_device_info_pool[new_addr].vendor_id = ((tusb_descriptor_device_t*) enum_data_buffer)->idVendor;
+ usbh_device_info_pool[new_addr].product_id = ((tusb_descriptor_device_t*) enum_data_buffer)->idProduct;
+ usbh_device_info_pool[new_addr].configure_count = ((tusb_descriptor_device_t*) enum_data_buffer)->bNumConfigurations;
+
+ uint8_t configure_selected = 1;
+ if (tusbh_device_attached_cb)
+ {
+ configure_selected = min8_of(1, tusbh_device_attached_cb( (tusb_descriptor_device_t*) enum_data_buffer) );
+ }
+
+ { // Get 9 bytes of configuration descriptor
+ tusb_std_request_t request_9byte_config_desc = {
+ .bmRequestType = { .direction = TUSB_DIR_DEV_TO_HOST, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE },
+ .bRequest = TUSB_REQUEST_GET_DESCRIPTOR,
+ .wValue = (TUSB_DESC_CONFIGURATION << 8),
+ .wLength = 9
+ };
+
+ (void) hcd_pipe_control_xfer(new_addr, &request_9byte_config_desc, enum_data_buffer);
+ osal_semaphore_wait(usbh_device_info_pool[new_addr].sem_hdl, OSAL_TIMEOUT_NORMAL, &error); // careful of local variable without static
+ TASK_ASSERT_STATUS_HANDLER(error, tusbh_device_mount_failed_cb(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL) );
+ }
+
+ TASK_ASSERT_HANDLER( TUSB_CFG_HOST_ENUM_BUFFER_SIZE > ((tusb_descriptor_configuration_t*)enum_data_buffer)->wTotalLength,
+ tusbh_device_mount_failed_cb(TUSB_ERROR_USBH_MOUNT_CONFIG_DESC_TOO_LONG, NULL) );
+
+ { // Get 9 bytes of configuration descriptor
+ tusb_std_request_t request_9byte_config_desc = {
+ .bmRequestType = { .direction = TUSB_DIR_DEV_TO_HOST, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE },
+ .bRequest = TUSB_REQUEST_GET_DESCRIPTOR,
+ .wValue = (TUSB_DESC_CONFIGURATION << 8),
+ .wLength = ((tusb_descriptor_configuration_t*)enum_data_buffer)->wTotalLength
+ };
+
+ (void) hcd_pipe_control_xfer(new_addr, &request_9byte_config_desc, enum_data_buffer);
+ osal_semaphore_wait(usbh_device_info_pool[new_addr].sem_hdl, OSAL_TIMEOUT_NORMAL, &error); // careful of local variable without static
+ TASK_ASSERT_STATUS_HANDLER(error, tusbh_device_mount_failed_cb(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL) );
}
OSAL_TASK_LOOP_END
diff --git a/tinyusb/host/usbh.h b/tinyusb/host/usbh.h
index 2d9c44a85..742d6ca01 100644
--- a/tinyusb/host/usbh.h
+++ b/tinyusb/host/usbh.h
@@ -129,7 +129,7 @@ typedef uint8_t tusbh_device_status_t;
//--------------------------------------------------------------------+
uint8_t tusbh_device_attached_cb (tusb_descriptor_device_t const *p_desc_device) ATTR_WEAK ATTR_WARN_UNUSED_RESULT;
void tusbh_device_mounted_cb (tusb_handle_device_t device_hdl) ATTR_WEAK;
-void tusbh_device_mount_failed_cb(tusb_error_t error, tusb_descriptor_device_t const *p_desc_device) ATTR_WEAK;
+void tusbh_device_mount_failed_cb(tusb_error_t error, tusb_descriptor_device_t const *p_desc_device) ATTR_WEAK; // TODO refractor remove desc_device
tusb_error_t tusbh_configuration_set (tusb_handle_device_t device_hdl, uint8_t configure_number) ATTR_WARN_UNUSED_RESULT;
tusbh_device_status_t tusbh_device_status_get (tusb_handle_device_t const device_hdl) ATTR_WARN_UNUSED_RESULT;
diff --git a/tinyusb/osal/osal.h b/tinyusb/osal/osal.h
index 21f322ba9..6217c767d 100644
--- a/tinyusb/osal/osal.h
+++ b/tinyusb/osal/osal.h
@@ -96,6 +96,10 @@ typedef uint32_t osal_task_t;
ASSERT_DEFINE(tusb_error_t status = (tusb_error_t)(sts),\
TUSB_ERROR_NONE == status, (void) 0, "%s", TUSB_ErrorStr[status])
+#define TASK_ASSERT_HANDLER(condition, func_call) \
+ ASSERT_DEFINE_WITH_HANDLER(TASK_ASSERT_ERROR_HANDLER, func_call, ,\
+ condition, (void) 0, "%s", "evaluated to false")
+
#define TASK_ASSERT(condition) ASSERT(condition, (void) 0)
tusb_error_t osal_task_create(osal_task_t *task);