mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-22 19:20:52 +00:00
update enumeration up to get full configuration descriptor
This commit is contained in:
parent
060c4b3b30
commit
e6ed1729b2
@ -103,6 +103,10 @@ semaphore_wait_timeout(1)
|
||||
semaphore_wait_timeout(2)
|
||||
semaphore_wait_timeout(3)
|
||||
semaphore_wait_timeout(4)
|
||||
semaphore_wait_timeout(5)
|
||||
semaphore_wait_timeout(6)
|
||||
semaphore_wait_timeout(7)
|
||||
semaphore_wait_timeout(8)
|
||||
|
||||
tusb_error_t control_xfer_stub(uint8_t dev_addr, const tusb_std_request_t * const p_request, uint8_t data[], int num_call)
|
||||
{
|
||||
@ -146,7 +150,7 @@ tusb_error_t control_xfer_stub(uint8_t dev_addr, const tusb_std_request_t * cons
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// enum connect directed
|
||||
// enumeration
|
||||
//--------------------------------------------------------------------+
|
||||
void test_addr0_failed_dev_desc(void)
|
||||
{
|
||||
@ -166,14 +170,11 @@ void test_addr0_failed_set_address(void)
|
||||
TEST_ASSERT_EQUAL_MEMORY(&desc_device, enum_data_buffer, 8);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void test_enum_failed_get_full_dev_desc(void)
|
||||
{
|
||||
pipe_handle_t a_pipe = 0x1111;
|
||||
osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(2));
|
||||
|
||||
hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, a_pipe);
|
||||
hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE);
|
||||
tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL);
|
||||
|
||||
usbh_enumeration_task();
|
||||
@ -185,15 +186,27 @@ void test_enum_failed_get_full_dev_desc(void)
|
||||
TEST_ASSERT_EQUAL(enum_connect.hub_port, usbh_device_info_pool[1].hub_port);
|
||||
}
|
||||
|
||||
void test_enum_update_new_device_info(void)
|
||||
void test_enum_failed_get_9byte_config_desc(void)
|
||||
{
|
||||
TEST_IGNORE();
|
||||
osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(3));
|
||||
|
||||
osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(2));
|
||||
hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE);
|
||||
tusbh_device_attached_cb_ExpectAndReturn((tusb_descriptor_device_t*) enum_data_buffer, 1);
|
||||
tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL);
|
||||
|
||||
usbh_enumeration_task();
|
||||
|
||||
|
||||
// hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE);
|
||||
|
||||
TEST_ASSERT_EQUAL(desc_device.idVendor, usbh_device_info_pool[1].vendor_id);
|
||||
TEST_ASSERT_EQUAL(desc_device.idProduct, usbh_device_info_pool[1].product_id);
|
||||
TEST_ASSERT_EQUAL(desc_device.bNumConfigurations, usbh_device_info_pool[1].configure_count);
|
||||
}
|
||||
|
||||
void test_enum_failed_get_full_config_desc(void)
|
||||
{
|
||||
osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(4));
|
||||
hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE);
|
||||
tusbh_device_attached_cb_ExpectAndReturn((tusb_descriptor_device_t*) enum_data_buffer, 1);
|
||||
tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL);
|
||||
|
||||
usbh_enumeration_task();
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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)\
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user