From 94486f55ec3b24f720cabf1218e8eb291b8f620c Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 4 Feb 2013 13:51:20 +0700 Subject: [PATCH] add usbh_hcd to hold common structure/typedef for usbh and hcd --- tests/test/host/test_usbd_host.c | 4 +- tinyusb/class/hid_host.h | 1 + tinyusb/common/common.h | 1 - tinyusb/host/hcd.h | 14 ++-- tinyusb/host/usbh.c | 2 +- tinyusb/host/usbh.h | 47 ++---------- tinyusb/host/usbh_hcd.h | 119 +++++++++++++++++++++++++++++++ 7 files changed, 136 insertions(+), 52 deletions(-) create mode 100644 tinyusb/host/usbh_hcd.h diff --git a/tests/test/host/test_usbd_host.c b/tests/test/host/test_usbd_host.c index 9143ef3f1..4d170804d 100644 --- a/tests/test/host/test_usbd_host.c +++ b/tests/test/host/test_usbd_host.c @@ -178,12 +178,10 @@ void test_enum_task_connect(void) { pipe_handle_t pipe_addr0 = 12; - - osal_queue_receive_StubWithCallback(queue_recv_stub); hcd_port_connect_status_ExpectAndReturn(enum_connect.core_id, true); hcd_port_speed_ExpectAndReturn(enum_connect.core_id, TUSB_SPEED_FULL); - hcd_pipe_addr0_open_ExpectAndReturn(enum_connect.core_id, TUSB_SPEED_FULL, 0, 0, pipe_addr0); + hcd_pipe_addr0_open_IgnoreAndReturn(pipe_addr0); hcd_pipe_control_xfer_StubWithCallback(pipe_control_stub); // hcd_pipe_control_open_ExpectAnd(1, ); diff --git a/tinyusb/class/hid_host.h b/tinyusb/class/hid_host.h index 4ef003868..0fb1c3299 100644 --- a/tinyusb/class/hid_host.h +++ b/tinyusb/class/hid_host.h @@ -55,6 +55,7 @@ extern "C" { #endif +#include "common/common.h" #include "host/usbh.h" #include "hid.h" diff --git a/tinyusb/common/common.h b/tinyusb/common/common.h index a56de956e..ec3e3f2ac 100644 --- a/tinyusb/common/common.h +++ b/tinyusb/common/common.h @@ -72,7 +72,6 @@ #include "errors.h" //------------- TUSB Header -------------// -//#include "hal/hal.h" #include "core/tusb_types.h" #include "core/std_descriptors.h" #include "core/std_request.h" diff --git a/tinyusb/host/hcd.h b/tinyusb/host/hcd.h index 31c1feb4d..d4c288223 100644 --- a/tinyusb/host/hcd.h +++ b/tinyusb/host/hcd.h @@ -56,19 +56,23 @@ #endif #include "common/common.h" -//#include "usbh.h" +#include "usbh_hcd.h" -typedef uint32_t pipe_handle_t; +//--------------------------------------------------------------------+ +// MACRO CONSTANT TYPEDEF +//--------------------------------------------------------------------+ + +//--------------------------------------------------------------------+ +// USBH-HCD API +//--------------------------------------------------------------------+ tusb_error_t hcd_init(uint8_t hostid) ATTR_WARN_UNUSED_RESULT; //--------------------------------------------------------------------+ // PIPE API //--------------------------------------------------------------------+ -//pipe_handle_t hcd_pipe_addr0_open(usbh_device_addr0_t const * dev_addr0); -pipe_handle_t hcd_pipe_addr0_open(uint8_t core_id, tusb_speed_t speed, uint8_t hub_addr, uint8_t hub_port); - +pipe_handle_t hcd_pipe_addr0_open(usbh_device_addr0_t const * dev_addr0); pipe_handle_t hcd_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size); tusb_error_t hcd_pipe_control_xfer(pipe_handle_t pipe_hdl, tusb_std_request_t const * p_request, uint8_t data[]); pipe_handle_t hcd_pipe_open(uint8_t dev_addr, tusb_descriptor_endpoint_t const * endpoint_desc); diff --git a/tinyusb/host/usbh.c b/tinyusb/host/usbh.c index 69d30467b..594a8c12d 100644 --- a/tinyusb/host/usbh.c +++ b/tinyusb/host/usbh.c @@ -105,7 +105,7 @@ void usbh_enumeration_task(void) .wLength = 8 }; device_addr0.speed = hcd_port_speed(device_addr0.enum_entry.core_id); -// pipe_handle_t pipe_addr0 = hcd_pipe_addr0_open(&device_addr0); + pipe_handle_t pipe_addr0 = hcd_pipe_addr0_open(&device_addr0); // hcd_pipe_control_xfer(pipe_addr0, &request_dev_desc) }else // device connect via a hub diff --git a/tinyusb/host/usbh.h b/tinyusb/host/usbh.h index d0ad72c02..cb71d2725 100644 --- a/tinyusb/host/usbh.h +++ b/tinyusb/host/usbh.h @@ -59,6 +59,7 @@ // INCLUDE //--------------------------------------------------------------------+ #include "common/common.h" +#include "usbh_hcd.h" #include "hcd.h" //--------------------------------------------------------------------+ @@ -101,60 +102,22 @@ enum { /// Device Status enum { - TUSB_DEVICE_STATUS_UNPLUG = 0, - TUSB_DEVICE_STATUS_READY = BIT_(0), + TUSB_DEVICE_STATUS_UNPLUG = 0, + TUSB_DEVICE_STATUS_READY = BIT_(0), - TUSB_DEVICE_STATUS_REMOVING = BIT_(2), + TUSB_DEVICE_STATUS_REMOVING = BIT_(2), TUSB_DEVICE_STATUS_SAFE_REMOVE = BIT_(3), }; -typedef uint8_t tusbh_device_status_t; -typedef uint32_t tusbh_flag_class_t; - -typedef struct { // TODO internal structure, re-order members - uint8_t core_id; - tusb_speed_t speed; - uint8_t hub_addr; - uint8_t hub_port; - - uint16_t vendor_id; - uint16_t product_id; - uint8_t configure_count; - - tusbh_device_status_t status; - pipe_handle_t pipe_control; - tusb_std_request_t request_control; - -#if 0 // TODO allow configure for vendor/product - struct { - uint8_t interface_count; - uint8_t attributes; - } configuration; -#endif - -} usbh_device_info_t; - typedef enum { PIPE_STATUS_AVAILABLE = 0, PIPE_STATUS_BUSY, PIPE_STATUS_COMPLETE } pipe_status_t; +typedef uint32_t tusbh_flag_class_t; typedef uint32_t tusb_handle_device_t; -typedef struct ATTR_ALIGNED(4){ - uint8_t core_id; - uint8_t hub_addr; - uint8_t hub_port; - uint8_t connect_status; -} usbh_enumerate_t; - -typedef struct { - usbh_enumerate_t enum_entry; - tusb_speed_t speed; - tusb_std_request_t request_packet; // needed to be on USB RAM -} usbh_device_addr0_t; - //--------------------------------------------------------------------+ // INTERNAL OBJECT & FUNCTION DECLARATION //--------------------------------------------------------------------+ diff --git a/tinyusb/host/usbh_hcd.h b/tinyusb/host/usbh_hcd.h new file mode 100644 index 000000000..923e5c3d9 --- /dev/null +++ b/tinyusb/host/usbh_hcd.h @@ -0,0 +1,119 @@ +/* + * usbh_hcd.h + * + * Created on: Feb 4, 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_USBH_HCD_H_ +#define _TUSB_USBH_HCD_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +//--------------------------------------------------------------------+ +// INCLUDE +//--------------------------------------------------------------------+ +#include "common/common.h" + +//--------------------------------------------------------------------+ +// USBH +//--------------------------------------------------------------------+ +typedef uint8_t tusbh_device_status_t; +typedef uint32_t pipe_handle_t; + +typedef struct ATTR_ALIGNED(4){ + uint8_t core_id; + uint8_t hub_addr; + uint8_t hub_port; + uint8_t connect_status; +} usbh_enumerate_t; + +typedef struct { + usbh_enumerate_t enum_entry; + tusb_speed_t speed; + tusb_std_request_t request_packet; // needed to be on USB RAM +} usbh_device_addr0_t; + +typedef struct { // TODO internal structure, re-order members + uint8_t core_id; + tusb_speed_t speed; + uint8_t hub_addr; + uint8_t hub_port; + + uint16_t vendor_id; + uint16_t product_id; + uint8_t configure_count; + + tusbh_device_status_t status; + pipe_handle_t pipe_control; + tusb_std_request_t request_control; + +#if 0 // TODO allow configure for vendor/product + struct { + uint8_t interface_count; + uint8_t attributes; + } configuration; +#endif + +} usbh_device_info_t; + +//--------------------------------------------------------------------+ +// HCD +//--------------------------------------------------------------------+ + +//--------------------------------------------------------------------+ +// IMPLEMENTATION +//--------------------------------------------------------------------+ + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_USBH_HCD_H_ */ + +/** @} */