summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-03-26 17:04:55 +0700
committerhathach <[email protected]>2013-03-26 17:04:55 +0700
commitb0ff7a7e235b1901def71305e6c35e6c3cda222c (patch)
tree37a3bf521d8f22d73af16e55f45a3069d0c02170
parentac905a8d09598067c53ff32835a2d70797d970be (diff)
add code & test for hidh_isr (set status for keyboard)
-rw-r--r--tests/test/host/hid/test_hid_host.c8
-rw-r--r--tests/test/host/hid/test_hidh_keyboard.c9
-rw-r--r--tinyusb/class/hid_host.c47
-rw-r--r--tinyusb/host/hcd.h6
4 files changed, 46 insertions, 24 deletions
diff --git a/tests/test/host/hid/test_hid_host.c b/tests/test/host/hid/test_hid_host.c
index 8c53fa083..f96f20eb2 100644
--- a/tests/test/host/hid/test_hid_host.c
+++ b/tests/test/host/hid/test_hid_host.c
@@ -72,7 +72,6 @@ void test_hidh_open_ok(void)
{
uint16_t length=0;
-
// TODO expect get HID report descriptor
hcd_pipe_open_IgnoreAndReturn( pipe_hdl );
@@ -95,10 +94,3 @@ void test_hidh_close(void)
TEST_ASSERT_MEM_ZERO(&keyboard_data[dev_addr-1], sizeof(hidh_keyboard_info_t));
}
-
-void test_hihd_isr(void)
-{
- TEST_IGNORE();
- //------------- Code Under TEST -------------//
-// hidh_isr()
-}
diff --git a/tests/test/host/hid/test_hidh_keyboard.c b/tests/test/host/hid/test_hidh_keyboard.c
index 101cc0bb9..9e95f0aa0 100644
--- a/tests/test/host/hid/test_hidh_keyboard.c
+++ b/tests/test/host/hid/test_hidh_keyboard.c
@@ -187,3 +187,12 @@ void test_keyboard_get_ok()
tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_BUSY, tusbh_hid_keyboard_status(dev_addr, 0));
}
+
+void test_keyboard_isr_event_complete(void)
+{
+ //------------- Code Under TEST -------------//
+ hidh_isr(p_hidh_kbd->pipe_hdl, BUS_EVENT_XFER_COMPLETE);
+
+ tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
+ TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_COMPLETE, tusbh_hid_keyboard_status(dev_addr, 0));
+}
diff --git a/tinyusb/class/hid_host.c b/tinyusb/class/hid_host.c
index bd63aa99d..e30d0d901 100644
--- a/tinyusb/class/hid_host.c
+++ b/tinyusb/class/hid_host.c
@@ -55,7 +55,7 @@
//--------------------------------------------------------------------+
//--------------------------------------------------------------------+
-// KEYBOARD PUBLIC API (parameter validation required)
+// KEYBOARD
//--------------------------------------------------------------------+
#if TUSB_CFG_HOST_HID_KEYBOARD
@@ -66,25 +66,12 @@ static inline hidh_keyboard_info_t* get_kbd_data(uint8_t dev_addr)
{
return &keyboard_data[dev_addr-1];
}
-
-
+//------------- KEYBOARD PUBLIC API (parameter validation required) -------------//
bool tusbh_hid_keyboard_is_supported(uint8_t dev_addr)
{
return tusbh_device_is_configured(dev_addr) && pipehandle_is_valid(keyboard_data[dev_addr-1].pipe_hdl);
}
-tusb_error_t hidh_keyboard_open(uint8_t dev_addr, tusb_descriptor_endpoint_t const *p_endpoint_desc)
-{
- hidh_keyboard_info_t *p_keyboard = get_kbd_data(dev_addr);
-
- p_keyboard->pipe_hdl = hcd_pipe_open(dev_addr, p_endpoint_desc, TUSB_CLASS_HID);
- p_keyboard->report_size = p_endpoint_desc->wMaxPacketSize.size; // TODO get size from report descriptor
-
- ASSERT (pipehandle_is_valid(p_keyboard->pipe_hdl), TUSB_ERROR_HCD_FAILED);
-
- return TUSB_ERROR_NONE;
-}
-
tusb_error_t tusbh_hid_keyboard_get_report(uint8_t dev_addr, uint8_t instance_num, tusb_keyboard_report_t * const report)
{
//------------- parameters validation -------------//
@@ -109,8 +96,22 @@ tusb_interface_status_t tusbh_hid_keyboard_status(uint8_t dev_addr, uint8_t inst
{
return tusbh_device_get_state(dev_addr) ? keyboard_data[dev_addr-1].status : TUSB_INTERFACE_STATUS_INVALID_PARA;
}
+//------------- Internal API -------------//
+static inline tusb_error_t hidh_keyboard_open(uint8_t dev_addr, tusb_descriptor_endpoint_t const *p_endpoint_desc) ATTR_ALWAYS_INLINE;
+static inline tusb_error_t hidh_keyboard_open(uint8_t dev_addr, tusb_descriptor_endpoint_t const *p_endpoint_desc)
+{
+ hidh_keyboard_info_t *p_keyboard = get_kbd_data(dev_addr);
+
+ p_keyboard->pipe_hdl = hcd_pipe_open(dev_addr, p_endpoint_desc, TUSB_CLASS_HID);
+ p_keyboard->report_size = p_endpoint_desc->wMaxPacketSize.size; // TODO get size from report descriptor
+
+ ASSERT (pipehandle_is_valid(p_keyboard->pipe_hdl), TUSB_ERROR_HCD_FAILED);
+
+ return TUSB_ERROR_NONE;
+}
-void hidh_keyboard_close(uint8_t dev_addr)
+static inline void hidh_keyboard_close(uint8_t dev_addr) ATTR_ALWAYS_INLINE;
+static inline void hidh_keyboard_close(uint8_t dev_addr)
{
pipe_handle_t pipe_hdl = keyboard_data[dev_addr-1].pipe_hdl;
if ( pipehandle_is_valid(pipe_hdl) )
@@ -187,7 +188,21 @@ tusb_error_t hidh_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t con
void hidh_isr(pipe_handle_t pipe_hdl, tusb_bus_event_t event)
{
+#if TUSB_CFG_HOST_HID_KEYBOARD
+ if ( pipehandle_is_equal(pipe_hdl, keyboard_data[pipe_hdl.dev_addr-1].pipe_hdl) )
+ {
+ keyboard_data[pipe_hdl.dev_addr-1].status = (event == BUS_EVENT_XFER_COMPLETE) ? TUSB_INTERFACE_STATUS_COMPLETE : TUSB_INTERFACE_STATUS_ERROR;
+ return;
+ }
+#endif
+
+#if TUSB_CFG_HOST_HID_MOUSE
+
+#endif
+
+#if TUSB_CFG_HOST_HID_GENERIC
+#endif
}
void hidh_close(uint8_t dev_addr)
diff --git a/tinyusb/host/hcd.h b/tinyusb/host/hcd.h
index b3c4a57ce..999fbf734 100644
--- a/tinyusb/host/hcd.h
+++ b/tinyusb/host/hcd.h
@@ -73,6 +73,12 @@ static inline bool pipehandle_is_valid(pipe_handle_t pipe_hdl)
return pipe_hdl.dev_addr > 0;
}
+static inline bool pipehandle_is_equal(pipe_handle_t x, pipe_handle_t y) ATTR_CONST ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
+static inline bool pipehandle_is_equal(pipe_handle_t x, pipe_handle_t y)
+{
+ return (x.dev_addr == y.dev_addr) && (x.xfer_type == y.xfer_type) && (x.index == y.index);
+}
+
//--------------------------------------------------------------------+
// USBH-HCD API
//--------------------------------------------------------------------+