blob: 5a469523c9fee2f1c3851c7b125c26578033bdba [file] [log] [blame]
Austin Schuh41baf202022-01-01 14:33:40 -08001/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2020 Ha Thach (tinyusb.org)
5 * Copyright (c) 2020 Reinhard Panhuber
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 *
25 * This file is part of the TinyUSB stack.
26 */
27
28#ifndef _TUSB_AUDIO_DEVICE_H_
29#define _TUSB_AUDIO_DEVICE_H_
30
31#include "audio.h"
32
33//--------------------------------------------------------------------+
34// Class Driver Configuration
35//--------------------------------------------------------------------+
36
37// All sizes are in bytes!
38
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
41#endif
42#if CFG_TUD_AUDIO > 1
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
45#endif
46#endif
47#if CFG_TUD_AUDIO > 2
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
50#endif
51#endif
52
53// Number of Standard AS Interface Descriptors (4.9.1) defined per audio function - this is required to be able to remember the current alternate settings of these interfaces
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!
56#endif
57#if CFG_TUD_AUDIO > 1
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!
60#endif
61#endif
62#if CFG_TUD_AUDIO > 2
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!
65#endif
66#endif
67
68// Size of control buffer used to receive and send control messages via EP0 - has to be big enough to hold your biggest request structure e.g. range requests with multiple intervals defined or cluster descriptors
69#ifndef CFG_TUD_AUDIO_FUNC_1_CTRL_BUF_SZ
70#error You must define an audio class control request buffer size!
71#endif
72
73#if CFG_TUD_AUDIO > 1
74#ifndef CFG_TUD_AUDIO_FUNC_2_CTRL_BUF_SZ
75#error You must define an audio class control request buffer size!
76#endif
77#endif
78
79#if CFG_TUD_AUDIO > 2
80#ifndef CFG_TUD_AUDIO_FUNC_3_CTRL_BUF_SZ
81#error You must define an audio class control request buffer size!
82#endif
83#endif
84
85// End point sizes IN BYTES - Limits: Full Speed <= 1023, High Speed <= 1024
86#ifndef CFG_TUD_AUDIO_ENABLE_EP_IN
87#define CFG_TUD_AUDIO_ENABLE_EP_IN 0 // TX
88#endif
89
90#ifndef CFG_TUD_AUDIO_ENABLE_EP_OUT
91#define CFG_TUD_AUDIO_ENABLE_EP_OUT 0 // RX
92#endif
93
94// Maximum EP sizes for all alternate AS interface settings - used for checks and buffer allocation
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!
98#endif
99#if CFG_TUD_AUDIO > 1
100#ifndef CFG_TUD_AUDIO_FUNC_2_EP_IN_SZ_MAX
101#error You must tell the driver the biggest EP IN size!
102#endif
103#endif
104#if CFG_TUD_AUDIO > 2
105#ifndef CFG_TUD_AUDIO_FUNC_3_EP_IN_SZ_MAX
106#error You must tell the driver the biggest EP IN size!
107#endif
108#endif
109#endif // CFG_TUD_AUDIO_ENABLE_EP_IN
110
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!
114#endif
115#if CFG_TUD_AUDIO > 1
116#ifndef CFG_TUD_AUDIO_FUNC_2_EP_OUT_SZ_MAX
117#error You must tell the driver the biggest EP OUT size!
118#endif
119#endif
120#if CFG_TUD_AUDIO > 2
121#ifndef CFG_TUD_AUDIO_FUNC_3_EP_OUT_SZ_MAX
122#error You must tell the driver the biggest EP OUT size!
123#endif
124#endif
125#endif // CFG_TUD_AUDIO_ENABLE_EP_OUT
126
127// Software EP FIFO buffer sizes - must be >= max EP SIZEs!
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
130#endif
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
133#endif
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
136#endif
137
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
140#endif
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
143#endif
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
146#endif
147
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
151#endif
152
153#if CFG_TUD_AUDIO > 1
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
156#endif
157#endif
158
159#if CFG_TUD_AUDIO > 2
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
162#endif
163#endif
164#endif
165
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
169#endif
170
171#if CFG_TUD_AUDIO > 1
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
174#endif
175#endif
176
177#if CFG_TUD_AUDIO > 2
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
180#endif
181#endif
182#endif
183
184// Enable/disable feedback EP (required for asynchronous RX applications)
185#ifndef CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
186#define CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP 0 // Feedback - 0 or 1
187#endif
188
189// Audio interrupt control EP size - disabled if 0
190#ifndef CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
191#define CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN 0 // Audio interrupt control - if required - 6 Bytes according to UAC 2 specification (p. 74)
192#endif
193
194#ifndef CFG_TUD_AUDIO_INT_CTR_EP_IN_SW_BUFFER_SIZE
195#define CFG_TUD_AUDIO_INT_CTR_EP_IN_SW_BUFFER_SIZE 6 // Buffer size of audio control interrupt EP - 6 Bytes according to UAC 2 specification (p. 74)
196#endif
197
198// Use software encoding/decoding
199
200// The software coding feature of the driver is not mandatory. It is useful if, for instance, you have two I2S streams which need to be interleaved
201// into a single PCM stream as SAMPLE_1 | SAMPLE_2 | SAMPLE_3 | SAMPLE_4.
202//
203// Currently, only PCM type I encoding/decoding is supported!
204//
205// If the coding feature is to be used, support FIFOs need to be configured. Their sizes and numbers are defined below.
206
207// Encoding/decoding is done in software and thus time consuming. If you can encode/decode your stream more efficiently do not use the
208// support FIFOs but write/read directly into/from the EP_X_SW_BUFFER_FIFOs using
209// - tud_audio_n_write() or
210// - tud_audio_n_read().
211// To write/read to/from the support FIFOs use
212// - tud_audio_n_write_support_ff() or
213// - tud_audio_n_read_support_ff().
214//
215// The encoding/decoding format type done is defined below.
216//
217// The encoding/decoding starts when the private callback functions
218// - audio_tx_done_cb()
219// - audio_rx_done_cb()
220// are invoked. If support FIFOs are used, the corresponding encoding/decoding functions are called from there.
221// Once encoding/decoding is done the result is put directly into the EP_X_SW_BUFFER_FIFOs. You can use the public callback functions
222// - tud_audio_tx_done_pre_load_cb() or tud_audio_tx_done_post_load_cb()
223// - tud_audio_rx_done_pre_read_cb() or tud_audio_rx_done_post_read_cb()
224// if you want to get informed what happened.
225//
226// If you don't use the support FIFOs you may use the public callback functions
227// - tud_audio_tx_done_pre_load_cb() or tud_audio_tx_done_post_load_cb()
228// - tud_audio_rx_done_pre_read_cb() or tud_audio_rx_done_post_read_cb()
229// to write/read from/into the EP_X_SW_BUFFER_FIFOs at the right time.
230//
231// If you need a different encoding which is not support so far implement it in the
232// - audio_tx_done_cb()
233// - audio_rx_done_cb()
234// functions.
235
236// Enable encoding/decodings - for these to work, support FIFOs need to be setup in appropriate numbers and size
237// The actual coding parameters of active AS alternate interface is parsed from the descriptors
238
239// The item size of the FIFO is always fixed to one i.e. bytes! Furthermore, the actively used FIFO depth is reconfigured such that the depth is a multiple of the current sample size in order to avoid samples to get split up in case of a wrap in the FIFO ring buffer (depth = (max_depth / sampe_sz) * sampe_sz)!
240// This is important to remind in case you use DMAs! If the sample sizes changes, the DMA MUST BE RECONFIGURED just like the FIFOs for a different depth!!!
241
242// For PCM encoding/decoding
243
244#ifndef CFG_TUD_AUDIO_ENABLE_ENCODING
245#define CFG_TUD_AUDIO_ENABLE_ENCODING 0
246#endif
247
248#ifndef CFG_TUD_AUDIO_ENABLE_DECODING
249#define CFG_TUD_AUDIO_ENABLE_DECODING 0
250#endif
251
252// This enabling allows to save the current coding parameters e.g. # of bytes per sample etc. - TYPE_I includes common PCM encoding
253#ifndef CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING
254#define CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING 0
255#endif
256
257#ifndef CFG_TUD_AUDIO_ENABLE_TYPE_I_DECODING
258#define CFG_TUD_AUDIO_ENABLE_TYPE_I_DECODING 0
259#endif
260
261// Type I Coding parameters not given within UAC2 descriptors
262// It would be possible to allow for a more flexible setting and not fix this parameter as done below. However, this is most often not needed and kept for later if really necessary. The more flexible setting could be implemented within set_interface(), however, how the values are saved per alternate setting is to be determined!
263#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING && CFG_TUD_AUDIO_ENABLE_TYPE_I_ENCODING
264#ifndef CFG_TUD_AUDIO_FUNC_1_CHANNEL_PER_FIFO_TX
265#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
266#endif
267#if CFG_TUD_AUDIO > 1
268#ifndef CFG_TUD_AUDIO_FUNC_2_CHANNEL_PER_FIFO_TX
269#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
270#endif
271#endif
272#if CFG_TUD_AUDIO > 2
273#ifndef CFG_TUD_AUDIO_FUNC_3_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
275#endif
276#endif
277#endif
278
279#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING && CFG_TUD_AUDIO_ENABLE_TYPE_I_DECODING
280#ifndef CFG_TUD_AUDIO_FUNC_1_CHANNEL_PER_FIFO_RX
281#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
282#endif
283#if CFG_TUD_AUDIO > 1
284#ifndef CFG_TUD_AUDIO_FUNC_2_CHANNEL_PER_FIFO_RX
285#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
286#endif
287#endif
288#if CFG_TUD_AUDIO > 2
289#ifndef CFG_TUD_AUDIO_FUNC_3_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
291#endif
292#endif
293#endif
294
295// Remaining types not support so far
296
297// Number of support FIFOs to set up - multiple channels can be handled by one FIFO - very common is two channels per FIFO stemming from one I2S interface
298#ifndef CFG_TUD_AUDIO_FUNC_1_N_TX_SUPP_SW_FIFO
299#define CFG_TUD_AUDIO_FUNC_1_N_TX_SUPP_SW_FIFO 0
300#endif
301#ifndef CFG_TUD_AUDIO_FUNC_2_N_TX_SUPP_SW_FIFO
302#define CFG_TUD_AUDIO_FUNC_2_N_TX_SUPP_SW_FIFO 0
303#endif
304#ifndef CFG_TUD_AUDIO_FUNC_3_N_TX_SUPP_SW_FIFO
305#define CFG_TUD_AUDIO_FUNC_3_N_TX_SUPP_SW_FIFO 0
306#endif
307
308#ifndef CFG_TUD_AUDIO_FUNC_1_N_RX_SUPP_SW_FIFO
309#define CFG_TUD_AUDIO_FUNC_1_N_RX_SUPP_SW_FIFO 0
310#endif
311#ifndef CFG_TUD_AUDIO_FUNC_2_N_RX_SUPP_SW_FIFO
312#define CFG_TUD_AUDIO_FUNC_2_N_RX_SUPP_SW_FIFO 0
313#endif
314#ifndef CFG_TUD_AUDIO_FUNC_3_N_RX_SUPP_SW_FIFO
315#define CFG_TUD_AUDIO_FUNC_3_N_RX_SUPP_SW_FIFO 0
316#endif
317
318// Size of support FIFOs IN BYTES - if size > 0 there are as many FIFOs set up as CFG_TUD_AUDIO_FUNC_X_N_TX_SUPP_SW_FIFO and CFG_TUD_AUDIO_FUNC_X_N_RX_SUPP_SW_FIFO
319#ifndef CFG_TUD_AUDIO_FUNC_1_TX_SUPP_SW_FIFO_SZ
320#define CFG_TUD_AUDIO_FUNC_1_TX_SUPP_SW_FIFO_SZ 0 // FIFO size - minimum size: ceil(f_s/1000) * max(# of TX channels) / (# of TX support FIFOs) * max(# of bytes per sample)
321#endif
322#ifndef CFG_TUD_AUDIO_FUNC_2_TX_SUPP_SW_FIFO_SZ
323#define CFG_TUD_AUDIO_FUNC_2_TX_SUPP_SW_FIFO_SZ 0
324#endif
325#ifndef CFG_TUD_AUDIO_FUNC_3_TX_SUPP_SW_FIFO_SZ
326#define CFG_TUD_AUDIO_FUNC_3_TX_SUPP_SW_FIFO_SZ 0
327#endif
328
329#ifndef CFG_TUD_AUDIO_FUNC_1_RX_SUPP_SW_FIFO_SZ
330#define CFG_TUD_AUDIO_FUNC_1_RX_SUPP_SW_FIFO_SZ 0 // FIFO size - minimum size: ceil(f_s/1000) * max(# of RX channels) / (# of RX support FIFOs) * max(# of bytes per sample)
331#endif
332#ifndef CFG_TUD_AUDIO_FUNC_2_RX_SUPP_SW_FIFO_SZ
333#define CFG_TUD_AUDIO_FUNC_2_RX_SUPP_SW_FIFO_SZ 0
334#endif
335#ifndef CFG_TUD_AUDIO_FUNC_3_RX_SUPP_SW_FIFO_SZ
336#define CFG_TUD_AUDIO_FUNC_3_RX_SUPP_SW_FIFO_SZ 0
337#endif
338
339//static_assert(sizeof(tud_audio_desc_lengths) != CFG_TUD_AUDIO, "Supply audio function descriptor pack length!");
340
341// Supported types of this driver:
342// AUDIO_DATA_FORMAT_TYPE_I_PCM - Required definitions: CFG_TUD_AUDIO_N_CHANNELS and CFG_TUD_AUDIO_BYTES_PER_CHANNEL
343
344#ifdef __cplusplus
345extern "C" {
346#endif
347
348/** \addtogroup AUDIO_Serial Serial
349 * @{
350 * \defgroup AUDIO_Serial_Device Device
351 * @{ */
352
353//--------------------------------------------------------------------+
354// Application API (Multiple Interfaces)
355// CFG_TUD_AUDIO > 1
356//--------------------------------------------------------------------+
357bool tud_audio_n_mounted (uint8_t func_id);
358
359#if CFG_TUD_AUDIO_ENABLE_EP_OUT && !CFG_TUD_AUDIO_ENABLE_DECODING
360uint16_t tud_audio_n_available (uint8_t func_id);
361uint16_t tud_audio_n_read (uint8_t func_id, void* buffer, uint16_t bufsize);
362bool tud_audio_n_clear_ep_out_ff (uint8_t func_id); // Delete all content in the EP OUT FIFO
363tu_fifo_t* tud_audio_n_get_ep_out_ff (uint8_t func_id);
364#endif
365
366#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING
367bool tud_audio_n_clear_rx_support_ff (uint8_t func_id, uint8_t ff_idx); // Delete all content in the support RX FIFOs
368uint16_t tud_audio_n_available_support_ff (uint8_t func_id, uint8_t ff_idx);
369uint16_t tud_audio_n_read_support_ff (uint8_t func_id, uint8_t ff_idx, void* buffer, uint16_t bufsize);
370tu_fifo_t* tud_audio_n_get_rx_support_ff (uint8_t func_id, uint8_t ff_idx);
371#endif
372
373#if CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_ENCODING
374uint16_t tud_audio_n_write (uint8_t func_id, const void * data, uint16_t len);
375bool tud_audio_n_clear_ep_in_ff (uint8_t func_id); // Delete all content in the EP IN FIFO
376tu_fifo_t* tud_audio_n_get_ep_in_ff (uint8_t func_id);
377#endif
378
379#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING
380uint16_t tud_audio_n_flush_tx_support_ff (uint8_t func_id); // Force all content in the support TX FIFOs to be written into EP SW FIFO
381bool tud_audio_n_clear_tx_support_ff (uint8_t func_id, uint8_t ff_idx);
382uint16_t tud_audio_n_write_support_ff (uint8_t func_id, uint8_t ff_idx, const void * data, uint16_t len);
383tu_fifo_t* tud_audio_n_get_tx_support_ff (uint8_t func_id, uint8_t ff_idx);
384#endif
385
386#if CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
387uint16_t tud_audio_int_ctr_n_write (uint8_t func_id, uint8_t const* buffer, uint16_t len);
388#endif
389
390//--------------------------------------------------------------------+
391// Application API (Interface0)
392//--------------------------------------------------------------------+
393
394static inline bool tud_audio_mounted (void);
395
396// RX API
397
398#if CFG_TUD_AUDIO_ENABLE_EP_OUT && !CFG_TUD_AUDIO_ENABLE_DECODING
399static inline uint16_t tud_audio_available (void);
400static inline bool tud_audio_clear_ep_out_ff (void); // Delete all content in the EP OUT FIFO
401static inline uint16_t tud_audio_read (void* buffer, uint16_t bufsize);
402static inline tu_fifo_t* tud_audio_get_ep_out_ff (void);
403#endif
404
405#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING
406static inline bool tud_audio_clear_rx_support_ff (uint8_t ff_idx);
407static inline uint16_t tud_audio_available_support_ff (uint8_t ff_idx);
408static inline uint16_t tud_audio_read_support_ff (uint8_t ff_idx, void* buffer, uint16_t bufsize);
409static inline tu_fifo_t* tud_audio_get_rx_support_ff (uint8_t ff_idx);
410#endif
411
412// TX API
413
414#if CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_ENCODING
415static inline uint16_t tud_audio_write (const void * data, uint16_t len);
416static inline bool tud_audio_clear_ep_in_ff (void);
417static inline tu_fifo_t* tud_audio_get_ep_in_ff (void);
418#endif
419
420#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING
421static inline uint16_t tud_audio_flush_tx_support_ff (void);
422static inline uint16_t tud_audio_clear_tx_support_ff (uint8_t ff_idx);
423static inline uint16_t tud_audio_write_support_ff (uint8_t ff_idx, const void * data, uint16_t len);
424static inline tu_fifo_t* tud_audio_get_tx_support_ff (uint8_t ff_idx);
425#endif
426
427// INT CTR API
428
429#if CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
430static inline uint16_t tud_audio_int_ctr_write (uint8_t const* buffer, uint16_t len);
431#endif
432
433// Buffer control EP data and schedule a transmit
434// This function is intended to be used if you do not have a persistent buffer or memory location available (e.g. non-local variables) and need to answer onto a
435// get request. This function buffers your answer request frame into the control buffer of the corresponding audio driver and schedules a transmit for sending it.
436// Since transmission is triggered via interrupts, a persistent memory location is required onto which the buffer pointer in pointing. If you already have such
437// available you may directly use 'tud_control_xfer(...)'. In this case data does not need to be copied into an additional buffer and you save some time.
438// If the request's wLength is zero, a status packet is sent instead.
439bool tud_audio_buffer_and_schedule_control_xfer(uint8_t rhport, tusb_control_request_t const * p_request, void* data, uint16_t len);
440
441//--------------------------------------------------------------------+
442// Application Callback API (weak is optional)
443//--------------------------------------------------------------------+
444
445#if CFG_TUD_AUDIO_ENABLE_EP_IN
446TU_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);
447TU_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);
448#endif
449
450#if CFG_TUD_AUDIO_ENABLE_EP_OUT
451TU_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);
452TU_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);
453#endif
454
455#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
456TU_ATTR_WEAK bool tud_audio_fb_done_cb(uint8_t rhport);
457// User code should call this function with feedback value in 16.16 format for FS and HS.
458// Value will be corrected for FS to 10.14 format automatically.
459// (see Universal Serial Bus Specification Revision 2.0 5.12.4.2).
460// Feedback value will be sent at FB endpoint interval till it's changed.
461bool tud_audio_n_fb_set(uint8_t func_id, uint32_t feedback);
462static inline bool tud_audio_fb_set(uint32_t feedback);
463#endif
464
465#if CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
466TU_ATTR_WEAK bool tud_audio_int_ctr_done_cb(uint8_t rhport, uint16_t n_bytes_copied);
467#endif
468
469// Invoked when audio set interface request received
470TU_ATTR_WEAK bool tud_audio_set_itf_cb(uint8_t rhport, tusb_control_request_t const * p_request);
471
472// Invoked when audio set interface request received which closes an EP
473TU_ATTR_WEAK bool tud_audio_set_itf_close_EP_cb(uint8_t rhport, tusb_control_request_t const * p_request);
474
475// Invoked when audio class specific set request received for an EP
476TU_ATTR_WEAK bool tud_audio_set_req_ep_cb(uint8_t rhport, tusb_control_request_t const * p_request, uint8_t *pBuff);
477
478// Invoked when audio class specific set request received for an interface
479TU_ATTR_WEAK bool tud_audio_set_req_itf_cb(uint8_t rhport, tusb_control_request_t const * p_request, uint8_t *pBuff);
480
481// Invoked when audio class specific set request received for an entity
482TU_ATTR_WEAK bool tud_audio_set_req_entity_cb(uint8_t rhport, tusb_control_request_t const * p_request, uint8_t *pBuff);
483
484// Invoked when audio class specific get request received for an EP
485TU_ATTR_WEAK bool tud_audio_get_req_ep_cb(uint8_t rhport, tusb_control_request_t const * p_request);
486
487// Invoked when audio class specific get request received for an interface
488TU_ATTR_WEAK bool tud_audio_get_req_itf_cb(uint8_t rhport, tusb_control_request_t const * p_request);
489
490// Invoked when audio class specific get request received for an entity
491TU_ATTR_WEAK bool tud_audio_get_req_entity_cb(uint8_t rhport, tusb_control_request_t const * p_request);
492
493//--------------------------------------------------------------------+
494// Inline Functions
495//--------------------------------------------------------------------+
496
497static inline bool tud_audio_mounted(void)
498{
499 return tud_audio_n_mounted(0);
500}
501
502// RX API
503
504#if CFG_TUD_AUDIO_ENABLE_EP_OUT && !CFG_TUD_AUDIO_ENABLE_DECODING
505
506static inline uint16_t tud_audio_available(void)
507{
508 return tud_audio_n_available(0);
509}
510
511static inline uint16_t tud_audio_read(void* buffer, uint16_t bufsize)
512{
513 return tud_audio_n_read(0, buffer, bufsize);
514}
515
516static inline bool tud_audio_clear_ep_out_ff(void)
517{
518 return tud_audio_n_clear_ep_out_ff(0);
519}
520
521static inline tu_fifo_t* tud_audio_get_ep_out_ff(void)
522{
523 return tud_audio_n_get_ep_out_ff(0);
524}
525
526#endif
527
528#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_DECODING
529
530static inline bool tud_audio_clear_rx_support_ff(uint8_t ff_idx)
531{
532 return tud_audio_n_clear_rx_support_ff(0, ff_idx);
533}
534
535static inline uint16_t tud_audio_available_support_ff(uint8_t ff_idx)
536{
537 return tud_audio_n_available_support_ff(0, ff_idx);
538}
539
540static inline uint16_t tud_audio_read_support_ff(uint8_t ff_idx, void* buffer, uint16_t bufsize)
541{
542 return tud_audio_n_read_support_ff(0, ff_idx, buffer, bufsize);
543}
544
545static inline tu_fifo_t* tud_audio_get_rx_support_ff(uint8_t ff_idx)
546{
547 return tud_audio_n_get_rx_support_ff(0, ff_idx);
548}
549
550#endif
551
552// TX API
553
554#if CFG_TUD_AUDIO_ENABLE_EP_IN && !CFG_TUD_AUDIO_ENABLE_ENCODING
555
556static inline uint16_t tud_audio_write(const void * data, uint16_t len)
557{
558 return tud_audio_n_write(0, data, len);
559}
560
561static inline bool tud_audio_clear_ep_in_ff(void)
562{
563 return tud_audio_n_clear_ep_in_ff(0);
564}
565
566static inline tu_fifo_t* tud_audio_get_ep_in_ff(void)
567{
568 return tud_audio_n_get_ep_in_ff(0);
569}
570
571#endif
572
573#if CFG_TUD_AUDIO_ENABLE_EP_IN && CFG_TUD_AUDIO_ENABLE_ENCODING
574
575static inline uint16_t tud_audio_flush_tx_support_ff(void)
576{
577 return tud_audio_n_flush_tx_support_ff(0);
578}
579
580static inline uint16_t tud_audio_clear_tx_support_ff(uint8_t ff_idx)
581{
582 return tud_audio_n_clear_tx_support_ff(0, ff_idx);
583}
584
585static inline uint16_t tud_audio_write_support_ff(uint8_t ff_idx, const void * data, uint16_t len)
586{
587 return tud_audio_n_write_support_ff(0, ff_idx, data, len);
588}
589
590static inline tu_fifo_t* tud_audio_get_tx_support_ff(uint8_t ff_idx)
591{
592 return tud_audio_n_get_tx_support_ff(0, ff_idx);
593}
594
595#endif
596
597#if CFG_TUD_AUDIO_INT_CTR_EPSIZE_IN
598static inline uint16_t tud_audio_int_ctr_write(uint8_t const* buffer, uint16_t len)
599{
600 return tud_audio_int_ctr_n_write(0, buffer, len);
601}
602#endif
603
604#if CFG_TUD_AUDIO_ENABLE_EP_OUT && CFG_TUD_AUDIO_ENABLE_FEEDBACK_EP
605static inline bool tud_audio_fb_set(uint32_t feedback)
606{
607 return tud_audio_n_fb_set(0, feedback);
608}
609#endif
610
611//--------------------------------------------------------------------+
612// Internal Class Driver API
613//--------------------------------------------------------------------+
614void audiod_init (void);
615void audiod_reset (uint8_t rhport);
616uint16_t audiod_open (uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len);
617bool audiod_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
618bool audiod_xfer_cb (uint8_t rhport, uint8_t edpt_addr, xfer_result_t result, uint32_t xferred_bytes);
619
620#ifdef __cplusplus
621}
622#endif
623
624#endif /* _TUSB_AUDIO_DEVICE_H_ */
625
626/** @} */
627/** @} */