diff --git a/demos/host/keyboard_app.c b/demos/host/keyboard_app.c new file mode 100644 index 000000000..20e6c64e1 --- /dev/null +++ b/demos/host/keyboard_app.c @@ -0,0 +1,58 @@ +/* + * keyboard_app.c + * + * Created on: Mar 24, 2013 + * Author: hathach + */ + +/* + * Software License Agreement (BSD License) + * Copyright (c) 2012, hathach (tinyusb.net) + * 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 +//--------------------------------------------------------------------+ +#include "tusb.h" +#include "keyboard_app.h" + +//--------------------------------------------------------------------+ +// MACRO CONSTANT TYPEDEF +//--------------------------------------------------------------------+ + +//--------------------------------------------------------------------+ +// INTERNAL OBJECT & FUNCTION DECLARATION +//--------------------------------------------------------------------+ + +//--------------------------------------------------------------------+ +// IMPLEMENTATION +//--------------------------------------------------------------------+ +void keyboard_app_task(void) +{ + +} diff --git a/demos/host/keyboard_app.h b/demos/host/keyboard_app.h new file mode 100644 index 000000000..060adc3bf --- /dev/null +++ b/demos/host/keyboard_app.h @@ -0,0 +1,66 @@ +/* + * keyboard_app.h + * + * Created on: Mar 24, 2013 + * Author: hathach + */ + +/* + * Software License Agreement (BSD License) + * Copyright (c) 2012, hathach (tinyusb.net) + * 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. + */ + +/** \file + * \brief TBD + * + * \note TBD + */ + +/** \ingroup TBD + * \defgroup TBD + * \brief TBD + * + * @{ + */ + +#ifndef _TUSB_KEYBOARD_APP_H_ +#define _TUSB_KEYBOARD_APP_H_ + +#ifdef __cplusplus + extern "C" { +#endif + + + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_KEYBOARD_APP_H_ */ + +/** @} */ diff --git a/tests/test/host/test_enum_task.c b/tests/test/host/test_enum_task.c index 90cc7a022..4d21e7a0f 100644 --- a/tests/test/host/test_enum_task.c +++ b/tests/test/host/test_enum_task.c @@ -49,7 +49,7 @@ extern usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; extern uint8_t enum_data_buffer[TUSB_CFG_HOST_ENUM_BUFFER_SIZE]; -tusb_handle_device_t dev_hdl; +uint8_t dev_addr; usbh_enumerate_t const enum_connect = { .core_id = 0, diff --git a/tests/test/host/test_hidh_keyboard.c b/tests/test/host/test_hidh_keyboard.c index ac690a8f9..6a619c143 100644 --- a/tests/test/host/test_hidh_keyboard.c +++ b/tests/test/host/test_hidh_keyboard.c @@ -55,14 +55,14 @@ tusb_keyboard_report_t sample_key[2] = } }; -tusb_handle_device_t device_hdl; +uint8_t dev_addr; tusb_descriptor_interface_t kbd_descriptor; tusb_keyboard_report_t report; uint8_t instance_num; void setUp(void) { - device_hdl = 0; // deviceID = 0 ; Configure = 1 + dev_addr = 0; instance_num = 0; memset(&report, 0, sizeof(tusb_keyboard_report_t)); @@ -101,11 +101,11 @@ void test_keyboard_no_instances_invalid_para(void) void test_keyboard_install_ok(void) { tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - TEST_ASSERT_EQUAL(0, tusbh_hid_keyboard_no_instances(device_hdl)); + TEST_ASSERT_EQUAL(0, tusbh_hid_keyboard_no_instances(dev_addr)); - TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, hidh_keyboard_install(device_hdl, (uint8_t*) &kbd_descriptor)); + TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, hidh_keyboard_install(dev_addr, (uint8_t*) &kbd_descriptor)); tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - TEST_ASSERT_EQUAL(1, tusbh_hid_keyboard_no_instances(device_hdl)); + TEST_ASSERT_EQUAL(1, tusbh_hid_keyboard_no_instances(dev_addr)); } void test_keyboard_init(void) @@ -163,19 +163,19 @@ void test_keyboard_get_invalid_para() void test_keyboard_get_class_not_supported() { tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - keyboard_info_pool[device_hdl].instance[0].pipe_in = (pipe_handle_t) { 0 }; - TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DEVICE_DONT_SUPPORT, tusbh_hid_keyboard_get(device_hdl, instance_num, &report)); + keyboard_info_pool[dev_addr].instance[0].pipe_in = (pipe_handle_t) { 0 }; + TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DEVICE_DONT_SUPPORT, tusbh_hid_keyboard_get(dev_addr, instance_num, &report)); } void test_keyboard_get_report_not_available() { tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); usbh_pipe_status_get_IgnoreAndReturn(PIPE_STATUS_BUSY); - TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report)); + TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(dev_addr, instance_num, &report)); tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); usbh_pipe_status_get_IgnoreAndReturn(PIPE_STATUS_READY); - TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report)); + TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(dev_addr, instance_num, &report)); } void test_keyboard_get_ok() @@ -183,16 +183,16 @@ void test_keyboard_get_ok() usbh_pipe_status_get_StubWithCallback(pipe_status_get_stub); tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report)); + TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_hid_keyboard_get(dev_addr, instance_num, &report)); TEST_ASSERT_EQUAL_MEMORY(&sample_key[0], &report, sizeof(tusb_keyboard_report_t)); tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report)); + TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(dev_addr, instance_num, &report)); tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report)); + TEST_ASSERT_EQUAL(TUSB_ERROR_CLASS_DATA_NOT_AVAILABLE, tusbh_hid_keyboard_get(dev_addr, instance_num, &report)); tusbh_device_status_get_IgnoreAndReturn(TUSB_DEVICE_STATE_CONFIGURED); - TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_hid_keyboard_get(device_hdl, instance_num, &report)); + TEST_ASSERT_EQUAL(TUSB_ERROR_NONE, tusbh_hid_keyboard_get(dev_addr, instance_num, &report)); TEST_ASSERT_EQUAL_MEMORY(&sample_key[1], &report, sizeof(tusb_keyboard_report_t)); } diff --git a/tests/test/host/test_usbh.c b/tests/test/host/test_usbh.c index 885da78c3..07b1ef072 100644 --- a/tests/test/host/test_usbh.c +++ b/tests/test/host/test_usbh.c @@ -47,10 +47,10 @@ #include "mock_hid_host.h" extern usbh_device_info_t usbh_device_info_pool[TUSB_CFG_HOST_DEVICE_MAX+1]; -tusb_handle_device_t dev_hdl; +uint8_t dev_addr; void setUp(void) { - dev_hdl = 0; + dev_addr = 0; memset(usbh_device_info_pool, 0, (TUSB_CFG_HOST_DEVICE_MAX+1)*sizeof(usbh_device_info_t)); } @@ -63,16 +63,16 @@ void tearDown(void) //--------------------------------------------------------------------+ void test_usbh_status_get_fail(void) { - usbh_device_info_pool[dev_hdl].state = 0; + usbh_device_info_pool[dev_addr].state = 0; TEST_ASSERT_EQUAL( 0, tusbh_device_status_get(TUSB_CFG_HOST_DEVICE_MAX+1) ); - TEST_ASSERT_EQUAL( TUSB_DEVICE_STATE_UNPLUG, tusbh_device_status_get(dev_hdl) ); + TEST_ASSERT_EQUAL( TUSB_DEVICE_STATE_UNPLUG, tusbh_device_status_get(dev_addr) ); } void test_usbh_status_get_succeed(void) { - usbh_device_info_pool[dev_hdl].state = TUSB_DEVICE_STATE_CONFIGURED; - TEST_ASSERT_EQUAL( TUSB_DEVICE_STATE_CONFIGURED, tusbh_device_status_get(dev_hdl) ); + usbh_device_info_pool[dev_addr].state = TUSB_DEVICE_STATE_CONFIGURED; + TEST_ASSERT_EQUAL( TUSB_DEVICE_STATE_CONFIGURED, tusbh_device_status_get(dev_addr) ); } //--------------------------------------------------------------------+ diff --git a/tests/test/support/tusb_callback.h b/tests/test/support/tusb_callback.h index 6c13b4528..3d142e39d 100644 --- a/tests/test/support/tusb_callback.h +++ b/tests/test/support/tusb_callback.h @@ -59,7 +59,7 @@ #include "usbh.h" uint8_t tusbh_device_attached_cb (tusb_descriptor_device_t const *p_desc_device) ATTR_WEAK ATTR_WARN_UNUSED_RESULT; -void tusbh_device_mount_succeed_cb (tusb_handle_device_t device_hdl) ATTR_WEAK; +void tusbh_device_mount_succeed_cb (uint8_t dev_addr) ATTR_WEAK; void tusbh_device_mount_failed_cb(tusb_error_t error, tusb_descriptor_device_t const *p_desc_device) ATTR_WEAK; #ifdef __cplusplus diff --git a/tinyusb/class/hid_host.c b/tinyusb/class/hid_host.c index c46125b95..320957759 100644 --- a/tinyusb/class/hid_host.c +++ b/tinyusb/class/hid_host.c @@ -61,15 +61,15 @@ STATIC_ class_hid_keyboard_info_t keyboard_info_pool[TUSB_CFG_HOST_DEVICE_MAX]; //--------------------------------------------------------------------+ // PUBLIC API (Parameter Verification is required) //--------------------------------------------------------------------+ -tusb_error_t tusbh_hid_keyboard_get(tusb_handle_device_t const device_hdl, uint8_t instance_num, tusb_keyboard_report_t * const report) +tusb_error_t tusbh_hid_keyboard_get(uint8_t const dev_addr, uint8_t instance_num, tusb_keyboard_report_t * const report) { keyboard_interface_t *p_kbd; - ASSERT_INT(TUSB_DEVICE_STATE_CONFIGURED, tusbh_device_status_get(device_hdl), TUSB_ERROR_DEVICE_NOT_READY); + ASSERT_INT(TUSB_DEVICE_STATE_CONFIGURED, tusbh_device_status_get(dev_addr), TUSB_ERROR_DEVICE_NOT_READY); ASSERT_PTR(report, TUSB_ERROR_INVALID_PARA); ASSERT(instance_num < TUSB_CFG_HOST_HID_KEYBOARD_NO_INSTANCES_PER_DEVICE, TUSB_ERROR_INVALID_PARA); - p_kbd = &keyboard_info_pool[device_hdl].instance[instance_num]; + p_kbd = &keyboard_info_pool[dev_addr].instance[instance_num]; ASSERT(0 != p_kbd->pipe_in.dev_addr, TUSB_ERROR_CLASS_DEVICE_DONT_SUPPORT); @@ -80,11 +80,11 @@ tusb_error_t tusbh_hid_keyboard_get(tusb_handle_device_t const device_hdl, uint8 return TUSB_ERROR_NONE; } -uint8_t tusbh_hid_keyboard_no_instances(tusb_handle_device_t const device_hdl) +uint8_t tusbh_hid_keyboard_no_instances(uint8_t const dev_addr) { - ASSERT_INT(TUSB_DEVICE_STATE_CONFIGURED, tusbh_device_status_get(device_hdl), 0); + ASSERT_INT(TUSB_DEVICE_STATE_CONFIGURED, tusbh_device_status_get(dev_addr), 0); - return keyboard_info_pool[device_hdl].instance_count; + return keyboard_info_pool[dev_addr].instance_count; } //--------------------------------------------------------------------+ diff --git a/tinyusb/class/hid_host.h b/tinyusb/class/hid_host.h index c0cb81702..669e962d6 100644 --- a/tinyusb/class/hid_host.h +++ b/tinyusb/class/hid_host.h @@ -62,8 +62,9 @@ //--------------------------------------------------------------------+ // APPLICATION API //--------------------------------------------------------------------+ -uint8_t tusbh_hid_keyboard_no_instances(tusb_handle_device_t const device_hdl) ATTR_WARN_UNUSED_RESULT; -tusb_error_t tusbh_hid_keyboard_get(tusb_handle_device_t const handle, uint8_t instance_num, tusb_keyboard_report_t * const report) ATTR_WARN_UNUSED_RESULT; +uint8_t tusbh_hid_keyboard_no_instances(uint8_t const dev_addr) ATTR_WARN_UNUSED_RESULT; +tusb_error_t tusbh_hid_keyboard_get(uint8_t const handle, uint8_t const instance_num, tusb_keyboard_report_t * const report) ATTR_WARN_UNUSED_RESULT; +pipe_status_t tusbh_hid_keyboard_pipe_status(uint8_t const handle, uint8_t const instance_num); //--------------------------------------------------------------------+ // INTERNAL API diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c index c841d3ceb..b22478b72 100644 --- a/tinyusb/host/usbh.c +++ b/tinyusb/host/usbh.c @@ -98,10 +98,10 @@ static inline uint8_t get_configure_number_for_device(tusb_descriptor_device_t* //--------------------------------------------------------------------+ // PUBLIC API (Parameter Verification is required) //--------------------------------------------------------------------+ -tusbh_device_status_t tusbh_device_status_get (tusb_handle_device_t const device_hdl) +tusbh_device_status_t tusbh_device_status_get (uint8_t const dev_addr) { - ASSERT(device_hdl <= TUSB_CFG_HOST_DEVICE_MAX, 0); - return usbh_device_info_pool[device_hdl].state; + ASSERT(dev_addr <= TUSB_CFG_HOST_DEVICE_MAX, 0); + return usbh_device_info_pool[dev_addr].state; } //--------------------------------------------------------------------+ diff --git a/tinyusb/host/usbh.h b/tinyusb/host/usbh.h index 2934e4c3c..d0e29a4ff 100644 --- a/tinyusb/host/usbh.h +++ b/tinyusb/host/usbh.h @@ -63,36 +63,6 @@ //--------------------------------------------------------------------+ // MACRO CONSTANT TYPEDEF //--------------------------------------------------------------------+ -#define CLASS_TABLE(ENTRY_EXPANDER) \ - ENTRY_EXPANDER(TUSB_CLASS_AUDIO)\ - ENTRY_EXPANDER(TUSB_CLASS_CDC)\ - ENTRY_EXPANDER(TUSB_CLASS_HID)\ - ENTRY_EXPANDER(TUSB_CLASS_PHYSICAL)\ - ENTRY_EXPANDER(TUSB_CLASS_IMAGE)\ - ENTRY_EXPANDER(TUSB_CLASS_PRINTER)\ - ENTRY_EXPANDER(TUSB_CLASS_MSC)\ - ENTRY_EXPANDER(TUSB_CLASS_HUB)\ - ENTRY_EXPANDER(TUSB_CLASS_CDC_DATA)\ - ENTRY_EXPANDER(TUSB_CLASS_SMART_CARD)\ - ENTRY_EXPANDER(TUSB_CLASS_CONTENT_SECURITY)\ - ENTRY_EXPANDER(TUSB_CLASS_VIDEO)\ - ENTRY_EXPANDER(TUSB_CLASS_PERSONAL_HEALTHCARE)\ - ENTRY_EXPANDER(TUSB_CLASS_AUDIO_VIDEO)\ - -#define CLASS_LOOKUP_EXPAND(class_code) - -#define CLASS_LOOKUP_INIT_FUNCTION(class_code)\ - -#define CLASS_EXPANDER_INIT(class_code)\ - - - -// TUSB_CLASS_DIAGNOSTIC = 0xDC , -// TUSB_CLASS_WIRELESS_CONTROLLER = 0xE0 , -// TUSB_CLASS_MISC = 0xEF , -// TUSB_CLASS_APPLICATION_SPECIFIC = 0xEF , -// TUSB_CLASS_VENDOR_SPECIFIC = 0xFF - typedef enum pipe_status_{ PIPE_STATUS_READY = 0, PIPE_STATUS_BUSY, @@ -101,7 +71,6 @@ typedef enum pipe_status_{ } pipe_status_t; typedef uint32_t tusbh_flag_class_t; -typedef uint32_t tusb_handle_device_t; typedef uint8_t tusbh_device_status_t; typedef struct { @@ -117,12 +86,17 @@ typedef struct { //--------------------------------------------------------------------+ // APPLICATION API //--------------------------------------------------------------------+ +tusb_device_state_t tusbh_device_get_state(uint8_t dev_addr); + +//--------------------------------------------------------------------+ +// APPLICATION CALLBACK +//--------------------------------------------------------------------+ uint8_t tusbh_device_attached_cb (tusb_descriptor_device_t const *p_desc_device) ATTR_WEAK ATTR_WARN_UNUSED_RESULT; -void tusbh_device_mount_succeed_cb (tusb_handle_device_t device_hdl) ATTR_WEAK; +void tusbh_device_mount_succeed_cb (uint8_t dev_addr) ATTR_WEAK; void tusbh_device_mount_failed_cb(tusb_error_t error, tusb_descriptor_device_t const *p_desc_device) ATTR_WEAK; // TODO refractor remove desc_device -tusb_error_t tusbh_configuration_set (tusb_handle_device_t device_hdl, uint8_t configure_number) ATTR_WARN_UNUSED_RESULT; -tusbh_device_status_t tusbh_device_status_get (tusb_handle_device_t const device_hdl) ATTR_WARN_UNUSED_RESULT; +tusb_error_t tusbh_configuration_set (uint8_t dev_addr, uint8_t configure_number) ATTR_WARN_UNUSED_RESULT; +tusbh_device_status_t tusbh_device_status_get (uint8_t const dev_addr) ATTR_WARN_UNUSED_RESULT; #if TUSB_CFG_OS == TUSB_OS_NONE // TODO move later //static inline void tusb_tick_tock(void) ATTR_ALWAYS_INLINE;