Skip to content

Commit

Permalink
feature(dcd): review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-marcisovsky committed Mar 27, 2024
1 parent 6cede67 commit 9dadcc0
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions src/portable/synopsys/dwc2/dcd_dwc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,11 +633,10 @@ void dcd_sof_enable(uint8_t rhport, bool en)
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32P4)

// Check if IN/OUT endpoint is avaliable before opening it
static bool dcd_ep_available(uint8_t rhport, uint8_t dir)
static bool dcd_edpt_available(uint8_t rhport, uint8_t dir)
{
// Verify that we have a vacant EP
if ((dwc_ep_config[rhport].in_ep + dwc_ep_config[rhport].out_ep) > (dwc_ep_config[rhport].ep_max_count - 1)) {
TU_LOG(1, "Trying to open an endpoint, but max number of endpoints: %d already opened on this target \r\n", dwc_ep_config[rhport].ep_max_count);
return false;
}
// Get the ep_count amount at the moment as a temporal variable and update it
Expand All @@ -648,7 +647,6 @@ static bool dcd_ep_available(uint8_t rhport, uint8_t dir)
#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
// ESP32Sx has 6 endpoints, from which only 5 can be confiugred as IN
if ((dir) && (new_ep_count > (dwc_ep_config[rhport].ep_max_count - 1))) {
TU_LOG(1, "Trying to open IN endpoint, but max number of IN endpoints: %d already opened on this target \r\n", dwc_ep_config[rhport].ep_max_count - 1);
return false;
}
#endif // TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3)
Expand All @@ -660,7 +658,19 @@ static bool dcd_ep_available(uint8_t rhport, uint8_t dir)
}
return true;
}
#endif // TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32P4)

// Release an endpoint.
static void dcd_edpt_release(uint8_t rhport, uint8_t dir)
{
if (dir) {
TU_ASSERT(dwc_ep_config[rhport].in_ep == 0); // Check if number of opened EPs is not zero
dwc_ep_config[rhport].in_ep--; // Release in_ep
} else {
TU_ASSERT(dwc_ep_config[rhport].out_ep == 0);
dwc_ep_config[rhport].out_ep--;
}
}
#endif

bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
{
Expand All @@ -673,7 +683,8 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
uint8_t const dir = tu_edpt_dir(desc_edpt->bEndpointAddress);

#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32P4)
if (!dcd_ep_available(rhport, dir)) {
if (!dcd_edpt_available(rhport, dir)) {
TU_LOG(1, "No endpoints available (ep_max=%d) \r\n", dwc_ep_config[rhport].ep_max_count);
return false;
}
#endif
Expand Down Expand Up @@ -920,10 +931,9 @@ void dcd_edpt_close (uint8_t rhport, uint8_t ep_addr)
dcd_edpt_disable(rhport, ep_addr, false);

#if TU_CHECK_MCU(OPT_MCU_ESP32S2, OPT_MCU_ESP32S3, OPT_MCU_ESP32P4)
if (dir) {
dwc_ep_config[rhport].in_ep--;
} else {
dwc_ep_config[rhport].out_ep--;
// Release an endpoint if it is not the 0 EP
if (epnum) {
dcd_edpt_release(rhport, dir);
}
#endif

Expand Down

0 comments on commit 9dadcc0

Please sign in to comment.