add set idle request for hidh_open_subtask
add interface number to hidh_interface_info_t refractor hidh_open_subtask to be a true subtask cannot run with set idle code ON because of semaphore misuse
This commit is contained in:
parent
ea2e63a332
commit
c81c4bb817
|
@ -69,19 +69,19 @@ void tearDown(void)
|
|||
{
|
||||
}
|
||||
|
||||
void test_hidh_open_ok(void)
|
||||
{
|
||||
uint16_t length=0;
|
||||
|
||||
// TODO expect get HID report descriptor
|
||||
hcd_pipe_open_IgnoreAndReturn( pipe_hdl );
|
||||
|
||||
//------------- Code Under TEST -------------//
|
||||
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, hidh_open_subtask(dev_addr, 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_open_ok(void)
|
||||
//{
|
||||
// uint16_t length=0;
|
||||
//
|
||||
// // TODO expect get HID report descriptor
|
||||
// hcd_pipe_open_IgnoreAndReturn( pipe_hdl );
|
||||
//
|
||||
// //------------- Code Under TEST -------------//
|
||||
// TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, hidh_open_subtask(dev_addr, 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)
|
||||
{
|
||||
|
|
|
@ -118,6 +118,24 @@ void test_keyboard_is_supported_ok(void)
|
|||
TEST_ASSERT_TRUE( tusbh_hid_keyboard_is_mounted(dev_addr) );
|
||||
}
|
||||
|
||||
static tusb_error_t stub_set_idle_request(uint8_t address, tusb_std_request_t const* p_request, uint8_t* data, int num_call)
|
||||
{
|
||||
TEST_ASSERT_EQUAL( dev_addr, address);
|
||||
|
||||
//------------- expecting Set Idle with value = 0 -------------//
|
||||
TEST_ASSERT_NOT_NULL( p_request );
|
||||
TEST_ASSERT_EQUAL(TUSB_DIR_HOST_TO_DEV , p_request->bmRequestType.direction);
|
||||
TEST_ASSERT_EQUAL(TUSB_REQUEST_TYPE_CLASS , p_request->bmRequestType.type);
|
||||
TEST_ASSERT_EQUAL(TUSB_REQUEST_RECIPIENT_INTERFACE , p_request->bmRequestType.recipient);
|
||||
TEST_ASSERT_EQUAL(HID_REQUEST_CONTROL_SET_IDLE , p_request->bRequest);
|
||||
TEST_ASSERT_EQUAL(0 , p_request->wValue);
|
||||
TEST_ASSERT_EQUAL(p_kbd_interface_desc->bInterfaceNumber , p_request->wIndex);
|
||||
|
||||
TEST_ASSERT_NULL(data);
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
void test_keyboard_open_ok(void)
|
||||
{
|
||||
uint16_t length=0;
|
||||
|
@ -125,6 +143,7 @@ void test_keyboard_open_ok(void)
|
|||
|
||||
hidh_init();
|
||||
|
||||
usbh_control_xfer_subtask_StubWithCallback(stub_set_idle_request);
|
||||
hcd_pipe_open_ExpectAndReturn(dev_addr, p_kdb_endpoint_desc, TUSB_CLASS_HID, pipe_hdl);
|
||||
tusbh_hid_keyboard_isr_Expect(dev_addr, TUSB_EVENT_INTERFACE_OPEN);
|
||||
|
||||
|
@ -135,6 +154,7 @@ void test_keyboard_open_ok(void)
|
|||
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);
|
||||
TEST_ASSERT_EQUAL(p_kbd_interface_desc->bInterfaceNumber, p_hidh_kbd->interface_number);
|
||||
|
||||
tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
|
||||
TEST_ASSERT_TRUE( tusbh_hid_keyboard_is_mounted(dev_addr) );
|
||||
|
|
|
@ -107,6 +107,24 @@ void test_mouse_is_supported_ok(void)
|
|||
TEST_ASSERT_TRUE( tusbh_hid_mouse_is_mounted(dev_addr) );
|
||||
}
|
||||
|
||||
static tusb_error_t stub_set_idle_request(uint8_t address, tusb_std_request_t const* p_request, uint8_t* data, int num_call)
|
||||
{
|
||||
TEST_ASSERT_EQUAL( dev_addr, address);
|
||||
|
||||
//------------- expecting Set Idle with value = 0 -------------//
|
||||
TEST_ASSERT_NOT_NULL( p_request );
|
||||
TEST_ASSERT_EQUAL(TUSB_DIR_HOST_TO_DEV , p_request->bmRequestType.direction);
|
||||
TEST_ASSERT_EQUAL(TUSB_REQUEST_TYPE_CLASS , p_request->bmRequestType.type);
|
||||
TEST_ASSERT_EQUAL(TUSB_REQUEST_RECIPIENT_INTERFACE , p_request->bmRequestType.recipient);
|
||||
TEST_ASSERT_EQUAL(HID_REQUEST_CONTROL_SET_IDLE , p_request->bRequest);
|
||||
TEST_ASSERT_EQUAL(0 , p_request->wValue);
|
||||
TEST_ASSERT_EQUAL(p_mouse_interface_desc->bInterfaceNumber , p_request->wIndex);
|
||||
|
||||
TEST_ASSERT_NULL(data);
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
void test_mouse_open_ok(void)
|
||||
{
|
||||
uint16_t length=0;
|
||||
|
@ -114,6 +132,7 @@ void test_mouse_open_ok(void)
|
|||
|
||||
hidh_init();
|
||||
|
||||
usbh_control_xfer_subtask_StubWithCallback(stub_set_idle_request);
|
||||
hcd_pipe_open_ExpectAndReturn(dev_addr, p_mouse_endpoint_desc, TUSB_CLASS_HID, pipe_hdl);
|
||||
tusbh_hid_mouse_isr_Expect(dev_addr, TUSB_EVENT_INTERFACE_OPEN);
|
||||
|
||||
|
@ -124,6 +143,7 @@ void test_mouse_open_ok(void)
|
|||
TEST_ASSERT_EQUAL(8, p_hidh_mouse->report_size);
|
||||
TEST_ASSERT_EQUAL(sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t),
|
||||
length);
|
||||
TEST_ASSERT_EQUAL(p_mouse_interface_desc->bInterfaceNumber, p_hidh_mouse->interface_number);
|
||||
|
||||
tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
|
||||
TEST_ASSERT_TRUE( tusbh_hid_mouse_is_mounted(dev_addr) );
|
||||
|
|
|
@ -68,11 +68,12 @@ tusb_interface_status_t hidh_interface_status(uint8_t dev_addr, hidh_interface_i
|
|||
}
|
||||
}
|
||||
|
||||
static inline tusb_error_t hidh_interface_open(uint8_t dev_addr, tusb_descriptor_endpoint_t const *p_endpoint_desc, hidh_interface_info_t *p_hid) ATTR_ALWAYS_INLINE;
|
||||
static inline tusb_error_t hidh_interface_open(uint8_t dev_addr, tusb_descriptor_endpoint_t const *p_endpoint_desc, hidh_interface_info_t *p_hid)
|
||||
static inline tusb_error_t hidh_interface_open(uint8_t dev_addr, uint8_t interface_number, tusb_descriptor_endpoint_t const *p_endpoint_desc, hidh_interface_info_t *p_hid) ATTR_ALWAYS_INLINE;
|
||||
static inline tusb_error_t hidh_interface_open(uint8_t dev_addr, uint8_t interface_number, tusb_descriptor_endpoint_t const *p_endpoint_desc, hidh_interface_info_t *p_hid)
|
||||
{
|
||||
p_hid->pipe_hdl = hcd_pipe_open(dev_addr, p_endpoint_desc, TUSB_CLASS_HID);
|
||||
p_hid->report_size = p_endpoint_desc->wMaxPacketSize.size; // TODO get size from report descriptor
|
||||
p_hid->pipe_hdl = hcd_pipe_open(dev_addr, p_endpoint_desc, TUSB_CLASS_HID);
|
||||
p_hid->report_size = p_endpoint_desc->wMaxPacketSize.size; // TODO get size from report descriptor
|
||||
p_hid->interface_number = interface_number;
|
||||
|
||||
ASSERT (pipehandle_is_valid(p_hid->pipe_hdl), TUSB_ERROR_HCD_FAILED);
|
||||
|
||||
|
@ -198,6 +199,7 @@ void hidh_init(void)
|
|||
|
||||
tusb_error_t hidh_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t const *p_interface_desc, uint16_t *p_length)
|
||||
{
|
||||
tusb_error_t error;
|
||||
uint8_t const *p_desc = (uint8_t const *) p_interface_desc;
|
||||
|
||||
//------------- HID descriptor -------------//
|
||||
|
@ -205,41 +207,68 @@ tusb_error_t hidh_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t con
|
|||
tusb_hid_descriptor_hid_t const *p_desc_hid = (tusb_hid_descriptor_hid_t const *) p_desc;
|
||||
ASSERT_INT(HID_DESC_TYPE_HID, p_desc_hid->bDescriptorType, TUSB_ERROR_INVALID_PARA);
|
||||
|
||||
//------------- TODO skip Get Report Descriptor -------------//
|
||||
uint8_t *p_report_desc = NULL; // report descriptor has to be global & in USB RAM
|
||||
|
||||
//------------- Endpoint Descriptor -------------//
|
||||
p_desc += p_desc[DESCRIPTOR_OFFSET_LENGTH];
|
||||
ASSERT_INT(TUSB_DESC_TYPE_ENDPOINT, p_desc[DESCRIPTOR_OFFSET_TYPE], TUSB_ERROR_INVALID_PARA);
|
||||
tusb_descriptor_endpoint_t const * p_endpoint_desc = (tusb_descriptor_endpoint_t const *) p_desc;
|
||||
ASSERT_INT(TUSB_DESC_TYPE_ENDPOINT, p_endpoint_desc->bDescriptorType, TUSB_ERROR_INVALID_PARA);
|
||||
|
||||
switch(p_interface_desc->bInterfaceProtocol)
|
||||
OSAL_SUBTASK_BEGIN
|
||||
|
||||
//------------- SET IDLE request -------------//
|
||||
// OSAL_SUBTASK_INVOKED_AND_WAIT(
|
||||
// usbh_control_xfer_subtask(
|
||||
// dev_addr,
|
||||
// &(tusb_std_request_t)
|
||||
// {
|
||||
// .bmRequestType = { .direction = TUSB_DIR_HOST_TO_DEV, .type = TUSB_REQUEST_TYPE_CLASS, .recipient = TUSB_REQUEST_RECIPIENT_INTERFACE },
|
||||
// .bRequest = HID_REQUEST_CONTROL_SET_IDLE,
|
||||
// .wValue = 0,
|
||||
// .wIndex = p_interface_desc->bInterfaceNumber
|
||||
// },
|
||||
// NULL ),
|
||||
// error
|
||||
// );
|
||||
|
||||
//------------- TODO skip Get Report Descriptor -------------//
|
||||
// uint8_t *p_report_desc = NULL; // report descriptor has to be global & in USB RAM
|
||||
|
||||
if ( HID_SUBCLASS_BOOT == p_interface_desc->bInterfaceSubClass )
|
||||
{
|
||||
#if TUSB_CFG_HOST_HID_KEYBOARD
|
||||
case HID_PROTOCOL_KEYBOARD:
|
||||
ASSERT_STATUS ( hidh_interface_open(dev_addr, (tusb_descriptor_endpoint_t const *) p_desc, &keyboard_data[dev_addr-1]) );
|
||||
if ( HID_PROTOCOL_KEYBOARD == p_interface_desc->bInterfaceProtocol)
|
||||
{
|
||||
SUBTASK_ASSERT_STATUS ( hidh_interface_open(dev_addr, p_interface_desc->bInterfaceNumber, p_endpoint_desc, &keyboard_data[dev_addr-1]) );
|
||||
if ( tusbh_hid_keyboard_isr )
|
||||
{
|
||||
tusbh_hid_keyboard_isr(dev_addr, TUSB_EVENT_INTERFACE_OPEN);
|
||||
}
|
||||
break;
|
||||
} else
|
||||
#endif
|
||||
|
||||
#if TUSB_CFG_HOST_HID_MOUSE
|
||||
case HID_PROTOCOL_MOUSE:
|
||||
ASSERT_STATUS ( hidh_interface_open(dev_addr, (tusb_descriptor_endpoint_t const *) p_desc, &mouse_data[dev_addr-1]) );
|
||||
if ( HID_PROTOCOL_MOUSE == p_interface_desc->bInterfaceProtocol)
|
||||
{
|
||||
SUBTASK_ASSERT_STATUS ( hidh_interface_open(dev_addr, p_interface_desc->bInterfaceNumber, p_endpoint_desc, &mouse_data[dev_addr-1]) );
|
||||
if (tusbh_hid_mouse_isr)
|
||||
{
|
||||
tusbh_hid_mouse_isr(dev_addr, TUSB_EVENT_INTERFACE_OPEN);
|
||||
}
|
||||
break;
|
||||
} else
|
||||
#endif
|
||||
|
||||
default: // TODO unknown, unsupported protocol --> skip this interface
|
||||
return TUSB_ERROR_NONE;
|
||||
{
|
||||
// TODO assert without breaking into debugger
|
||||
SUBTASK_ASSERT_STATUS(TUSB_ERROR_HIDH_NOT_SUPPORTED_PROTOCOL);
|
||||
}
|
||||
}else
|
||||
{
|
||||
// TODO assert without breaking into debugger
|
||||
SUBTASK_ASSERT_STATUS(TUSB_ERROR_HIDH_NOT_SUPPORTED_SUBCLASS);
|
||||
}
|
||||
|
||||
*p_length = sizeof(tusb_descriptor_interface_t) + sizeof(tusb_hid_descriptor_hid_t) + sizeof(tusb_descriptor_endpoint_t);
|
||||
return TUSB_ERROR_NONE;
|
||||
|
||||
OSAL_SUBTASK_END
|
||||
}
|
||||
|
||||
void hidh_isr(pipe_handle_t pipe_hdl, tusb_event_t event)
|
||||
|
|
|
@ -93,6 +93,7 @@ void tusbh_hid_generic_isr(uint8_t dev_addr, tusb_event_t event) ATTR_WEAK;
|
|||
typedef struct {
|
||||
pipe_handle_t pipe_hdl;
|
||||
uint16_t report_size;
|
||||
uint8_t interface_number;
|
||||
volatile tusb_interface_status_t status;
|
||||
}hidh_interface_info_t;
|
||||
|
||||
|
|
|
@ -77,6 +77,8 @@
|
|||
ENTRY(TUSB_ERROR_EHCI_NOT_ENOUGH_QTD )\
|
||||
ENTRY(TUSB_ERROR_USBD_DESCRIPTOR_STRING )\
|
||||
ENTRY(TUSB_ERROR_HIDD_DESCRIPTOR_INTERFACE )\
|
||||
ENTRY(TUSB_ERROR_HIDH_NOT_SUPPORTED_PROTOCOL )\
|
||||
ENTRY(TUSB_ERROR_HIDH_NOT_SUPPORTED_SUBCLASS )\
|
||||
ENTRY(TUSB_ERROR_NOT_SUPPORTED_YET )\
|
||||
ENTRY(TUSB_ERROR_FAILED )\
|
||||
|
||||
|
|
|
@ -58,8 +58,8 @@
|
|||
|
||||
typedef ATTR_PREPACKED struct ATTR_PACKED {
|
||||
ATTR_PREPACKED struct ATTR_PACKED {
|
||||
uint8_t recipient : 5; /**< Recipient type. */
|
||||
uint8_t type : 2; /**< Request type. */
|
||||
uint8_t recipient : 5; /**< Recipient type tusb_std_request_recipient_t. */
|
||||
uint8_t type : 2; /**< Request type tusb_std_request_type_t. */
|
||||
uint8_t direction : 1; /**< Direction type. tusb_direction_t */
|
||||
} bmRequestType;
|
||||
|
||||
|
|
|
@ -176,7 +176,7 @@ tusb_error_t usbh_control_xfer_subtask(uint8_t dev_addr, tusb_std_request_t cons
|
|||
|
||||
usbh_devices[dev_addr].control.pipe_status = TUSB_INTERFACE_STATUS_BUSY;
|
||||
usbh_devices[dev_addr].control.request = *p_request;
|
||||
(void) hcd_pipe_control_xfer(dev_addr, &usbh_devices[dev_addr].control.request, data);
|
||||
SUBTASK_ASSERT_STATUS( hcd_pipe_control_xfer(dev_addr, &usbh_devices[dev_addr].control.request, data) );
|
||||
|
||||
osal_semaphore_wait(usbh_devices[dev_addr].control.sem_hdl, OSAL_TIMEOUT_NORMAL, &error); // careful of local variable without static
|
||||
// TODO make handler for this function general purpose
|
||||
|
@ -447,6 +447,9 @@ tusb_error_t enumeration_body_subtask(void)
|
|||
|
||||
usbh_devices[new_addr].state = TUSB_DEVICE_STATE_CONFIGURED;
|
||||
|
||||
//------------- TODO Get String Descriptors -------------//
|
||||
|
||||
|
||||
//------------- parse configuration & install drivers -------------//
|
||||
p_desc = enum_data_buffer + sizeof(tusb_descriptor_configuration_t);
|
||||
|
||||
|
@ -472,12 +475,12 @@ tusb_error_t enumeration_body_subtask(void)
|
|||
error
|
||||
);
|
||||
|
||||
if (error == TUSB_ERROR_NONE) // Interface open failed, for example a subclass is not supported
|
||||
if (error == TUSB_ERROR_NONE)
|
||||
{
|
||||
SUBTASK_ASSERT( length >= sizeof(tusb_descriptor_interface_t) );
|
||||
usbh_devices[new_addr].flag_supported_class |= BIT_(class_index);
|
||||
p_desc += length;
|
||||
}else
|
||||
}else // Interface open failed, for example a subclass is not supported
|
||||
{
|
||||
p_desc += p_desc[DESCRIPTOR_OFFSET_LENGTH]; // skip this interface, the rest will be skipped by the above loop
|
||||
}
|
||||
|
|
|
@ -111,6 +111,8 @@ void tusbh_device_mount_failed_cb(tusb_error_t error, tusb_descriptor_de
|
|||
OSAL_TASK_FUNCTION (usbh_enumeration_task) (void* p_task_para);
|
||||
tusb_error_t usbh_init(void);
|
||||
|
||||
tusb_error_t usbh_control_xfer_subtask(uint8_t dev_addr, tusb_std_request_t const* p_request, uint8_t* data);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -93,6 +93,7 @@ static inline volatile uint32_t osal_tick_get(void)
|
|||
|
||||
#define OSAL_TASK_FUNCTION(task_func) \
|
||||
tusb_error_t task_func
|
||||
|
||||
#define TASK_RESTART \
|
||||
state = 0
|
||||
|
||||
|
@ -144,6 +145,7 @@ static inline volatile uint32_t osal_tick_get(void)
|
|||
ASSERT_DEFINE_WITH_HANDLER(_SUBTASK_ASSERT_ERROR_HANDLER, func_call, tusb_error_t status = (tusb_error_t)(sts),\
|
||||
TUSB_ERROR_NONE == status, status, "%s", TUSB_ErrorStr[status])
|
||||
|
||||
// TODO allow to specify error return
|
||||
#define SUBTASK_ASSERT(condition) \
|
||||
ASSERT_DEFINE_WITH_HANDLER(_SUBTASK_ASSERT_ERROR_HANDLER, , , \
|
||||
(condition), TUSB_ERROR_OSAL_TASK_FAILED, "%s", "evaluated to false")
|
||||
|
|
Loading…
Reference in New Issue