rename tusbh_device_mount_succeed_cb
add set configure and tusbh_device_mount_succeed_cb invocation refractor get_configure_number_for_device
This commit is contained in:
parent
5eca6d69c3
commit
b1d33c7ffc
|
@ -153,6 +153,12 @@ tusb_error_t control_xfer_stub(uint8_t dev_addr, const tusb_std_request_t * cons
|
||||||
return TUSB_ERROR_NONE;
|
return TUSB_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tusb_error_t hidh_install_stub(uint8_t dev_addr, uint8_t const *descriptor, uint16_t *p_length, int num_call)
|
||||||
|
{
|
||||||
|
*p_length = sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t);
|
||||||
|
return TUSB_ERROR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// enumeration
|
// enumeration
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
@ -215,15 +221,33 @@ void test_enum_failed_get_full_config_desc(void)
|
||||||
usbh_enumeration_task();
|
usbh_enumeration_task();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void class_install_expect(void)
|
||||||
|
{
|
||||||
|
hidh_install_subtask_StubWithCallback(hidh_install_stub);
|
||||||
|
}
|
||||||
|
|
||||||
void test_enum_parse_config_desc(void)
|
void test_enum_parse_config_desc(void)
|
||||||
{
|
{
|
||||||
osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(5));
|
osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(5));
|
||||||
hcd_pipe_control_open_ExpectAndReturn(1, desc_device.bMaxPacketSize0, TUSB_ERROR_NONE);
|
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_attached_cb_ExpectAndReturn((tusb_descriptor_device_t*) enum_data_buffer, 1);
|
||||||
|
|
||||||
hidh_install_subtask_IgnoreAndReturn(TUSB_ERROR_NONE);
|
class_install_expect();
|
||||||
|
tusbh_device_mount_failed_cb_Expect(TUSB_ERROR_USBH_MOUNT_DEVICE_NOT_RESPOND, NULL); // fail to set configure
|
||||||
|
|
||||||
usbh_enumeration_task();
|
usbh_enumeration_task();
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL(desc_configuration.configuration.bNumInterfaces, usbh_device_info_pool[1].interface_count);
|
TEST_ASSERT_EQUAL(desc_configuration.configuration.bNumInterfaces, usbh_device_info_pool[1].interface_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_enum_set_configure(void)
|
||||||
|
{
|
||||||
|
osal_semaphore_wait_StubWithCallback(semaphore_wait_timeout_stub(6));
|
||||||
|
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);
|
||||||
|
class_install_expect();
|
||||||
|
|
||||||
|
tusbh_device_mount_succeed_cb_Expect(1);
|
||||||
|
|
||||||
|
usbh_enumeration_task();
|
||||||
|
}
|
||||||
|
|
|
@ -59,7 +59,7 @@
|
||||||
#include "usbh.h"
|
#include "usbh.h"
|
||||||
|
|
||||||
uint8_t tusbh_device_attached_cb (tusb_descriptor_device_t const *p_desc_device) ATTR_WEAK ATTR_WARN_UNUSED_RESULT;
|
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;
|
void tusbh_device_mount_failed_cb(tusb_error_t error, tusb_descriptor_device_t const *p_desc_device) ATTR_WEAK;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
|
@ -69,6 +69,7 @@ STATIC_ uint8_t enum_data_buffer[TUSB_CFG_HOST_ENUM_BUFFER_SIZE] TUSB_CFG_ATTR_U
|
||||||
|
|
||||||
//------------- 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_descriptor_device_t* dev_desc) ATTR_ALWAYS_INLINE;
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// PUBLIC API (Parameter Verification is required)
|
// 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].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;
|
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 -------------//
|
configure_selected = get_configure_number_for_device((tusb_descriptor_device_t*) enum_data_buffer);
|
||||||
if (tusbh_device_attached_cb)
|
TASK_ASSERT(configure_selected <= usbh_device_info_pool[new_addr].configure_count);
|
||||||
{
|
|
||||||
configure_selected = min8_of(1,
|
|
||||||
tusbh_device_attached_cb( (tusb_descriptor_device_t*) enum_data_buffer) );
|
|
||||||
}else
|
|
||||||
{
|
|
||||||
configure_selected = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//------------- Get 9 bytes of configuration descriptor -------------//
|
//------------- Get 9 bytes of configuration descriptor -------------//
|
||||||
OSAL_SUBTASK_INVOKED_AND_WAIT(
|
OSAL_SUBTASK_INVOKED_AND_WAIT(
|
||||||
|
@ -284,18 +278,20 @@ OSAL_TASK_DECLARE(usbh_enumeration_task)
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------- Set Configure -------------//
|
//------------- Set Configure -------------//
|
||||||
// (void) hcd_pipe_control_xfer(
|
OSAL_SUBTASK_INVOKED_AND_WAIT (
|
||||||
// new_addr,
|
usbh_control_xfer_subtask(
|
||||||
// &(tusb_std_request_t)
|
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,
|
.bmRequestType = { .direction = TUSB_DIR_HOST_TO_DEV, .type = TUSB_REQUEST_TYPE_STANDARD, .recipient = TUSB_REQUEST_RECIPIENT_DEVICE },
|
||||||
// .wValue = configure_selected
|
.bRequest = TUSB_REQUEST_SET_CONFIGURATION,
|
||||||
// },
|
.wValue = configure_selected
|
||||||
// NULL
|
},
|
||||||
// );
|
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) );
|
);
|
||||||
|
|
||||||
|
tusbh_device_mount_succeed_cb(new_addr);
|
||||||
|
|
||||||
// TODO invoke mounted callback
|
// TODO invoke mounted callback
|
||||||
OSAL_TASK_LOOP_END
|
OSAL_TASK_LOOP_END
|
||||||
|
@ -323,3 +319,15 @@ static inline uint8_t get_new_address(void)
|
||||||
return addr;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -128,7 +128,7 @@ typedef uint8_t tusbh_device_status_t;
|
||||||
// APPLICATION API
|
// APPLICATION API
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
uint8_t tusbh_device_attached_cb (tusb_descriptor_device_t const *p_desc_device) ATTR_WEAK ATTR_WARN_UNUSED_RESULT;
|
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
|
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;
|
tusb_error_t tusbh_configuration_set (tusb_handle_device_t device_hdl, uint8_t configure_number) ATTR_WARN_UNUSED_RESULT;
|
||||||
|
|
Loading…
Reference in New Issue