mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-25 10:43:44 +00:00
Add EP close. Fix bug in set_interface within audio.
This commit is contained in:
parent
c557bf7b2e
commit
444e4d2821
@ -70,7 +70,7 @@ typedef struct
|
||||
#endif
|
||||
|
||||
#if CFG_TUD_AUDIO_N_AS_INT
|
||||
uint8_t altSetting[CFG_TUD_AUDIO_N_AS_INT];
|
||||
uint8_t altSetting[CFG_TUD_AUDIO_N_AS_INT]; // We need to save the current alternate setting this way, because it is possible that there are AS interfaces which do not have an EP!
|
||||
#endif
|
||||
/*------------- From this point, data is not cleared by bus reset -------------*/
|
||||
|
||||
@ -766,13 +766,12 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *
|
||||
// Find correct interface
|
||||
if (tu_desc_type(p_desc) == TUSB_DESC_INTERFACE && ((tusb_desc_interface_t const * )p_desc)->bInterfaceNumber == itf && ((tusb_desc_interface_t const * )p_desc)->bAlternateSetting == alt)
|
||||
{
|
||||
// Open EPs
|
||||
uint8_t foundEPs = 0;
|
||||
while (foundEPs < ((tusb_desc_interface_t const * )p_desc)->bNumEndpoints && p_desc < p_desc_end)
|
||||
// From this point forward follow the EP descriptors associated to the current alternate setting interface - Open EPs if necessary
|
||||
uint8_t foundEPs = 0, nEps = ((tusb_desc_interface_t const * )p_desc)->bNumEndpoints;
|
||||
while (foundEPs < nEps && p_desc < p_desc_end)
|
||||
{
|
||||
if (tu_desc_type(p_desc) == TUSB_DESC_ENDPOINT)
|
||||
{
|
||||
// TU_ASSERT(dcd_edpt_open(rhport, (tusb_desc_endpoint_t const *) p_desc), false);
|
||||
TU_ASSERT(usbd_edpt_open(rhport, (tusb_desc_endpoint_t const *)p_desc));
|
||||
uint8_t ep_addr = ((tusb_desc_endpoint_t const *) p_desc)->bEndpointAddress;
|
||||
|
||||
@ -780,6 +779,7 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *
|
||||
if (tu_edpt_dir(ep_addr) == TUSB_DIR_IN && ((tusb_desc_endpoint_t const *) p_desc)->bmAttributes.usage == 0x00) // Check if usage is data EP
|
||||
{
|
||||
_audiod_itf[idxDriver].ep_in = ep_addr;
|
||||
_audiod_itf[idxDriver].ep_in_as_intf_num = itf;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -789,6 +789,7 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *
|
||||
{
|
||||
// Save address
|
||||
_audiod_itf[idxDriver].ep_out = ep_addr;
|
||||
_audiod_itf[idxDriver].ep_out_as_intf_num = itf;
|
||||
|
||||
// Prepare for incoming data
|
||||
TU_ASSERT(usbd_edpt_xfer(rhport, ep_addr, _audiod_itf[idxDriver].epout_buf, CFG_TUD_AUDIO_EPSIZE_OUT), false);
|
||||
@ -807,16 +808,18 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
}
|
||||
|
||||
TU_VERIFY(foundEPs == nEps);
|
||||
|
||||
// We are done - abort loop
|
||||
break;
|
||||
}
|
||||
|
||||
// Increase index, bytes read, and pointer
|
||||
// Moving forward
|
||||
p_desc = tu_desc_next(p_desc);
|
||||
}
|
||||
|
||||
// Check for nothing found - we can rely on this since EP descriptors are never the last descriptors, there are always also class specific EP descriptors following!
|
||||
TU_VERIFY(p_desc < p_desc_end);
|
||||
// // Check for nothing found - we can rely on this since EP descriptors are never the last descriptors, there are always also class specific EP descriptors following!
|
||||
// TU_VERIFY(p_desc < p_desc_end);
|
||||
|
||||
// Save current alternative interface setting
|
||||
_audiod_itf[idxDriver].altSetting[idxItf] = alt;
|
||||
@ -827,6 +830,8 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *
|
||||
if (!tud_audio_set_itf_cb(rhport, p_request)) return false;
|
||||
}
|
||||
|
||||
// Start sending or receiving?
|
||||
|
||||
tud_control_status(rhport, p_request);
|
||||
|
||||
return true;
|
||||
|
@ -673,6 +673,43 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * desc_edpt)
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Close an EP.
|
||||
*
|
||||
* Currently, we only deactivate the EPs and do not fully disable them - this might not be necessary!
|
||||
*
|
||||
*/
|
||||
void dcd_edpt_close (uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
(void)rhport;
|
||||
uint32_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint32_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
USB_OTG_DeviceTypeDef * dev = DEVICE_BASE(rhport);
|
||||
|
||||
if(dir == TUSB_DIR_IN)
|
||||
{
|
||||
USB_OTG_INEndpointTypeDef * in_ep = IN_EP_BASE(rhport);
|
||||
|
||||
// Disable interrupt for this EP
|
||||
dev->DAINTMSK &= ~(1 << (USB_OTG_DAINTMSK_IEPM_Pos + epnum));
|
||||
|
||||
// Clear USB active EP
|
||||
in_ep[epnum].DIEPCTL &= ~USB_OTG_DIEPCTL_USBAEP;
|
||||
}
|
||||
else
|
||||
{
|
||||
USB_OTG_OUTEndpointTypeDef * out_ep = OUT_EP_BASE(rhport);
|
||||
|
||||
// Disable interrupt for this EP
|
||||
dev->DAINTMSK &= ~(1 << (USB_OTG_DAINTMSK_OEPM_Pos + epnum));;
|
||||
|
||||
// Clear USB active EP bit
|
||||
out_ep[epnum].DOEPCTL &= ~USB_OTG_DOEPCTL_USBAEP;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes)
|
||||
{
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
|
Loading…
x
Reference in New Issue
Block a user