refactor hcd api
This commit is contained in:
@@ -609,10 +609,10 @@ static void port_connect_status_change_isr(uint8_t hostid)
|
||||
if (regs->portsc_bit.current_connect_status)
|
||||
{
|
||||
hcd_port_reset(hostid);
|
||||
usbh_hcd_rhport_plugged_isr(hostid);
|
||||
hcd_event_device_attach(hostid);
|
||||
}else // device unplugged
|
||||
{
|
||||
usbh_hcd_rhport_unplugged_isr(hostid);
|
||||
hcd_event_device_remove(hostid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -121,6 +121,12 @@ void hcd_int_disable(uint8_t rhport);
|
||||
//--------------------------------------------------------------------+
|
||||
void hcd_event_handler(hcd_event_t const* event, bool in_isr);
|
||||
|
||||
// Helper to send device attach event
|
||||
void hcd_event_device_attach(uint8_t rhport);
|
||||
|
||||
// Helper to send device removal event
|
||||
void hcd_event_device_remove(uint8_t hostid);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// Endpoints API
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
@@ -745,10 +745,10 @@ void hal_hcd_isr(uint8_t hostid)
|
||||
{
|
||||
// TODO reset port immediately, without this controller will got 2-3 (debouncing connection status change)
|
||||
OHCI_REG->rhport_status[0] = OHCI_RHPORT_PORT_RESET_STATUS_MASK;
|
||||
usbh_hcd_rhport_plugged_isr(0);
|
||||
hcd_event_device_attach(0);
|
||||
}else
|
||||
{
|
||||
usbh_hcd_rhport_unplugged_isr(0);
|
||||
hcd_event_device_remove(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -305,11 +305,11 @@ void usbh_hub_port_plugged_isr(uint8_t hub_addr, uint8_t hub_port)
|
||||
hcd_event_handler(&event, true);
|
||||
}
|
||||
|
||||
void usbh_hcd_rhport_plugged_isr(uint8_t hostid)
|
||||
void hcd_event_device_attach(uint8_t rhport)
|
||||
{
|
||||
hcd_event_t event =
|
||||
{
|
||||
.rhport = hostid,
|
||||
.rhport = rhport,
|
||||
.event_id = HCD_EVENT_DEVICE_ATTACH
|
||||
};
|
||||
|
||||
@@ -329,6 +329,21 @@ void hcd_event_handler(hcd_event_t const* event, bool in_isr)
|
||||
}
|
||||
}
|
||||
|
||||
void hcd_event_device_remove(uint8_t hostid)
|
||||
{
|
||||
hcd_event_t event =
|
||||
{
|
||||
.rhport = hostid,
|
||||
.event_id = HCD_EVENT_DEVICE_REMOVE
|
||||
};
|
||||
|
||||
event.attach.hub_addr = 0;
|
||||
event.attach.hub_port = 0;
|
||||
|
||||
hcd_event_handler(&event, true);
|
||||
}
|
||||
|
||||
|
||||
// a device unplugged on hostid, hub_addr, hub_port
|
||||
// return true if found and unmounted device, false if cannot find
|
||||
static void usbh_device_unplugged(uint8_t hostid, uint8_t hub_addr, uint8_t hub_port)
|
||||
@@ -369,20 +384,6 @@ static void usbh_device_unplugged(uint8_t hostid, uint8_t hub_addr, uint8_t hub_
|
||||
|
||||
}
|
||||
|
||||
void usbh_hcd_rhport_unplugged_isr(uint8_t hostid)
|
||||
{
|
||||
hcd_event_t event =
|
||||
{
|
||||
.rhport = hostid,
|
||||
.event_id = HCD_EVENT_DEVICE_REMOVE
|
||||
};
|
||||
|
||||
event.attach.hub_addr = 0;
|
||||
event.attach.hub_port = 0;
|
||||
|
||||
hcd_event_handler(&event, true);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// ENUMERATION TASK
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
@@ -94,8 +94,7 @@ extern usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1]; // including zer
|
||||
// callback from HCD ISR
|
||||
//--------------------------------------------------------------------+
|
||||
void usbh_xfer_isr(pipe_handle_t pipe_hdl, uint8_t class_code, xfer_result_t event, uint32_t xferred_bytes);
|
||||
void usbh_hcd_rhport_plugged_isr(uint8_t hostid);
|
||||
void usbh_hcd_rhport_unplugged_isr(uint8_t hostid);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user