From e6a44b3fe9a0af6ce33f8340c8703bf0bbc43d5a Mon Sep 17 00:00:00 2001 From: hathach Date: Tue, 9 Apr 2013 13:28:07 +0700 Subject: add test & code for TUSB_EVENT_INTERFACE_OPEN for tusbh_hid_keyboard_isr tusbh_hid_mouse_isr --- tests/test/host/hid/test_hidh_keyboard.c | 1 + tests/test/host/hid/test_hidh_mouse.c | 15 ++- tests/test/host/integration/test_hidh_keyboard.c | 130 -------------------- .../integration/test_hidh_keyboard_integrate.c | 131 +++++++++++++++++++++ tinyusb/class/hid_host.c | 8 ++ 5 files changed, 154 insertions(+), 131 deletions(-) delete mode 100644 tests/test/host/integration/test_hidh_keyboard.c create mode 100644 tests/test/host/integration/test_hidh_keyboard_integrate.c 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.c deleted file mode 100644 index f7662f954..000000000 --- a/tests/test/host/integration/test_hidh_keyboard.c +++ /dev/null @@ -1,130 +0,0 @@ -/* - * test_hidh_keyboard.c - * - * Created on: Apr 5, 2013 - * Author: hathach - */ - -/* - * Software License Agreement (BSD License) - * Copyright (c) 2012, hathach (tinyusb.org) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * 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; - -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(); - -} - -void tearDown(void) -{ -} -// -//osal_semaphore_handle_t sem_create_stub(osal_semaphore_t * const sem, int num_call) -//{ -// (*p_sem) = 0; -// return (osal_semaphore_handle_t) p_sem; -//} -//void sem_wait_stub(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error, int num_call) -//{ -// -//} -//tusb_error_t sem_post_stub(osal_semaphore_handle_t const sem_hdl, int num_call) -//{ -// (*sem_hdl)++; -// -// return TUSB_ERROR_NONE; -//} -//void sem_reset_stub(osal_semaphore_handle_t const sem_hdl, int num_call) -//{ -// (*sem_hdl) = 0; -//} -// -//osal_queue_handle_t queue_create_stub (osal_queue_t *p_queue, int num_call) -//{ -// p_queue->count = p_queue->wr_idx = p_queue->rd_idx = 0; -// return (osal_queue_handle_t) p_queue; -//} -//void queue_receive_stub (osal_queue_handle_t const queue_hdl, uint32_t *p_data, uint32_t msec, tusb_error_t *p_error, int num_call) -//{ -// -//} -//tusb_error_t queue_send_stub (osal_queue_handle_t const queue_hdl, uint32_t data, int num_call) -//{ -// //TODO mutex lock hal_interrupt_disable -// -// queue_hdl->buffer[queue_hdl->wr_idx] = data; -// queue_hdl->wr_idx = (queue_hdl->wr_idx + 1) % queue_hdl->depth; -// -// if (queue_hdl->depth == queue_hdl->count) // queue is full, 1st rd is overwritten -// { -// queue_hdl->rd_idx = queue_hdl->wr_idx; // keep full state -// }else -// { -// queue_hdl->count++; -// } -// -// //TODO mutex unlock hal_interrupt_enable -// -// return TUSB_ERROR_NONE; -//} -//void queue_flush_stub(osal_queue_handle_t const queue_hdl, int num_call) -//{ -// queue_hdl->count = queue_hdl->rd_idx = queue_hdl->wr_idx = 0; -//} -// -//void test_(void) -//{ -// ehci_controller_device_plug(hostid, TUSB_SPEED_HIGH); -// -// tusb_task_runner(); // get 8-byte descriptor -// ehci_controller_control_xfer_proceed(0, &desc_device); -// -// tusb_task_runner(); // get 8-byte descriptor -//} diff --git a/tests/test/host/integration/test_hidh_keyboard_integrate.c b/tests/test/host/integration/test_hidh_keyboard_integrate.c new file mode 100644 index 000000000..a0ce152c0 --- /dev/null +++ b/tests/test/host/integration/test_hidh_keyboard_integrate.c @@ -0,0 +1,131 @@ +/* + * test_hidh_keyboard.c + * + * Created on: Apr 5, 2013 + * Author: hathach + */ + +/* + * Software License Agreement (BSD License) + * Copyright (c) 2012, hathach (tinyusb.org) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT + * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT + * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY + * OF SUCH DAMAGE. + * + * 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 "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(); +// +} +// +void tearDown(void) +{ +} +// +//osal_semaphore_handle_t sem_create_stub(osal_semaphore_t * const sem, int num_call) +//{ +// (*p_sem) = 0; +// return (osal_semaphore_handle_t) p_sem; +//} +//void sem_wait_stub(osal_semaphore_handle_t const sem_hdl, uint32_t msec, tusb_error_t *p_error, int num_call) +//{ +// +//} +//tusb_error_t sem_post_stub(osal_semaphore_handle_t const sem_hdl, int num_call) +//{ +// (*sem_hdl)++; +// +// return TUSB_ERROR_NONE; +//} +//void sem_reset_stub(osal_semaphore_handle_t const sem_hdl, int num_call) +//{ +// (*sem_hdl) = 0; +//} +// +//osal_queue_handle_t queue_create_stub (osal_queue_t *p_queue, int num_call) +//{ +// p_queue->count = p_queue->wr_idx = p_queue->rd_idx = 0; +// return (osal_queue_handle_t) p_queue; +//} +//void queue_receive_stub (osal_queue_handle_t const queue_hdl, uint32_t *p_data, uint32_t msec, tusb_error_t *p_error, int num_call) +//{ +// +//} +//tusb_error_t queue_send_stub (osal_queue_handle_t const queue_hdl, uint32_t data, int num_call) +//{ +// //TODO mutex lock hal_interrupt_disable +// +// queue_hdl->buffer[queue_hdl->wr_idx] = data; +// queue_hdl->wr_idx = (queue_hdl->wr_idx + 1) % queue_hdl->depth; +// +// if (queue_hdl->depth == queue_hdl->count) // queue is full, 1st rd is overwritten +// { +// queue_hdl->rd_idx = queue_hdl->wr_idx; // keep full state +// }else +// { +// queue_hdl->count++; +// } +// +// //TODO mutex unlock hal_interrupt_enable +// +// return TUSB_ERROR_NONE; +//} +//void queue_flush_stub(osal_queue_handle_t const queue_hdl, int num_call) +//{ +// queue_hdl->count = queue_hdl->rd_idx = queue_hdl->wr_idx = 0; +//} +// +//void test_(void) +//{ +// ehci_controller_device_plug(hostid, TUSB_SPEED_HIGH); +// +// tusb_task_runner(); // get 8-byte descriptor +// ehci_controller_control_xfer_proceed(0, &desc_device); +// +// tusb_task_runner(); // get 8-byte descriptor +//} 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 -- cgit v1.3.1