28#ifndef _TUSB_AUDIO_DEVICE_H_
29#define _TUSB_AUDIO_DEVICE_H_
39#ifndef CFG_TUD_AUDIO_FUNC_1_DESC_LEN
40#error You must tell the driver the length of the audio function descriptor including IAD descriptor
43#ifndef CFG_TUD_AUDIO_FUNC_2_DESC_LEN
44#error You must tell the driver the length of the audio function descriptor including IAD descriptor
48#ifndef CFG_TUD_AUDIO_FUNC_3_DESC_LEN
49#error You must tell the driver the length of the audio function descriptor including IAD descriptor
54#ifndef CFG_TUD_AUDIO_FUNC_1_N_AS_INT
55#error You must tell the driver the number of Standard AS Interface Descriptors you have defined in the audio function descriptor!
58#ifndef CFG_TUD_AUDIO_FUNC_2_N_AS_INT
59#error You must tell the driver the number of Standard AS Interface Descriptors you have defined in the audio function descriptor!
63#ifndef CFG_TUD_AUDIO_FUNC_3_N_AS_INT
64#error You must tell the driver the number of Standard AS Interface Descriptors you have defined in the audio function descriptor!
69#ifndef CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ
70#error You must define an audio class control request buffer size!
74#ifndef CFG_TUD_AUDIO_FUNC_2_CTRL_BUF_SZ
75#error You must define an audio class control request buffer size!
80#ifndef CFG_TUD_AUDIO_FUNC_3_CTRL_BUF_SZ
81#error You must define an audio class control request buffer size!
86#ifndef CFG_TUD_AUDIO_ENABLE_EP_IN
87#define CFG_TUD_AUDIO_ENABLE_EP_IN 0
90#ifndef CFG_TUD_AUDIO_ENABLE_EP_OUT
91#define CFG_TUD_AUDIO_ENABLE_EP_OUT 0
95#if CFG_TUD_AUDIO_ENABLE_EP_IN
96#ifndef CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX
97#error You must tell the driver the biggest EP IN size!
100#ifndef CFG_TUD_AUDIO_FUNC_2_EP_IN_SZ_MAX
101#error You must tell the driver the biggest EP IN size!
105#ifndef CFG_TUD_AUDIO_FUNC_3_EP_IN_SZ_MAX
106#error You must tell the driver the biggest EP IN size!
111#if CFG_TUD_AUDIO_ENABLE_EP_OUT
112#ifndef CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX
113#error You must tell the driver the biggest EP OUT size!
116#ifndef CFG_TUD_AUDIO_FUNC_2_EP_OUT_SZ_MAX
117#error You must tell the driver the biggest EP OUT size!
121#ifndef CFG_TUD_AUDIO_FUNC_3_EP_OUT_SZ_MAX
122#error You must tell the driver the biggest EP OUT size!
128#ifndef CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ
129#define CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ 0
131#ifndef CFG_TUD_AUDIO_FUNC_2_EP_IN_SW_BUF_SZ
132#define CFG_TUD_AUDIO_FUNC_2_EP_IN_SW_BUF_SZ 0
134#ifndef CFG_TUD_AUDIO_FUNC_3_EP_IN_SW_BUF_SZ
135#define CFG_TUD_AUDIO_FUNC_3_EP_IN_SW_BUF_SZ 0
138#ifndef CFG_TUD_AUDIO_FUNC_1_EP_OUT_SW_BUF_SZ
139#define CFG_TUD_AUDIO_FUNC_1_EP_OUT_SW_BUF_SZ 0
141#ifndef CFG_TUD_AUDIO_FUNC_2_EP_OUT_SW_BUF_SZ
142#define CFG_TUD_AUDIO_FUNC_2_EP_OUT_SW_BUF_SZ 0
144#ifndef CFG_TUD_AUDIO_FUNC_3_EP_OUT_SW_BUF_SZ
145#define CFG_TUD_AUDIO_FUNC_3_EP_OUT_SW_BUF_SZ 0
148#if CFG_TUD_AUDIO_ENABLE_EP_IN
149#if CFG_TUD_AUDIO_FUNC_1_EP_IN_SW_BUF_SZ < CFG_TUD_AUDIO_FUNC_1_EP_IN_SZ_MAX
150#error EP software buffer size MUST BE at least as big as maximum EP size
154#if CFG_TUD_AUDIO_FUNC_2_EP_IN_SW_BUF_SZ < CFG_TUD_AUDIO_FUNC_2_EP_IN_SZ_MAX
155#error EP software buffer size MUST BE at least as big as maximum EP size
160#if CFG_TUD_AUDIO_FUNC_3_EP_IN_SW_BUF_SZ < CFG_TUD_AUDIO_FUNC_3_EP_IN_SZ_MAX
161#error EP software buffer size MUST BE at least as big as maximum EP size
166#if CFG_TUD_AUDIO_ENABLE_EP_OUT
167#if CFG_TUD_AUDIO_FUNC_1_EP_OUT_SW_BUF_SZ < CFG_TUD_AUDIO_FUNC_1_EP_OUT_SZ_MAX
168#error EP software buffer size MUST BE at least as big as maximum EP size
172#if CFG_TUD_AUDIO_FUNC_2_EP_OUT_SW_BUF_SZ < CFG_TUD_AUDIO_FUNC_2_EP_OUT_SZ_MAX
173#error EP software buffer size MUST BE at least as big as maximum EP size
178#if CFG_TUD_AUDIO_FUNC_3_EP_OUT_SW_BUF_SZ < CFG_TUD_AUDIO_FUNC_3_EP_OUT_SZ_MAX
179#error EP software buffer size MUST BE at least as big as maximum EP size
185#ifndef CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
186#define CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP 0
190#ifndef CFG_TUD_AUDIO_ENABLE_FEEDBACK_FORMAT_CORRECTION
191#define CFG_TUD_AUDIO_ENABLE_FEEDBACK_FORMAT_CORRECTION 0
195#ifndef CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
196#define CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN 0
199#ifndef CFG_TUD_AUDIO_INT_CTR_EP_IN_SW_BUFFER_SIZE
200#define CFG_TUD_AUDIO_INT_CTR_EP_IN_SW_BUFFER_SIZE 6
249#ifndef CFG_TUD_AUDIO_ENABLE_ENCODING
250#define CFG_TUD_AUDIO_ENABLE_ENCODING 0
253#ifndef CFG_TUD_AUDIO_ENABLE_DECODING
254#define CFG_TUD_AUDIO_ENABLE_DECODING 0
258#ifndef CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING
259#define CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING 0
262#ifndef CFG_TUD_AUDIO_ENABLE_TYPE_I_DECODING
263#define CFG_TUD_AUDIO_ENABLE_TYPE_I_DECODING 0
268#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING && CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING
269#ifndef CFG_TUD_AUDIO_FUNC_1_CHANNEL_PER_FIFO_TX
270#error You must tell the driver the number of channels per FIFO for the interleaved encoding! E.g. for an I2S interface having two channels, CHANNEL_PER_FIFO = 2 as the I2S stream having two channels is usually saved within one FIFO
273#ifndef CFG_TUD_AUDIO_FUNC_2_CHANNEL_PER_FIFO_TX
274#error You must tell the driver the number of channels per FIFO for the interleaved encoding! E.g. for an I2S interface having two channels, CHANNEL_PER_FIFO = 2 as the I2S stream having two channels is usually saved within one FIFO
278#ifndef CFG_TUD_AUDIO_FUNC_3_CHANNEL_PER_FIFO_TX
279#error You must tell the driver the number of channels per FIFO for the interleaved encoding! E.g. for an I2S interface having two channels, CHANNEL_PER_FIFO = 2 as the I2S stream having two channels is usually saved within one FIFO
284#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING && CFG_TUD_AUDIO_ENABLE_TYPE_I_DECODING
285#ifndef CFG_TUD_AUDIO_FUNC_1_CHANNEL_PER_FIFO_RX
286#error You must tell the driver the number of channels per FIFO for the interleaved encoding! E.g. for an I2S interface having two channels, CHANNEL_PER_FIFO = 2 as the I2S stream having two channels is usually saved within one FIFO
289#ifndef CFG_TUD_AUDIO_FUNC_2_CHANNEL_PER_FIFO_RX
290#error You must tell the driver the number of channels per FIFO for the interleaved encoding! E.g. for an I2S interface having two channels, CHANNEL_PER_FIFO = 2 as the I2S stream having two channels is usually saved within one FIFO
294#ifndef CFG_TUD_AUDIO_FUNC_3_CHANNEL_PER_FIFO_RX
295#error You must tell the driver the number of channels per FIFO for the interleaved encoding! E.g. for an I2S interface having two channels, CHANNEL_PER_FIFO = 2 as the I2S stream having two channels is usually saved within one FIFO
303#ifndef CFG_TUD_AUDIO_FUNC_1_N_TX_SUPP_SW_FIFO
304#define CFG_TUD_AUDIO_FUNC_1_N_TX_SUPP_SW_FIFO 0
306#ifndef CFG_TUD_AUDIO_FUNC_2_N_TX_SUPP_SW_FIFO
307#define CFG_TUD_AUDIO_FUNC_2_N_TX_SUPP_SW_FIFO 0
309#ifndef CFG_TUD_AUDIO_FUNC_3_N_TX_SUPP_SW_FIFO
310#define CFG_TUD_AUDIO_FUNC_3_N_TX_SUPP_SW_FIFO 0
313#ifndef CFG_TUD_AUDIO_FUNC_1_N_RX_SUPP_SW_FIFO
314#define CFG_TUD_AUDIO_FUNC_1_N_RX_SUPP_SW_FIFO 0
316#ifndef CFG_TUD_AUDIO_FUNC_2_N_RX_SUPP_SW_FIFO
317#define CFG_TUD_AUDIO_FUNC_2_N_RX_SUPP_SW_FIFO 0
319#ifndef CFG_TUD_AUDIO_FUNC_3_N_RX_SUPP_SW_FIFO
320#define CFG_TUD_AUDIO_FUNC_3_N_RX_SUPP_SW_FIFO 0
324#ifndef CFG_TUD_AUDIO_FUNC_1_TX_SUPP_SW_FIFO_SZ
325#define CFG_TUD_AUDIO_FUNC_1_TX_SUPP_SW_FIFO_SZ 0
327#ifndef CFG_TUD_AUDIO_FUNC_2_TX_SUPP_SW_FIFO_SZ
328#define CFG_TUD_AUDIO_FUNC_2_TX_SUPP_SW_FIFO_SZ 0
330#ifndef CFG_TUD_AUDIO_FUNC_3_TX_SUPP_SW_FIFO_SZ
331#define CFG_TUD_AUDIO_FUNC_3_TX_SUPP_SW_FIFO_SZ 0
334#ifndef CFG_TUD_AUDIO_FUNC_1_RX_SUPP_SW_FIFO_SZ
335#define CFG_TUD_AUDIO_FUNC_1_RX_SUPP_SW_FIFO_SZ 0
337#ifndef CFG_TUD_AUDIO_FUNC_2_RX_SUPP_SW_FIFO_SZ
338#define CFG_TUD_AUDIO_FUNC_2_RX_SUPP_SW_FIFO_SZ 0
340#ifndef CFG_TUD_AUDIO_FUNC_3_RX_SUPP_SW_FIFO_SZ
341#define CFG_TUD_AUDIO_FUNC_3_RX_SUPP_SW_FIFO_SZ 0
362bool tud_audio_n_mounted (uint8_t func_id);
364#if CFG_TUD_AUDIO_ENABLE_EP_OUT && !CFG_TUD_AUDIO_ENABLE_DECODING
365uint16_t tud_audio_n_available (uint8_t func_id);
366uint16_t tud_audio_n_read (uint8_t func_id,
void* buffer, uint16_t bufsize);
367bool tud_audio_n_clear_ep_out_ff (uint8_t func_id);
368tu_fifo_t* tud_audio_n_get_ep_out_ff (uint8_t func_id);
371#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING
372bool tud_audio_n_clear_rx_support_ff (uint8_t func_id, uint8_t ff_idx);
373uint16_t tud_audio_n_available_support_ff (uint8_t func_id, uint8_t ff_idx);
374uint16_t tud_audio_n_read_support_ff (uint8_t func_id, uint8_t ff_idx,
void* buffer, uint16_t bufsize);
375tu_fifo_t* tud_audio_n_get_rx_support_ff (uint8_t func_id, uint8_t ff_idx);
378#if CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_ENCODING
379uint16_t tud_audio_n_write (uint8_t func_id,
const void * data, uint16_t len);
380bool tud_audio_n_clear_ep_in_ff (uint8_t func_id);
381tu_fifo_t* tud_audio_n_get_ep_in_ff (uint8_t func_id);
384#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING
385uint16_t tud_audio_n_flush_tx_support_ff (uint8_t func_id);
386bool tud_audio_n_clear_tx_support_ff (uint8_t func_id, uint8_t ff_idx);
387uint16_t tud_audio_n_write_support_ff (uint8_t func_id, uint8_t ff_idx,
const void * data, uint16_t len);
388tu_fifo_t* tud_audio_n_get_tx_support_ff (uint8_t func_id, uint8_t ff_idx);
391#if CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
392uint16_t tud_audio_int_ctr_n_write (uint8_t func_id, uint8_t
const* buffer, uint16_t len);
399static inline bool tud_audio_mounted (
void);
403#if CFG_TUD_AUDIO_ENABLE_EP_OUT && !CFG_TUD_AUDIO_ENABLE_DECODING
404static inline uint16_t tud_audio_available (
void);
405static inline bool tud_audio_clear_ep_out_ff (
void);
406static inline uint16_t tud_audio_read (
void* buffer, uint16_t bufsize);
407static inline tu_fifo_t* tud_audio_get_ep_out_ff (
void);
410#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING
411static inline bool tud_audio_clear_rx_support_ff (uint8_t ff_idx);
412static inline uint16_t tud_audio_available_support_ff (uint8_t ff_idx);
413static inline uint16_t tud_audio_read_support_ff (uint8_t ff_idx,
void* buffer, uint16_t bufsize);
414static inline tu_fifo_t* tud_audio_get_rx_support_ff (uint8_t ff_idx);
419#if CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_ENCODING
420static inline uint16_t tud_audio_write (
const void * data, uint16_t len);
421static inline bool tud_audio_clear_ep_in_ff (
void);
422static inline tu_fifo_t* tud_audio_get_ep_in_ff (
void);
425#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING
426static inline uint16_t tud_audio_flush_tx_support_ff (
void);
427static inline uint16_t tud_audio_clear_tx_support_ff (uint8_t ff_idx);
428static inline uint16_t tud_audio_write_support_ff (uint8_t ff_idx,
const void * data, uint16_t len);
429static inline tu_fifo_t* tud_audio_get_tx_support_ff (uint8_t ff_idx);
434#if CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
435static inline uint16_t tud_audio_int_ctr_write (uint8_t
const* buffer, uint16_t len);
444bool tud_audio_buffer_and_schedule_control_xfer(uint8_t rhport,
tusb_control_request_t const * p_request,
void* data, uint16_t len);
450#if CFG_TUD_AUDIO_ENABLE_EP_IN
451TU_ATTR_WEAK
bool tud_audio_tx_done_pre_load_cb(uint8_t rhport, uint8_t func_id, uint8_t ep_in, uint8_t cur_alt_setting);
452TU_ATTR_WEAK
bool tud_audio_tx_done_post_load_cb(uint8_t rhport, uint16_t n_bytes_copied, uint8_t func_id, uint8_t ep_in, uint8_t cur_alt_setting);
455#if CFG_TUD_AUDIO_ENABLE_EP_OUT
456TU_ATTR_WEAK
bool tud_audio_rx_done_pre_read_cb(uint8_t rhport, uint16_t n_bytes_received, uint8_t func_id, uint8_t ep_out, uint8_t cur_alt_setting);
457TU_ATTR_WEAK
bool tud_audio_rx_done_post_read_cb(uint8_t rhport, uint16_t n_bytes_received, uint8_t func_id, uint8_t ep_out, uint8_t cur_alt_setting);
460#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
461TU_ATTR_WEAK
void tud_audio_fb_done_cb(uint8_t func_id);
487bool tud_audio_n_fb_set(uint8_t func_id, uint32_t feedback);
488static inline bool tud_audio_fb_set(uint32_t feedback);
494uint32_t tud_audio_feedback_update(uint8_t func_id, uint32_t cycles);
497 AUDIO_FEEDBACK_METHOD_DISABLED,
498 AUDIO_FEEDBACK_METHOD_FREQUENCY_FIXED,
499 AUDIO_FEEDBACK_METHOD_FREQUENCY_FLOAT,
500 AUDIO_FEEDBACK_METHOD_FREQUENCY_POWER_OF_2,
508 uint32_t sample_freq;
517 uint32_t threshold_bytes;
521}audio_feedback_params_t;
524TU_ATTR_WEAK
void tud_audio_feedback_params_cb(uint8_t func_id, uint8_t alt_itf, audio_feedback_params_t* feedback_param);
530TU_ATTR_WEAK TU_ATTR_FAST_FUNC
void tud_audio_feedback_interval_isr(uint8_t func_id, uint32_t frame_number, uint8_t interval_shift);
534#if CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
535TU_ATTR_WEAK
bool tud_audio_int_ctr_done_cb(uint8_t rhport, uint16_t n_bytes_copied);
545TU_ATTR_WEAK
bool tud_audio_set_req_ep_cb(uint8_t rhport,
tusb_control_request_t const * p_request, uint8_t *pBuff);
548TU_ATTR_WEAK
bool tud_audio_set_req_itf_cb(uint8_t rhport,
tusb_control_request_t const * p_request, uint8_t *pBuff);
551TU_ATTR_WEAK
bool tud_audio_set_req_entity_cb(uint8_t rhport,
tusb_control_request_t const * p_request, uint8_t *pBuff);
566static inline bool tud_audio_mounted(
void)
568 return tud_audio_n_mounted(0);
573#if CFG_TUD_AUDIO_ENABLE_EP_OUT && !CFG_TUD_AUDIO_ENABLE_DECODING
575static inline uint16_t tud_audio_available(
void)
577 return tud_audio_n_available(0);
580static inline uint16_t tud_audio_read(
void* buffer, uint16_t bufsize)
582 return tud_audio_n_read(0, buffer, bufsize);
585static inline bool tud_audio_clear_ep_out_ff(
void)
587 return tud_audio_n_clear_ep_out_ff(0);
590static inline tu_fifo_t* tud_audio_get_ep_out_ff(
void)
592 return tud_audio_n_get_ep_out_ff(0);
597#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING
599static inline bool tud_audio_clear_rx_support_ff(uint8_t ff_idx)
601 return tud_audio_n_clear_rx_support_ff(0, ff_idx);
604static inline uint16_t tud_audio_available_support_ff(uint8_t ff_idx)
606 return tud_audio_n_available_support_ff(0, ff_idx);
609static inline uint16_t tud_audio_read_support_ff(uint8_t ff_idx,
void* buffer, uint16_t bufsize)
611 return tud_audio_n_read_support_ff(0, ff_idx, buffer, bufsize);
614static inline tu_fifo_t* tud_audio_get_rx_support_ff(uint8_t ff_idx)
616 return tud_audio_n_get_rx_support_ff(0, ff_idx);
623#if CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_ENCODING
625static inline uint16_t tud_audio_write(
const void * data, uint16_t len)
627 return tud_audio_n_write(0, data, len);
630static inline bool tud_audio_clear_ep_in_ff(
void)
632 return tud_audio_n_clear_ep_in_ff(0);
635static inline tu_fifo_t* tud_audio_get_ep_in_ff(
void)
637 return tud_audio_n_get_ep_in_ff(0);
642#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING
644static inline uint16_t tud_audio_flush_tx_support_ff(
void)
646 return tud_audio_n_flush_tx_support_ff(0);
649static inline uint16_t tud_audio_clear_tx_support_ff(uint8_t ff_idx)
651 return tud_audio_n_clear_tx_support_ff(0, ff_idx);
654static inline uint16_t tud_audio_write_support_ff(uint8_t ff_idx,
const void * data, uint16_t len)
656 return tud_audio_n_write_support_ff(0, ff_idx, data, len);
659static inline tu_fifo_t* tud_audio_get_tx_support_ff(uint8_t ff_idx)
661 return tud_audio_n_get_tx_support_ff(0, ff_idx);
666#if CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
667static inline uint16_t tud_audio_int_ctr_write(uint8_t
const* buffer, uint16_t len)
669 return tud_audio_int_ctr_n_write(0, buffer, len);
673#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
675static inline bool tud_audio_fb_set(uint32_t feedback)
677 return tud_audio_n_fb_set(0, feedback);
685void audiod_init (
void);
686void audiod_reset (uint8_t rhport);
689bool audiod_xfer_cb (uint8_t rhport, uint8_t edpt_addr, xfer_result_t result, uint32_t xferred_bytes);
690void audiod_sof_isr (uint8_t rhport, uint32_t frame_count);
AUDIO Channel Cluster Descriptor (4.1)
Definition audio.h:647
Definition tusb_fifo.h:108