start to add pio usb (host) support
run as proof of concept
This commit is contained in:
@@ -143,9 +143,20 @@ void hcd_device_close(uint8_t rhport, uint8_t dev_addr);
|
||||
// Endpoints API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8]);
|
||||
// Open an endpoint
|
||||
bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * ep_desc);
|
||||
|
||||
// Submit a transfer, when complete hcd_event_xfer_complete() must be invoked
|
||||
bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen);
|
||||
|
||||
// Submit a special transfer to send 8-byte Setup Packet, when complete hcd_event_xfer_complete() must be invoked
|
||||
bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8]);
|
||||
|
||||
// Optional: some controllers are capable of carry out the whole Control Transfer (setup, data, status)
|
||||
// without help of USBH.
|
||||
bool hcd_edpt_control_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t const setup_packet[8], uint8_t* data) TU_ATTR_WEAK;
|
||||
|
||||
// clear stall, data toggle is also reset to DATA0
|
||||
bool hcd_edpt_clear_stall(uint8_t dev_addr, uint8_t ep_addr);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
@@ -358,12 +358,12 @@ void tuh_task(void)
|
||||
case HCD_EVENT_DEVICE_ATTACH:
|
||||
// TODO due to the shared _usbh_ctrl_buf, we must complete enumerating
|
||||
// one device before enumerating another one.
|
||||
TU_LOG2("USBH DEVICE ATTACH\r\n");
|
||||
TU_LOG2("[rh%d] USBH DEVICE ATTACH\r\n", event.rhport);
|
||||
enum_new_device(&event);
|
||||
break;
|
||||
|
||||
case HCD_EVENT_DEVICE_REMOVE:
|
||||
TU_LOG2("USBH DEVICE REMOVED\r\n");
|
||||
TU_LOG2("[rh%d] USBH DEVICE REMOVED\r\n", event.rhport);
|
||||
process_device_unplugged(event.rhport, event.connection.hub_addr, event.connection.hub_port);
|
||||
|
||||
#if CFG_TUH_HUB
|
||||
@@ -703,7 +703,9 @@ static bool enum_new_device(hcd_event_t* event)
|
||||
if (_dev0.hub_addr == 0)
|
||||
{
|
||||
// wait until device is stable TODO non blocking
|
||||
hcd_port_reset(_dev0.rhport);
|
||||
osal_task_delay(RESET_DELAY);
|
||||
hcd_port_reset_end( _dev0.rhport);
|
||||
|
||||
// device unplugged while delaying
|
||||
if ( !hcd_port_connect_status(_dev0.rhport) ) return true;
|
||||
@@ -772,13 +774,17 @@ static bool enum_get_addr0_device_desc_complete(uint8_t dev_addr, tusb_control_r
|
||||
TU_ASSERT( tu_desc_type(desc_device) == TUSB_DESC_DEVICE );
|
||||
|
||||
// Reset device again before Set Address
|
||||
// reset port after 8 byte descriptor
|
||||
TU_LOG2("Port reset \r\n");
|
||||
|
||||
if (_dev0.hub_addr == 0)
|
||||
{
|
||||
#if !CFG_TUH_RPI_PIO // skip this reset for pio-usb
|
||||
// connected directly to roothub
|
||||
hcd_port_reset( _dev0.rhport ); // reset port after 8 byte descriptor
|
||||
hcd_port_reset(_dev0.rhport);
|
||||
osal_task_delay(RESET_DELAY);
|
||||
hcd_port_reset_end(_dev0.rhport);
|
||||
#endif
|
||||
|
||||
enum_request_set_addr();
|
||||
}
|
||||
|
||||
@@ -71,7 +71,14 @@ bool tuh_control_xfer (uint8_t dev_addr, tusb_control_request_t const* request,
|
||||
TU_LOG2("\r\n");
|
||||
|
||||
// Send setup packet
|
||||
TU_ASSERT( hcd_setup_send(rhport, dev_addr, (uint8_t const*) &_ctrl_xfer.request) );
|
||||
if ( hcd_edpt_control_xfer )
|
||||
{
|
||||
_ctrl_xfer.stage = STAGE_ACK;
|
||||
TU_ASSERT( hcd_edpt_control_xfer(rhport, dev_addr, (uint8_t const*) &_ctrl_xfer.request, buffer) );
|
||||
}else
|
||||
{
|
||||
TU_ASSERT( hcd_setup_send(rhport, dev_addr, (uint8_t const*) &_ctrl_xfer.request) );
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user