summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-06-27 03:20:14 +0700
committerhathach <[email protected]>2013-06-27 03:20:14 +0700
commitc81c4bb817925f385b45c46857b3f0630edb99ed (patch)
treedd5abf6ca10c6f5dd9119ab00c0c3e44d2af2c87
parentea2e63a332a0d46971f32bd84c84851c2246fe8c (diff)
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
-rw-r--r--tests/test/test/host/hid/test_hid_host.c26
-rw-r--r--tests/test/test/host/hid/test_hidh_keyboard.c20
-rw-r--r--tests/test/test/host/hid/test_hidh_mouse.c20
-rw-r--r--tinyusb/class/hid_host.c65
-rw-r--r--tinyusb/class/hid_host.h1
-rw-r--r--tinyusb/common/errors.h2
-rw-r--r--tinyusb/core/std_request.h4
-rw-r--r--tinyusb/host/usbh.c9
-rw-r--r--tinyusb/host/usbh.h2
-rw-r--r--tinyusb/osal/osal_none.h2
10 files changed, 115 insertions, 36 deletions
diff --git a/tests/test/test/host/hid/test_hid_host.c b/tests/test/test/host/hid/test_hid_host.c
index 19111840e..900319e5e 100644
--- a/tests/test/test/host/hid/test_hid_host.c
+++ b/tests/test/test/host/hid/test_hid_host.c
@@ -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)
{
diff --git a/tests/test/test/host/hid/test_hidh_keyboard.c b/tests/test/test/host/hid/test_hidh_keyboard.c
index 3b0a02d08..62bcc8b45 100644
--- a/tests/test/test/host/hid/test_hidh_keyboard.c
+++ b/tests/test/test/host/hid/test_hidh_keyboard.c
@@ -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) );
diff --git a/tests/test/test/host/hid/test_hidh_mouse.c b/tests/test/test/host/hid/test_hidh_mouse.c
index 16c70b269..0156f5a58 100644
--- a/tests/test/test/host/hid/test_hidh_mouse.c
+++ b/tests/test/test/host/hid/test_hidh_mouse.c
@@ -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) );
diff --git a/tinyusb/class/hid_host.c b/tinyusb/class/hid_host.c
index 98f0753c1..bdadc5666 100644
--- a/tinyusb/class/hid_host.c
+++ b/tinyusb/class/hid_host.c
@@ -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);
+
+ 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
+// );
- switch(p_interface_desc->bInterfaceProtocol)
+ //------------- 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)
diff --git a/tinyusb/class/hid_host.h b/tinyusb/class/hid_host.h
index 547752ea3..e9337b5c1 100644
--- a/tinyusb/class/hid_host.h
+++ b/tinyusb/class/hid_host.h
@@ -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;
diff --git a/tinyusb/common/errors.h b/tinyusb/common/errors.h
index d16191b7d..9017d99f4 100644
--- a/tinyusb/common/errors.h
+++ b/tinyusb/common/errors.h
@@ -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 )\
diff --git a/tinyusb/core/std_request.h b/tinyusb/core/std_request.h
index 1cc64285d..15b34e66a 100644
--- a/tinyusb/core/std_request.h
+++ b/tinyusb/core/std_request.h
@@ -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;
diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c
index 62d6b056c..419b1a534 100644
--- a/tinyusb/host/usbh.c
+++ b/tinyusb/host/usbh.c
@@ -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
}
diff --git a/tinyusb/host/usbh.h b/tinyusb/host/usbh.h
index 5879e7321..97eb4542b 100644
--- a/tinyusb/host/usbh.h
+++ b/tinyusb/host/usbh.h
@@ -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
diff --git a/tinyusb/osal/osal_none.h b/tinyusb/osal/osal_none.h
index 07ebd1f99..936513d1b 100644
--- a/tinyusb/osal/osal_none.h
+++ b/tinyusb/osal/osal_none.h
@@ -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")