mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-17 05:32:55 +08:00
refractor
- rename TUSB_DEVICE_STATE_READY to TUSB_DEVICE_STATE_CONFIGURED - move device_state to core/tusb_types.h - remove usbh_device_hcd_data_cleaned_up_cb, hcd now set the state directly
This commit is contained in:
parent
d7ba86c85e
commit
e14864759d
@ -78,7 +78,7 @@ void setUp(void)
|
||||
usbh_device_info_pool[i].hub_addr = hub_addr;
|
||||
usbh_device_info_pool[i].hub_port = hub_port;
|
||||
usbh_device_info_pool[i].speed = TUSB_SPEED_HIGH;
|
||||
usbh_device_info_pool[i].state = TUSB_DEVICE_STATE_READY;
|
||||
usbh_device_info_pool[i].state = TUSB_DEVICE_STATE_CONFIGURED;
|
||||
}
|
||||
|
||||
regs = get_operational_register(hostid);
|
||||
|
@ -100,11 +100,11 @@ void test_keyboard_no_instances_invalid_para(void)
|
||||
|
||||
void test_keyboard_install_ok(void)
|
||||
{
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_READY);
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
|
||||
TEST_ASSERT_EQUAL(0, tusbh_hid_keyboard_no_instances(device_hdl));
|
||||
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, hidh_keyboard_install(device_hdl, (uint8_t*) &kbd_descriptor));
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_READY);
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
|
||||
TEST_ASSERT_EQUAL(1, tusbh_hid_keyboard_no_instances(device_hdl));
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@ pipe_status_t pipe_status_get_stub(pipe_handle_t pipe_hdl, int num_call)
|
||||
|
||||
void test_keyboard_get_invalid_para()
|
||||
{
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_READY);
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_keyboard_get(0, 0, NULL));
|
||||
|
||||
tusbh_device_status_get_IgnoreAndReturn(0);
|
||||
@ -162,18 +162,18 @@ void test_keyboard_get_invalid_para()
|
||||
|
||||
void test_keyboard_get_class_not_supported()
|
||||
{
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_READY);
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
|
||||
keyboard_info_pool[device_hdl].instance[0].pipe_in = (pipe_handle_t) { 0 };
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DEVICE_DONT_SUPPORT, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
}
|
||||
|
||||
void test_keyboard_get_report_not_available()
|
||||
{
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_READY);
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
|
||||
usbh_pipe_status_get_IgnoreAndReturn(PIPE_STATUS_BUSY);
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_READY);
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
|
||||
usbh_pipe_status_get_IgnoreAndReturn(PIPE_STATUS_AVAILABLE);
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
}
|
||||
@ -182,16 +182,16 @@ void test_keyboard_get_ok()
|
||||
{
|
||||
usbh_pipe_status_get_StubWithCallback(pipe_status_get_stub);
|
||||
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_READY);
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
TEST_ASSERT_EQUAL_MEMORY(&sample_key[0], &report, sizeof(tusb_keyboard_report_t));
|
||||
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_READY);
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_READY);
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_READY);
|
||||
tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
TEST_ASSERT_EQUAL_MEMORY(&sample_key[1], &report, sizeof(tusb_keyboard_report_t));
|
||||
}
|
||||
|
@ -71,8 +71,8 @@ void test_usbh_status_get_fail(void)
|
||||
|
||||
void test_usbh_status_get_succeed(void)
|
||||
{
|
||||
usbh_device_info_pool[dev_hdl].state = TUSB_DEVICE_STATE_READY;
|
||||
TEST_ASSERT_EQUAL( TUSB_DEVICE_STATE_READY, tusbh_device_status_get(dev_hdl) );
|
||||
usbh_device_info_pool[dev_hdl].state = TUSB_DEVICE_STATE_CONFIGURED;
|
||||
TEST_ASSERT_EQUAL( TUSB_DEVICE_STATE_CONFIGURED, tusbh_device_status_get(dev_hdl) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -179,7 +179,7 @@ void test_usbh_device_unplugged_isr(void)
|
||||
{
|
||||
uint8_t dev_addr = 1;
|
||||
|
||||
usbh_device_info_pool[dev_addr].state = TUSB_DEVICE_STATE_READY;
|
||||
usbh_device_info_pool[dev_addr].state = TUSB_DEVICE_STATE_CONFIGURED;
|
||||
usbh_device_info_pool[dev_addr].core_id = 0;
|
||||
usbh_device_info_pool[dev_addr].hub_addr = 0;
|
||||
usbh_device_info_pool[dev_addr].hub_port = 0;
|
||||
|
@ -65,7 +65,7 @@ tusb_error_t tusbh_hid_keyboard_get(tusb_handle_device_t const device_hdl, uint8
|
||||
{
|
||||
keyboard_interface_t *p_kbd;
|
||||
|
||||
ASSERT_INT(TUSB_DEVICE_STATE_READY, tusbh_device_status_get(device_hdl), TUSB_ERROR_DEVICE_NOT_READY);
|
||||
ASSERT_INT(TUSB_DEVICE_STATE_CONFIGURED, tusbh_device_status_get(device_hdl), TUSB_ERROR_DEVICE_NOT_READY);
|
||||
ASSERT_PTR(report, TUSB_ERROR_INVALID_PARA);
|
||||
ASSERT(instance_num < TUSB_CFG_HOST_HID_KEYBOARD_NO_INSTANCES_PER_DEVICE, TUSB_ERROR_INVALID_PARA);
|
||||
|
||||
@ -82,7 +82,7 @@ tusb_error_t tusbh_hid_keyboard_get(tusb_handle_device_t const device_hdl, uint8
|
||||
|
||||
uint8_t tusbh_hid_keyboard_no_instances(tusb_handle_device_t const device_hdl)
|
||||
{
|
||||
ASSERT_INT(TUSB_DEVICE_STATE_READY, tusbh_device_status_get(device_hdl), 0);
|
||||
ASSERT_INT(TUSB_DEVICE_STATE_CONFIGURED, tusbh_device_status_get(device_hdl), 0);
|
||||
|
||||
return keyboard_info_pool[device_hdl].instance_count;
|
||||
}
|
||||
|
@ -153,6 +153,17 @@ enum {
|
||||
|
||||
#define TUSB_DESC_CONFIG_POWER_MA(x) ((x)/2)
|
||||
|
||||
/// Device State
|
||||
enum tusb_device_state_{
|
||||
TUSB_DEVICE_STATE_UNPLUG = 0 ,
|
||||
TUSB_DEVICE_STATE_ADDRESSED ,
|
||||
|
||||
TUSB_DEVICE_STATE_CONFIGURED ,
|
||||
|
||||
TUSB_DEVICE_STATE_REMOVING ,
|
||||
TUSB_DEVICE_STATE_SAFE_REMOVE ,
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -166,8 +166,8 @@ void async_advance_isr(ehci_qhd_t * const async_head)
|
||||
p_control_qhd->used = 0;
|
||||
p_control_qhd->p_qtd_list_head = p_control_qhd->p_qtd_list_tail = NULL;
|
||||
|
||||
// TODO abstract: Host Controller has cleaned up its data for this device, notify usbh
|
||||
usbh_device_hcd_data_cleaned_up_cb(relative_dev_addr+1);
|
||||
// Host Controller has cleaned up its cached data for this device, set state to unplug
|
||||
usbh_device_info_pool[relative_dev_addr+1].state = TUSB_DEVICE_STATE_UNPLUG;
|
||||
}
|
||||
|
||||
// check if any other endpoints in pool is removing
|
||||
|
@ -226,16 +226,11 @@ void usbh_device_unplugged_isr(uint8_t hostid)
|
||||
|
||||
usbh_pipe_control_close(dev_addr);
|
||||
|
||||
// set to REMOVING to end wait for HCD to clean up its cached data for this device
|
||||
// set to REMOVING to allow HCD to clean up its cached data for this device
|
||||
// HCD must set this device's state to TUSB_DEVICE_STATE_UNPLUG when done
|
||||
usbh_device_info_pool[dev_addr].state = TUSB_DEVICE_STATE_REMOVING;
|
||||
}
|
||||
|
||||
// HCD cleaned up cached data for this device
|
||||
void usbh_device_hcd_data_cleaned_up_cb(uint8_t dev_addr)
|
||||
{
|
||||
usbh_device_info_pool[dev_addr].state = TUSB_DEVICE_STATE_UNPLUG;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// ENUMERATION TASK
|
||||
//--------------------------------------------------------------------+
|
||||
@ -409,7 +404,7 @@ OSAL_TASK_DECLARE(usbh_enumeration_task)
|
||||
)
|
||||
);
|
||||
|
||||
usbh_device_info_pool[new_addr].state = TUSB_DEVICE_STATE_READY;
|
||||
usbh_device_info_pool[new_addr].state = TUSB_DEVICE_STATE_CONFIGURED;
|
||||
tusbh_device_mount_succeed_cb(new_addr);
|
||||
|
||||
// TODO invoke mounted callback
|
||||
|
@ -93,17 +93,6 @@
|
||||
// TUSB_CLASS_APPLICATION_SPECIFIC = 0xEF ,
|
||||
// TUSB_CLASS_VENDOR_SPECIFIC = 0xFF
|
||||
|
||||
/// Device Status
|
||||
enum tusbh_device_status_{
|
||||
TUSB_DEVICE_STATE_UNPLUG = 0,
|
||||
TUSB_DEVICE_STATE_ADDRESSED,
|
||||
|
||||
TUSB_DEVICE_STATE_READY, /* Configured */
|
||||
|
||||
TUSB_DEVICE_STATE_REMOVING,
|
||||
TUSB_DEVICE_STATE_SAFE_REMOVE,
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
PIPE_STATUS_AVAILABLE = 0,
|
||||
PIPE_STATUS_BUSY,
|
||||
|
@ -92,6 +92,7 @@ typedef struct { // TODO internal structure, re-order members
|
||||
|
||||
uint8_t state; // value from enum tusbh_device_status_
|
||||
|
||||
//------------- control pipe -------------//
|
||||
tusb_std_request_t control_request;
|
||||
OSAL_SEM_DEF(semaphore);
|
||||
osal_semaphore_handle_t sem_hdl;
|
||||
@ -103,7 +104,6 @@ extern usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; //
|
||||
void usbh_isr(pipe_handle_t pipe_hdl, uint8_t class_code);
|
||||
void usbh_device_plugged_isr(uint8_t hostid, tusb_speed_t speed);
|
||||
void usbh_device_unplugged_isr(uint8_t hostid);
|
||||
void usbh_device_hcd_data_cleaned_up_cb(uint8_t dev_addr); // hcd called this function when it cleaned all its cached data for this device
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user