summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhathach <[email protected]>2022-03-19 00:43:31 +0700
committerhathach <[email protected]>2022-03-19 00:43:31 +0700
commit4795cca04ac60d58fbc78d554cd7af7039cd310a (patch)
treecd2ebf85439a5ab1634a3a72392ed8da8b8db119 /src
parentba1185bf28331da718cca38e6598361889fce54d (diff)
add parse config descriptor to example
move usbh_edpt_open() to public API, remove rhport from its signature
Diffstat (limited to 'src')
-rw-r--r--src/class/cdc/cdc_host.c5
-rw-r--r--src/class/hid/hid.h2
-rw-r--r--src/class/hid/hid_host.c3
-rw-r--r--src/class/msc/msc_host.c3
-rw-r--r--src/host/hub.c4
-rw-r--r--src/host/usbh.c11
-rw-r--r--src/host/usbh.h14
-rw-r--r--src/host/usbh_classdriver.h3
-rw-r--r--src/portable/ehci/ehci.c25
-rw-r--r--src/tusb.h2
10 files changed, 51 insertions, 21 deletions
diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c
index f946974e8..82cf911cf 100644
--- a/src/class/cdc/cdc_host.c
+++ b/src/class/cdc/cdc_host.c
@@ -161,6 +161,7 @@ void cdch_init(void)
bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t max_len)
{
+ (void) rhport;
(void) max_len;
// Only support ACM subclass
@@ -196,7 +197,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
// notification endpoint
tusb_desc_endpoint_t const * desc_ep = (tusb_desc_endpoint_t const *) p_desc;
- TU_ASSERT( usbh_edpt_open(rhport, dev_addr, desc_ep) );
+ TU_ASSERT( usbh_edpt_open(dev_addr, desc_ep) );
p_cdc->ep_notif = desc_ep->bEndpointAddress;
drv_len += tu_desc_len(p_desc);
@@ -217,7 +218,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
tusb_desc_endpoint_t const *desc_ep = (tusb_desc_endpoint_t const *) p_desc;
TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType && TUSB_XFER_BULK == desc_ep->bmAttributes.xfer);
- TU_ASSERT(usbh_edpt_open(rhport, dev_addr, desc_ep));
+ TU_ASSERT(usbh_edpt_open(dev_addr, desc_ep));
if ( tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN )
{
diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h
index 940454bd9..44a464be1 100644
--- a/src/class/hid/hid.h
+++ b/src/class/hid/hid.h
@@ -43,7 +43,7 @@
/** \defgroup ClassDriver_HID_Common Common Definitions
* @{ */
- /// USB HID Descriptor
+/// USB HID Descriptor
typedef struct TU_ATTR_PACKED
{
uint8_t bLength; /**< Numeric expression that is the total size of the HID descriptor */
diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c
index 2bdd1db79..2280e87b4 100644
--- a/src/class/hid/hid_host.c
+++ b/src/class/hid/hid_host.c
@@ -324,6 +324,7 @@ void hidh_close(uint8_t dev_addr)
bool hidh_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *desc_itf, uint16_t max_len)
{
+ (void) rhport;
(void) max_len;
TU_VERIFY(TUSB_CLASS_HID == desc_itf->bInterfaceClass);
@@ -355,7 +356,7 @@ bool hidh_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *de
for(int i = 0; i < desc_itf->bNumEndpoints; i++)
{
TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType);
- TU_ASSERT( usbh_edpt_open(rhport, dev_addr, desc_ep) );
+ TU_ASSERT( usbh_edpt_open(dev_addr, desc_ep) );
if(tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN)
{
diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c
index 06af781f5..4033cc429 100644
--- a/src/class/msc/msc_host.c
+++ b/src/class/msc/msc_host.c
@@ -365,6 +365,7 @@ static bool config_read_capacity_complete(uint8_t dev_addr, msc_cbw_t const* cbw
bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *desc_itf, uint16_t max_len)
{
+ (void) rhport;
TU_VERIFY (MSC_SUBCLASS_SCSI == desc_itf->bInterfaceSubClass &&
MSC_PROTOCOL_BOT == desc_itf->bInterfaceProtocol);
@@ -378,7 +379,7 @@ bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *de
for(uint32_t i=0; i<2; i++)
{
TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType && TUSB_XFER_BULK == ep_desc->bmAttributes.xfer);
- TU_ASSERT(usbh_edpt_open(rhport, dev_addr, ep_desc));
+ TU_ASSERT(usbh_edpt_open(dev_addr, ep_desc));
if ( tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN )
{
diff --git a/src/host/hub.c b/src/host/hub.c
index da4f6fe3a..b4d369aca 100644
--- a/src/host/hub.c
+++ b/src/host/hub.c
@@ -183,6 +183,8 @@ void hub_init(void)
bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t max_len)
{
+ (void) rhport;
+
TU_VERIFY(TUSB_CLASS_HUB == itf_desc->bInterfaceClass &&
0 == itf_desc->bInterfaceSubClass);
@@ -199,7 +201,7 @@ bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf
TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType &&
TUSB_XFER_INTERRUPT == desc_ep->bmAttributes.xfer, 0);
- TU_ASSERT(usbh_edpt_open(rhport, dev_addr, desc_ep));
+ TU_ASSERT(usbh_edpt_open(dev_addr, desc_ep));
hub_interface_t* p_hub = get_itf(dev_addr);
diff --git a/src/host/usbh.c b/src/host/usbh.c
index 497badfde..466e5decd 100644
--- a/src/host/usbh.c
+++ b/src/host/usbh.c
@@ -806,10 +806,11 @@ static bool usbh_edpt_control_open(uint8_t dev_addr, uint8_t max_packet_size)
return hcd_edpt_open(usbh_get_rhport(dev_addr), dev_addr, &ep0_desc);
}
-bool usbh_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * desc_ep)
+bool usbh_edpt_open(uint8_t dev_addr, tusb_desc_endpoint_t const * desc_ep)
{
TU_ASSERT( tu_edpt_validate(desc_ep, tuh_speed_get(dev_addr)) );
- return hcd_edpt_open(rhport, dev_addr, desc_ep);
+
+ return hcd_edpt_open(usbh_get_rhport(dev_addr), dev_addr, desc_ep);
}
bool usbh_edpt_busy(uint8_t dev_addr, uint8_t ep_addr)
@@ -1189,7 +1190,7 @@ enum {
};
static bool enum_request_set_addr(void);
-static bool parse_configuration_descriptor (uint8_t dev_addr, tusb_desc_configuration_t const* desc_cfg);
+static bool _parse_configuration_descriptor (uint8_t dev_addr, tusb_desc_configuration_t const* desc_cfg);
static void enum_full_complete(void);
// process device enumeration
@@ -1350,7 +1351,7 @@ static void process_enumeration(tuh_xfer_t* xfer)
case ENUM_SET_CONFIG:
// Parse configuration & set up drivers
// Driver open aren't allowed to make any usb transfer yet
- TU_ASSERT( parse_configuration_descriptor(daddr, (tusb_desc_configuration_t*) _usbh_ctrl_buf), );
+ TU_ASSERT( _parse_configuration_descriptor(daddr, (tusb_desc_configuration_t*) _usbh_ctrl_buf), );
TU_ASSERT( tuh_configuration_set(daddr, CONFIG_NUM, process_enumeration, ENUM_CONFIG_DRIVER), );
break;
@@ -1496,7 +1497,7 @@ static bool enum_request_set_addr(void)
return true;
}
-static bool parse_configuration_descriptor(uint8_t dev_addr, tusb_desc_configuration_t const* desc_cfg)
+static bool _parse_configuration_descriptor(uint8_t dev_addr, tusb_desc_configuration_t const* desc_cfg)
{
usbh_device_t* dev = get_device(dev_addr);
diff --git a/src/host/usbh.h b/src/host/usbh.h
index 772c4cfd6..a2df0153e 100644
--- a/src/host/usbh.h
+++ b/src/host/usbh.h
@@ -44,8 +44,10 @@ typedef struct tuh_xfer_s tuh_xfer_t;
typedef void (*tuh_xfer_cb_t)(tuh_xfer_t* xfer);
-// Note: layout and order of this will be changed in near future
+// Note1: layout and order of this will be changed in near future
// it is advised to initialize it using member name
+// Note2: not all field is available/meaningful in callback, some info is not saved by
+// usbh to save SRAM
struct tuh_xfer_s
{
uint8_t daddr;
@@ -124,14 +126,18 @@ static inline bool tuh_ready(uint8_t daddr)
//--------------------------------------------------------------------+
// Submit a control transfer
-// Note: blocking if complete callback is NULL, in this case xfer contents will be updated to reflect the result
+// - async: complete callback invoked when finished.
+// - sync : blocking if complete callback is NULL.
bool tuh_control_xfer(tuh_xfer_t* xfer);
// Submit a bulk/interrupt transfer
-// xfer memory must exist until transfer is complete.
-// Note: blocking if complete callback is NULL.
+// - async: complete callback invoked when finished.
+// - sync : blocking if complete callback is NULL.
bool tuh_edpt_xfer(tuh_xfer_t* xfer);
+// Open an endpoint
+bool usbh_edpt_open(uint8_t dev_addr, tusb_desc_endpoint_t const * desc_ep);
+
// Set Configuration (control transfer)
// config_num = 0 will un-configure device. Note: config_num = config_descriptor_index + 1
// true on success, false if there is on-going control transfer or incorrect parameters
diff --git a/src/host/usbh_classdriver.h b/src/host/usbh_classdriver.h
index 30e97535d..c156afea0 100644
--- a/src/host/usbh_classdriver.h
+++ b/src/host/usbh_classdriver.h
@@ -63,9 +63,6 @@ void usbh_int_set(bool enabled);
// USBH Endpoint API
//--------------------------------------------------------------------+
-// Open an endpoint
-bool usbh_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * desc_ep);
-
// Submit a usb transfer with callback support, require CFG_TUH_API_EDPT_XFER
bool usbh_edpt_xfer_with_callback(uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes,
tuh_xfer_cb_t complete_cb, uintptr_t user_data);
diff --git a/src/portable/ehci/ehci.c b/src/portable/ehci/ehci.c
index 8d420f26a..665f2380b 100644
--- a/src/portable/ehci/ehci.c
+++ b/src/portable/ehci/ehci.c
@@ -656,6 +656,26 @@ static void xfer_error_isr(uint8_t hostid)
}
}
+#if CFG_TUSB_DEBUG >= EHCI_DBG
+
+static inline void print_portsc(ehci_registers_t* regs)
+{
+ TU_LOG_HEX(EHCI_DBG, regs->portsc);
+ TU_LOG(EHCI_DBG, " Current Connect Status: %u\r\n", regs->portsc_bm.current_connect_status);
+ TU_LOG(EHCI_DBG, " Connect Status Change : %u\r\n", regs->portsc_bm.connect_status_change);
+ TU_LOG(EHCI_DBG, " Port Enabled : %u\r\n", regs->portsc_bm.port_enabled);
+ TU_LOG(EHCI_DBG, " Port Enabled Change : %u\r\n", regs->portsc_bm.port_enable_change);
+
+ TU_LOG(EHCI_DBG, " Port Reset : %u\r\n", regs->portsc_bm.port_reset);
+ TU_LOG(EHCI_DBG, " Port Power : %u\r\n", regs->portsc_bm.port_power);
+}
+
+#else
+
+#define print_portsc(_reg)
+
+#endif
+
//------------- Host Controller Driver's Interrupt Handler -------------//
void hcd_int_handler(uint8_t rhport)
{
@@ -675,9 +695,8 @@ void hcd_int_handler(uint8_t rhport)
if (int_status & EHCI_INT_MASK_PORT_CHANGE)
{
- uint32_t port_status = regs->portsc & EHCI_PORTSC_MASK_ALL;
-
- TU_LOG_HEX(EHCI_DBG, regs->portsc);
+ uint32_t const port_status = regs->portsc & EHCI_PORTSC_MASK_ALL;
+ print_portsc(regs);
if (regs->portsc_bm.connect_status_change)
{
diff --git a/src/tusb.h b/src/tusb.h
index 222855fcb..b776d7d01 100644
--- a/src/tusb.h
+++ b/src/tusb.h
@@ -38,6 +38,8 @@
#include "osal/osal.h"
#include "common/tusb_fifo.h"
+#include "class/hid/hid.h"
+
//------------- HOST -------------//
#if CFG_TUH_ENABLED
#include "host/usbh.h"