rename hcd_devtree_info_t to tuh_bus_info_t, hcd_devtree_get_info to hcd_bus_info_get
streamline bus info to usbh_devies, also replace dev0 (renamed to dev0_bus)
This commit is contained in:
14
.idea/debugServers/esp32s2.xml
generated
Normal file
14
.idea/debugServers/esp32s2.xml
generated
Normal file
@@ -0,0 +1,14 @@
|
||||
<component name="DebugServers">
|
||||
<generic-debug-target name="esp32s2" uniqueID="254eff00-2acf-48fe-b255-1d0c0c9c4a7a">
|
||||
<debugger version="1">
|
||||
<debugger kind="GDB">$USER_HOME$/.espressif/tools/xtensa-esp-elf-gdb/14.2_20240403/xtensa-esp-elf-gdb/bin/xtensa-esp32s2-elf-gdb</debugger>
|
||||
<env />
|
||||
</debugger>
|
||||
<gdbserver exe="$USER_HOME$/.espressif/tools/openocd-esp32/v0.12.0-esp32-20241016/openocd-esp32/bin/openocd" args="-f board/esp32s2-kaluga-1.cfg">
|
||||
<env />
|
||||
</gdbserver>
|
||||
<console port="4444" />
|
||||
<target download-type="NONE" reset-command="monitor reset halt" reset-before="false" />
|
||||
<connection extended-remote="false" remote-string="tcp::3333" warmup-ms="500" />
|
||||
</generic-debug-target>
|
||||
</component>
|
2
.idea/debugServers/rp2350.xml
generated
2
.idea/debugServers/rp2350.xml
generated
@@ -1,5 +1,5 @@
|
||||
<component name="DebugServers">
|
||||
<generic-debug-target name="rp2350" uniqueID="939fdf16-9c30-4261-8435-3e8df7fd5800" selected="true">
|
||||
<generic-debug-target name="rp2350" uniqueID="939fdf16-9c30-4261-8435-3e8df7fd5800">
|
||||
<debugger version="1">
|
||||
<debugger kind="GDB" isBundled="true" />
|
||||
<env />
|
||||
|
13
.idea/debugServers/stm32f769.xml
generated
Normal file
13
.idea/debugServers/stm32f769.xml
generated
Normal file
@@ -0,0 +1,13 @@
|
||||
<component name="DebugServers">
|
||||
<jlink-debug-target name="stm32f769" uniqueID="7a47302f-f7e5-434b-b20b-78e95318dd0c" selected="true">
|
||||
<debugger version="1">
|
||||
<debugger kind="GDB" isBundled="true" />
|
||||
<env />
|
||||
</debugger>
|
||||
<gdbserver exe="/usr/bin/JLinkGDBServerCLExe" />
|
||||
<console port="19021" type="RTT" />
|
||||
<target device="STM32F769NI" reset-before="false" frequency="16000" />
|
||||
<connection extended-remote="false" port="4444" warmup-ms="500" />
|
||||
<swo />
|
||||
</jlink-debug-target>
|
||||
</component>
|
13
.idea/debugServers/stm32h563.xml
generated
Normal file
13
.idea/debugServers/stm32h563.xml
generated
Normal file
@@ -0,0 +1,13 @@
|
||||
<component name="DebugServers">
|
||||
<jlink-debug-target name="stm32h563" uniqueID="a3e9293d-113b-48b3-b83d-dd4249984abe">
|
||||
<debugger version="1">
|
||||
<debugger kind="GDB" isBundled="true" />
|
||||
<env />
|
||||
</debugger>
|
||||
<gdbserver exe="/usr/bin/JLinkGDBServerCLExe" />
|
||||
<console port="2334" type="RTT" />
|
||||
<target device="STM32H562ZI" reset-before="false" frequency="16000" />
|
||||
<connection extended-remote="false" port="4444" warmup-ms="500" />
|
||||
<swo />
|
||||
</jlink-debug-target>
|
||||
</component>
|
13
.idea/debugServers/stm32h743.xml
generated
Normal file
13
.idea/debugServers/stm32h743.xml
generated
Normal file
@@ -0,0 +1,13 @@
|
||||
<component name="DebugServers">
|
||||
<jlink-debug-target name="stm32h743" uniqueID="6d6a3ed6-f66d-4f6a-9e70-6aafe5c971d0">
|
||||
<debugger version="1">
|
||||
<debugger kind="GDB" isBundled="true" />
|
||||
<env />
|
||||
</debugger>
|
||||
<gdbserver exe="/usr/bin/JLinkGDBServerCLExe" />
|
||||
<console port="2334" type="RTT" />
|
||||
<target device="STM32H743XI" reset-before="false" frequency="16000" />
|
||||
<connection extended-remote="false" port="4444" warmup-ms="500" />
|
||||
<swo />
|
||||
</jlink-debug-target>
|
||||
</component>
|
@@ -30,13 +30,11 @@
|
||||
//--------------------------------------------------------------------+
|
||||
static scsi_inquiry_resp_t inquiry_resp;
|
||||
|
||||
bool inquiry_complete_cb(uint8_t dev_addr, tuh_msc_complete_data_t const * cb_data)
|
||||
{
|
||||
static bool inquiry_complete_cb(uint8_t dev_addr, tuh_msc_complete_data_t const * cb_data) {
|
||||
msc_cbw_t const* cbw = cb_data->cbw;
|
||||
msc_csw_t const* csw = cb_data->csw;
|
||||
|
||||
if (csw->status != 0)
|
||||
{
|
||||
if (csw->status != 0) {
|
||||
printf("Inquiry failed\r\n");
|
||||
return false;
|
||||
}
|
||||
@@ -55,16 +53,14 @@ bool inquiry_complete_cb(uint8_t dev_addr, tuh_msc_complete_data_t const * cb_da
|
||||
}
|
||||
|
||||
//------------- IMPLEMENTATION -------------//
|
||||
void tuh_msc_mount_cb(uint8_t dev_addr)
|
||||
{
|
||||
void tuh_msc_mount_cb(uint8_t dev_addr) {
|
||||
printf("A MassStorage device is mounted\r\n");
|
||||
|
||||
uint8_t const lun = 0;
|
||||
tuh_msc_inquiry(dev_addr, lun, &inquiry_resp, inquiry_complete_cb, 0);
|
||||
}
|
||||
|
||||
void tuh_msc_umount_cb(uint8_t dev_addr)
|
||||
{
|
||||
void tuh_msc_umount_cb(uint8_t dev_addr) {
|
||||
(void) dev_addr;
|
||||
printf("A MassStorage device is unmounted\r\n");
|
||||
}
|
||||
|
@@ -95,7 +95,7 @@ typedef struct {
|
||||
uint8_t hub_addr;
|
||||
uint8_t hub_port;
|
||||
uint8_t speed;
|
||||
} hcd_devtree_info_t;
|
||||
} tuh_bus_info_t;
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Memory API
|
||||
@@ -186,12 +186,8 @@ bool hcd_edpt_clear_stall(uint8_t rhport, 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 -------------//
|
||||
// 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
|
||||
extern void hcd_event_handler(hcd_event_t const* event, bool in_isr);
|
||||
@@ -239,4 +235,4 @@ void hcd_event_xfer_complete(uint8_t dev_addr, uint8_t ep_addr, uint32_t xferred
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _TUSB_HCD_H_ */
|
||||
#endif
|
||||
|
125
src/host/usbh.c
125
src/host/usbh.c
@@ -92,19 +92,7 @@ TU_ATTR_WEAK bool hcd_dcache_clean_invalidate(const void* addr, uint32_t data_si
|
||||
// USBH-HCD common data structure
|
||||
//--------------------------------------------------------------------+
|
||||
typedef struct {
|
||||
// port
|
||||
uint8_t rhport;
|
||||
uint8_t hub_addr;
|
||||
uint8_t hub_port;
|
||||
uint8_t speed;
|
||||
} usbh_dev0_t;
|
||||
|
||||
typedef struct {
|
||||
// port, must be same layout as usbh_dev0_t
|
||||
uint8_t rhport;
|
||||
uint8_t hub_addr;
|
||||
uint8_t hub_port;
|
||||
uint8_t speed;
|
||||
tuh_bus_info_t bus_info;
|
||||
|
||||
// Device State
|
||||
struct TU_ATTR_PACKED {
|
||||
@@ -231,8 +219,8 @@ static usbh_class_driver_t const usbh_class_drivers[] = {
|
||||
enum { BUILTIN_DRIVER_COUNT = TU_ARRAY_SIZE(usbh_class_drivers) };
|
||||
|
||||
// Additional class drivers implemented by application
|
||||
tu_static usbh_class_driver_t const * _app_driver = NULL;
|
||||
tu_static uint8_t _app_driver_count = 0;
|
||||
static usbh_class_driver_t const * _app_driver = NULL;
|
||||
static uint8_t _app_driver_count = 0;
|
||||
|
||||
#define TOTAL_DRIVER_COUNT (_app_driver_count + BUILTIN_DRIVER_COUNT)
|
||||
|
||||
@@ -255,9 +243,6 @@ static inline usbh_class_driver_t const *get_driver(uint8_t drv_id) {
|
||||
// sum of end device + hub
|
||||
#define TOTAL_DEVICES (CFG_TUH_DEVICE_MAX + CFG_TUH_HUB)
|
||||
|
||||
// Device with address = 0 for enumeration
|
||||
static usbh_dev0_t _dev0;
|
||||
|
||||
// all devices excluding zero-address
|
||||
// hub address start from CFG_TUH_DEVICE_MAX+1
|
||||
// TODO: hub can has its own simpler struct to save memory
|
||||
@@ -299,6 +284,8 @@ CFG_TUH_MEM_SECTION static usbh_epbuf_t _usbh_epbuf;
|
||||
typedef struct {
|
||||
uint8_t controller_id; // controller ID
|
||||
uint8_t enumerating_daddr; // device address of the device being enumerated
|
||||
|
||||
tuh_bus_info_t dev0_bus; // bus info for dev0 in enumeration
|
||||
} usbh_data_t;
|
||||
|
||||
static usbh_data_t _usbh_data = {
|
||||
@@ -353,9 +340,10 @@ bool tuh_vid_pid_get(uint8_t dev_addr, uint16_t *vid, uint16_t *pid) {
|
||||
return true;
|
||||
}
|
||||
|
||||
tusb_speed_t tuh_speed_get(uint8_t dev_addr) {
|
||||
usbh_device_t *dev = get_device(dev_addr);
|
||||
return (tusb_speed_t) (dev ? get_device(dev_addr)->speed : _dev0.speed);
|
||||
tusb_speed_t tuh_speed_get(uint8_t daddr) {
|
||||
tuh_bus_info_t bus_info;
|
||||
hcd_bus_info_get(daddr, &bus_info);
|
||||
return bus_info.speed;
|
||||
}
|
||||
|
||||
bool tuh_rhport_is_active(uint8_t rhport) {
|
||||
@@ -423,9 +411,9 @@ bool tuh_rhport_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) {
|
||||
}
|
||||
|
||||
// Device
|
||||
tu_memclr(&_dev0, sizeof(_dev0));
|
||||
tu_memclr(_usbh_devices, sizeof(_usbh_devices));
|
||||
tu_memclr(&_ctrl_xfer, sizeof(_ctrl_xfer));
|
||||
tu_memclr(&_usbh_data, sizeof(_usbh_data));
|
||||
|
||||
_usbh_data.controller_id = TUSB_INDEX_INVALID_8;
|
||||
_usbh_data.enumerating_daddr = TUSB_INDEX_INVALID_8;
|
||||
@@ -530,8 +518,8 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr) {
|
||||
// due to the shared control buffer, we must fully complete enumerating one device first.
|
||||
// TODO better to have an separated queue for newly attached devices
|
||||
if (_usbh_data.enumerating_daddr != TUSB_INDEX_INVALID_8) {
|
||||
if (event.rhport == _dev0.rhport &&
|
||||
event.connection.hub_addr == _dev0.hub_addr && event.connection.hub_port == _dev0.hub_port) {
|
||||
if (event.rhport == _usbh_data.dev0_bus.rhport &&
|
||||
event.connection.hub_addr == _usbh_data.dev0_bus.hub_addr && event.connection.hub_port == _usbh_data.dev0_bus.hub_port) {
|
||||
// Some device can cause multiple duplicated attach events
|
||||
// drop current enumerating and start over for a proper port reset
|
||||
// abort/cancel current enumeration and start new one
|
||||
@@ -859,7 +847,7 @@ bool tuh_edpt_abort_xfer(uint8_t daddr, uint8_t ep_addr) {
|
||||
const uint8_t dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
if (epnum == 0) {
|
||||
// Also include dev0 for aborting enumerating
|
||||
// Also include dev0_bus for aborting enumerating
|
||||
const uint8_t rhport = usbh_get_rhport(daddr);
|
||||
|
||||
// control transfer: only 1 control at a time, check if we are aborting the current one
|
||||
@@ -871,7 +859,7 @@ bool tuh_edpt_abort_xfer(uint8_t daddr, uint8_t ep_addr) {
|
||||
TU_VERIFY(dev);
|
||||
|
||||
TU_VERIFY(dev->ep_status[epnum][dir].busy); // non-control skip if not busy
|
||||
hcd_edpt_abort_xfer(dev->rhport, daddr, ep_addr);
|
||||
hcd_edpt_abort_xfer(dev->bus_info.rhport, daddr, ep_addr);
|
||||
|
||||
// mark as ready and release endpoint if transfer is aborted
|
||||
dev->ep_status[epnum][dir].busy = false;
|
||||
@@ -885,9 +873,10 @@ bool tuh_edpt_abort_xfer(uint8_t daddr, uint8_t ep_addr) {
|
||||
// USBH API For Class Driver
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
uint8_t usbh_get_rhport(uint8_t dev_addr) {
|
||||
usbh_device_t *dev = get_device(dev_addr);
|
||||
return dev ? dev->rhport : _dev0.rhport;
|
||||
uint8_t usbh_get_rhport(uint8_t daddr) {
|
||||
tuh_bus_info_t bus_info;
|
||||
hcd_bus_info_get(daddr, &bus_info);
|
||||
return bus_info.rhport;
|
||||
}
|
||||
|
||||
uint8_t *usbh_get_enum_buf(void) {
|
||||
@@ -972,7 +961,7 @@ bool usbh_edpt_xfer_with_callback(uint8_t dev_addr, uint8_t ep_addr, uint8_t* bu
|
||||
dev->ep_callback[epnum][dir].user_data = user_data;
|
||||
#endif
|
||||
|
||||
if (hcd_edpt_xfer(dev->rhport, dev_addr, ep_addr, buffer, total_bytes)) {
|
||||
if (hcd_edpt_xfer(dev->bus_info.rhport, dev_addr, ep_addr, buffer, total_bytes)) {
|
||||
TU_LOG_USBH("OK\r\n");
|
||||
return true;
|
||||
} else {
|
||||
@@ -1024,19 +1013,14 @@ bool usbh_edpt_busy(uint8_t dev_addr, uint8_t ep_addr) {
|
||||
// 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);
|
||||
bool hcd_bus_info_get(uint8_t daddr, tuh_bus_info_t* bus_info) {
|
||||
usbh_device_t const* dev = get_device(daddr);
|
||||
if (dev) {
|
||||
devtree_info->rhport = dev->rhport;
|
||||
devtree_info->hub_addr = dev->hub_addr;
|
||||
devtree_info->hub_port = dev->hub_port;
|
||||
devtree_info->speed = dev->speed;
|
||||
*bus_info = dev->bus_info;
|
||||
} else {
|
||||
devtree_info->rhport = _dev0.rhport;
|
||||
devtree_info->hub_addr = _dev0.hub_addr;
|
||||
devtree_info->hub_port = _dev0.hub_port;
|
||||
devtree_info->speed = _dev0.speed;
|
||||
*bus_info = _usbh_data.dev0_bus;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
TU_ATTR_FAST_FUNC void hcd_event_handler(hcd_event_t const* event, bool in_isr) {
|
||||
@@ -1269,10 +1253,10 @@ TU_ATTR_ALWAYS_INLINE static inline bool is_hub_addr(uint8_t daddr) {
|
||||
|
||||
// a device unplugged from rhport:hub_addr:hub_port
|
||||
static void process_removing_device(uint8_t rhport, uint8_t hub_addr, uint8_t hub_port) {
|
||||
// dev0 is unplugged
|
||||
if ((_usbh_data.enumerating_daddr == 0) && (rhport == _dev0.rhport) &&
|
||||
(hub_addr == _dev0.hub_addr) && (hub_port == _dev0.hub_port)) {
|
||||
hcd_device_close(_dev0.rhport, 0);
|
||||
// dev0_bus is unplugged
|
||||
if ((_usbh_data.enumerating_daddr == 0) && (rhport == _usbh_data.dev0_bus.rhport) &&
|
||||
(hub_addr == _usbh_data.dev0_bus.hub_addr) && (hub_port == _usbh_data.dev0_bus.hub_port)) {
|
||||
hcd_device_close(_usbh_data.dev0_bus.rhport, 0);
|
||||
if (_ctrl_xfer.daddr == 0) {
|
||||
_control_set_xfer_stage(CONTROL_STAGE_IDLE);
|
||||
}
|
||||
@@ -1288,9 +1272,9 @@ static void process_removing_device(uint8_t rhport, uint8_t hub_addr, uint8_t hu
|
||||
uint8_t const daddr = dev_id + 1;
|
||||
|
||||
// hub_addr = 0 means roothub, hub_port = 0 means all devices of downstream hub
|
||||
if (dev->rhport == rhport && dev->connected &&
|
||||
(hub_addr == 0 || dev->hub_addr == hub_addr) &&
|
||||
(hub_port == 0 || dev->hub_port == hub_port)) {
|
||||
if (dev->bus_info.rhport == rhport && dev->connected &&
|
||||
(hub_addr == 0 || dev->bus_info.hub_addr == hub_addr) &&
|
||||
(hub_port == 0 || dev->bus_info.hub_port == hub_port)) {
|
||||
TU_LOG_USBH("[%u:%u:%u] unplugged address = %u\r\n", rhport, hub_addr, hub_port, daddr);
|
||||
|
||||
if (is_hub_addr(daddr)) {
|
||||
@@ -1439,12 +1423,12 @@ static void process_enumeration(tuh_xfer_t* xfer) {
|
||||
return;
|
||||
}
|
||||
|
||||
_dev0.speed = (port_status.status.high_speed) ? TUSB_SPEED_HIGH :
|
||||
_usbh_data.dev0_bus.speed = (port_status.status.high_speed) ? TUSB_SPEED_HIGH :
|
||||
(port_status.status.low_speed) ? TUSB_SPEED_LOW : TUSB_SPEED_FULL;
|
||||
|
||||
// Acknowledge Port Reset Change
|
||||
if (port_status.change.reset) {
|
||||
hub_port_clear_reset_change(_dev0.hub_addr, _dev0.hub_port,
|
||||
hub_port_clear_reset_change(_usbh_data.dev0_bus.hub_addr, _usbh_data.dev0_bus.hub_port,
|
||||
process_enumeration, ENUM_ADDR0_DEVICE_DESC);
|
||||
}
|
||||
break;
|
||||
@@ -1452,7 +1436,7 @@ static void process_enumeration(tuh_xfer_t* xfer) {
|
||||
|
||||
case ENUM_HUB_GET_STATUS_2:
|
||||
tusb_time_delay_ms_api(ENUM_RESET_DELAY_MS);
|
||||
TU_ASSERT(hub_port_get_status(_dev0.hub_addr, _dev0.hub_port, _usbh_epbuf.ctrl,
|
||||
TU_ASSERT(hub_port_get_status(_usbh_data.dev0_bus.hub_addr, _usbh_data.dev0_bus.hub_port, _usbh_epbuf.ctrl,
|
||||
process_enumeration, ENUM_HUB_CLEAR_RESET_2),);
|
||||
break;
|
||||
|
||||
@@ -1462,7 +1446,7 @@ static void process_enumeration(tuh_xfer_t* xfer) {
|
||||
|
||||
// Acknowledge Port Reset Change if Reset Successful
|
||||
if (port_status.change.reset) {
|
||||
TU_ASSERT(hub_port_clear_reset_change(_dev0.hub_addr, _dev0.hub_port,
|
||||
TU_ASSERT(hub_port_clear_reset_change(_usbh_data.dev0_bus.hub_addr, _usbh_data.dev0_bus.hub_port,
|
||||
process_enumeration, ENUM_SET_ADDR),);
|
||||
}
|
||||
break;
|
||||
@@ -1495,7 +1479,7 @@ static void process_enumeration(tuh_xfer_t* xfer) {
|
||||
new_dev->addressed = 1;
|
||||
_usbh_data.enumerating_daddr = new_addr;
|
||||
|
||||
hcd_device_close(_dev0.rhport, 0); // close dev0
|
||||
hcd_device_close(_usbh_data.dev0_bus.rhport, 0); // close dev0_bus
|
||||
|
||||
TU_ASSERT(usbh_edpt_control_open(new_addr, new_dev->ep0_size),); // open new control endpoint
|
||||
|
||||
@@ -1667,38 +1651,38 @@ static void process_enumeration(tuh_xfer_t* xfer) {
|
||||
}
|
||||
|
||||
static bool enum_new_device(hcd_event_t* event) {
|
||||
_dev0.rhport = event->rhport;
|
||||
_dev0.hub_addr = event->connection.hub_addr;
|
||||
_dev0.hub_port = event->connection.hub_port;
|
||||
_usbh_data.dev0_bus.rhport = event->rhport;
|
||||
_usbh_data.dev0_bus.hub_addr = event->connection.hub_addr;
|
||||
_usbh_data.dev0_bus.hub_port = event->connection.hub_port;
|
||||
|
||||
if (_dev0.hub_addr == 0) {
|
||||
if (_usbh_data.dev0_bus.hub_addr == 0) {
|
||||
// connected directly to roothub
|
||||
|
||||
// wait until device connection is stable TODO non blocking
|
||||
tusb_time_delay_ms_api(ENUM_DEBOUNCING_DELAY_MS);
|
||||
|
||||
// device unplugged while delaying
|
||||
if (!hcd_port_connect_status(_dev0.rhport)) {
|
||||
if (!hcd_port_connect_status(_usbh_data.dev0_bus.rhport)) {
|
||||
enum_full_complete();
|
||||
return true;
|
||||
}
|
||||
|
||||
hcd_port_reset(_dev0.rhport); // reset device
|
||||
hcd_port_reset(_usbh_data.dev0_bus.rhport); // reset device
|
||||
|
||||
// Since we are in middle of rhport reset, frame number is not available yet.
|
||||
// need to depend on tusb_time_millis_api()
|
||||
tusb_time_delay_ms_api(ENUM_RESET_DELAY_MS);
|
||||
|
||||
hcd_port_reset_end(_dev0.rhport);
|
||||
hcd_port_reset_end(_usbh_data.dev0_bus.rhport);
|
||||
|
||||
// device unplugged while delaying
|
||||
if (!hcd_port_connect_status(_dev0.rhport)) {
|
||||
if (!hcd_port_connect_status(_usbh_data.dev0_bus.rhport)) {
|
||||
enum_full_complete();
|
||||
return true;
|
||||
}
|
||||
|
||||
_dev0.speed = hcd_port_speed_get(_dev0.rhport);
|
||||
TU_LOG_USBH("%s Speed\r\n", tu_str_speed[_dev0.speed]);
|
||||
_usbh_data.dev0_bus.speed = hcd_port_speed_get(_usbh_data.dev0_bus.rhport);
|
||||
TU_LOG_USBH("%s Speed\r\n", tu_str_speed[_usbh_data.dev0.speed]);
|
||||
|
||||
// fake transfer to kick-off the enumeration process
|
||||
tuh_xfer_t xfer;
|
||||
@@ -1715,7 +1699,7 @@ static bool enum_new_device(hcd_event_t* event) {
|
||||
tusb_time_delay_ms_api(ENUM_DEBOUNCING_DELAY_MS);
|
||||
|
||||
// ENUM_HUB_GET_STATUS
|
||||
TU_ASSERT(hub_port_get_status(_dev0.hub_addr, _dev0.hub_port, _usbh_epbuf.ctrl,
|
||||
TU_ASSERT(hub_port_get_status(_usbh_data.dev0_bus.hub_addr, _usbh_data.dev0_bus.hub_port, _usbh_epbuf.ctrl,
|
||||
process_enumeration, ENUM_HUB_CLEAR_RESET_1));
|
||||
}
|
||||
#endif // hub
|
||||
@@ -1749,10 +1733,7 @@ static bool enum_request_set_addr(tusb_desc_device_t const* desc_device) {
|
||||
TU_LOG_USBH("Set Address = %d\r\n", new_addr);
|
||||
|
||||
usbh_device_t* new_dev = get_device(new_addr);
|
||||
new_dev->rhport = _dev0.rhport;
|
||||
new_dev->hub_addr = _dev0.hub_addr;
|
||||
new_dev->hub_port = _dev0.hub_port;
|
||||
new_dev->speed = _dev0.speed;
|
||||
new_dev->bus_info = _usbh_data.dev0_bus;
|
||||
new_dev->connected = 1;
|
||||
new_dev->ep0_size = desc_device->bMaxPacketSize0;
|
||||
|
||||
@@ -1768,7 +1749,7 @@ static bool enum_request_set_addr(tusb_desc_device_t const* desc_device) {
|
||||
.wLength = 0
|
||||
};
|
||||
tuh_xfer_t xfer = {
|
||||
.daddr = 0, // dev0
|
||||
.daddr = 0,
|
||||
.ep_addr = 0,
|
||||
.setup = &request,
|
||||
.buffer = NULL,
|
||||
@@ -1841,7 +1822,7 @@ static bool enum_parse_configuration_desc(uint8_t dev_addr, tusb_desc_configurat
|
||||
// Find driver for this interface
|
||||
for (uint8_t drv_id = 0; drv_id < TOTAL_DRIVER_COUNT; drv_id++) {
|
||||
usbh_class_driver_t const * driver = get_driver(drv_id);
|
||||
if (driver && driver->open(dev->rhport, dev_addr, desc_itf, drv_len) ) {
|
||||
if (driver && driver->open(dev->bus_info.rhport, dev_addr, desc_itf, drv_len) ) {
|
||||
// open successfully
|
||||
TU_LOG_USBH(" %s opened\r\n", driver->name);
|
||||
|
||||
@@ -1862,7 +1843,7 @@ static bool enum_parse_configuration_desc(uint8_t dev_addr, tusb_desc_configurat
|
||||
|
||||
if (drv_id == TOTAL_DRIVER_COUNT - 1) {
|
||||
TU_LOG_USBH("[%u:%u] Interface %u: class = %u subclass = %u protocol = %u is not supported\r\n",
|
||||
dev->rhport, dev_addr, desc_itf->bInterfaceNumber, desc_itf->bInterfaceClass, desc_itf->bInterfaceSubClass, desc_itf->bInterfaceProtocol);
|
||||
dev->bus_info.rhport, dev_addr, desc_itf->bInterfaceNumber, desc_itf->bInterfaceClass, desc_itf->bInterfaceSubClass, desc_itf->bInterfaceProtocol);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1909,8 +1890,8 @@ static void enum_full_complete(void) {
|
||||
_usbh_data.enumerating_daddr = TUSB_INDEX_INVALID_8;
|
||||
|
||||
#if CFG_TUH_HUB
|
||||
if (_dev0.hub_addr) {
|
||||
hub_edpt_status_xfer(_dev0.hub_addr); // get next hub status
|
||||
if (_usbh_data.dev0_bus.hub_addr != 0) {
|
||||
hub_edpt_status_xfer(_usbh_data.dev0_bus.hub_addr); // get next hub status
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@@ -63,7 +63,7 @@ usbh_class_driver_t const* usbh_app_driver_get_cb(uint8_t* driver_count) TU_ATTR
|
||||
// Call by class driver to tell USBH that it has complete the enumeration
|
||||
void usbh_driver_set_config_complete(uint8_t dev_addr, uint8_t itf_num);
|
||||
|
||||
uint8_t usbh_get_rhport(uint8_t dev_addr);
|
||||
uint8_t usbh_get_rhport(uint8_t daddr);
|
||||
|
||||
uint8_t* usbh_get_enum_buf(void);
|
||||
|
||||
|
@@ -837,8 +837,8 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, tusb_desc_endpoint_t c
|
||||
tu_memclr(p_qhd, sizeof(ehci_qhd_t));
|
||||
}
|
||||
|
||||
hcd_devtree_info_t devtree_info;
|
||||
hcd_devtree_get_info(dev_addr, &devtree_info);
|
||||
tuh_bus_info_t bus_info;
|
||||
hcd_bus_info_get(dev_addr, &bus_info);
|
||||
|
||||
uint8_t const xfer_type = ep_desc->bmAttributes.xfer;
|
||||
uint8_t const interval = ep_desc->bInterval;
|
||||
@@ -846,7 +846,7 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, tusb_desc_endpoint_t c
|
||||
p_qhd->dev_addr = dev_addr;
|
||||
p_qhd->fl_inactive_next_xact = 0;
|
||||
p_qhd->ep_number = tu_edpt_number(ep_desc->bEndpointAddress);
|
||||
p_qhd->ep_speed = devtree_info.speed;
|
||||
p_qhd->ep_speed = bus_info.speed;
|
||||
p_qhd->data_toggle_control= (xfer_type == TUSB_XFER_CONTROL) ? 1 : 0;
|
||||
p_qhd->head_list_flag = (dev_addr == 0) ? 1 : 0; // addr0's endpoint is the static async list head
|
||||
p_qhd->max_packet_size = tu_edpt_packet_size(ep_desc);
|
||||
@@ -887,8 +887,8 @@ static void qhd_init(ehci_qhd_t *p_qhd, uint8_t dev_addr, tusb_desc_endpoint_t c
|
||||
default: break;
|
||||
}
|
||||
|
||||
p_qhd->fl_hub_addr = devtree_info.hub_addr;
|
||||
p_qhd->fl_hub_port = devtree_info.hub_port;
|
||||
p_qhd->fl_hub_addr = bus_info.hub_addr;
|
||||
p_qhd->fl_hub_port = bus_info.hub_port;
|
||||
p_qhd->mult = 1; // TODO not use high bandwidth/park mode yet
|
||||
|
||||
//------------- HCD Management Data -------------//
|
||||
|
@@ -695,16 +695,16 @@ bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet
|
||||
_hcd.pipe0.length = 8;
|
||||
_hcd.pipe0.remaining = 0;
|
||||
|
||||
hcd_devtree_info_t devtree;
|
||||
hcd_devtree_get_info(dev_addr, &devtree);
|
||||
switch (devtree.speed) {
|
||||
tuh_bus_info_t bus_info;
|
||||
hcd_bus_info_get(dev_addr, &bus_info);
|
||||
switch (bus_info.speed) {
|
||||
default: return false;
|
||||
case TUSB_SPEED_LOW: USB0->TYPE0 = USB_TYPE0_SPEED_LOW; break;
|
||||
case TUSB_SPEED_FULL: USB0->TYPE0 = USB_TYPE0_SPEED_FULL; break;
|
||||
case TUSB_SPEED_HIGH: USB0->TYPE0 = USB_TYPE0_SPEED_HIGH; break;
|
||||
}
|
||||
USB0->TXHUBADDR0 = devtree.hub_addr;
|
||||
USB0->TXHUBPORT0 = devtree.hub_port;
|
||||
USB0->TXHUBADDR0 = bus_info.hub_addr;
|
||||
USB0->TXHUBPORT0 = bus_info.hub_port;
|
||||
USB0->TXFUNCADDR0 = dev_addr;
|
||||
USB0->CSRL0 = USB_CSRL0_TXRDY | USB_CSRL0_SETUP;
|
||||
return true;
|
||||
@@ -744,9 +744,9 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const
|
||||
pipe->remaining = 0;
|
||||
|
||||
uint8_t pipe_type = 0;
|
||||
hcd_devtree_info_t devtree;
|
||||
hcd_devtree_get_info(dev_addr, &devtree);
|
||||
switch (devtree.speed) {
|
||||
tuh_bus_info_t bus_info;
|
||||
hcd_bus_info_get(dev_addr, &bus_info);
|
||||
switch (bus_info.speed) {
|
||||
default: return false;
|
||||
case TUSB_SPEED_LOW: pipe_type |= USB_TXTYPE1_SPEED_LOW; break;
|
||||
case TUSB_SPEED_FULL: pipe_type |= USB_TXTYPE1_SPEED_FULL; break;
|
||||
@@ -763,8 +763,8 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const
|
||||
hw_endpoint_t volatile *regs = edpt_regs(pipenum - 1);
|
||||
if (dir_tx) {
|
||||
fadr->TXFUNCADDR = dev_addr;
|
||||
fadr->TXHUBADDR = devtree.hub_addr;
|
||||
fadr->TXHUBPORT = devtree.hub_port;
|
||||
fadr->TXHUBADDR = bus_info.hub_addr;
|
||||
fadr->TXHUBPORT = bus_info.hub_port;
|
||||
regs->TXMAXP = mps;
|
||||
regs->TXTYPE = pipe_type | epn;
|
||||
regs->TXINTERVAL = ep_desc->bInterval;
|
||||
@@ -775,8 +775,8 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const
|
||||
USB0->TXIE |= TU_BIT(pipenum);
|
||||
} else {
|
||||
fadr->RXFUNCADDR = dev_addr;
|
||||
fadr->RXHUBADDR = devtree.hub_addr;
|
||||
fadr->RXHUBPORT = devtree.hub_port;
|
||||
fadr->RXHUBADDR = bus_info.hub_addr;
|
||||
fadr->RXHUBPORT = bus_info.hub_port;
|
||||
regs->RXMAXP = mps;
|
||||
regs->RXTYPE = pipe_type | epn;
|
||||
regs->RXINTERVAL = ep_desc->bInterval;
|
||||
|
@@ -328,13 +328,13 @@ static void ed_init(ohci_ed_t *p_ed, uint8_t dev_addr, uint16_t ep_size, uint8_t
|
||||
tu_memclr(p_ed, sizeof(ohci_ed_t));
|
||||
}
|
||||
|
||||
hcd_devtree_info_t devtree_info;
|
||||
hcd_devtree_get_info(dev_addr, &devtree_info);
|
||||
tuh_bus_info_t bus_info;
|
||||
hcd_bus_info_get(dev_addr, &bus_info);
|
||||
|
||||
p_ed->dev_addr = dev_addr;
|
||||
p_ed->ep_number = ep_addr & 0x0F;
|
||||
p_ed->pid = (xfer_type == TUSB_XFER_CONTROL) ? PID_FROM_TD : (tu_edpt_dir(ep_addr) ? PID_IN : PID_OUT);
|
||||
p_ed->speed = devtree_info.speed;
|
||||
p_ed->speed = bus_info.speed;
|
||||
p_ed->is_iso = (xfer_type == TUSB_XFER_ISOCHRONOUS) ? 1 : 0;
|
||||
p_ed->max_packet_size = ep_size;
|
||||
|
||||
|
@@ -114,9 +114,9 @@ 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) {
|
||||
hcd_devtree_info_t dev_tree;
|
||||
hcd_devtree_get_info(dev_addr, &dev_tree);
|
||||
bool const need_pre = (dev_tree.hub_addr && dev_tree.speed == TUSB_SPEED_LOW);
|
||||
tuh_bus_info_t bus_info;
|
||||
hcd_bus_info_get(dev_addr, &bus_info);
|
||||
bool const need_pre = (bus_info.hub_addr && bus_info.speed == TUSB_SPEED_LOW);
|
||||
|
||||
uint8_t const pio_rhport = RHPORT_PIO(rhport);
|
||||
return pio_usb_host_endpoint_open(pio_rhport, dev_addr, (uint8_t const *) desc_ep, need_pre);
|
||||
|
@@ -662,13 +662,13 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const
|
||||
|
||||
if (0 == epn) {
|
||||
rusb->DCPCTR = RUSB2_PIPE_CTR_PID_NAK;
|
||||
hcd_devtree_info_t devtree;
|
||||
hcd_devtree_get_info(dev_addr, &devtree);
|
||||
tuh_bus_info_t bus_info;
|
||||
hcd_bus_info_get(dev_addr, &bus_info);
|
||||
uint16_t volatile *devadd = (uint16_t volatile *)(uintptr_t) &rusb->DEVADD[0];
|
||||
devadd += dev_addr;
|
||||
while (rusb->DCPCTR_b.PBUSY) {}
|
||||
rusb->DCPMAXP = (dev_addr << 12) | mps;
|
||||
*devadd = (TUSB_SPEED_FULL == devtree.speed) ? RUSB2_DEVADD_USBSPD_FS : RUSB2_DEVADD_USBSPD_LS;
|
||||
*devadd = (TUSB_SPEED_FULL == bus_info.speed) ? RUSB2_DEVADD_USBSPD_FS : RUSB2_DEVADD_USBSPD_LS;
|
||||
_hcd.ctl_mps[dev_addr] = mps;
|
||||
return true;
|
||||
}
|
||||
|
@@ -475,8 +475,8 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, const tusb_desc_endpoint_t*
|
||||
dwc2_regs_t* dwc2 = DWC2_REG(rhport);
|
||||
const tusb_speed_t rh_speed = hprt_speed_get(dwc2);
|
||||
|
||||
hcd_devtree_info_t devtree_info;
|
||||
hcd_devtree_get_info(dev_addr, &devtree_info);
|
||||
tuh_bus_info_t bus_info;
|
||||
hcd_bus_info_get(dev_addr, &bus_info);
|
||||
|
||||
// find a free endpoint
|
||||
const uint8_t ep_id = edpt_alloc();
|
||||
@@ -487,7 +487,7 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, const tusb_desc_endpoint_t*
|
||||
hcchar_bm->ep_size = tu_edpt_packet_size(desc_ep);
|
||||
hcchar_bm->ep_num = tu_edpt_number(desc_ep->bEndpointAddress);
|
||||
hcchar_bm->ep_dir = tu_edpt_dir(desc_ep->bEndpointAddress);
|
||||
hcchar_bm->low_speed_dev = (devtree_info.speed == TUSB_SPEED_LOW) ? 1 : 0;
|
||||
hcchar_bm->low_speed_dev = (bus_info.speed == TUSB_SPEED_LOW) ? 1 : 0;
|
||||
hcchar_bm->ep_type = desc_ep->bmAttributes.xfer; // ep_type matches TUSB_XFER_*
|
||||
hcchar_bm->err_multi_count = 0;
|
||||
hcchar_bm->dev_addr = dev_addr;
|
||||
@@ -496,21 +496,21 @@ bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, const tusb_desc_endpoint_t*
|
||||
hcchar_bm->enable = 1;
|
||||
|
||||
dwc2_channel_split_t* hcsplt_bm = &edpt->hcsplt_bm;
|
||||
hcsplt_bm->hub_port = devtree_info.hub_port;
|
||||
hcsplt_bm->hub_addr = devtree_info.hub_addr;
|
||||
hcsplt_bm->hub_port = bus_info.hub_port;
|
||||
hcsplt_bm->hub_addr = bus_info.hub_addr;
|
||||
hcsplt_bm->xact_pos = 0;
|
||||
hcsplt_bm->split_compl = 0;
|
||||
hcsplt_bm->split_en = (rh_speed == TUSB_SPEED_HIGH && devtree_info.speed != TUSB_SPEED_HIGH) ? 1 : 0;
|
||||
hcsplt_bm->split_en = (rh_speed == TUSB_SPEED_HIGH && bus_info.speed != TUSB_SPEED_HIGH) ? 1 : 0;
|
||||
|
||||
edpt->speed = devtree_info.speed;
|
||||
edpt->speed = bus_info.speed;
|
||||
edpt->next_pid = HCTSIZ_PID_DATA0;
|
||||
if (desc_ep->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS) {
|
||||
edpt->uframe_interval = 1 << (desc_ep->bInterval - 1);
|
||||
if (devtree_info.speed == TUSB_SPEED_FULL) {
|
||||
if (bus_info.speed == TUSB_SPEED_FULL) {
|
||||
edpt->uframe_interval <<= 3;
|
||||
}
|
||||
} else if (desc_ep->bmAttributes.xfer == TUSB_XFER_INTERRUPT) {
|
||||
if (devtree_info.speed == TUSB_SPEED_HIGH) {
|
||||
if (bus_info.speed == TUSB_SPEED_HIGH) {
|
||||
edpt->uframe_interval = 1 << (desc_ep->bInterval - 1);
|
||||
} else {
|
||||
edpt->uframe_interval = desc_ep->bInterval << 3;
|
||||
|
Reference in New Issue
Block a user