mirror of
https://github.com/hathach/tinyusb.git
synced 2025-03-26 08:37:16 +00:00
Merge pull request #1 from kasjer/kasjer/uac2
audio_device: Fix small issues here and there
This commit is contained in:
commit
e3840d6bc0
@ -80,7 +80,7 @@ typedef struct
|
|||||||
// FIFO
|
// FIFO
|
||||||
#if CFG_TUD_AUDIO_EPSIZE_IN && CFG_TUD_AUDIO_TX_FIFO_SIZE
|
#if CFG_TUD_AUDIO_EPSIZE_IN && CFG_TUD_AUDIO_TX_FIFO_SIZE
|
||||||
tu_fifo_t tx_ff[CFG_TUD_AUDIO_N_CHANNELS_TX];
|
tu_fifo_t tx_ff[CFG_TUD_AUDIO_N_CHANNELS_TX];
|
||||||
CFG_TUSB_MEM_ALIGN uint8_t tx_ff_buf[CFG_TUD_AUDIO_N_CHANNELS_TX][CFG_TUD_AUDIO_TX_FIFO_SIZE];
|
CFG_TUSB_MEM_ALIGN uint8_t tx_ff_buf[CFG_TUD_AUDIO_N_CHANNELS_TX][CFG_TUD_AUDIO_TX_FIFO_SIZE * CFG_TUD_AUDIO_TX_ITEMSIZE];
|
||||||
#if CFG_FIFO_MUTEX
|
#if CFG_FIFO_MUTEX
|
||||||
osal_mutex_def_t tx_ff_mutex[CFG_TUD_AUDIO_N_CHANNELS_TX];
|
osal_mutex_def_t tx_ff_mutex[CFG_TUD_AUDIO_N_CHANNELS_TX];
|
||||||
#endif
|
#endif
|
||||||
@ -88,7 +88,7 @@ typedef struct
|
|||||||
|
|
||||||
#if CFG_TUD_AUDIO_EPSIZE_OUT && CFG_TUD_AUDIO_RX_FIFO_SIZE
|
#if CFG_TUD_AUDIO_EPSIZE_OUT && CFG_TUD_AUDIO_RX_FIFO_SIZE
|
||||||
tu_fifo_t rx_ff[CFG_TUD_AUDIO_N_CHANNELS_RX];
|
tu_fifo_t rx_ff[CFG_TUD_AUDIO_N_CHANNELS_RX];
|
||||||
CFG_TUSB_MEM_ALIGN uint8_t rx_ff_buf[CFG_TUD_AUDIO_N_CHANNELS_RX][CFG_TUD_AUDIO_RX_FIFO_SIZE];
|
CFG_TUSB_MEM_ALIGN uint8_t rx_ff_buf[CFG_TUD_AUDIO_N_CHANNELS_RX][CFG_TUD_AUDIO_RX_FIFO_SIZE * CFG_TUD_AUDIO_RX_ITEMSIZE];
|
||||||
#if CFG_FIFO_MUTEX
|
#if CFG_FIFO_MUTEX
|
||||||
osal_mutex_def_t rx_ff_mutex[CFG_TUD_AUDIO_N_CHANNELS_RX];
|
osal_mutex_def_t rx_ff_mutex[CFG_TUD_AUDIO_N_CHANNELS_RX];
|
||||||
#endif
|
#endif
|
||||||
@ -404,10 +404,12 @@ static bool audio_tx_done_type_I_pcm_ff_cb(uint8_t rhport, audiod_interface_t* a
|
|||||||
TU_VERIFY(!usbd_edpt_busy(rhport, audio->ep_in));
|
TU_VERIFY(!usbd_edpt_busy(rhport, audio->ep_in));
|
||||||
|
|
||||||
// Determine amount of samples
|
// Determine amount of samples
|
||||||
uint16_t nSamplesPerChannelToSend = 0xFFFF;
|
uint16_t const nEndpointSampleCapacity = CFG_TUD_AUDIO_EPSIZE_IN / CFG_TUD_AUDIO_N_CHANNELS_TX / CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_TX;
|
||||||
|
uint16_t nSamplesPerChannelToSend = tu_fifo_count(&audio->tx_ff[0]);
|
||||||
|
uint16_t nBytesToSend;
|
||||||
uint8_t cntChannel;
|
uint8_t cntChannel;
|
||||||
|
|
||||||
for (cntChannel = 0; cntChannel < CFG_TUD_AUDIO_N_CHANNELS_TX; cntChannel++)
|
for (cntChannel = 1; cntChannel < CFG_TUD_AUDIO_N_CHANNELS_TX; cntChannel++)
|
||||||
{
|
{
|
||||||
if (audio->tx_ff[cntChannel].count < nSamplesPerChannelToSend)
|
if (audio->tx_ff[cntChannel].count < nSamplesPerChannelToSend)
|
||||||
{
|
{
|
||||||
@ -423,10 +425,8 @@ static bool audio_tx_done_type_I_pcm_ff_cb(uint8_t rhport, audiod_interface_t* a
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Limit to maximum sample number - THIS IS A POSSIBLE ERROR SOURCE IF TOO MANY SAMPLE WOULD NEED TO BE SENT BUT CAN NOT!
|
// Limit to maximum sample number - THIS IS A POSSIBLE ERROR SOURCE IF TOO MANY SAMPLE WOULD NEED TO BE SENT BUT CAN NOT!
|
||||||
if (nSamplesPerChannelToSend * CFG_TUD_AUDIO_N_CHANNELS_TX * CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_TX > CFG_TUD_AUDIO_EPSIZE_IN)
|
nSamplesPerChannelToSend = min(nSamplesPerChannelToSend, nEndpointSampleCapacity);
|
||||||
{
|
nBytesToSend = nSamplesPerChannelToSend * CFG_TUD_AUDIO_N_CHANNELS_TX * CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_TX;
|
||||||
nSamplesPerChannelToSend = CFG_TUD_AUDIO_EPSIZE_IN / CFG_TUD_AUDIO_N_CHANNELS_TX / CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_TX;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Encode
|
// Encode
|
||||||
uint16_t cntSample;
|
uint16_t cntSample;
|
||||||
@ -456,8 +456,8 @@ static bool audio_tx_done_type_I_pcm_ff_cb(uint8_t rhport, audiod_interface_t* a
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Schedule transmit
|
// Schedule transmit
|
||||||
TU_VERIFY(usbd_edpt_xfer(rhport, audio->ep_in, audio->epin_buf, nSamplesPerChannelToSend*CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_TX));
|
TU_VERIFY(usbd_edpt_xfer(rhport, audio->ep_in, audio->epin_buf, nBytesToSend));
|
||||||
*n_bytes_copied = nSamplesPerChannelToSend*CFG_TUD_AUDIO_N_BYTES_PER_SAMPLE_TX;
|
*n_bytes_copied = nBytesToSend;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -689,7 +689,7 @@ static bool audiod_set_interface(uint8_t rhport, tusb_control_request_t const *
|
|||||||
|
|
||||||
// Open new EP if necessary - EPs are only to be closed or opened for AS interfaces - Look for AS interface with correct alternate interface
|
// Open new EP if necessary - EPs are only to be closed or opened for AS interfaces - Look for AS interface with correct alternate interface
|
||||||
// Get pointer at end
|
// Get pointer at end
|
||||||
uint8_t const *p_desc_end = _audiod_itf[idxDriver].p_desc + tud_audio_desc_lengths[idxDriver];
|
uint8_t const *p_desc_end = _audiod_itf[idxDriver].p_desc + tud_audio_desc_lengths[idxDriver] - TUD_AUDIO_DESC_IAD_LEN;
|
||||||
|
|
||||||
// p_desc starts at required interface with alternate setting zero
|
// p_desc starts at required interface with alternate setting zero
|
||||||
while (p_desc < p_desc_end)
|
while (p_desc < p_desc_end)
|
||||||
@ -1002,10 +1002,10 @@ bool audiod_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t result, uint3
|
|||||||
// This is the only place where we can fill something into the EPs buffer!
|
// This is the only place where we can fill something into the EPs buffer!
|
||||||
|
|
||||||
// Load new data
|
// Load new data
|
||||||
uint16_t *n_bytes_copied = NULL;
|
uint16_t n_bytes_copied;
|
||||||
TU_VERIFY(audio_tx_done_cb(rhport, &_audiod_itf[idxDriver], n_bytes_copied));
|
TU_VERIFY(audio_tx_done_cb(rhport, &_audiod_itf[idxDriver], &n_bytes_copied));
|
||||||
|
|
||||||
if (*n_bytes_copied == 0)
|
if (n_bytes_copied == 0)
|
||||||
{
|
{
|
||||||
// Load with ZLP
|
// Load with ZLP
|
||||||
return usbd_edpt_xfer(rhport, ep_addr, NULL, 0);
|
return usbd_edpt_xfer(rhport, ep_addr, NULL, 0);
|
||||||
@ -1113,7 +1113,7 @@ static bool audiod_get_AS_interface_index(uint8_t itf, uint8_t *idxDriver, uint8
|
|||||||
if (_audiod_itf[i].p_desc)
|
if (_audiod_itf[i].p_desc)
|
||||||
{
|
{
|
||||||
// Get pointer at end
|
// Get pointer at end
|
||||||
uint8_t const *p_desc_end = _audiod_itf[i].p_desc + tud_audio_desc_lengths[i];
|
uint8_t const *p_desc_end = _audiod_itf[i].p_desc + tud_audio_desc_lengths[i] - TUD_AUDIO_DESC_IAD_LEN;
|
||||||
|
|
||||||
// Advance past AC descriptors
|
// Advance past AC descriptors
|
||||||
uint8_t const *p_desc = tu_desc_next(_audiod_itf[i].p_desc);
|
uint8_t const *p_desc = tu_desc_next(_audiod_itf[i].p_desc);
|
||||||
@ -1178,7 +1178,7 @@ static bool audiod_verify_itf_exists(uint8_t itf, uint8_t *idxDriver)
|
|||||||
{
|
{
|
||||||
// Get pointer at beginning and end
|
// Get pointer at beginning and end
|
||||||
uint8_t const *p_desc = _audiod_itf[i].p_desc;
|
uint8_t const *p_desc = _audiod_itf[i].p_desc;
|
||||||
uint8_t const *p_desc_end = _audiod_itf[i].p_desc + tud_audio_desc_lengths[i];
|
uint8_t const *p_desc_end = _audiod_itf[i].p_desc + tud_audio_desc_lengths[i] - TUD_AUDIO_DESC_IAD_LEN;
|
||||||
|
|
||||||
while (p_desc < p_desc_end)
|
while (p_desc < p_desc_end)
|
||||||
{
|
{
|
||||||
|
@ -171,7 +171,7 @@ uint16_t tud_audio_n_read (uint8_t itf, uint8_t channelId, void* buffer, u
|
|||||||
void tud_audio_n_read_flush (uint8_t itf, uint8_t channelId);
|
void tud_audio_n_read_flush (uint8_t itf, uint8_t channelId);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CFG_TUD_AUDIO_EPSIZE_IN && CFG_TUD_AUDIO_TX_BUFSIZE
|
#if CFG_TUD_AUDIO_EPSIZE_IN && CFG_TUD_AUDIO_TX_FIFO_SIZE
|
||||||
uint16_t tud_audio_n_write (uint8_t itf, uint8_t channelId, uint8_t const* buffer, uint16_t bufsize);
|
uint16_t tud_audio_n_write (uint8_t itf, uint8_t channelId, uint8_t const* buffer, uint16_t bufsize);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -194,7 +194,7 @@ inline uint16_t tud_audio_read (void* buffer, uint16_t bufsize);
|
|||||||
inline void tud_audio_read_flush (void);
|
inline void tud_audio_read_flush (void);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CFG_TUD_AUDIO_EPSIZE_IN && CFG_TUD_AUDIO_TX_BUFSIZE
|
#if CFG_TUD_AUDIO_EPSIZE_IN && CFG_TUD_AUDIO_TX_FIFO_SIZE
|
||||||
inline uint16_t tud_audio_write (uint8_t channelId, uint8_t const* buffer, uint16_t bufsize);
|
inline uint16_t tud_audio_write (uint8_t channelId, uint8_t const* buffer, uint16_t bufsize);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -263,12 +263,12 @@ inline bool tud_audio_mounted(void)
|
|||||||
return tud_audio_n_mounted(0);
|
return tud_audio_n_mounted(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CFG_TUD_AUDIO_EPSIZE_IN && CFG_TUD_AUDIO_TX_BUFSIZE
|
#if CFG_TUD_AUDIO_EPSIZE_IN && CFG_TUD_AUDIO_TX_FIFO_SIZE
|
||||||
inline uint16_t tud_audio_write (uint8_t channelId, uint8_t const* buffer, uint16_t bufsize) // Short version if only one audio function is used
|
inline uint16_t tud_audio_write (uint8_t channelId, uint8_t const* buffer, uint16_t bufsize) // Short version if only one audio function is used
|
||||||
{
|
{
|
||||||
return tud_audio_n_write(0, channelId, buffer, bufsize);
|
return tud_audio_n_write(0, channelId, buffer, bufsize);
|
||||||
}
|
}
|
||||||
#endif // CFG_TUD_AUDIO_EPSIZE_IN && CFG_TUD_AUDIO_TX_BUFSIZE
|
#endif // CFG_TUD_AUDIO_EPSIZE_IN && CFG_TUD_AUDIO_TX_FIFO_SIZE
|
||||||
|
|
||||||
#if CFG_TUD_AUDIO_EPSIZE_OUT && CFG_TUD_AUDIO_RX_BUFSIZE
|
#if CFG_TUD_AUDIO_EPSIZE_OUT && CFG_TUD_AUDIO_RX_BUFSIZE
|
||||||
inline uint16_t tud_audio_available(uint8_t channelId)
|
inline uint16_t tud_audio_available(uint8_t channelId)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user