only attempt to clear if stalled, and stall if cleared

This commit is contained in:
hathach 2021-09-01 16:54:03 +07:00
parent 15fa2f447b
commit 1398226bb5
No known key found for this signature in database
GPG Key ID: 2FA891220FBFD581
1 changed files with 16 additions and 9 deletions

View File

@ -1333,26 +1333,33 @@ bool usbd_edpt_busy(uint8_t rhport, uint8_t ep_addr)
void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr) void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
{ {
TU_LOG(USBD_DBG, " Stall EP %02X\r\n", ep_addr);
uint8_t const epnum = tu_edpt_number(ep_addr); uint8_t const epnum = tu_edpt_number(ep_addr);
uint8_t const dir = tu_edpt_dir(ep_addr); uint8_t const dir = tu_edpt_dir(ep_addr);
dcd_edpt_stall(rhport, ep_addr); // only stalled if currently cleared
_usbd_dev.ep_status[epnum][dir].stalled = true; if ( !_usbd_dev.ep_status[epnum][dir].stalled )
_usbd_dev.ep_status[epnum][dir].busy = true; {
TU_LOG(USBD_DBG, " Stall EP %02X\r\n", ep_addr);
dcd_edpt_stall(rhport, ep_addr);
_usbd_dev.ep_status[epnum][dir].stalled = true;
_usbd_dev.ep_status[epnum][dir].busy = true;
}
} }
void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr) void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
{ {
TU_LOG(USBD_DBG, " Clear Stall EP %02X\r\n", ep_addr);
uint8_t const epnum = tu_edpt_number(ep_addr); uint8_t const epnum = tu_edpt_number(ep_addr);
uint8_t const dir = tu_edpt_dir(ep_addr); uint8_t const dir = tu_edpt_dir(ep_addr);
dcd_edpt_clear_stall(rhport, ep_addr); // only clear if currently stalled
_usbd_dev.ep_status[epnum][dir].stalled = false; if ( _usbd_dev.ep_status[epnum][dir].stalled )
_usbd_dev.ep_status[epnum][dir].busy = false; {
TU_LOG(USBD_DBG, " Clear Stall EP %02X\r\n", ep_addr);
dcd_edpt_clear_stall(rhport, ep_addr);
_usbd_dev.ep_status[epnum][dir].stalled = false;
_usbd_dev.ep_status[epnum][dir].busy = false;
}
} }
bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr) bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr)