mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-22 19:20:52 +00:00
add flag_supported_class to usbh_devices
remove all ATTR_WEAK in init,open,isr,close driver functions of USBH-CLASS API - prefer testing
This commit is contained in:
parent
ff03b452d9
commit
086a8e4a2d
@ -42,6 +42,8 @@
|
||||
|
||||
#include "hal.h"
|
||||
#include "mock_osal.h"
|
||||
#include "mock_hid_host.h"
|
||||
|
||||
#include "hcd.h"
|
||||
#include "usbh_hcd.h"
|
||||
#include "usbh.h"
|
||||
|
@ -37,44 +37,62 @@
|
||||
|
||||
#include "stdlib.h"
|
||||
#include "unity.h"
|
||||
#include "common/common.h"
|
||||
#include "tusb_option.h"
|
||||
#include "errors.h"
|
||||
#include "hid_host.h"
|
||||
#include "binary.h"
|
||||
|
||||
#include "descriptor_test.h"
|
||||
#include "mock_osal.h"
|
||||
#include "mock_hcd.h"
|
||||
#include "mock_usbh.h"
|
||||
#include "mock_hid_host_keyboard.h"
|
||||
|
||||
|
||||
#include "hid_host.h"
|
||||
|
||||
uint8_t dev_addr;
|
||||
uint8_t instance_num;
|
||||
|
||||
tusb_descriptor_interface_t const *p_kbd_interface_desc = &desc_configuration.keyboard_interface;
|
||||
tusb_hid_descriptor_hid_t const *p_kbh_hid_desc = &desc_configuration.keyboard_hid;
|
||||
tusb_descriptor_endpoint_t const *p_kdb_endpoint_desc = &desc_configuration.keyboard_endpoint;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
instance_num = 0;
|
||||
// dev_addr = RANDOM(TUSB_CFG_HOST_DEVICE_MAX)+1;
|
||||
dev_addr = RANDOM(TUSB_CFG_HOST_DEVICE_MAX)+1;
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void test_hidh_init(void)
|
||||
void test_hidh_init_ok(void)
|
||||
{
|
||||
hidh_keyboard_init_Expect();
|
||||
// hidh_keyboard_init_Expect();
|
||||
// TODO mouse, generic expect
|
||||
|
||||
//------------- Code Under TEST -------------//
|
||||
if (!hidh_init)
|
||||
TEST_IGNORE();
|
||||
// hidh_init();
|
||||
}
|
||||
|
||||
void test_hidh_open_ok(void)
|
||||
{
|
||||
uint16_t length=0;
|
||||
//
|
||||
// hidh_keyboard_open_subtask_ExpectAndReturn(dev_addr, p_kbd_interface_desc, &length, TUSB_ERROR_NONE);
|
||||
//
|
||||
//------------- Code Under TEST -------------//
|
||||
// hidh_open_subtask(dev_addr, (uint8_t*) p_kbd_interface_desc, &length);
|
||||
|
||||
// TEST_ASSERT_EQUAL(sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t),
|
||||
// length);
|
||||
}
|
||||
|
||||
void test_hidh_close(void)
|
||||
{
|
||||
if (!hidh_close)
|
||||
TEST_IGNORE();
|
||||
hidh_keyboard_init_Ignore();
|
||||
hidh_keyboard_close_Expect(dev_addr);
|
||||
|
||||
//------------- Code Under TEST -------------//
|
||||
// hidh_close(dev_addr);
|
||||
}
|
||||
|
||||
void test_hihd_isr(void)
|
@ -126,7 +126,7 @@ void test_keyboard_open_ok(void)
|
||||
TEST_ASSERT_PIPE_HANDLE(pipe_hdl, p_hidh_kbd->pipe_hdl);
|
||||
TEST_ASSERT_EQUAL(8, p_hidh_kbd->report_size);
|
||||
TEST_ASSERT_EQUAL(sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t),
|
||||
length);
|
||||
length);
|
||||
|
||||
tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
|
||||
TEST_ASSERT_TRUE( tusbh_hid_keyboard_is_supported(dev_addr) );
|
||||
|
@ -256,6 +256,7 @@ void test_enum_parse_config_desc(void)
|
||||
usbh_enumeration_task();
|
||||
|
||||
TEST_ASSERT_EQUAL(desc_configuration.configuration.bNumInterfaces, usbh_devices[1].interface_count);
|
||||
TEST_ASSERT_EQUAL(TUSB_CLASS_FLAG_HID, usbh_devices[1].flag_supported_class); // TODO change later
|
||||
}
|
||||
|
||||
void test_enum_set_configure(void)
|
||||
|
@ -111,7 +111,17 @@ void hidh_isr(pipe_handle_t pipe_hdl, tusb_bus_event_t event)
|
||||
|
||||
void hidh_close(uint8_t dev_addr)
|
||||
{
|
||||
#if TUSB_CFG_HOST_HID_KEYBOARD
|
||||
hidh_keyboard_close(dev_addr);
|
||||
#endif
|
||||
|
||||
#if TUSB_CFG_HOST_HID_MOUSE
|
||||
hidh_mouse_close(dev_addr);
|
||||
#endif
|
||||
|
||||
#if TUSB_CFG_HOST_HID_GENERIC
|
||||
hidh_generic_close(dev_addr);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -72,14 +72,14 @@
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// CLASS DRIVER FUNCTION (all declared with WEAK)
|
||||
// CLASS DRIVER FUNCTION
|
||||
//--------------------------------------------------------------------+
|
||||
#ifdef _TINY_USB_SOURCE_FILE_
|
||||
|
||||
void hidh_init(void) ATTR_WEAK;
|
||||
tusb_error_t hidh_open_subtask(uint8_t dev_addr, uint8_t const *descriptor, uint16_t *p_length) ATTR_WEAK ATTR_WARN_UNUSED_RESULT;
|
||||
void hidh_isr(pipe_handle_t pipe_hdl, tusb_bus_event_t event) ATTR_WEAK;
|
||||
void hidh_close(uint8_t dev_addr) ATTR_WEAK;
|
||||
void hidh_init(void);
|
||||
tusb_error_t hidh_open_subtask(uint8_t dev_addr, uint8_t const *descriptor, uint16_t *p_length) ATTR_WARN_UNUSED_RESULT;
|
||||
void hidh_isr(pipe_handle_t pipe_hdl, tusb_bus_event_t event);
|
||||
void hidh_close(uint8_t dev_addr);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -63,19 +63,24 @@ void tusb_tick_tock(void)
|
||||
// TODO fix/compress number of class driver
|
||||
static host_class_driver_t const usbh_class_drivers[TUSB_CLASS_MAX_CONSEC_NUMBER] =
|
||||
{
|
||||
#if HOST_CLASS_HID
|
||||
[TUSB_CLASS_HID] = {
|
||||
.init = hidh_init,
|
||||
.open_subtask = hidh_open_subtask,
|
||||
.isr = hidh_isr,
|
||||
.close = hidh_close
|
||||
},
|
||||
#endif
|
||||
|
||||
#if TUSB_CFG_HOST_CLASS_MSC
|
||||
[TUSB_CLASS_MSC] = {
|
||||
.init = msch_init,
|
||||
.open_subtask = msch_open_subtask,
|
||||
.isr = msch_isr,
|
||||
.close = msch_close
|
||||
}
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -237,6 +242,7 @@ void usbh_device_unplugged_isr(uint8_t hostid)
|
||||
// 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_devices[dev_addr].state = TUSB_DEVICE_STATE_REMOVING;
|
||||
usbh_devices[dev_addr].flag_supported_class = 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
@ -384,12 +390,16 @@ OSAL_TASK_DECLARE(usbh_enumeration_task)
|
||||
{
|
||||
TASK_ASSERT( false ); // corrupted data, abort enumeration
|
||||
}
|
||||
// supported class
|
||||
else if ( class_code < TUSB_CLASS_MAX_CONSEC_NUMBER && usbh_class_drivers[class_code].open_subtask) // TODO custom class
|
||||
// supported class TODO custom class
|
||||
else if ( class_code < TUSB_CLASS_MAX_CONSEC_NUMBER && usbh_class_drivers[class_code].open_subtask)
|
||||
{
|
||||
uint16_t length=0;
|
||||
OSAL_SUBTASK_INVOKED_AND_WAIT ( // parameters in task/sub_task must be static storage (static or global)
|
||||
usbh_class_drivers[ ((tusb_descriptor_interface_t*) p_desc)->bInterfaceClass ].open_subtask(new_addr, p_desc, &length) );
|
||||
|
||||
// TODO check class_open_subtask status
|
||||
usbh_devices[new_addr].flag_supported_class |= BIT_(((tusb_descriptor_interface_t*) p_desc)->bInterfaceClass);
|
||||
|
||||
p_desc += length;
|
||||
} else // unsupported class (not enable or yet implemented)
|
||||
{
|
||||
|
@ -76,21 +76,23 @@ typedef struct ATTR_ALIGNED(4){
|
||||
} usbh_enumerate_t;
|
||||
|
||||
typedef struct { // TODO internal structure, re-order members
|
||||
//------------- port info -------------//
|
||||
//------------- port -------------//
|
||||
uint8_t core_id;
|
||||
uint8_t hub_addr;
|
||||
uint8_t hub_port;
|
||||
uint8_t speed;
|
||||
|
||||
//------------- device descriptor info -------------//
|
||||
//------------- device descriptor -------------//
|
||||
uint16_t vendor_id;
|
||||
uint16_t product_id;
|
||||
uint8_t configure_count; // bNumConfigurations alias
|
||||
|
||||
//------------- configuration descriptor info -------------//
|
||||
//------------- configuration descriptor -------------//
|
||||
uint8_t interface_count; // bNumInterfaces alias
|
||||
|
||||
//------------- device -------------//
|
||||
volatile uint8_t state; // device state, value from enum tusbh_device_state_t
|
||||
uint32_t flag_supported_class; // a bitmap of supported class
|
||||
|
||||
//------------- control pipe -------------//
|
||||
struct {
|
||||
|
Loading…
x
Reference in New Issue
Block a user