mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-31 05:52:55 +08:00
change configure handle to device handle
change test case accordingly
This commit is contained in:
parent
3015776078
commit
fdc9a82e8c
@ -41,7 +41,7 @@
|
|||||||
#include "mock_osal.h"
|
#include "mock_osal.h"
|
||||||
#include "mock_usbd_host.h"
|
#include "mock_usbd_host.h"
|
||||||
|
|
||||||
tusb_device_info_t usbh_device_pool [2];
|
usbh_device_info_t usbh_device_pool [2];
|
||||||
|
|
||||||
tusb_keyboard_report_t sample_key[2] =
|
tusb_keyboard_report_t sample_key[2] =
|
||||||
{
|
{
|
||||||
@ -55,21 +55,16 @@ tusb_keyboard_report_t sample_key[2] =
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
tusb_handle_configure_t config_hdl;
|
tusb_handle_device_t device_hdl;
|
||||||
tusb_keyboard_report_t report;
|
tusb_keyboard_report_t report;
|
||||||
tusb_configure_info_t *p_cfg_info;
|
|
||||||
|
|
||||||
void setUp(void)
|
void setUp(void)
|
||||||
{
|
{
|
||||||
config_hdl = 1; // deviceID = 0 ; Configure = 1
|
device_hdl = 0; // deviceID = 0 ; Configure = 1
|
||||||
memset(&report, 0, sizeof(tusb_keyboard_report_t));
|
memset(&report, 0, sizeof(tusb_keyboard_report_t));
|
||||||
p_cfg_info = NULL;
|
|
||||||
|
|
||||||
usbh_device_pool[0].configuration[0].classes.hid_keyboard.pipe_in = 1;
|
usbh_device_pool[0].configuration.classes.hid_keyboard.pipe_in = 1;
|
||||||
usbh_device_pool[0].configuration[0].classes.hid_keyboard.qid = 1;
|
usbh_device_pool[0].configuration.classes.hid_keyboard.qid = 1;
|
||||||
|
|
||||||
usbh_device_pool[0].configuration[1].classes.hid_keyboard.pipe_in = 0;
|
|
||||||
usbh_device_pool[0].configuration[1].classes.hid_keyboard.qid = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tearDown(void)
|
void tearDown(void)
|
||||||
@ -82,50 +77,51 @@ tusb_error_t queue_get_stub(osal_queue_id_t qid, uint32_t *data, osal_timeout_t
|
|||||||
return TUSB_ERROR_NONE;
|
return TUSB_ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
tusb_error_t get_configure_class_not_support_stub(tusb_handle_configure_t configure_hdl, tusb_configure_info_t **pp_configure_info, int num_call)
|
usbh_device_info_t* get_device_class_not_support_stub(tusb_handle_device_t device_hdl, int num_call)
|
||||||
{
|
{
|
||||||
(*pp_configure_info) = &(usbh_device_pool[0].configuration[1]);
|
usbh_device_pool[0].configuration.classes.hid_keyboard.pipe_in = 0;
|
||||||
return TUSB_ERROR_NONE;
|
usbh_device_pool[0].configuration.classes.hid_keyboard.qid = 0;
|
||||||
|
|
||||||
|
return &(usbh_device_pool[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
tusb_error_t get_configure_stub(tusb_handle_configure_t configure_hdl, tusb_configure_info_t **pp_configure_info, int num_call)
|
usbh_device_info_t* get_device_stub(tusb_handle_device_t device_hdl, int num_call)
|
||||||
{
|
{
|
||||||
(*pp_configure_info) = &(usbh_device_pool[0].configuration[0]);
|
return &(usbh_device_pool[0]);
|
||||||
return TUSB_ERROR_NONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_keyboard_get_invalid_para()
|
void test_keyboard_get_invalid_para()
|
||||||
{
|
{
|
||||||
usbh_configure_info_get_IgnoreAndReturn(TUSB_ERROR_INVALID_PARA);
|
usbh_device_info_get_IgnoreAndReturn(NULL);
|
||||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_get(config_hdl, NULL));
|
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_get(device_hdl, NULL));
|
||||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_get(config_hdl, &report));
|
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_get(device_hdl, &report));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_keyboard_get_class_not_supported()
|
void test_keyboard_get_class_not_supported()
|
||||||
{
|
{
|
||||||
usbh_configure_info_get_StubWithCallback(get_configure_class_not_support_stub);
|
usbh_device_info_get_StubWithCallback(get_device_class_not_support_stub);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DEVICE_DONT_SUPPORT, tusbh_keyboard_get(config_hdl, &report));
|
TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DEVICE_DONT_SUPPORT, tusbh_keyboard_get(device_hdl, &report));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_keyboard_get_from_empty_queue()
|
void test_keyboard_get_from_empty_queue()
|
||||||
{
|
{
|
||||||
usbh_configure_info_get_StubWithCallback(get_configure_stub);
|
usbh_device_info_get_StubWithCallback(get_device_stub);
|
||||||
osal_queue_get_IgnoreAndReturn(TUSB_ERROR_OSAL_TIMEOUT);
|
osal_queue_get_IgnoreAndReturn(TUSB_ERROR_OSAL_TIMEOUT);
|
||||||
// osal_queue_get_ExpectAndReturn( usbh_device_pool[0].configuration[0].classes.hid_keyboard.qid, );
|
// osal_queue_get_ExpectAndReturn( usbh_device_pool[0].configuration[0].classes.hid_keyboard.qid, );
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_TIMEOUT, tusbh_keyboard_get(config_hdl, &report));
|
TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_TIMEOUT, tusbh_keyboard_get(device_hdl, &report));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_keyboard_get_ok()
|
void test_keyboard_get_ok()
|
||||||
{
|
{
|
||||||
usbh_configure_info_get_StubWithCallback(get_configure_stub);
|
usbh_device_info_get_StubWithCallback(get_device_stub);
|
||||||
osal_queue_get_StubWithCallback(queue_get_stub);
|
osal_queue_get_StubWithCallback(queue_get_stub);
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_keyboard_get(config_hdl, &report));
|
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_keyboard_get(device_hdl, &report));
|
||||||
TEST_ASSERT_EQUAL_MEMORY(&sample_key[0], &report, sizeof(tusb_keyboard_report_t));
|
TEST_ASSERT_EQUAL_MEMORY(&sample_key[0], &report, sizeof(tusb_keyboard_report_t));
|
||||||
|
|
||||||
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_keyboard_get(config_hdl, &report));
|
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_keyboard_get(device_hdl, &report));
|
||||||
TEST_ASSERT_EQUAL_MEMORY(&sample_key[1], &report, sizeof(tusb_keyboard_report_t));
|
TEST_ASSERT_EQUAL_MEMORY(&sample_key[1], &report, sizeof(tusb_keyboard_report_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,18 +41,19 @@
|
|||||||
|
|
||||||
#include "hid_host.h"
|
#include "hid_host.h"
|
||||||
|
|
||||||
tusb_error_t tusbh_keyboard_get(tusb_handle_configure_t const config_hdl, tusb_keyboard_report_t * const report)
|
tusb_error_t tusbh_keyboard_get(tusb_handle_device_t const device_hdl, tusb_keyboard_report_t * const report)
|
||||||
{
|
{
|
||||||
tusb_configure_info_t *p_cfg_info;
|
usbh_device_info_t *p_device_info;
|
||||||
|
|
||||||
pipe_handle_t pipe_in;
|
pipe_handle_t pipe_in;
|
||||||
osal_queue_id_t qid;
|
osal_queue_id_t qid;
|
||||||
|
|
||||||
ASSERT_PTR(report, TUSB_ERROR_INVALID_PARA);
|
ASSERT_PTR(report, TUSB_ERROR_INVALID_PARA);
|
||||||
ASSERT_STATUS( usbh_configure_info_get(config_hdl, &p_cfg_info) );
|
p_device_info = usbh_device_info_get(device_hdl);
|
||||||
|
ASSERT_PTR(p_device_info, TUSB_ERROR_INVALID_PARA);
|
||||||
|
|
||||||
pipe_in = p_cfg_info->classes.hid_keyboard.pipe_in;
|
pipe_in = p_device_info->configuration.classes.hid_keyboard.pipe_in;
|
||||||
qid = p_cfg_info->classes.hid_keyboard.qid;
|
qid = p_device_info->configuration.classes.hid_keyboard.qid;
|
||||||
|
|
||||||
ASSERT(0 != pipe_in, TUSB_ERROR_CLASS_DEVICE_DONT_SUPPORT);
|
ASSERT(0 != pipe_in, TUSB_ERROR_CLASS_DEVICE_DONT_SUPPORT);
|
||||||
ASSERT_STATUS( osal_queue_get(qid, (uint32_t*)report, OSAL_TIMEOUT_WAIT_FOREVER) );
|
ASSERT_STATUS( osal_queue_get(qid, (uint32_t*)report, OSAL_TIMEOUT_WAIT_FOREVER) );
|
||||||
|
@ -57,7 +57,7 @@
|
|||||||
|
|
||||||
#include "hid.h"
|
#include "hid.h"
|
||||||
|
|
||||||
tusb_error_t tusbh_keyboard_get(tusb_handle_configure_t const handle, tusb_keyboard_report_t * const report);
|
tusb_error_t tusbh_keyboard_get(tusb_handle_device_t const handle, tusb_keyboard_report_t * const report);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,6 @@ tusb_error_t tusbh_keyboard_open(tusb_handle_device_t device_hdl, uint8_t config
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
tusb_device_info_t usbh_device_pool[TUSB_CFG_HOST_DEVICE_MAX];
|
usbh_device_info_t usbh_device_pool[TUSB_CFG_HOST_DEVICE_MAX];
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -71,61 +71,37 @@ typedef struct {
|
|||||||
// hid_info_t hid_mouse;
|
// hid_info_t hid_mouse;
|
||||||
// hid_info_t hid_generic;
|
// hid_info_t hid_generic;
|
||||||
} classes;
|
} classes;
|
||||||
} tusb_configure_info_t;
|
} usbh_configure_info_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t core_id;
|
uint8_t core_id;
|
||||||
uint8_t configure_num;
|
|
||||||
uint8_t configure_active; // TODO CONFIG multiple only
|
|
||||||
|
|
||||||
#if 0 // TODO allow configure for vendor/product
|
#if 0 // TODO allow configure for vendor/product
|
||||||
uint16_t vendor_id;
|
uint16_t vendor_id;
|
||||||
uint16_t product_id;
|
uint16_t product_id;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
tusb_configure_info_t configuration[TUSB_CFG_CONFIGURATION_MAX];
|
usbh_configure_info_t configuration;
|
||||||
} tusb_device_info_t;
|
} usbh_device_info_t;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Structures & Types
|
// Structures & Types
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
typedef uint32_t tusb_handle_device_t;
|
typedef uint32_t tusb_handle_device_t;
|
||||||
typedef uint32_t tusb_handle_configure_t;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
uint8_t device_id;
|
|
||||||
uint8_t configure_num;
|
|
||||||
} _tusb_handle_configure_t;
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// APPLICATION API
|
// APPLICATION API
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
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_mounted_cb (tusb_error_t error, tusb_handle_device_t device_hdl, uint32_t *configure_flags, uint8_t number_of_configure);
|
||||||
|
tusb_error_t tusbh_configuration_set (tusb_handle_device_t const device_hdl, uint8_t const configure_number);
|
||||||
|
|
||||||
tusb_error_t tusbh_configuration_set (tusb_handle_device_t const device_hdl, uint8_t const configure_number, tusb_handle_configure_t *configure_hdl);
|
|
||||||
|
|
||||||
//tusb_error_t tusbh_configure_get (tusb_handle_device_t device_hdl, uint8_t configure_number, tusb_handle_configure_t *configure_handle);
|
|
||||||
//tusb_error_t tusbh_class_open (tusb_handle_device_t device_hdl, uint8_t class, tusb_handle_class_t *interface_handle);
|
|
||||||
//tusb_error_t tusbh_interface_get_info(tusb_handle_interface_t interface_handle, tusb_descriptor_interface_t *interface_desc);
|
|
||||||
|
|
||||||
// TODO hiding from application include
|
// TODO hiding from application include
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// CLASS API
|
// CLASS API
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
tusb_error_t usbh_configure_info_get (tusb_handle_configure_t configure_hdl, tusb_configure_info_t **pp_configure_info);
|
usbh_device_info_t* usbh_device_info_get (tusb_handle_device_t device_hdl);
|
||||||
|
|
||||||
#if 0
|
|
||||||
void tusbh_usbd_mounted(tusb_error_t error, tusb_handle_device_t device_hdl);
|
|
||||||
|
|
||||||
tusb_error_t tusbh_usbd_get_configiure (tusb_handle_device_t device_hdl , tusb_handle_configure_t *configure_hdl);
|
|
||||||
tusb_error_t tusbh_usbd_get_configiure_next (tusb_handle_configure_t prev_hdl , tusb_handle_configure_t *next_hdl);
|
|
||||||
|
|
||||||
tusb_error_t tusbh_usbd_get_interface (tusb_handle_configure_t configure_hdl , tusb_handle_interface_t *interface_hdl);
|
|
||||||
tusb_error_t tusbh_usbd_get_interface_next (tusb_handle_interface_t prev_hdl , tusb_handle_interface_t *next_hdl);
|
|
||||||
tusb_error_t tusbh_usbd_get_interface_alternate (tusb_handle_interface_t current_hdl , tusb_handle_interface_t *alternate_hdl);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
@ -40,4 +40,5 @@
|
|||||||
#if TUSB_CFG_OS == TUSB_OS_NONE
|
#if TUSB_CFG_OS == TUSB_OS_NONE
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -55,6 +55,8 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "osal.h"
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// QUEUE API
|
// QUEUE API
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
Loading…
x
Reference in New Issue
Block a user