use dcd_edpt0_status_complete() to set address without blocking for samd21/samd51/stm32_fsdev
This commit is contained in:
@@ -98,13 +98,13 @@ void dcd_int_disable(uint8_t rhport)
|
||||
|
||||
void dcd_set_address (uint8_t rhport, uint8_t dev_addr)
|
||||
{
|
||||
// Response with status first before changing device address
|
||||
dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0);
|
||||
(void) dev_addr;
|
||||
|
||||
// Wait for EP0 to finish before switching the address.
|
||||
while (USB->DEVICE.DeviceEndpoint[0].EPSTATUS.bit.BK1RDY == 1) {}
|
||||
// Response with zlp status
|
||||
dcd_edpt_xfer(rhport, 0x80, NULL, 0);
|
||||
|
||||
USB->DEVICE.DADD.reg = USB_DEVICE_DADD_DADD(dev_addr) | USB_DEVICE_DADD_ADDEN;
|
||||
// DCD can only set address after status for this request is complete
|
||||
// do it at dcd_edpt0_status_complete()
|
||||
|
||||
// Enable SUSPEND interrupt since the bus signal D+/D- are stable now.
|
||||
USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTENCLR_SUSPEND; // clear pending
|
||||
@@ -116,7 +116,6 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num)
|
||||
(void) rhport;
|
||||
(void) config_num;
|
||||
// Nothing to do
|
||||
|
||||
}
|
||||
|
||||
void dcd_remote_wakeup(uint8_t rhport)
|
||||
@@ -130,6 +129,20 @@ void dcd_remote_wakeup(uint8_t rhport)
|
||||
/* DCD Endpoint port
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
// Invoked when a control transfer's status stage is complete.
|
||||
// May help DCD to prepare for next control transfer, this API is optional.
|
||||
void dcd_edpt0_status_complete(uint8_t rhport, tusb_control_request_t const * request)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
if (request->bRequest == TUSB_REQ_SET_ADDRESS)
|
||||
{
|
||||
uint8_t const dev_addr = (uint8_t) request->wValue;
|
||||
USB->DEVICE.DADD.reg = USB_DEVICE_DADD_DADD(dev_addr) | USB_DEVICE_DADD_ADDEN;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
@@ -104,13 +104,13 @@ void dcd_int_disable(uint8_t rhport)
|
||||
|
||||
void dcd_set_address (uint8_t rhport, uint8_t dev_addr)
|
||||
{
|
||||
// Response with status first before changing device address
|
||||
dcd_edpt_xfer(rhport, tu_edpt_addr(0, TUSB_DIR_IN), NULL, 0);
|
||||
(void) dev_addr;
|
||||
|
||||
// Wait for EP0 to finish before switching the address.
|
||||
while (USB->DEVICE.DeviceEndpoint[0].EPSTATUS.bit.BK1RDY == 1) {}
|
||||
// Response with zlp status
|
||||
dcd_edpt_xfer(rhport, 0x80, NULL, 0);
|
||||
|
||||
USB->DEVICE.DADD.reg = USB_DEVICE_DADD_DADD(dev_addr) | USB_DEVICE_DADD_ADDEN;
|
||||
// DCD can only set address after status for this request is complete
|
||||
// do it at dcd_edpt0_status_complete()
|
||||
|
||||
// Enable SUSPEND interrupt since the bus signal D+/D- are stable now.
|
||||
USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTENCLR_SUSPEND; // clear pending
|
||||
@@ -135,6 +135,19 @@ void dcd_remote_wakeup(uint8_t rhport)
|
||||
/* DCD Endpoint port
|
||||
*------------------------------------------------------------------*/
|
||||
|
||||
// Invoked when a control transfer's status stage is complete.
|
||||
// May help DCD to prepare for next control transfer, this API is optional.
|
||||
void dcd_edpt0_status_complete(uint8_t rhport, tusb_control_request_t const * request)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
if (request->bRequest == TUSB_REQ_SET_ADDRESS)
|
||||
{
|
||||
uint8_t const dev_addr = (uint8_t) request->wValue;
|
||||
USB->DEVICE.DADD.reg = USB_DEVICE_DADD_DADD(dev_addr) | USB_DEVICE_DADD_ADDEN;
|
||||
}
|
||||
}
|
||||
|
||||
bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
@@ -120,7 +120,10 @@ void dcd_set_address (uint8_t rhport, uint8_t dev_addr)
|
||||
(void) rhport;
|
||||
(void) dev_addr;
|
||||
|
||||
// SAMG can only set address after status for this request is complete
|
||||
// Response with zlp status
|
||||
dcd_edpt_xfer(rhport, 0x80, NULL, 0);
|
||||
|
||||
// DCD can only set address after status for this request is complete.
|
||||
// do it at dcd_edpt0_status_complete()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user