diff options
| author | hathach <[email protected]> | 2013-02-27 12:42:32 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2013-02-27 12:42:32 +0700 |
| commit | b1d33c7ffc72ded2bff672f9b728017230c248a3 (patch) | |
| tree | c7c5279169dc16063f82a2676bd0f322992c1a0f /tinyusb/host | |
| parent | 5eca6d69c3447cd997c129797f431fe5d0356dff (diff) | |
rename tusbh_device_mount_succeed_cb
add set configure and tusbh_device_mount_succeed_cb invocation
refractor get_configure_number_for_device
Diffstat (limited to 'tinyusb/host')
| -rw-r--r-- | tinyusb/host/usbh.c | 50 | ||||
| -rw-r--r-- | tinyusb/host/usbh.h | 2 |
2 files changed, 30 insertions, 22 deletions
diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c index 58b51cb09..fcfaee7c6 100644 --- a/tinyusb/host/usbh.c +++ b/tinyusb/host/usbh.c @@ -69,6 +69,7 @@ STATIC_ uint8_t enum_data_buffer[TUSB_CFG_HOST_ENUM_BUFFER_SIZE] TUSB_CFG_ATTR_U //------------- Helper Function Prototypes -------------// static inline uint8_t get_new_address(void) ATTR_ALWAYS_INLINE; +static inline uint8_t get_configure_number_for_device(tusb_descriptor_device_t* dev_desc) ATTR_ALWAYS_INLINE; //--------------------------------------------------------------------+ // PUBLIC API (Parameter Verification is required) @@ -206,15 +207,8 @@ OSAL_TASK_DECLARE(usbh_enumeration_task) 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; - //------------- invoke callback to ask user which configuration to select -------------// - if (tusbh_device_attached_cb) - { - configure_selected = min8_of(1, - tusbh_device_attached_cb( (tusb_descriptor_device_t*) enum_data_buffer) ); - }else - { - configure_selected = 1; - } + configure_selected = get_configure_number_for_device((tusb_descriptor_device_t*) enum_data_buffer); + TASK_ASSERT(configure_selected <= usbh_device_info_pool[new_addr].configure_count); //------------- Get 9 bytes of configuration descriptor -------------// OSAL_SUBTASK_INVOKED_AND_WAIT( @@ -284,18 +278,20 @@ OSAL_TASK_DECLARE(usbh_enumeration_task) } //------------- Set Configure -------------// -// (void) hcd_pipe_control_xfer( -// new_addr, -// &(tusb_std_request_t) -// { -// .bmRequestType = { .direction = TUSB_DIR_HOST_TO_DEV, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE }, -// .bRequest = TUSB_REQUEST_SET_CONFIGURATION, -// .wValue = configure_selected -// }, -// NULL -// ); -// osal_semaphore_wait(usbh_device_info_pool[new_addr].sem_hdl, OSAL_TIMEOUT_NORMAL, &error); // careful of local variable without static -// TASK_ASSERT_STATUS_WITH_HANDLER(error, tusbh_device_mount_failed_cb(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL) ); + OSAL_SUBTASK_INVOKED_AND_WAIT ( + usbh_control_xfer_subtask( + new_addr, + &(tusb_std_request_t) + { + .bmRequestType = { .direction = TUSB_DIR_HOST_TO_DEV, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE }, + .bRequest = TUSB_REQUEST_SET_CONFIGURATION, + .wValue = configure_selected + }, + NULL + ) + ); + + tusbh_device_mount_succeed_cb(new_addr); // TODO invoke mounted callback OSAL_TASK_LOOP_END @@ -323,3 +319,15 @@ static inline uint8_t get_new_address(void) return addr; } +static inline uint8_t get_configure_number_for_device(tusb_descriptor_device_t* dev_desc) +{ + uint8_t config_num = 1; + + // invoke callback to ask user which configuration to select + if (tusbh_device_attached_cb) + { + config_num = min8_of(1, tusbh_device_attached_cb(dev_desc) ); + } + + return config_num; +} diff --git a/tinyusb/host/usbh.h b/tinyusb/host/usbh.h index ea3a1d7e9..f34504c35 100644 --- a/tinyusb/host/usbh.h +++ b/tinyusb/host/usbh.h @@ -128,7 +128,7 @@ typedef uint8_t tusbh_device_status_t; // APPLICATION API //--------------------------------------------------------------------+ 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_succeed_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; // 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; |
