Przeglądaj źródła

add code & test for hidh_isr (set status for keyboard)

hathach 13 lat temu
rodzic
commit
b0ff7a7e23

+ 0 - 8
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()
-}

+ 9 - 0
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));
+}

+ 31 - 16
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)

+ 6 - 0
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
 //--------------------------------------------------------------------+