summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-04-09 13:28:07 +0700
committerhathach <[email protected]>2013-04-09 13:28:07 +0700
commite6a44b3fe9a0af6ce33f8340c8703bf0bbc43d5a (patch)
tree9fe35b73fd7fb1921979889f6323b0a28785b091
parenta6cf4f228e3036c4df69066df524b3fde74b271c (diff)
add test & code for TUSB_EVENT_INTERFACE_OPEN for tusbh_hid_keyboard_isr tusbh_hid_mouse_isr
-rw-r--r--tests/test/host/hid/test_hidh_keyboard.c1
-rw-r--r--tests/test/host/hid/test_hidh_mouse.c15
-rw-r--r--tests/test/host/integration/test_hidh_keyboard_integrate.c (renamed from tests/test/host/integration/test_hidh_keyboard.c)49
-rw-r--r--tinyusb/class/hid_host.c8
4 files changed, 48 insertions, 25 deletions
diff --git a/tests/test/host/hid/test_hidh_keyboard.c b/tests/test/host/hid/test_hidh_keyboard.c
index 7045fd46c..fa15f221b 100644
--- a/tests/test/host/hid/test_hidh_keyboard.c
+++ b/tests/test/host/hid/test_hidh_keyboard.c
@@ -125,6 +125,7 @@ void test_keyboard_open_ok(void)
hidh_init();
hcd_pipe_open_ExpectAndReturn(dev_addr, p_kdb_endpoint_desc, TUSB_CLASS_HID, pipe_hdl);
+ tusbh_hid_keyboard_isr_Expect(dev_addr, 0, TUSB_EVENT_INTERFACE_OPEN);
//------------- Code Under TEST -------------//
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, hidh_open_subtask(dev_addr, p_kbd_interface_desc, &length));
diff --git a/tests/test/host/hid/test_hidh_mouse.c b/tests/test/host/hid/test_hidh_mouse.c
index 74aedba9d..15dcddf36 100644
--- a/tests/test/host/hid/test_hidh_mouse.c
+++ b/tests/test/host/hid/test_hidh_mouse.c
@@ -113,6 +113,7 @@ void test_mouse_open_ok(void)
hidh_init();
hcd_pipe_open_ExpectAndReturn(dev_addr, p_mouse_endpoint_desc, TUSB_CLASS_HID, pipe_hdl);
+ tusbh_hid_mouse_isr_Expect(dev_addr, 0, TUSB_EVENT_INTERFACE_OPEN);
//------------- Code Under TEST -------------//
TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, hidh_open_subtask(dev_addr, p_mouse_interface_desc, &length));
@@ -180,7 +181,7 @@ void test_mouse_get_ok()
TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_BUSY, tusbh_hid_mouse_status(dev_addr, 0));
}
-void test_mouse_isr_event_complete(void)
+void test_mouse_isr_event_xfer_complete(void)
{
tusbh_hid_mouse_isr_Expect(dev_addr, 0, TUSB_EVENT_XFER_COMPLETE);
@@ -191,4 +192,16 @@ void test_mouse_isr_event_complete(void)
TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_COMPLETE, tusbh_hid_mouse_status(dev_addr, 0));
}
+void test_mouse_isr_event_xfer_error(void)
+{
+ tusbh_hid_mouse_isr_Expect(dev_addr, 0, TUSB_EVENT_XFER_ERROR);
+
+ //------------- Code Under TEST -------------//
+ hidh_isr(p_hidh_mouse->pipe_hdl, TUSB_EVENT_XFER_ERROR);
+
+ tusbh_device_get_state_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED);
+ TEST_ASSERT_EQUAL(TUSB_INTERFACE_STATUS_ERROR, tusbh_hid_mouse_status(dev_addr, 0));
+}
+
+
diff --git a/tests/test/host/integration/test_hidh_keyboard.c b/tests/test/host/integration/test_hidh_keyboard_integrate.c
index f7662f954..a0ce152c0 100644
--- a/tests/test/host/integration/test_hidh_keyboard.c
+++ b/tests/test/host/integration/test_hidh_keyboard_integrate.c
@@ -35,33 +35,34 @@
* This file is part of the tiny usb stack.
*/
-#include "stdlib.h"
-#include "unity.h"
-#include "type_helper.h"
-#include "tusb_option.h"
-#include "errors.h"
-
-#include "mock_osal.h"
-#include "hcd.h"
-#include "usbh.h"
-#include "tusb.h"
-#include "hid_host.h"
-
-#include "descriptor_test.h"
-
-uint8_t dev_addr;
-uint8_t hostid;
-
+//#include "stdlib.h"
+//#include "unity.h"
+//#include "type_helper.h"
+//#include "tusb_option.h"
+//#include "errors.h"
+//
+//#include "mock_osal.h"
+//#include "hcd.h"
+//#include "usbh.h"
+//#include "tusb.h"
+//#include "hid_host.h"
+////#include "ehci_controller.h"
+//
+//#include "descriptor_test.h"
+//
+//uint8_t dev_addr;
+//uint8_t hostid;
+//
void setUp(void)
{
- dev_addr = RANDOM(TUSB_CFG_HOST_DEVICE_MAX)+1;
- hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX;
-
- ehci_controller_init();
- tusb_init();
-
+// dev_addr = RANDOM(TUSB_CFG_HOST_DEVICE_MAX)+1;
+// hostid = RANDOM(CONTROLLER_HOST_NUMBER) + TEST_CONTROLLER_HOST_START_INDEX;
+//
+//// ehci_controller_init();
+// tusb_init();
+//
}
-
+//
void tearDown(void)
{
}
diff --git a/tinyusb/class/hid_host.c b/tinyusb/class/hid_host.c
index 3668af9c0..412465b5b 100644
--- a/tinyusb/class/hid_host.c
+++ b/tinyusb/class/hid_host.c
@@ -199,12 +199,20 @@ tusb_error_t hidh_open_subtask(uint8_t dev_addr, tusb_descriptor_interface_t con
#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 ( tusbh_hid_keyboard_isr )
+ {
+ tusbh_hid_keyboard_isr(dev_addr, 0, TUSB_EVENT_INTERFACE_OPEN);
+ }
break;
#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 (tusbh_hid_mouse_isr)
+ {
+ tusbh_hid_mouse_isr(dev_addr, 0, TUSB_EVENT_INTERFACE_OPEN);
+ }
break;
#endif