summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2020-05-19 00:55:43 +0700
committerhathach <[email protected]>2020-05-19 00:55:43 +0700
commit58cedf4c061fbf9f95cd88cafb6e581fc04549ff (patch)
tree3a8d0855fd69d45501750c93ff8072c17d575b3e
parent905a80d1b2de5e8ad67b3687ffd0543d90ac904e (diff)
usb0 host on mcb1800 work with fullspeed mode.
use usbh_edpt_open() to correctly map ep2drv[]
-rw-r--r--examples/host/cdc_msc_hid/Makefile3
-rw-r--r--examples/host/cdc_msc_hid/ses/lpc18xx/lpc18xx.emProject4
-rw-r--r--examples/host/cdc_msc_hid/src/main.c15
-rw-r--r--examples/host/cdc_msc_hid/src/msc_app.c36
-rw-r--r--examples/host/cdc_msc_hid/src/tusb_config.h6
-rw-r--r--hw/bsp/ea4357/board.mk2
-rw-r--r--hw/bsp/mcb1800/board.mk4
-rw-r--r--hw/bsp/mcb1800/mcb1800.c3
-rw-r--r--src/class/cdc/cdc_host.c4
-rw-r--r--src/class/hid/hid_host.c2
-rw-r--r--src/class/msc/msc_host.c2
-rw-r--r--src/class/vendor/vendor_host.c2
-rw-r--r--src/host/ehci/ehci.c21
-rw-r--r--src/host/ehci/ehci.h4
-rw-r--r--src/host/hcd.h1
-rw-r--r--src/host/hub.c2
-rw-r--r--src/host/usbh.c68
-rw-r--r--src/host/usbh.h2
18 files changed, 115 insertions, 66 deletions
diff --git a/examples/host/cdc_msc_hid/Makefile b/examples/host/cdc_msc_hid/Makefile
index 20cd7ba69..373dbbf9e 100644
--- a/examples/host/cdc_msc_hid/Makefile
+++ b/examples/host/cdc_msc_hid/Makefile
@@ -15,8 +15,9 @@ SRC_C += \
src/host/usbh.c \
src/host/hub.c \
src/host/ehci/ehci.c \
- src/class/cdc/cdc_host.c \
src/host/ehci/ehci.c \
+ src/class/cdc/cdc_host.c \
+ src/class/msc/msc_host.c \
src/portable/nxp/lpc18_43/hcd_lpc18_43.c
include ../../rules.mk
diff --git a/examples/host/cdc_msc_hid/ses/lpc18xx/lpc18xx.emProject b/examples/host/cdc_msc_hid/ses/lpc18xx/lpc18xx.emProject
index 2b68bfa23..e0a2f6f97 100644
--- a/examples/host/cdc_msc_hid/ses/lpc18xx/lpc18xx.emProject
+++ b/examples/host/cdc_msc_hid/ses/lpc18xx/lpc18xx.emProject
@@ -124,6 +124,10 @@
</folder>
</folder>
</folder>
+ <configuration
+ Name="MCB1800"
+ arm_target_interface_type="JTAG"
+ speed="12000" />
</project>
<configuration
Name="MCB1800"
diff --git a/examples/host/cdc_msc_hid/src/main.c b/examples/host/cdc_msc_hid/src/main.c
index 6f5df1250..273c95c77 100644
--- a/examples/host/cdc_msc_hid/src/main.c
+++ b/examples/host/cdc_msc_hid/src/main.c
@@ -75,7 +75,7 @@ CFG_TUSB_MEM_SECTION static char serial_in_buffer[64] = { 0 };
void tuh_mount_cb(uint8_t dev_addr)
{
// application set-up
- printf("\na CDC device (address %d) is mounted\n", dev_addr);
+ printf("\na device with address %d is mounted\n", dev_addr);
tuh_cdc_receive(dev_addr, serial_in_buffer, sizeof(serial_in_buffer), true); // schedule first transfer
}
@@ -83,7 +83,7 @@ void tuh_mount_cb(uint8_t dev_addr)
void tuh_umount_cb(uint8_t dev_addr)
{
// application tear-down
- printf("\na CDC device (address %d) is unmounted \n", dev_addr);
+ printf("\na device with address %d is unmounted \n", dev_addr);
}
// invoked ISR context
@@ -195,8 +195,15 @@ void print_greeting(void)
printf("This Host demo is configured to support:\r\n");
printf(" - RTOS = %s\n", rtos_name[CFG_TUSB_OS]);
-// if (CFG_TUH_CDC ) puts(" - Communication Device Class");
-// if (CFG_TUH_MSC ) puts(" - Mass Storage");
+
+#if CFG_TUH_CDC
+ printf(" - Communication Device Class\r\n");
+#endif
+
+#if CFG_TUH_MSC
+ printf(" - Mass Storage\r\n");
+#endif
+
// if (CFG_TUH_HID_KEYBOARD ) puts(" - HID Keyboard");
// if (CFG_TUH_HID_MOUSE ) puts(" - HID Mouse");
}
diff --git a/examples/host/cdc_msc_hid/src/msc_app.c b/examples/host/cdc_msc_hid/src/msc_app.c
index 20ac88744..93dc6d3fe 100644
--- a/examples/host/cdc_msc_hid/src/msc_app.c
+++ b/examples/host/cdc_msc_hid/src/msc_app.c
@@ -35,23 +35,24 @@
//------------- IMPLEMENTATION -------------//
void tuh_msc_mounted_cb(uint8_t dev_addr)
{
- puts("\na MassStorage device is mounted");
+ printf("a MassStorage device is mounted\r\n");
-// //------------- Disk Information -------------//
-// // SCSI VendorID[8] & ProductID[16] from Inquiry Command
-// uint8_t const* p_vendor = tuh_msc_get_vendor_name(dev_addr);
-// uint8_t const* p_product = tuh_msc_get_product_name(dev_addr);
-//
-// for(uint8_t i=0; i<8; i++) putchar(p_vendor[i]);
-//
-// putchar(' ');
-// for(uint8_t i=0; i<16; i++) putchar(p_product[i]);
-// putchar('\n');
-//
-// uint32_t last_lba, block_size;
-// tuh_msc_get_capacity(dev_addr, &last_lba, &block_size);
-// printf("Disk Size: %d MB\n", (last_lba+1)/ ((1024*1024)/block_size) );
-// printf("LBA 0-0x%X Block Size: %d\n", last_lba, block_size);
+ //------------- Disk Information -------------//
+ // SCSI VendorID[8] & ProductID[16] from Inquiry Command
+ uint8_t const* p_vendor = tuh_msc_get_vendor_name(dev_addr);
+ uint8_t const* p_product = tuh_msc_get_product_name(dev_addr);
+
+ for(uint8_t i=0; i<8; i++) putchar(p_vendor[i]);
+
+ putchar(' ');
+ for(uint8_t i=0; i<16; i++) putchar(p_product[i]);
+ putchar('\n');
+
+ uint32_t last_lba = 0;
+ uint32_t block_size = 0;
+ tuh_msc_get_capacity(dev_addr, &last_lba, &block_size);
+ printf("Disk Size: %ld MB\r\n", (last_lba+1)/ ((1024*1024)/block_size) );
+ printf("LBA 0-0x%lX Block Size: %ld\r\n", last_lba, block_size);
//
// //------------- file system (only 1 LUN support) -------------//
// uint8_t phy_disk = dev_addr-1;
@@ -81,7 +82,8 @@ void tuh_msc_mounted_cb(uint8_t dev_addr)
void tuh_msc_unmounted_cb(uint8_t dev_addr)
{
- puts("\na MassStorage device is unmounted");
+ (void) dev_addr;
+ printf("a MassStorage device is unmounted\r\n");
// uint8_t phy_disk = dev_addr-1;
//
diff --git a/examples/host/cdc_msc_hid/src/tusb_config.h b/examples/host/cdc_msc_hid/src/tusb_config.h
index a929e36d8..dd50c7050 100644
--- a/examples/host/cdc_msc_hid/src/tusb_config.h
+++ b/examples/host/cdc_msc_hid/src/tusb_config.h
@@ -40,9 +40,9 @@
#endif
#if CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX
-#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_HOST | OPT_MODE_HIGH_SPEED)
+ #define CFG_TUSB_RHPORT0_MODE (OPT_MODE_HOST | OPT_MODE_HIGH_SPEED)
#else
-#define CFG_TUSB_RHPORT0_MODE OPT_MODE_HOST
+ #define CFG_TUSB_RHPORT0_MODE OPT_MODE_HOST
#endif
#define CFG_TUSB_OS OPT_OS_NONE
@@ -74,7 +74,7 @@
#define CFG_TUH_HID_KEYBOARD 0
#define CFG_TUH_HID_MOUSE 0
#define CFG_TUSB_HOST_HID_GENERIC 0 // (not yet supported)
-#define CFG_TUH_MSC 0
+#define CFG_TUH_MSC 1
#define CFG_TUH_VENDOR 0
#define CFG_TUSB_HOST_DEVICE_MAX (CFG_TUH_HUB ? 5 : 1) // normal hub has 4 ports
diff --git a/hw/bsp/ea4357/board.mk b/hw/bsp/ea4357/board.mk
index dd987f476..2ee6b695c 100644
--- a/hw/bsp/ea4357/board.mk
+++ b/hw/bsp/ea4357/board.mk
@@ -41,7 +41,7 @@ FREERTOS_PORT = ARM_CM4F
# For flash-jlink target
JLINK_DEVICE = LPC4357
-JLINK_IF = jtag
+JLINK_IF = jtag
# flash using jlink
flash: flash-jlink
diff --git a/hw/bsp/mcb1800/board.mk b/hw/bsp/mcb1800/board.mk
index 7806bff46..6037310a6 100644
--- a/hw/bsp/mcb1800/board.mk
+++ b/hw/bsp/mcb1800/board.mk
@@ -5,8 +5,8 @@ CFLAGS += \
-mcpu=cortex-m3 \
-nostdlib \
-DCORE_M3 \
- -DCFG_TUSB_MCU=OPT_MCU_LPC18XX \
-D__USE_LPCOPEN
+ -DCFG_TUSB_MCU=OPT_MCU_LPC18XX \
# mcu driver cause following warnings
CFLAGS += -Wno-error=unused-parameter -Wno-error=strict-prototypes
@@ -37,7 +37,7 @@ FREERTOS_PORT = ARM_CM3
# For flash-jlink target
JLINK_DEVICE = LPC1857
-JLINK_IF = swd
+JLINK_IF = jtag
# flash using jlink
flash: flash-jlink
diff --git a/hw/bsp/mcb1800/mcb1800.c b/hw/bsp/mcb1800/mcb1800.c
index bfeb126fc..1d7ffb35f 100644
--- a/hw/bsp/mcb1800/mcb1800.c
+++ b/hw/bsp/mcb1800/mcb1800.c
@@ -172,8 +172,7 @@ void board_init(void)
// Set mode
#if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
LPC_USB0->USBMODE_H = USBMODE_HOST | (USBMODE_VBUS_HIGH << 5);
-
-// LPC_USB0->PORTSC1_D |= (1<<24); // FIXME force full speed for debugging
+ LPC_USB0->PORTSC1_H |= (1<<24); // FIXME force full speed for debugging
#else // TODO OTG
LPC_USB0->USBMODE_D = USBMODE_DEVICE;
LPC_USB0->OTGSC = (1<<3) | (1<<0) /*| (1<<16)| (1<<24)| (1<<25)| (1<<26)| (1<<27)| (1<<28)| (1<<29)| (1<<30)*/;
diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c
index 6b36ea94d..e62f47b72 100644
--- a/src/class/cdc/cdc_host.c
+++ b/src/class/cdc/cdc_host.c
@@ -158,7 +158,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
// notification endpoint
tusb_desc_endpoint_t const * ep_desc = (tusb_desc_endpoint_t const *) p_desc;
- TU_ASSERT( hcd_edpt_open(rhport, dev_addr, ep_desc) );
+ TU_ASSERT( usbh_edpt_open(rhport, dev_addr, ep_desc) );
p_cdc->ep_notif = ep_desc->bEndpointAddress;
(*p_length) += p_desc[DESC_OFFSET_LEN];
@@ -179,7 +179,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType);
TU_ASSERT(TUSB_XFER_BULK == ep_desc->bmAttributes.xfer);
- TU_ASSERT(hcd_edpt_open(rhport, dev_addr, ep_desc));
+ TU_ASSERT(usbh_edpt_open(rhport, dev_addr, ep_desc));
if ( tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN )
{
diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c
index 69c49b012..8abb3cd22 100644
--- a/src/class/hid/hid_host.c
+++ b/src/class/hid/hid_host.c
@@ -40,7 +40,7 @@
//--------------------------------------------------------------------+
static inline bool hidh_interface_open(uint8_t dev_addr, uint8_t interface_number, tusb_desc_endpoint_t const *p_endpoint_desc, hidh_interface_info_t *p_hid)
{
- p_hid->pipe_hdl = hcd_edpt_open(dev_addr, p_endpoint_desc, TUSB_CLASS_HID);
+ p_hid->pipe_hdl = usbh_edpt_open(dev_addr, p_endpoint_desc, TUSB_CLASS_HID);
p_hid->report_size = p_endpoint_desc->wMaxPacketSize.size; // TODO get size from report descriptor
p_hid->interface_number = interface_number;
diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c
index e20969f57..98c71eb70 100644
--- a/src/class/msc/msc_host.c
+++ b/src/class/msc/msc_host.c
@@ -293,7 +293,7 @@ bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType);
TU_ASSERT(TUSB_XFER_BULK == ep_desc->bmAttributes.xfer);
- TU_ASSERT(hcd_edpt_open(rhport, dev_addr, ep_desc));
+ TU_ASSERT(usbh_edpt_open(rhport, dev_addr, ep_desc));
if ( tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN )
{
diff --git a/src/class/vendor/vendor_host.c b/src/class/vendor/vendor_host.c
index 3e8dac0f6..0524cb981 100644
--- a/src/class/vendor/vendor_host.c
+++ b/src/class/vendor/vendor_host.c
@@ -107,7 +107,7 @@ tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_
pipe_handle_t * p_pipe_hdl = ( p_endpoint->bEndpointAddress & TUSB_DIR_IN_MASK ) ?
&custom_interface[dev_addr-1].pipe_in : &custom_interface[dev_addr-1].pipe_out;
- *p_pipe_hdl = hcd_edpt_open(dev_addr, p_endpoint, TUSB_CLASS_VENDOR_SPECIFIC);
+ *p_pipe_hdl = usbh_edpt_open(dev_addr, p_endpoint, TUSB_CLASS_VENDOR_SPECIFIC);
TU_ASSERT ( pipehandle_is_valid(*p_pipe_hdl), TUSB_ERROR_HCD_OPEN_PIPE_FAILED );
p_desc = tu_desc_next(p_desc);
diff --git a/src/host/ehci/ehci.c b/src/host/ehci/ehci.c
index 048affb1e..e2ead7b08 100644
--- a/src/host/ehci/ehci.c
+++ b/src/host/ehci/ehci.c
@@ -120,10 +120,27 @@ void hcd_port_reset(uint8_t rhport)
ehci_registers_t* regs = ehci_data.regs;
- regs->portsc_bm.port_enabled = 0; // disable port before reset
- regs->portsc_bm.port_reset = 1;
+// regs->portsc_bm.port_enabled = 0; // disable port before reset
+// regs->portsc_bm.port_reset = 1;
+
+ uint32_t portsc = regs->portsc;
+
+ portsc &= ~(EHCI_PORTSC_MASK_PORT_EANBLED);
+ portsc |= EHCI_PORTSC_MASK_PORT_RESET;
+
+ regs->portsc = portsc;
}
+#if 0
+void hcd_port_reset_end(uint8_t rhport)
+{
+ (void) rhport;
+
+ ehci_registers_t* regs = ehci_data.regs;
+ regs->portsc_bm.port_reset = 0;
+}
+#endif
+
bool hcd_port_connect_status(uint8_t rhport)
{
(void) rhport;
diff --git a/src/host/ehci/ehci.h b/src/host/ehci/ehci.h
index f11c4536a..a6342b2d2 100644
--- a/src/host/ehci/ehci.h
+++ b/src/host/ehci/ehci.h
@@ -311,10 +311,14 @@ enum ehci_usbcmd_pos_ {
};
enum ehci_portsc_change_mask_{
+ EHCI_PORTSC_MASK_CURRENT_CONNECT_STATUS = TU_BIT(0),
EHCI_PORTSC_MASK_CONNECT_STATUS_CHANGE = TU_BIT(1),
+ EHCI_PORTSC_MASK_PORT_EANBLED = TU_BIT(2),
EHCI_PORTSC_MASK_PORT_ENABLE_CHAGNE = TU_BIT(3),
EHCI_PORTSC_MASK_OVER_CURRENT_CHANGE = TU_BIT(5),
+ EHCI_PORTSC_MASK_PORT_RESET = TU_BIT(8),
+
EHCI_PORTSC_MASK_ALL =
EHCI_PORTSC_MASK_CONNECT_STATUS_CHANGE |
EHCI_PORTSC_MASK_PORT_ENABLE_CHAGNE |
diff --git a/src/host/hcd.h b/src/host/hcd.h
index d9307ca09..f2ca0a1d6 100644
--- a/src/host/hcd.h
+++ b/src/host/hcd.h
@@ -104,6 +104,7 @@ static inline uint32_t hcd_frame_number(uint8_t rhport)
/// return the current connect status of roothub port
bool hcd_port_connect_status(uint8_t hostid);
void hcd_port_reset(uint8_t hostid);
+void hcd_port_reset_end(uint8_t rhport);
tusb_speed_t hcd_port_speed_get(uint8_t hostid);
// HCD closes all opened endpoints belong to this device
diff --git a/src/host/hub.c b/src/host/hub.c
index 00450b704..eb85dfa42 100644
--- a/src/host/hub.c
+++ b/src/host/hub.c
@@ -154,7 +154,7 @@ bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf
TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType);
TU_ASSERT(TUSB_XFER_INTERRUPT == ep_desc->bmAttributes.xfer);
- TU_ASSERT(hcd_edpt_open(rhport, dev_addr, ep_desc));
+ TU_ASSERT(usbh_edpt_open(rhport, dev_addr, ep_desc));
hub_data[dev_addr-1].itf_num = itf_desc->bInterfaceNumber;
hub_data[dev_addr-1].ep_status = ep_desc->bEndpointAddress;
diff --git a/src/host/usbh.c b/src/host/usbh.c
index 7171f6bab..8536cec0a 100644
--- a/src/host/usbh.c
+++ b/src/host/usbh.c
@@ -116,7 +116,6 @@ CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(4) static uint8_t _usbh_ctrl_buf[CFG_TUSB_H
//------------- Helper Function Prototypes -------------//
static inline uint8_t get_new_address(void);
static inline uint8_t get_configure_number_for_device(tusb_desc_device_t* dev_desc);
-static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc, uint16_t desc_len, uint8_t driver_id);
//--------------------------------------------------------------------+
// PUBLIC API (Parameter Verification is required)
@@ -225,6 +224,30 @@ tusb_error_t usbh_pipe_control_open(uint8_t dev_addr, uint8_t max_packet_size)
return TUSB_ERROR_NONE;
}
+bool usbh_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc)
+{
+ bool ret = hcd_edpt_open(rhport, dev_addr, ep_desc);
+
+ if (ret)
+ {
+ usbh_device_t* dev = &_usbh_devices[dev_addr];
+
+ // new endpoints belongs to latest interface (last valid value)
+ uint8_t drvid = 0xff;
+ for(uint8_t i=0; i < sizeof(dev->itf2drv); i++)
+ {
+ if ( dev->itf2drv[i] == 0xff ) break;
+ drvid = dev->itf2drv[i];
+ }
+ TU_ASSERT(drvid < USBH_CLASS_DRIVER_COUNT);
+
+ uint8_t const ep_addr = ep_desc->bEndpointAddress;
+ dev->ep2drv[tu_edpt_number(ep_addr)][tu_edpt_dir(ep_addr)] = drvid;
+ }
+
+ return ret;
+}
+
//--------------------------------------------------------------------+
// USBH-HCD ISR/Callback API
//--------------------------------------------------------------------+
@@ -358,6 +381,8 @@ bool enum_task(hcd_event_t* event)
{
if( hcd_port_connect_status(dev0->rhport) )
{
+ TU_LOG2("Connect \r\n");
+
// connection event
osal_task_delay(POWER_STABLE_DELAY); // wait until device is stable. Increase this if the first 8 bytes is failed to get
@@ -371,6 +396,8 @@ bool enum_task(hcd_event_t* event)
}
else
{
+ TU_LOG2("Disconnect \r\n");
+
// disconnection event
usbh_device_unplugged(dev0->rhport, 0, 0);
return true; // restart task
@@ -424,6 +451,7 @@ bool enum_task(hcd_event_t* event)
TU_ASSERT_ERR( usbh_pipe_control_open(0, 8) );
//------------- Get first 8 bytes of device descriptor to get Control Endpoint Size -------------//
+ TU_LOG2("Get 8 byte of Device Descriptor \r\n");
request = (tusb_control_request_t ) {
.bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_DEVICE, .type = TUSB_REQ_TYPE_STANDARD, .direction = TUSB_DIR_IN },
.bRequest = TUSB_REQ_GET_DESCRIPTOR,
@@ -434,12 +462,16 @@ bool enum_task(hcd_event_t* event)
bool is_ok = usbh_control_xfer(0, &request, _usbh_ctrl_buf);
//------------- Reset device again before Set Address -------------//
+ TU_LOG2("Port reset \r\n");
+
if (dev0->hub_addr == 0)
{
// connected directly to roothub
TU_ASSERT(is_ok); // TODO some slow device is observed to fail the very fist controller xfer, can try more times
hcd_port_reset( dev0->rhport ); // reset port after 8 byte descriptor
osal_task_delay(RESET_DELAY);
+// hcd_port_reset_end(dev0->rhport);
+// osal_task_delay(RESET_DELAY);
}
#if CFG_TUH_HUB
else
@@ -458,6 +490,7 @@ bool enum_task(hcd_event_t* event)
#endif
//------------- Set new address -------------//
+ TU_LOG2("Set Address \r\n");
uint8_t const new_addr = get_new_address();
TU_ASSERT(new_addr <= CFG_TUSB_HOST_DEVICE_MAX); // TODO notify application we reach max devices
@@ -484,6 +517,7 @@ bool enum_task(hcd_event_t* event)
TU_ASSERT_ERR ( usbh_pipe_control_open(new_addr, ((tusb_desc_device_t*) _usbh_ctrl_buf)->bMaxPacketSize0 ) );
//------------- Get full device descriptor -------------//
+ TU_LOG2("Get Device Descriptor \r\n");
request = (tusb_control_request_t ) {
.bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_DEVICE, .type = TUSB_REQ_TYPE_STANDARD, .direction = TUSB_DIR_IN },
.bRequest = TUSB_REQ_GET_DESCRIPTOR,
@@ -502,6 +536,7 @@ bool enum_task(hcd_event_t* event)
TU_ASSERT(configure_selected <= new_dev->configure_count); // TODO notify application when invalid configuration
//------------- Get 9 bytes of configuration descriptor -------------//
+ TU_LOG2("Get 9 bytes of Configuration Descriptor \r\n");
request = (tusb_control_request_t ) {
.bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_DEVICE, .type = TUSB_REQ_TYPE_STANDARD, .direction = TUSB_DIR_IN },
.bRequest = TUSB_REQ_GET_DESCRIPTOR,
@@ -515,6 +550,7 @@ bool enum_task(hcd_event_t* event)
TU_ASSERT( CFG_TUSB_HOST_ENUM_BUFFER_SIZE >= ((tusb_desc_configuration_t*)_usbh_ctrl_buf)->wTotalLength );
//------------- Get full configuration descriptor -------------//
+ TU_LOG2("Get full Configuration Descriptor \r\n");
request.wLength = ((tusb_desc_configuration_t*)_usbh_ctrl_buf)->wTotalLength; // full length
TU_ASSERT( usbh_control_xfer( new_addr, &request, _usbh_ctrl_buf ) );
@@ -522,6 +558,7 @@ bool enum_task(hcd_event_t* event)
new_dev->interface_count = ((tusb_desc_configuration_t*) _usbh_ctrl_buf)->bNumInterfaces;
//------------- Set Configure -------------//
+ TU_LOG2("Set Configuration Descriptor \r\n");
request = (tusb_control_request_t ) {
.bmRequestType_bit = { .recipient = TUSB_REQ_RCPT_DEVICE, .type = TUSB_REQ_TYPE_STANDARD, .direction = TUSB_DIR_OUT },
.bRequest = TUSB_REQ_SET_CONFIGURATION,
@@ -577,11 +614,7 @@ bool enum_task(hcd_event_t* event)
{
uint16_t itf_len = 0;
- if ( usbh_class_drivers[drv_id].open(new_dev->rhport, new_addr, desc_itf, &itf_len) )
- {
- mark_interface_endpoint(new_dev->ep2drv, p_desc, itf_len, drv_id);
- }
-
+ TU_ASSERT( usbh_class_drivers[drv_id].open(new_dev->rhport, new_addr, desc_itf, &itf_len) );
TU_ASSERT( itf_len >= sizeof(tusb_desc_interface_t) );
p_desc += itf_len;
}
@@ -597,7 +630,7 @@ bool enum_task(hcd_event_t* event)
/* USB Host Driver task
* This top level thread manages all host controller event and delegates events to class-specific drivers.
* This should be called periodically within the mainloop or rtos thread.
- *
+ *_usbh_devices[dev_addr].
@code
int main(void)
{
@@ -661,25 +694,4 @@ static inline uint8_t get_configure_number_for_device(tusb_desc_device_t* dev_de
return config_num;
}
-// Helper marking endpoint of interface belongs to class driver
-// TODO merge with usbd
-static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc, uint16_t desc_len, uint8_t driver_id)
-{
- uint16_t len = 0;
-
- while( len < desc_len )
- {
- if ( TUSB_DESC_ENDPOINT == tu_desc_type(p_desc) )
- {
- uint8_t const ep_addr = ((tusb_desc_endpoint_t const*) p_desc)->bEndpointAddress;
-
- ep2drv[ tu_edpt_number(ep_addr) ][ tu_edpt_dir(ep_addr) ] = driver_id;
- }
-
- len += tu_desc_len(p_desc);
- p_desc = tu_desc_next(p_desc);
- }
-}
-
-
#endif
diff --git a/src/host/usbh.h b/src/host/usbh.h
index 42a2bd095..bc0abcccc 100644
--- a/src/host/usbh.h
+++ b/src/host/usbh.h
@@ -94,6 +94,8 @@ TU_ATTR_WEAK void tuh_umount_cb(uint8_t dev_addr);
bool usbh_init(void);
bool usbh_control_xfer (uint8_t dev_addr, tusb_control_request_t* request, uint8_t* data);
+bool usbh_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc);
+
#ifdef __cplusplus
}
#endif