rename and expose tuh_bus_info_get() to application

This commit is contained in:
hathach
2025-04-23 16:03:40 +07:00
parent 741cb3cf02
commit a2da575793
14 changed files with 35 additions and 23 deletions

View File

@@ -90,13 +90,6 @@ typedef struct {
}; };
} hcd_event_t; } hcd_event_t;
typedef struct {
uint8_t rhport;
uint8_t hub_addr;
uint8_t hub_port;
uint8_t speed;
} tuh_bus_info_t;
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Memory API // Memory API
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
@@ -186,9 +179,6 @@ bool hcd_edpt_clear_stall(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr);
// USBH implemented API // USBH implemented API
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Get device port information
extern bool hcd_bus_info_get(uint8_t daddr, tuh_bus_info_t* bus_info);
// Called by HCD to notify stack // Called by HCD to notify stack
extern void hcd_event_handler(hcd_event_t const* event, bool in_isr); extern void hcd_event_handler(hcd_event_t const* event, bool in_isr);

View File

@@ -28,9 +28,9 @@
#if CFG_TUH_ENABLED #if CFG_TUH_ENABLED
#include "host/hcd.h" #include "hcd.h"
#include "tusb.h" #include "tusb.h"
#include "host/usbh_pvt.h" #include "usbh_pvt.h"
#include "hub.h" #include "hub.h"
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
@@ -342,7 +342,7 @@ bool tuh_vid_pid_get(uint8_t dev_addr, uint16_t *vid, uint16_t *pid) {
tusb_speed_t tuh_speed_get(uint8_t daddr) { tusb_speed_t tuh_speed_get(uint8_t daddr) {
tuh_bus_info_t bus_info; tuh_bus_info_t bus_info;
hcd_bus_info_get(daddr, &bus_info); tuh_bus_info_get(daddr, &bus_info);
return bus_info.speed; return bus_info.speed;
} }
@@ -875,7 +875,7 @@ bool tuh_edpt_abort_xfer(uint8_t daddr, uint8_t ep_addr) {
uint8_t usbh_get_rhport(uint8_t daddr) { uint8_t usbh_get_rhport(uint8_t daddr) {
tuh_bus_info_t bus_info; tuh_bus_info_t bus_info;
hcd_bus_info_get(daddr, &bus_info); tuh_bus_info_get(daddr, &bus_info);
return bus_info.rhport; return bus_info.rhport;
} }
@@ -1013,7 +1013,7 @@ bool usbh_edpt_busy(uint8_t dev_addr, uint8_t ep_addr) {
// HCD Event Handler // HCD Event Handler
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
bool hcd_bus_info_get(uint8_t daddr, tuh_bus_info_t* bus_info) { bool tuh_bus_info_get(uint8_t daddr, tuh_bus_info_t* bus_info) {
usbh_device_t const* dev = get_device(daddr); usbh_device_t const* dev = get_device(daddr);
if (dev) { if (dev) {
*bus_info = dev->bus_info; *bus_info = dev->bus_info;

View File

@@ -47,7 +47,6 @@
// forward declaration // forward declaration
struct tuh_xfer_s; struct tuh_xfer_s;
typedef struct tuh_xfer_s tuh_xfer_t; typedef struct tuh_xfer_s tuh_xfer_t;
typedef void (*tuh_xfer_cb_t)(tuh_xfer_t* xfer); typedef void (*tuh_xfer_cb_t)(tuh_xfer_t* xfer);
// Note1: layout and order of this will be changed in near future // Note1: layout and order of this will be changed in near future
@@ -80,6 +79,14 @@ typedef struct {
tusb_desc_interface_t desc; tusb_desc_interface_t desc;
} tuh_itf_info_t; } tuh_itf_info_t;
typedef struct {
uint8_t rhport;
uint8_t hub_addr;
uint8_t hub_port;
uint8_t speed;
} tuh_bus_info_t;
// ConfigID for tuh_configure() // ConfigID for tuh_configure()
enum { enum {
TUH_CFGID_INVALID = 0, TUH_CFGID_INVALID = 0,
@@ -177,6 +184,8 @@ extern void hcd_int_handler(uint8_t rhport, bool in_isr);
#define _tuh_int_handler_arg0() TU_VERIFY_STATIC(false, "tuh_int_handler() must have 1 or 2 arguments") #define _tuh_int_handler_arg0() TU_VERIFY_STATIC(false, "tuh_int_handler() must have 1 or 2 arguments")
#define _tuh_int_handler_arg1(_rhport) hcd_int_handler(_rhport, true) #define _tuh_int_handler_arg1(_rhport) hcd_int_handler(_rhport, true)
#define _tuh_int_handler_arg2(_rhport, _in_isr) hcd_int_handler(_rhport, _in_isr) #define _tuh_int_handler_arg2(_rhport, _in_isr) hcd_int_handler(_rhport, _in_isr)
// 1st argument is rhport (mandatory), 2nd argument in_isr (optional)
#define tuh_int_handler(...) TU_FUNC_OPTIONAL_ARG(_tuh_int_handler, __VA_ARGS__) #define tuh_int_handler(...) TU_FUNC_OPTIONAL_ARG(_tuh_int_handler, __VA_ARGS__)
// Check if roothub port is initialized and active as a host // Check if roothub port is initialized and active as a host
@@ -214,6 +223,9 @@ TU_ATTR_ALWAYS_INLINE static inline bool tuh_ready(uint8_t daddr) {
return tuh_mounted(daddr) && !tuh_suspended(daddr); return tuh_mounted(daddr) && !tuh_suspended(daddr);
} }
// Get bus information of device
bool tuh_bus_info_get(uint8_t daddr, tuh_bus_info_t* bus_info);
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Transfer API // Transfer API
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+

View File

@@ -35,6 +35,7 @@
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
#include "common/tusb_common.h" #include "common/tusb_common.h"
#include "host/hcd.h" #include "host/hcd.h"
#include "host/usbh.h"
#include "portable/ehci/ehci_api.h" #include "portable/ehci/ehci_api.h"
#include "ci_hs_type.h" #include "ci_hs_type.h"

View File

@@ -34,6 +34,7 @@
#include "osal/osal.h" #include "osal/osal.h"
#include "host/hcd.h" #include "host/hcd.h"
#include "host/usbh.h"
#include "ehci_api.h" #include "ehci_api.h"
#include "ehci.h" #include "ehci.h"
@@ -838,7 +839,7 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, tusb_desc_endpoint_t c
} }
tuh_bus_info_t bus_info; tuh_bus_info_t bus_info;
hcd_bus_info_get(dev_addr, &bus_info); tuh_bus_info_get(dev_addr, &bus_info);
uint8_t const xfer_type = ep_desc->bmAttributes.xfer; uint8_t const xfer_type = ep_desc->bmAttributes.xfer;
uint8_t const interval = ep_desc->bInterval; uint8_t const interval = ep_desc->bInterval;

View File

@@ -36,6 +36,7 @@ _Pragma("GCC diagnostic ignored \"-Waddress-of-packed-member\"");
#endif #endif
#include "host/hcd.h" #include "host/hcd.h"
#include "host/usbh.h"
#include "musb_type.h" #include "musb_type.h"
@@ -696,7 +697,7 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet
_hcd.pipe0.remaining = 0; _hcd.pipe0.remaining = 0;
tuh_bus_info_t bus_info; tuh_bus_info_t bus_info;
hcd_bus_info_get(dev_addr, &bus_info); tuh_bus_info_get(dev_addr, &bus_info);
switch (bus_info.speed) { switch (bus_info.speed) {
default: return false; default: return false;
case TUSB_SPEED_LOW: USB0->TYPE0 = USB_TYPE0_SPEED_LOW; break; case TUSB_SPEED_LOW: USB0->TYPE0 = USB_TYPE0_SPEED_LOW; break;
@@ -745,7 +746,7 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const
uint8_t pipe_type = 0; uint8_t pipe_type = 0;
tuh_bus_info_t bus_info; tuh_bus_info_t bus_info;
hcd_bus_info_get(dev_addr, &bus_info); tuh_bus_info_get(dev_addr, &bus_info);
switch (bus_info.speed) { switch (bus_info.speed) {
default: return false; default: return false;
case TUSB_SPEED_LOW: pipe_type |= USB_TXTYPE1_SPEED_LOW; break; case TUSB_SPEED_LOW: pipe_type |= USB_TXTYPE1_SPEED_LOW; break;

View File

@@ -36,6 +36,7 @@
#endif #endif
#include "host/hcd.h" #include "host/hcd.h"
#include "host/usbh.h"
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// MACRO TYPEDEF CONSTANT ENUM DECLARATION // MACRO TYPEDEF CONSTANT ENUM DECLARATION

View File

@@ -31,6 +31,7 @@
#include "chip.h" #include "chip.h"
#include "host/hcd.h" #include "host/hcd.h"
#include "host/usbh.h"
void hcd_int_enable(uint8_t rhport) void hcd_int_enable(uint8_t rhport)
{ {

View File

@@ -38,6 +38,7 @@
#include "osal/osal.h" #include "osal/osal.h"
#include "host/hcd.h" #include "host/hcd.h"
#include "host/usbh.h"
#include "ohci.h" #include "ohci.h"
// TODO remove // TODO remove
@@ -329,7 +330,7 @@ static void ed_init(ohci_ed_t *p_ed, uint8_t dev_addr, uint16_t ep_size, uint8_t
} }
tuh_bus_info_t bus_info; tuh_bus_info_t bus_info;
hcd_bus_info_get(dev_addr, &bus_info); tuh_bus_info_get(dev_addr, &bus_info);
p_ed->dev_addr = dev_addr; p_ed->dev_addr = dev_addr;
p_ed->ep_number = ep_addr & 0x0F; p_ed->ep_number = ep_addr & 0x0F;

View File

@@ -115,7 +115,7 @@ void hcd_int_disable(uint8_t rhport) {
bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const *desc_ep) { bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const *desc_ep) {
tuh_bus_info_t bus_info; tuh_bus_info_t bus_info;
hcd_bus_info_get(dev_addr, &bus_info); tuh_bus_info_get(dev_addr, &bus_info);
bool const need_pre = (bus_info.hub_addr && bus_info.speed == TUSB_SPEED_LOW); bool const need_pre = (bus_info.hub_addr && bus_info.speed == TUSB_SPEED_LOW);
uint8_t const pio_rhport = RHPORT_PIO(rhport); uint8_t const pio_rhport = RHPORT_PIO(rhport);

View File

@@ -30,6 +30,7 @@
#if CFG_TUH_ENABLED && defined(TUP_USBIP_RUSB2) #if CFG_TUH_ENABLED && defined(TUP_USBIP_RUSB2)
#include "host/hcd.h" #include "host/hcd.h"
#include "host/usbh.h"
#include "rusb2_type.h" #include "rusb2_type.h"
#if TU_CHECK_MCU(OPT_MCU_RX63X, OPT_MCU_RX65X, OPT_MCU_RX72N) #if TU_CHECK_MCU(OPT_MCU_RX63X, OPT_MCU_RX65X, OPT_MCU_RX72N)
@@ -663,7 +664,7 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const
if (0 == epn) { if (0 == epn) {
rusb->DCPCTR = RUSB2_PIPE_CTR_PID_NAK; rusb->DCPCTR = RUSB2_PIPE_CTR_PID_NAK;
tuh_bus_info_t bus_info; tuh_bus_info_t bus_info;
hcd_bus_info_get(dev_addr, &bus_info); tuh_bus_info_get(dev_addr, &bus_info);
uint16_t volatile *devadd = (uint16_t volatile *)(uintptr_t) &rusb->DEVADD[0]; uint16_t volatile *devadd = (uint16_t volatile *)(uintptr_t) &rusb->DEVADD[0];
devadd += dev_addr; devadd += dev_addr;
while (rusb->DCPCTR_b.PBUSY) {} while (rusb->DCPCTR_b.PBUSY) {}

View File

@@ -36,6 +36,7 @@
#if CFG_TUH_ENABLED #if CFG_TUH_ENABLED
#include "host/hcd.h" #include "host/hcd.h"
#include "host/usbh.h"
#endif #endif
#include "dwc2_common.h" #include "dwc2_common.h"

View File

@@ -36,6 +36,7 @@
#define DWC2_DEBUG 2 #define DWC2_DEBUG 2
#include "host/hcd.h" #include "host/hcd.h"
#include "host/usbh.h"
#include "dwc2_common.h" #include "dwc2_common.h"
// Max number of endpoints application can open, can be larger than DWC2_CHANNEL_COUNT_MAX // Max number of endpoints application can open, can be larger than DWC2_CHANNEL_COUNT_MAX
@@ -476,7 +477,7 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, const tusb_desc_endpoint_t*
const tusb_speed_t rh_speed = hprt_speed_get(dwc2); const tusb_speed_t rh_speed = hprt_speed_get(dwc2);
tuh_bus_info_t bus_info; tuh_bus_info_t bus_info;
hcd_bus_info_get(dev_addr, &bus_info); tuh_bus_info_get(dev_addr, &bus_info);
// find a free endpoint // find a free endpoint
const uint8_t ep_id = edpt_alloc(); const uint8_t ep_id = edpt_alloc();

View File

@@ -29,6 +29,7 @@
#if CFG_TUH_ENABLED && CFG_TUSB_MCU == OPT_MCU_NONE #if CFG_TUH_ENABLED && CFG_TUSB_MCU == OPT_MCU_NONE
#include "host/hcd.h" #include "host/hcd.h"
#include "host/usbh.h"
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
// Controller API // Controller API