mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-17 05:32:55 +08:00
update usbh_init and test
This commit is contained in:
parent
06f923c7bb
commit
6db8af2023
@ -190,34 +190,3 @@ void test_keyboard_get_ok()
|
||||
TEST_ASSERT_EQUAL_MEMORY(&sample_key[1], &report, sizeof(tusb_keyboard_report_t));
|
||||
}
|
||||
|
||||
#if 0
|
||||
void test_keyboard_open_invalid_para()
|
||||
{
|
||||
tusb_handle_keyboard_t keyboard_handle;
|
||||
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_open(TUSB_CFG_HOST_DEVICE_MAX, 1, &keyboard_handle) );
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_open(0, 0, &keyboard_handle) );
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_open(0, TUSB_CFG_CONFIGURATION_MAX+1, &keyboard_handle) );
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_open(0, 1, NULL) );
|
||||
}
|
||||
|
||||
void test_keyboard_open_succeed()
|
||||
{
|
||||
tusb_handle_keyboard_t keyboard_handle = 0;
|
||||
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_keyboard_open(0, 1, &keyboard_handle));
|
||||
TEST_ASSERT_TRUE( 0 != keyboard_handle);
|
||||
}
|
||||
|
||||
void test_keyboard_callback__()
|
||||
{
|
||||
TEST_IGNORE();
|
||||
tusb_handle_device_t device_handle = __LINE__;
|
||||
tusb_handle_configure_t configure_handle = __LINE__;
|
||||
tusb_handle_interface_t interface_handle = __LINE__;
|
||||
uint32_t configure_flags = BIT_(TUSB_CLASS_HID);
|
||||
tusbh_usbd_device_mounted_cb_ExpectWithArray(TUSB_ERROR_NONE, device_handle, &configure_flags, 1, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -37,6 +37,7 @@
|
||||
|
||||
#include "unity.h"
|
||||
#include "usbd_host.h"
|
||||
#include "mock_osal.h"
|
||||
|
||||
extern usbh_device_info_t device_info_pool[TUSB_CFG_HOST_DEVICE_MAX];
|
||||
tusb_handle_device_t dev_hdl;
|
||||
@ -50,16 +51,26 @@ void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void test_usbh_init(void)
|
||||
//--------------------------------------------------------------------+
|
||||
// init, get_status
|
||||
//--------------------------------------------------------------------+
|
||||
void test_usbh_init_checkmem(void)
|
||||
{
|
||||
usbh_device_info_t device_info_zero[TUSB_CFG_HOST_DEVICE_MAX];
|
||||
memset(device_info_zero, 0, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX);
|
||||
|
||||
usbh_init();
|
||||
osal_queue_create_IgnoreAndReturn(TUSB_ERROR_NONE);
|
||||
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, usbh_init());
|
||||
TEST_ASSERT_EQUAL_MEMORY(device_info_zero, device_info_pool, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX);
|
||||
}
|
||||
|
||||
void test_usbh_init_queue_create_fail(void)
|
||||
{
|
||||
osal_queue_create_IgnoreAndReturn(TUSB_ERROR_OSAL_QUEUE_FAILED);
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_OSAL_QUEUE_FAILED, usbh_init());
|
||||
}
|
||||
|
||||
void test_usbh_status_get_fail(void)
|
||||
{
|
||||
usbh_init();
|
||||
@ -73,3 +84,43 @@ void test_usbh_status_get_succeed(void)
|
||||
TEST_ASSERT_EQUAL( TUSB_DEVICE_STATUS_READY, tusbh_device_status_get(dev_hdl) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// enum task
|
||||
//--------------------------------------------------------------------+
|
||||
void test_enum_task(void)
|
||||
{
|
||||
// osal_queue_
|
||||
TEST_IGNORE();
|
||||
usbh_enumerate_task();
|
||||
}
|
||||
|
||||
|
||||
#if 0
|
||||
void test_keyboard_open_invalid_para()
|
||||
{
|
||||
tusb_handle_keyboard_t keyboard_handle;
|
||||
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_open(TUSB_CFG_HOST_DEVICE_MAX, 1, &keyboard_handle) );
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_open(0, 0, &keyboard_handle) );
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_open(0, TUSB_CFG_CONFIGURATION_MAX+1, &keyboard_handle) );
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_INVALID_PARA, tusbh_keyboard_open(0, 1, NULL) );
|
||||
}
|
||||
|
||||
void test_keyboard_open_succeed()
|
||||
{
|
||||
tusb_handle_keyboard_t keyboard_handle = 0;
|
||||
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_keyboard_open(0, 1, &keyboard_handle));
|
||||
TEST_ASSERT_TRUE( 0 != keyboard_handle);
|
||||
}
|
||||
|
||||
void test_keyboard_callback__()
|
||||
{
|
||||
TEST_IGNORE();
|
||||
tusb_handle_device_t device_handle = __LINE__;
|
||||
tusb_handle_configure_t configure_handle = __LINE__;
|
||||
tusb_handle_interface_t interface_handle = __LINE__;
|
||||
uint32_t configure_flags = BIT_(TUSB_CLASS_HID);
|
||||
tusbh_usbd_device_mounted_cb_ExpectWithArray(TUSB_ERROR_NONE, device_handle, &configure_flags, 1, 1);
|
||||
}
|
||||
#endif
|
||||
|
@ -66,6 +66,7 @@
|
||||
ENTRY(TUSB_ERROR_CLASS_DEVICE_DONT_SUPPORT)\
|
||||
ENTRY(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE)\
|
||||
ENTRY(TUSB_ERROR_OSAL_TIMEOUT)\
|
||||
ENTRY(TUSB_ERROR_OSAL_QUEUE_FAILED)\
|
||||
ENTRY(TUSB_ERROR_FAILED)\
|
||||
|
||||
|
||||
|
@ -46,6 +46,7 @@
|
||||
//--------------------------------------------------------------------+
|
||||
#include "common/common.h"
|
||||
#include "usbd_host.h"
|
||||
#include "osal/osal.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO CONSTANT TYPEDEF
|
||||
@ -57,6 +58,10 @@
|
||||
//--------------------------------------------------------------------+
|
||||
STATIC_ usbh_device_info_t device_info_pool[TUSB_CFG_HOST_DEVICE_MAX];
|
||||
|
||||
#define ENUM_DEPTH 2
|
||||
STATIC_ osal_queue_t queue_enumerate;
|
||||
STATIC_ uint8_t queue_enumerate_buffer[ENUM_DEPTH*sizeof(usbh_enumerate_t)];
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// PUBLIC API (Parameter Verification is required)
|
||||
//--------------------------------------------------------------------+
|
||||
@ -69,21 +74,16 @@ tusbh_device_status_t tusbh_device_status_get (tusb_handle_device_t const device
|
||||
//--------------------------------------------------------------------+
|
||||
// CLASS-USBD API (don't require to verify parameters)
|
||||
//--------------------------------------------------------------------+
|
||||
void usbh_init(void)
|
||||
tusb_error_t usbh_init(void)
|
||||
{
|
||||
memset(device_info_pool, 0, sizeof(usbh_device_info_t)*TUSB_CFG_HOST_DEVICE_MAX);
|
||||
}
|
||||
|
||||
#if 0
|
||||
tusb_error_t tusbh_keyboard_open(tusb_handle_device_t device_hdl, uint8_t configure_num, tusb_handle_keyboard_t *keyboard_hdl)
|
||||
{
|
||||
ASSERT(device_hdl < TUSB_CFG_HOST_DEVICE_MAX, TUSB_ERROR_INVALID_PARA);
|
||||
ASSERT_INT_WITHIN(1, TUSB_CFG_CONFIGURATION_MAX, configure_num, TUSB_ERROR_INVALID_PARA);
|
||||
ASSERT_PTR(keyboard_hdl, TUSB_ERROR_INVALID_PARA);
|
||||
|
||||
// ASSERT_STATUS(osal_queue_create());
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
#endif
|
||||
|
||||
void usbh_enumerate_task(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -135,6 +135,13 @@ typedef enum {
|
||||
} pipe_status_t;
|
||||
|
||||
typedef uint32_t tusb_handle_device_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t core_id;
|
||||
uint8_t hub_address;
|
||||
uint8_t hub_port;
|
||||
} usbh_enumerate_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// INTERNAL OBJECT & FUNCTION DECLARATION
|
||||
//--------------------------------------------------------------------+
|
||||
@ -153,8 +160,9 @@ tusbh_device_status_t tusbh_device_status_get (tusb_handle_device_t const device
|
||||
//--------------------------------------------------------------------+
|
||||
#ifdef _TINY_USB_SOURCE_FILE_
|
||||
|
||||
void usbh_init(void);
|
||||
tusb_error_t usbh_init(void);
|
||||
pipe_status_t usbh_pipe_status_get(pipe_handle_t pipe_hdl) ATTR_WARN_UNUSED_RESULT;
|
||||
void usbh_enum_task(void);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -80,8 +80,8 @@ enum
|
||||
// QUEUE API
|
||||
//--------------------------------------------------------------------+
|
||||
typedef uint32_t osal_queue_id_t;
|
||||
|
||||
tusb_error_t osal_queue_create(osal_queue_id_t qid, uint8_t *buffer);
|
||||
//osal_queue_id_t osal_queue_create(osal_queue_t *queue, uint8_t *buffer);
|
||||
osal_queue_id_t osal_queue_create(osal_queue_id_t *queue, uint8_t *buffer);
|
||||
tusb_error_t osal_queue_put(osal_queue_id_t qid, uint32_t data, osal_timeout_t msec);
|
||||
tusb_error_t osal_queue_get(osal_queue_id_t qid, uint32_t *data, osal_timeout_t msec);
|
||||
|
||||
|
@ -68,6 +68,8 @@ typedef struct{
|
||||
volatile uint16_t rd_ptr ; ///< read pointer
|
||||
} osal_queue_t;
|
||||
|
||||
//typedef osal_queue_t osal_queue_id_t*;
|
||||
|
||||
#define OSAL_DEF_QUEUE(name, size)\
|
||||
osal_queue_t name;\
|
||||
uint8_t buffer_##name[size]
|
||||
|
Loading…
x
Reference in New Issue
Block a user