summaryrefslogtreecommitdiff
path: root/src/host
diff options
context:
space:
mode:
authorhathach <[email protected]>2021-08-23 17:00:41 +0700
committerhathach <[email protected]>2021-08-23 17:00:41 +0700
commit75cd593b609340b3101d0b002ac765c5595fa2eb (patch)
treeda79de4b89c6dce4e45097f6c3ddc4e81f753901 /src/host
parenta490a3fe616205115ed351ddbc0bd202bcbdc3db (diff)
add hcd_devtree_get_info()
remove usbh_hcd.h
Diffstat (limited to 'src/host')
-rw-r--r--src/host/hcd.h15
-rw-r--r--src/host/hcd_attr.h1
-rw-r--r--src/host/usbh.c78
-rw-r--r--src/host/usbh_control.c9
-rw-r--r--src/host/usbh_hcd.h106
5 files changed, 94 insertions, 115 deletions
diff --git a/src/host/hcd.h b/src/host/hcd.h
index e1d21bf45..eb53d2e80 100644
--- a/src/host/hcd.h
+++ b/src/host/hcd.h
@@ -92,6 +92,14 @@ enum {
//#define HCD_MAX_ENDPOINT 16
//#define HCD_MAX_XFER 16
+
+typedef struct {
+ uint8_t rhport;
+ uint8_t hub_addr;
+ uint8_t hub_port;
+ uint8_t speed;
+} hcd_devtree_info_t;
+
#endif
//--------------------------------------------------------------------+
@@ -145,6 +153,13 @@ bool hcd_edpt_clear_stall(uint8_t dev_addr, uint8_t ep_addr);
// USBH implemented API
//--------------------------------------------------------------------+
+// Get device tree information of a device
+// USB device tree can be complicated and manged by USBH, this help HCD to retrieve
+// needed topology info to carry out its work
+extern void hcd_devtree_get_info(uint8_t dev_addr, hcd_devtree_info_t* devtree_info);
+
+//------------- Event API -------------//
+
// Called by HCD to notify stack
extern void hcd_event_handler(hcd_event_t const* event, bool in_isr);
diff --git a/src/host/hcd_attr.h b/src/host/hcd_attr.h
index d18686587..729fc407b 100644
--- a/src/host/hcd_attr.h
+++ b/src/host/hcd_attr.h
@@ -35,6 +35,7 @@
//------------- NXP -------------//
#if TU_CHECK_MCU(LPC175X_6X) || TU_CHECK_MCU(LPC177X_8X) || TU_CHECK_MCU(LPC40XX)
+ #define HCD_ATTR_OHCI
#elif TU_CHECK_MCU(LPC18XX) || TU_CHECK_MCU(LPC43XX)
#define HCD_ATTR_EHCI_TRANSDIMENSION
diff --git a/src/host/usbh.c b/src/host/usbh.c
index 76c1ba078..8e9628cb2 100644
--- a/src/host/usbh.c
+++ b/src/host/usbh.c
@@ -32,12 +32,16 @@
#include "host/usbh.h"
#include "host/usbh_classdriver.h"
#include "hub.h"
-#include "usbh_hcd.h"
//--------------------------------------------------------------------+
// USBH Configuration
//--------------------------------------------------------------------+
+// TODO remove,update
+#ifndef CFG_TUH_EP_MAX
+#define CFG_TUH_EP_MAX 9
+#endif
+
#ifndef CFG_TUH_TASK_QUEUE_SZ
#define CFG_TUH_TASK_QUEUE_SZ 16
#endif
@@ -46,6 +50,57 @@
#define USBH_DBG_LVL 2
//--------------------------------------------------------------------+
+// USBH-HCD common data structure
+//--------------------------------------------------------------------+
+
+typedef struct {
+ //------------- port -------------//
+ uint8_t rhport;
+ uint8_t hub_addr;
+ uint8_t hub_port;
+ uint8_t speed;
+
+ //------------- device descriptor -------------//
+ uint16_t vendor_id;
+ uint16_t product_id;
+ uint8_t ep0_packet_size;
+
+ //------------- configuration descriptor -------------//
+ // uint8_t interface_count; // bNumInterfaces alias
+
+ //------------- device -------------//
+ struct TU_ATTR_PACKED
+ {
+ uint8_t connected : 1;
+ uint8_t addressed : 1;
+ uint8_t configured : 1;
+ uint8_t suspended : 1;
+ };
+
+ volatile uint8_t state; // device state, value from enum tusbh_device_state_t
+
+ uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid)
+ uint8_t ep2drv[CFG_TUH_EP_MAX][2]; // map endpoint to driver ( 0xff is invalid )
+
+ struct TU_ATTR_PACKED
+ {
+ volatile bool busy : 1;
+ volatile bool stalled : 1;
+ volatile bool claimed : 1;
+
+ // TODO merge ep2drv here, 4-bit should be sufficient
+ }ep_status[CFG_TUH_EP_MAX][2];
+
+ // Mutex for claiming endpoint, only needed when using with preempted RTOS
+#if CFG_TUSB_OS != OPT_OS_NONE
+ osal_mutex_def_t mutexdef;
+ osal_mutex_t mutex;
+#endif
+
+} usbh_device_t;
+
+
+//--------------------------------------------------------------------+
// MACRO CONSTANT TYPEDEF
//--------------------------------------------------------------------+
@@ -130,7 +185,7 @@ static bool _usbh_initialized = false;
// all devices including hub and zero-address TODO exclude device0 to save space
// hub address start from CFG_TUH_DEVICE_MAX
-CFG_TUSB_MEM_SECTION usbh_device_t _usbh_devices[CFG_TUH_DEVICE_MAX+1];
+CFG_TUSB_MEM_SECTION usbh_device_t _usbh_devices[1+CFG_TUH_DEVICE_MAX+CFG_TUH_HUB];
// Event queue
// role device/host is used by OS NONE for mutex (disable usb isr)
@@ -139,7 +194,14 @@ static osal_queue_t _usbh_q;
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t _usbh_ctrl_buf[CFG_TUH_ENUMERATION_BUFSIZE];
-//------------- Helper Function Prototypes -------------//
+//------------- Helper Function -------------//
+
+TU_ATTR_ALWAYS_INLINE
+static inline usbh_device_t* get_device(uint8_t dev_addr)
+{
+ return &_usbh_devices[dev_addr];
+}
+
static bool enum_new_device(hcd_event_t* event);
static void process_device_unplugged(uint8_t rhport, uint8_t hub_addr, uint8_t hub_port);
static bool usbh_edpt_control_open(uint8_t dev_addr, uint8_t max_packet_size);
@@ -326,6 +388,16 @@ uint8_t* usbh_get_enum_buf(void)
// HCD Event Handler
//--------------------------------------------------------------------+
+void hcd_devtree_get_info(uint8_t dev_addr, hcd_devtree_info_t* devtree_info)
+{
+ usbh_device_t const* dev = get_device(dev_addr);
+
+ devtree_info->rhport = dev->rhport;
+ devtree_info->hub_addr = dev->hub_addr;
+ devtree_info->hub_port = dev->hub_port;
+ devtree_info->speed = dev->speed;
+}
+
void hcd_event_handler(hcd_event_t const* event, bool in_isr)
{
switch (event->event_id)
diff --git a/src/host/usbh_control.c b/src/host/usbh_control.c
index 0bdb66fb5..9204576ac 100644
--- a/src/host/usbh_control.c
+++ b/src/host/usbh_control.c
@@ -29,7 +29,7 @@
#if TUSB_OPT_HOST_ENABLED
#include "tusb.h"
-#include "usbh_hcd.h"
+#include "usbh_classdriver.h"
enum
{
@@ -59,9 +59,7 @@ static usbh_control_xfer_t _ctrl_xfer;
bool tuh_control_xfer (uint8_t dev_addr, tusb_control_request_t const* request, void* buffer, tuh_control_complete_cb_t complete_cb)
{
// TODO need to claim the endpoint first
-
- usbh_device_t* dev = &_usbh_devices[dev_addr];
- const uint8_t rhport = dev->rhport;
+ const uint8_t rhport = usbh_get_rhport(dev_addr);
_ctrl_xfer.request = (*request);
_ctrl_xfer.buffer = buffer;
@@ -89,8 +87,7 @@ bool usbh_control_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result_t resu
(void) ep_addr;
(void) xferred_bytes;
- usbh_device_t* dev = &_usbh_devices[dev_addr];
- const uint8_t rhport = dev->rhport;
+ const uint8_t rhport = usbh_get_rhport(dev_addr);
tusb_control_request_t const * request = &_ctrl_xfer.request;
diff --git a/src/host/usbh_hcd.h b/src/host/usbh_hcd.h
deleted file mode 100644
index 9f8d3407d..000000000
--- a/src/host/usbh_hcd.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * The MIT License (MIT)
- *
- * Copyright (c) 2019 Ha Thach (tinyusb.org)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * This file is part of the TinyUSB stack.
- */
-
-/** \ingroup Group_HCD
- * @{ */
-
-#ifndef _TUSB_USBH_HCD_H_
-#define _TUSB_USBH_HCD_H_
-
-#ifdef __cplusplus
- extern "C" {
-#endif
-
-//--------------------------------------------------------------------+
-// INCLUDE
-//--------------------------------------------------------------------+
-#include "common/tusb_common.h"
-#include "osal/osal.h"
-
-#ifndef CFG_TUH_EP_MAX
-#define CFG_TUH_EP_MAX 9
-#endif
-
-//--------------------------------------------------------------------+
-// USBH-HCD common data structure
-//--------------------------------------------------------------------+
-
-// TODO move to usbh.c
-typedef struct {
- //------------- port -------------//
- uint8_t rhport;
- uint8_t hub_addr;
- uint8_t hub_port;
- uint8_t speed;
-
- //------------- device descriptor -------------//
- uint16_t vendor_id;
- uint16_t product_id;
- uint8_t ep0_packet_size;
-
- //------------- configuration descriptor -------------//
- // uint8_t interface_count; // bNumInterfaces alias
-
- //------------- device -------------//
- struct TU_ATTR_PACKED
- {
- uint8_t connected : 1;
- uint8_t addressed : 1;
- uint8_t configured : 1;
- uint8_t suspended : 1;
- };
-
- volatile uint8_t state; // device state, value from enum tusbh_device_state_t
-
- uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid)
- uint8_t ep2drv[CFG_TUH_EP_MAX][2]; // map endpoint to driver ( 0xff is invalid )
-
- struct TU_ATTR_PACKED
- {
- volatile bool busy : 1;
- volatile bool stalled : 1;
- volatile bool claimed : 1;
-
- // TODO merge ep2drv here, 4-bit should be sufficient
- }ep_status[CFG_TUH_EP_MAX][2];
-
- // Mutex for claiming endpoint, only needed when using with preempted RTOS
-#if CFG_TUSB_OS != OPT_OS_NONE
- osal_mutex_def_t mutexdef;
- osal_mutex_t mutex;
-#endif
-
-} usbh_device_t;
-
-extern usbh_device_t _usbh_devices[CFG_TUH_DEVICE_MAX+1]; // including zero-address
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif /* _TUSB_USBH_HCD_H_ */
-
-/** @} */