mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-23 22:43:49 +00:00
add check device API for stack usage
bool usbh_device_is_plugged(tusb_handle_device_t const device_hdl);
This commit is contained in:
parent
7edda37518
commit
d286c95765
@ -66,6 +66,7 @@ void setUp(void)
|
||||
instance_num = 0;
|
||||
memset(&report, 0, sizeof(tusb_keyboard_report_t));
|
||||
|
||||
keyboard_info_pool[0].instance_count = 0;
|
||||
keyboard_info_pool[0].instance[0].pipe_in = 1;
|
||||
keyboard_info_pool[0].instance[0].report_size = sizeof(tusb_keyboard_report_t);
|
||||
|
||||
@ -91,19 +92,16 @@ void tearDown(void)
|
||||
//--------------------------------------------------------------------+
|
||||
// keyboard_install, keyboard_no_instances
|
||||
//--------------------------------------------------------------------+
|
||||
void test_keyboard_install_invalid_para(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, class_hid_keyboard_install(TUSB_CFG_HOST_DEVICE_MAX, (uint8_t*) &kbd_descriptor));
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, class_hid_keyboard_install(device_hdl, NULL));
|
||||
}
|
||||
|
||||
void test_keyboard_no_instances_invalid_para(void)
|
||||
{
|
||||
usbh_device_is_plugged_IgnoreAndReturn(false);
|
||||
TEST_ASSERT_EQUAL(0, tusbh_hid_keyboard_no_instances(TUSB_CFG_HOST_DEVICE_MAX));
|
||||
}
|
||||
|
||||
void test_keyboard_install_ok(void)
|
||||
{
|
||||
usbh_device_is_plugged_IgnoreAndReturn(true);
|
||||
|
||||
TEST_ASSERT_EQUAL(0, tusbh_hid_keyboard_no_instances(device_hdl));
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, class_hid_keyboard_install(device_hdl, (uint8_t*) &kbd_descriptor));
|
||||
TEST_ASSERT_EQUAL(1, tusbh_hid_keyboard_no_instances(device_hdl));
|
||||
@ -141,6 +139,7 @@ pipe_status_t pipe_status_get_stub(pipe_handle_t pipe_hdl, int num_call)
|
||||
|
||||
void test_keyboard_get_invalid_para()
|
||||
{
|
||||
usbh_device_is_plugged_IgnoreAndReturn(false);
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_keyboard_get(0, 0, NULL));
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_keyboard_get(TUSB_CFG_HOST_DEVICE_MAX, 0, &report));
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_hid_keyboard_get(0, TUSB_CFG_HOST_HID_KEYBOARD_NO_INSTANCES_PER_DEVICE, &report));
|
||||
@ -148,12 +147,15 @@ void test_keyboard_get_invalid_para()
|
||||
|
||||
void test_keyboard_get_class_not_supported()
|
||||
{
|
||||
usbh_device_is_plugged_IgnoreAndReturn(true);
|
||||
keyboard_info_pool[device_hdl].instance[0].pipe_in = 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()
|
||||
{
|
||||
usbh_device_is_plugged_IgnoreAndReturn(true);
|
||||
|
||||
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));
|
||||
|
||||
@ -163,6 +165,7 @@ void test_keyboard_get_report_not_available()
|
||||
|
||||
void test_keyboard_get_ok()
|
||||
{
|
||||
usbh_device_is_plugged_IgnoreAndReturn(true);
|
||||
usbh_pipe_status_get_StubWithCallback(pipe_status_get_stub);
|
||||
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report));
|
||||
|
@ -61,8 +61,8 @@ tusb_error_t tusbh_hid_keyboard_get(tusb_handle_device_t const device_hdl, uint8
|
||||
{
|
||||
keyboard_interface_t *p_kbd;
|
||||
|
||||
ASSERT(usbh_device_is_plugged(device_hdl), TUSB_ERROR_INVALID_PARA);
|
||||
ASSERT_PTR(report, TUSB_ERROR_INVALID_PARA);
|
||||
ASSERT(device_hdl < TUSB_CFG_HOST_DEVICE_MAX, TUSB_ERROR_INVALID_PARA);
|
||||
ASSERT(instance_num < TUSB_CFG_HOST_HID_KEYBOARD_NO_INSTANCES_PER_DEVICE, TUSB_ERROR_INVALID_PARA);
|
||||
|
||||
p_kbd = &keyboard_info_pool[device_hdl].instance[instance_num];
|
||||
@ -78,13 +78,14 @@ 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)
|
||||
{
|
||||
return 0;
|
||||
ASSERT(usbh_device_is_plugged(device_hdl), 0);
|
||||
|
||||
return keyboard_info_pool[device_hdl].instance_count;
|
||||
}
|
||||
|
||||
tusb_error_t class_hid_keyboard_install(uint8_t const dev_addr, uint8_t const *descriptor)
|
||||
{
|
||||
ASSERT(dev_addr < TUSB_CFG_HOST_DEVICE_MAX, TUSB_ERROR_INVALID_PARA);
|
||||
ASSERT_PTR(descriptor, TUSB_ERROR_INVALID_PARA);
|
||||
keyboard_info_pool[0].instance_count++;
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
@ -94,22 +94,21 @@ enum {
|
||||
|
||||
typedef uint32_t tusbh_flag_class_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t interface_count;
|
||||
uint8_t attributes;
|
||||
} usbh_configure_info_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t core_id;
|
||||
pipe_handle_t pipe_control;
|
||||
uint8_t configure_count;
|
||||
|
||||
#if 0 // TODO allow configure for vendor/product
|
||||
uint16_t vendor_id;
|
||||
uint16_t product_id;
|
||||
|
||||
uint8_t configure_count;
|
||||
struct {
|
||||
uint8_t interface_count;
|
||||
uint8_t attributes;
|
||||
} configuration;
|
||||
#endif
|
||||
|
||||
usbh_configure_info_t configuration;
|
||||
} usbh_device_info_t;
|
||||
|
||||
typedef enum {
|
||||
@ -125,8 +124,8 @@ typedef uint32_t tusb_handle_device_t;
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION API
|
||||
//--------------------------------------------------------------------+
|
||||
void tusbh_device_mounting_cb (tusb_error_t error, tusb_handle_device_t device_hdl, uint32_t *configure_flags, uint8_t number_of_configure);
|
||||
void tusbh_device_mounted_cb (tusb_error_t error, tusb_handle_device_t device_hdl, uint32_t *configure_flags, uint8_t number_of_configure);
|
||||
void tusbh_device_mounting_cb (tusb_error_t const error, tusb_handle_device_t const device_hdl);
|
||||
void tusbh_device_mounted_cb (tusb_error_t const error, tusb_handle_device_t const device_hdl);
|
||||
tusb_error_t tusbh_configuration_set (tusb_handle_device_t const device_hdl, uint8_t const configure_number);
|
||||
|
||||
|
||||
@ -134,8 +133,8 @@ tusb_error_t tusbh_configuration_set (tusb_handle_device_t const device_hdl,
|
||||
//--------------------------------------------------------------------+
|
||||
// CLASS API
|
||||
//--------------------------------------------------------------------+
|
||||
usbh_device_info_t* usbh_device_info_get(tusb_handle_device_t device_hdl);
|
||||
pipe_status_t usbh_pipe_status_get(pipe_handle_t pipe_hdl);
|
||||
bool usbh_device_is_plugged(tusb_handle_device_t const device_hdl);
|
||||
pipe_status_t usbh_pipe_status_get(pipe_handle_t pipe_hdl);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user