mikroSDK Reference Manual
usbd.h
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2019 Ha Thach (tinyusb.org)
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 *
24 * This file is part of the TinyUSB stack.
25 */
26
27#ifndef _TUSB_USBD_H_
28#define _TUSB_USBD_H_
29
30#include "common/tusb_common.h"
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36//--------------------------------------------------------------------+
37// Application API
38//--------------------------------------------------------------------+
39
40// Init device stack
41bool tud_init (uint8_t rhport);
42
43// Check if device stack is already initialized
44bool tud_inited(void);
45
46// Task function should be called in main/rtos loop, extended version of tud_task()
47// - timeout_ms: millisecond to wait, zero = no wait, 0xFFFFFFFF = wait forever
48// - in_isr: if function is called in ISR
49void tud_task_ext(uint32_t timeout_ms, bool in_isr);
50
51// Task function should be called in main/rtos loop
52TU_ATTR_ALWAYS_INLINE static inline
53void tud_task (void)
54{
55 tud_task_ext(UINT32_MAX, false);
56}
57
58// Check if there is pending events need processing by tud_task()
59bool tud_task_event_ready(void);
60
61#ifndef _TUSB_DCD_H_
62extern void dcd_int_handler(uint8_t rhport);
63#endif
64
65// Interrupt handler, name alias to DCD
66#define tud_int_handler dcd_int_handler
67
68// Get current bus speed
69tusb_speed_t tud_speed_get(void);
70
71// Check if device is connected (may not mounted/configured yet)
72// True if just got out of Bus Reset and received the very first data from host
73bool tud_connected(void);
74
75// Check if device is connected and configured
76bool tud_mounted(void);
77
78// Check if device is suspended
79bool tud_suspended(void);
80
81// Check if device is ready to transfer
82TU_ATTR_ALWAYS_INLINE static inline
83bool tud_ready(void)
84{
85 return tud_mounted() && !tud_suspended();
86}
87
88// Remote wake up host, only if suspended and enabled by host
89bool tud_remote_wakeup(void);
90
91// Enable pull-up resistor on D+ D-
92// Return false on unsupported MCUs
93bool tud_disconnect(void);
94
95// Disable pull-up resistor on D+ D-
96// Return false on unsupported MCUs
97bool tud_connect(void);
98
99// Carry out Data and Status stage of control transfer
100// - If len = 0, it is equivalent to sending status only
101// - If len > wLength : it will be truncated
102bool tud_control_xfer(uint8_t rhport, tusb_control_request_t const * request, void* buffer, uint16_t len);
103
104// Send STATUS (zero length) packet
105bool tud_control_status(uint8_t rhport, tusb_control_request_t const * request);
106
107//--------------------------------------------------------------------+
108// Application Callbacks (WEAK is optional)
109//--------------------------------------------------------------------+
110
111// Invoked when received GET DEVICE DESCRIPTOR request
112// Application return pointer to descriptor
113uint8_t const * tud_descriptor_device_cb(void);
114
115// Invoked when received GET CONFIGURATION DESCRIPTOR request
116// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
117uint8_t const * tud_descriptor_configuration_cb(uint8_t index);
118
119// Invoked when received GET STRING DESCRIPTOR request
120// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
121uint16_t const* tud_descriptor_string_cb(uint8_t index, uint16_t langid);
122
123// Invoked when received GET BOS DESCRIPTOR request
124// Application return pointer to descriptor
125TU_ATTR_WEAK uint8_t const * tud_descriptor_bos_cb(void);
126
127// Invoked when received GET DEVICE QUALIFIER DESCRIPTOR request
128// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete.
129// device_qualifier descriptor describes information about a high-speed capable device that would
130// change if the device were operating at the other speed. If not highspeed capable stall this request.
131TU_ATTR_WEAK uint8_t const* tud_descriptor_device_qualifier_cb(void);
132
133// Invoked when received GET OTHER SEED CONFIGURATION DESCRIPTOR request
134// Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
135// Configuration descriptor in the other speed e.g if high speed then this is for full speed and vice versa
136TU_ATTR_WEAK uint8_t const* tud_descriptor_other_speed_configuration_cb(uint8_t index);
137
138// Invoked when device is mounted (configured)
139TU_ATTR_WEAK void tud_mount_cb(void);
140
141// Invoked when device is unmounted
142TU_ATTR_WEAK void tud_umount_cb(void);
143
144// Invoked when usb bus is suspended
145// Within 7ms, device must draw an average of current less than 2.5 mA from bus
146TU_ATTR_WEAK void tud_suspend_cb(bool remote_wakeup_en);
147
148// Invoked when usb bus is resumed
149TU_ATTR_WEAK void tud_resume_cb(void);
150
151// Invoked when received control request with VENDOR TYPE
152TU_ATTR_WEAK bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t const * request);
153
154//--------------------------------------------------------------------+
155// Binary Device Object Store (BOS) Descriptor Templates
156//--------------------------------------------------------------------+
157
158#define TUD_BOS_DESC_LEN 5
159
160// total length, number of device caps
161#define TUD_BOS_DESCRIPTOR(_total_len, _caps_num) \
162 5, TUSB_DESC_BOS, U16_TO_U8S_LE(_total_len), _caps_num
163
164// Device Capability Platform 128-bit UUID + Data
165#define TUD_BOS_PLATFORM_DESCRIPTOR(...) \
166 4+TU_ARGS_NUM(__VA_ARGS__), TUSB_DESC_DEVICE_CAPABILITY, DEVICE_CAPABILITY_PLATFORM, 0x00, __VA_ARGS__
167
168//------------- WebUSB BOS Platform -------------//
169
170// Descriptor Length
171#define TUD_BOS_WEBUSB_DESC_LEN 24
172
173// Vendor Code, iLandingPage
174#define TUD_BOS_WEBUSB_DESCRIPTOR(_vendor_code, _ipage) \
175 TUD_BOS_PLATFORM_DESCRIPTOR(TUD_BOS_WEBUSB_UUID, U16_TO_U8S_LE(0x0100), _vendor_code, _ipage)
176
177#define TUD_BOS_WEBUSB_UUID \
178 0x38, 0xB6, 0x08, 0x34, 0xA9, 0x09, 0xA0, 0x47, \
179 0x8B, 0xFD, 0xA0, 0x76, 0x88, 0x15, 0xB6, 0x65
180
181//------------- Microsoft OS 2.0 Platform -------------//
182#define TUD_BOS_MICROSOFT_OS_DESC_LEN 28
183
184// Total Length of descriptor set, vendor code
185#define TUD_BOS_MS_OS_20_DESCRIPTOR(_desc_set_len, _vendor_code) \
186 TUD_BOS_PLATFORM_DESCRIPTOR(TUD_BOS_MS_OS_20_UUID, U32_TO_U8S_LE(0x06030000), U16_TO_U8S_LE(_desc_set_len), _vendor_code, 0)
187
188#define TUD_BOS_MS_OS_20_UUID \
189 0xDF, 0x60, 0xDD, 0xD8, 0x89, 0x45, 0xC7, 0x4C, \
190 0x9C, 0xD2, 0x65, 0x9D, 0x9E, 0x64, 0x8A, 0x9F
191
192//--------------------------------------------------------------------+
193// Configuration Descriptor Templates
194//--------------------------------------------------------------------+
195
196#define TUD_CONFIG_DESC_LEN (9)
197
198// Config number, interface count, string index, total length, attribute, power in mA
199#define TUD_CONFIG_DESCRIPTOR(config_num, _itfcount, _stridx, _total_len, _attribute, _power_ma) \
200 9, TUSB_DESC_CONFIGURATION, U16_TO_U8S_LE(_total_len), _itfcount, config_num, _stridx, TU_BIT(7) | _attribute, (_power_ma)/2
201
202//--------------------------------------------------------------------+
203// CDC Descriptor Templates
204//--------------------------------------------------------------------+
205
206// Length of template descriptor: 66 bytes
207#define TUD_CDC_DESC_LEN (8+9+5+5+4+5+7+9+7+7)
208
209// CDC Descriptor Template
210// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
211#define TUD_CDC_DESCRIPTOR(_itfnum, _stridx, _ep_notif, _ep_notif_size, _epout, _epin, _epsize) \
212 /* Interface Associate */\
213 8, TUSB_DESC_INTERFACE_ASSOCIATION, _itfnum, 2, TUSB_CLASS_CDC, CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL, CDC_COMM_PROTOCOL_NONE, 0,\
214 /* CDC Control Interface */\
215 9, TUSB_DESC_INTERFACE, _itfnum, 0, 1, TUSB_CLASS_CDC, CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL, CDC_COMM_PROTOCOL_NONE, _stridx,\
216 /* CDC Header */\
217 5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_HEADER, U16_TO_U8S_LE(0x0120),\
218 /* CDC Call */\
219 5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_CALL_MANAGEMENT, 0, (uint8_t)((_itfnum) + 1),\
220 /* CDC ACM: support line request */\
221 4, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT, 2,\
222 /* CDC Union */\
223 5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_UNION, _itfnum, (uint8_t)((_itfnum) + 1),\
224 /* Endpoint Notification */\
225 7, TUSB_DESC_ENDPOINT, _ep_notif, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_ep_notif_size), 16,\
226 /* CDC Data Interface */\
227 9, TUSB_DESC_INTERFACE, (uint8_t)((_itfnum)+1), 0, 2, TUSB_CLASS_CDC_DATA, 0, 0, 0,\
228 /* Endpoint Out */\
229 7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\
230 /* Endpoint In */\
231 7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0
232
233//--------------------------------------------------------------------+
234// MSC Descriptor Templates
235//--------------------------------------------------------------------+
236
237// Length of template descriptor: 23 bytes
238#define TUD_MSC_DESC_LEN (9 + 7 + 7)
239
240// Interface number, string index, EP Out & EP In address, EP size
241#define TUD_MSC_DESCRIPTOR(_itfnum, _stridx, _epout, _epin, _epsize) \
242 /* Interface */\
243 9, TUSB_DESC_INTERFACE, _itfnum, 0, 2, TUSB_CLASS_MSC, MSC_SUBCLASS_SCSI, MSC_PROTOCOL_BOT, _stridx,\
244 /* Endpoint Out */\
245 7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\
246 /* Endpoint In */\
247 7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0
248
249
250//--------------------------------------------------------------------+
251// HID Descriptor Templates
252//--------------------------------------------------------------------+
253
254// Length of template descriptor: 25 bytes
255#define TUD_HID_DESC_LEN (9 + 9 + 7)
256
257// HID Input only descriptor
258// Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval
259#define TUD_HID_DESCRIPTOR(_itfnum, _stridx, _boot_protocol, _report_desc_len, _epin, _epsize, _ep_interval) \
260 /* Interface */\
261 9, TUSB_DESC_INTERFACE, _itfnum, 0, 1, TUSB_CLASS_HID, (uint8_t)((_boot_protocol) ? (uint8_t)HID_SUBCLASS_BOOT : 0), _boot_protocol, _stridx,\
262 /* HID descriptor */\
263 9, HID_DESC_TYPE_HID, U16_TO_U8S_LE(0x0111), 0, 1, HID_DESC_TYPE_REPORT, U16_TO_U8S_LE(_report_desc_len),\
264 /* Endpoint In */\
265 7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_epsize), _ep_interval
266
267// Length of template descriptor: 32 bytes
268#define TUD_HID_INOUT_DESC_LEN (9 + 9 + 7 + 7)
269
270// HID Input & Output descriptor
271// Interface number, string index, protocol, report descriptor len, EP OUT & IN address, size & polling interval
272#define TUD_HID_INOUT_DESCRIPTOR(_itfnum, _stridx, _boot_protocol, _report_desc_len, _epout, _epin, _epsize, _ep_interval) \
273 /* Interface */\
274 9, TUSB_DESC_INTERFACE, _itfnum, 0, 2, TUSB_CLASS_HID, (uint8_t)((_boot_protocol) ? (uint8_t)HID_SUBCLASS_BOOT : 0), _boot_protocol, _stridx,\
275 /* HID descriptor */\
276 9, HID_DESC_TYPE_HID, U16_TO_U8S_LE(0x0111), 0, 1, HID_DESC_TYPE_REPORT, U16_TO_U8S_LE(_report_desc_len),\
277 /* Endpoint Out */\
278 7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_epsize), _ep_interval, \
279 /* Endpoint In */\
280 7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_epsize), _ep_interval
281
282//--------------------------------------------------------------------+
283// MIDI Descriptor Templates
284// Note: MIDI v1.0 is based on Audio v1.0
285//--------------------------------------------------------------------+
286
287#define TUD_MIDI_DESC_HEAD_LEN (9 + 9 + 9 + 7)
288#define TUD_MIDI_DESC_HEAD(_itfnum, _stridx, _numcables) \
289 /* Audio Control (AC) Interface */\
290 9, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_CONTROL, AUDIO_FUNC_PROTOCOL_CODE_UNDEF, _stridx,\
291 /* AC Header */\
292 9, TUSB_DESC_CS_INTERFACE, AUDIO_CS_AC_INTERFACE_HEADER, U16_TO_U8S_LE(0x0100), U16_TO_U8S_LE(0x0009), 1, (uint8_t)((_itfnum) + 1),\
293 /* MIDI Streaming (MS) Interface */\
294 9, TUSB_DESC_INTERFACE, (uint8_t)((_itfnum) + 1), 0, 2, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_MIDI_STREAMING, AUDIO_FUNC_PROTOCOL_CODE_UNDEF, 0,\
295 /* MS Header */\
296 7, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_HEADER, U16_TO_U8S_LE(0x0100), U16_TO_U8S_LE(7 + (_numcables) * TUD_MIDI_DESC_JACK_LEN + 2 * TUD_MIDI_DESC_EP_LEN(_numcables))
297
298#define TUD_MIDI_JACKID_IN_EMB(_cablenum) \
299 (uint8_t)(((_cablenum) - 1) * 4 + 1)
300
301#define TUD_MIDI_JACKID_IN_EXT(_cablenum) \
302 (uint8_t)(((_cablenum) - 1) * 4 + 2)
303
304#define TUD_MIDI_JACKID_OUT_EMB(_cablenum) \
305 (uint8_t)(((_cablenum) - 1) * 4 + 3)
306
307#define TUD_MIDI_JACKID_OUT_EXT(_cablenum) \
308 (uint8_t)(((_cablenum) - 1) * 4 + 4)
309
310#define TUD_MIDI_DESC_JACK_LEN (6 + 6 + 9 + 9)
311#define TUD_MIDI_DESC_JACK_DESC(_cablenum, _stridx) \
312 /* MS In Jack (Embedded) */\
313 6, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_IN_JACK, MIDI_JACK_EMBEDDED, TUD_MIDI_JACKID_IN_EMB(_cablenum), _stridx,\
314 /* MS In Jack (External) */\
315 6, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_IN_JACK, MIDI_JACK_EXTERNAL, TUD_MIDI_JACKID_IN_EXT(_cablenum), _stridx,\
316 /* MS Out Jack (Embedded), connected to In Jack External */\
317 9, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_OUT_JACK, MIDI_JACK_EMBEDDED, TUD_MIDI_JACKID_OUT_EMB(_cablenum), 1, TUD_MIDI_JACKID_IN_EXT(_cablenum), 1, _stridx,\
318 /* MS Out Jack (External), connected to In Jack Embedded */\
319 9, TUSB_DESC_CS_INTERFACE, MIDI_CS_INTERFACE_OUT_JACK, MIDI_JACK_EXTERNAL, TUD_MIDI_JACKID_OUT_EXT(_cablenum), 1, TUD_MIDI_JACKID_IN_EMB(_cablenum), 1, _stridx
320
321#define TUD_MIDI_DESC_JACK(_cablenum) TUD_MIDI_DESC_JACK_DESC(_cablenum, 0)
322
323#define TUD_MIDI_DESC_EP_LEN(_numcables) (9 + 4 + (_numcables))
324#define TUD_MIDI_DESC_EP(_epout, _epsize, _numcables) \
325 /* Endpoint: Note Audio v1.0's endpoint has 9 bytes instead of 7 */\
326 9, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0, 0, 0, \
327 /* MS Endpoint (connected to embedded jack) */\
328 (uint8_t)(4 + (_numcables)), TUSB_DESC_CS_ENDPOINT, MIDI_CS_ENDPOINT_GENERAL, _numcables
329
330// Length of template descriptor (88 bytes)
331#define TUD_MIDI_DESC_LEN (TUD_MIDI_DESC_HEAD_LEN + TUD_MIDI_DESC_JACK_LEN + TUD_MIDI_DESC_EP_LEN(1) * 2)
332
333// MIDI simple descriptor
334// - 1 Embedded Jack In connected to 1 External Jack Out
335// - 1 Embedded Jack out connected to 1 External Jack In
336#define TUD_MIDI_DESCRIPTOR(_itfnum, _stridx, _epout, _epin, _epsize) \
337 TUD_MIDI_DESC_HEAD(_itfnum, _stridx, 1),\
338 TUD_MIDI_DESC_JACK_DESC(1, 0),\
339 TUD_MIDI_DESC_EP(_epout, _epsize, 1),\
340 TUD_MIDI_JACKID_IN_EMB(1),\
341 TUD_MIDI_DESC_EP(_epin, _epsize, 1),\
342 TUD_MIDI_JACKID_OUT_EMB(1)
343
344//--------------------------------------------------------------------+
345// Audio v2.0 Descriptor Templates
346//--------------------------------------------------------------------+
347
348/* Standard Interface Association Descriptor (IAD) */
349#define TUD_AUDIO_DESC_IAD_LEN 8
350#define TUD_AUDIO_DESC_IAD(_firstitf, _nitfs, _stridx) \
351 TUD_AUDIO_DESC_IAD_LEN, TUSB_DESC_INTERFACE_ASSOCIATION, _firstitf, _nitfs, TUSB_CLASS_AUDIO, AUDIO_FUNCTION_SUBCLASS_UNDEFINED, AUDIO_FUNC_PROTOCOL_CODE_V2, _stridx
352
353/* Standard AC Interface Descriptor(4.7.1) */
354#define TUD_AUDIO_DESC_STD_AC_LEN 9
355#define TUD_AUDIO_DESC_STD_AC(_itfnum, _nEPs, _stridx) /* _nEPs is 0 or 1 */\
356 TUD_AUDIO_DESC_STD_AC_LEN, TUSB_DESC_INTERFACE, _itfnum, /* fixed to zero */ 0x00, _nEPs, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_CONTROL, AUDIO_INT_PROTOCOL_CODE_V2, _stridx
357
358/* Class-Specific AC Interface Header Descriptor(4.7.2) */
359#define TUD_AUDIO_DESC_CS_AC_LEN 9
360#define TUD_AUDIO_DESC_CS_AC(_bcdADC, _category, _totallen, _ctrl) /* _bcdADC : Audio Device Class Specification Release Number in Binary-Coded Decimal, _category : see audio_function_t, _totallen : Total number of bytes returned for the class-specific AudioControl interface i.e. Clock Source, Unit and Terminal descriptors - Do not include TUD_AUDIO_DESC_CS_AC_LEN, we already do this here*/ \
361 TUD_AUDIO_DESC_CS_AC_LEN, TUSB_DESC_CS_INTERFACE, AUDIO_CS_AC_INTERFACE_HEADER, U16_TO_U8S_LE(_bcdADC), _category, U16_TO_U8S_LE(_totallen + TUD_AUDIO_DESC_CS_AC_LEN), _ctrl
362
363/* Clock Source Descriptor(4.7.2.1) */
364#define TUD_AUDIO_DESC_CLK_SRC_LEN 8
365#define TUD_AUDIO_DESC_CLK_SRC(_clkid, _attr, _ctrl, _assocTerm, _stridx) \
366 TUD_AUDIO_DESC_CLK_SRC_LEN, TUSB_DESC_CS_INTERFACE, AUDIO_CS_AC_INTERFACE_CLOCK_SOURCE, _clkid, _attr, _ctrl, _assocTerm, _stridx
367
368/* Input Terminal Descriptor(4.7.2.4) */
369#define TUD_AUDIO_DESC_INPUT_TERM_LEN 17
370#define TUD_AUDIO_DESC_INPUT_TERM(_termid, _termtype, _assocTerm, _clkid, _nchannelslogical, _channelcfg, _idxchannelnames, _ctrl, _stridx) \
371 TUD_AUDIO_DESC_INPUT_TERM_LEN, TUSB_DESC_CS_INTERFACE, AUDIO_CS_AC_INTERFACE_INPUT_TERMINAL, _termid, U16_TO_U8S_LE(_termtype), _assocTerm, _clkid, _nchannelslogical, U32_TO_U8S_LE(_channelcfg), _idxchannelnames, U16_TO_U8S_LE(_ctrl), _stridx
372
373/* Output Terminal Descriptor(4.7.2.5) */
374#define TUD_AUDIO_DESC_OUTPUT_TERM_LEN 12
375#define TUD_AUDIO_DESC_OUTPUT_TERM(_termid, _termtype, _assocTerm, _srcid, _clkid, _ctrl, _stridx) \
376 TUD_AUDIO_DESC_OUTPUT_TERM_LEN, TUSB_DESC_CS_INTERFACE, AUDIO_CS_AC_INTERFACE_OUTPUT_TERMINAL, _termid, U16_TO_U8S_LE(_termtype), _assocTerm, _srcid, _clkid, U16_TO_U8S_LE(_ctrl), _stridx
377
378/* Feature Unit Descriptor(4.7.2.8) */
379// 1 - Channel
380#define TUD_AUDIO_DESC_FEATURE_UNIT_ONE_CHANNEL_LEN 6+(1+1)*4
381#define TUD_AUDIO_DESC_FEATURE_UNIT_ONE_CHANNEL(_unitid, _srcid, _ctrlch0master, _ctrlch1, _stridx) \
382 TUD_AUDIO_DESC_FEATURE_UNIT_ONE_CHANNEL_LEN, TUSB_DESC_CS_INTERFACE, AUDIO_CS_AC_INTERFACE_FEATURE_UNIT, _unitid, _srcid, U32_TO_U8S_LE(_ctrlch0master), U32_TO_U8S_LE(_ctrlch1), _stridx
383
384// 2 - Channels
385#define TUD_AUDIO_DESC_FEATURE_UNIT_TWO_CHANNEL_LEN (6+(2+1)*4)
386#define TUD_AUDIO_DESC_FEATURE_UNIT_TWO_CHANNEL(_unitid, _srcid, _ctrlch0master, _ctrlch1, _ctrlch2, _stridx) \
387 TUD_AUDIO_DESC_FEATURE_UNIT_TWO_CHANNEL_LEN, TUSB_DESC_CS_INTERFACE, AUDIO_CS_AC_INTERFACE_FEATURE_UNIT, _unitid, _srcid, U32_TO_U8S_LE(_ctrlch0master), U32_TO_U8S_LE(_ctrlch1), U32_TO_U8S_LE(_ctrlch2), _stridx
388// 4 - Channels
389#define TUD_AUDIO_DESC_FEATURE_UNIT_FOUR_CHANNEL_LEN (6+(4+1)*4)
390#define TUD_AUDIO_DESC_FEATURE_UNIT_FOUR_CHANNEL(_unitid, _srcid, _ctrlch0master, _ctrlch1, _ctrlch2, _ctrlch3, _ctrlch4, _stridx) \
391 TUD_AUDIO_DESC_FEATURE_UNIT_FOUR_CHANNEL_LEN, TUSB_DESC_CS_INTERFACE, AUDIO_CS_AC_INTERFACE_FEATURE_UNIT, _unitid, _srcid, U32_TO_U8S_LE(_ctrlch0master), U32_TO_U8S_LE(_ctrlch1), U32_TO_U8S_LE(_ctrlch2), U32_TO_U8S_LE(_ctrlch3), U32_TO_U8S_LE(_ctrlch4), _stridx
392
393// For more channels, add definitions here
394
395/* Standard AS Interface Descriptor(4.9.1) */
396#define TUD_AUDIO_DESC_STD_AS_INT_LEN 9
397#define TUD_AUDIO_DESC_STD_AS_INT(_itfnum, _altset, _nEPs, _stridx) \
398 TUD_AUDIO_DESC_STD_AS_INT_LEN, TUSB_DESC_INTERFACE, _itfnum, _altset, _nEPs, TUSB_CLASS_AUDIO, AUDIO_SUBCLASS_STREAMING, AUDIO_INT_PROTOCOL_CODE_V2, _stridx
399
400/* Class-Specific AS Interface Descriptor(4.9.2) */
401#define TUD_AUDIO_DESC_CS_AS_INT_LEN 16
402#define TUD_AUDIO_DESC_CS_AS_INT(_termid, _ctrl, _formattype, _formats, _nchannelsphysical, _channelcfg, _stridx) \
403 TUD_AUDIO_DESC_CS_AS_INT_LEN, TUSB_DESC_CS_INTERFACE, AUDIO_CS_AS_INTERFACE_AS_GENERAL, _termid, _ctrl, _formattype, U32_TO_U8S_LE(_formats), _nchannelsphysical, U32_TO_U8S_LE(_channelcfg), _stridx
404
405/* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */
406#define TUD_AUDIO_DESC_TYPE_I_FORMAT_LEN 6
407#define TUD_AUDIO_DESC_TYPE_I_FORMAT(_subslotsize, _bitresolution) /* _subslotsize is number of bytes per sample (i.e. subslot) and can be 1,2,3, or 4 */\
408 TUD_AUDIO_DESC_TYPE_I_FORMAT_LEN, TUSB_DESC_CS_INTERFACE, AUDIO_CS_AS_INTERFACE_FORMAT_TYPE, AUDIO_FORMAT_TYPE_I, _subslotsize, _bitresolution
409
410/* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */
411#define TUD_AUDIO_DESC_STD_AS_ISO_EP_LEN 7
412#define TUD_AUDIO_DESC_STD_AS_ISO_EP(_ep, _attr, _maxEPsize, _interval) \
413 TUD_AUDIO_DESC_STD_AS_ISO_EP_LEN, TUSB_DESC_ENDPOINT, _ep, _attr, U16_TO_U8S_LE(_maxEPsize), _interval
414
415/* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */
416#define TUD_AUDIO_DESC_CS_AS_ISO_EP_LEN 8
417#define TUD_AUDIO_DESC_CS_AS_ISO_EP(_attr, _ctrl, _lockdelayunit, _lockdelay) \
418 TUD_AUDIO_DESC_CS_AS_ISO_EP_LEN, TUSB_DESC_CS_ENDPOINT, AUDIO_CS_EP_SUBTYPE_GENERAL, _attr, _ctrl, _lockdelayunit, U16_TO_U8S_LE(_lockdelay)
419
420/* Standard AS Isochronous Feedback Endpoint Descriptor(4.10.2.1) */
421#define TUD_AUDIO_DESC_STD_AS_ISO_FB_EP_LEN 7
422#define TUD_AUDIO_DESC_STD_AS_ISO_FB_EP(_ep, _interval) \
423 TUD_AUDIO_DESC_STD_AS_ISO_FB_EP_LEN, TUSB_DESC_ENDPOINT, _ep, (uint8_t) (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_NO_SYNC | TUSB_ISO_EP_ATT_EXPLICIT_FB), U16_TO_U8S_LE(4), _interval
424
425// AUDIO simple descriptor (UAC2) for 1 microphone input
426// - 1 Input Terminal, 1 Feature Unit (Mute and Volume Control), 1 Output Terminal, 1 Clock Source
427
428#define TUD_AUDIO_MIC_ONE_CH_DESC_LEN (TUD_AUDIO_DESC_IAD_LEN\
429 + TUD_AUDIO_DESC_STD_AC_LEN\
430 + TUD_AUDIO_DESC_CS_AC_LEN\
431 + TUD_AUDIO_DESC_CLK_SRC_LEN\
432 + TUD_AUDIO_DESC_INPUT_TERM_LEN\
433 + TUD_AUDIO_DESC_OUTPUT_TERM_LEN\
434 + TUD_AUDIO_DESC_FEATURE_UNIT_ONE_CHANNEL_LEN\
435 + TUD_AUDIO_DESC_STD_AS_INT_LEN\
436 + TUD_AUDIO_DESC_STD_AS_INT_LEN\
437 + TUD_AUDIO_DESC_CS_AS_INT_LEN\
438 + TUD_AUDIO_DESC_TYPE_I_FORMAT_LEN\
439 + TUD_AUDIO_DESC_STD_AS_ISO_EP_LEN\
440 + TUD_AUDIO_DESC_CS_AS_ISO_EP_LEN)
441
442#define TUD_AUDIO_MIC_ONE_CH_DESC_N_AS_INT 1 // Number of AS interfaces
443
444#define TUD_AUDIO_MIC_ONE_CH_DESCRIPTOR(_itfnum, _stridx, _nBytesPerSample, _nBitsUsedPerSample, _epin, _epsize) \
445 /* Standard Interface Association Descriptor (IAD) */\
446 TUD_AUDIO_DESC_IAD(/*_firstitf*/ _itfnum, /*_nitfs*/ 0x02, /*_stridx*/ 0x00),\
447 /* Standard AC Interface Descriptor(4.7.1) */\
448 TUD_AUDIO_DESC_STD_AC(/*_itfnum*/ _itfnum, /*_nEPs*/ 0x00, /*_stridx*/ _stridx),\
449 /* Class-Specific AC Interface Header Descriptor(4.7.2) */\
450 TUD_AUDIO_DESC_CS_AC(/*_bcdADC*/ 0x0200, /*_category*/ AUDIO_FUNC_MICROPHONE, /*_totallen*/ TUD_AUDIO_DESC_CLK_SRC_LEN+TUD_AUDIO_DESC_INPUT_TERM_LEN+TUD_AUDIO_DESC_OUTPUT_TERM_LEN+TUD_AUDIO_DESC_FEATURE_UNIT_ONE_CHANNEL_LEN, /*_ctrl*/ AUDIO_CS_AS_INTERFACE_CTRL_LATENCY_POS),\
451 /* Clock Source Descriptor(4.7.2.1) */\
452 TUD_AUDIO_DESC_CLK_SRC(/*_clkid*/ 0x04, /*_attr*/ AUDIO_CLOCK_SOURCE_ATT_INT_FIX_CLK, /*_ctrl*/ (AUDIO_CTRL_R << AUDIO_CLOCK_SOURCE_CTRL_CLK_FRQ_POS), /*_assocTerm*/ 0x01, /*_stridx*/ 0x00),\
453 /* Input Terminal Descriptor(4.7.2.4) */\
454 TUD_AUDIO_DESC_INPUT_TERM(/*_termid*/ 0x01, /*_termtype*/ AUDIO_TERM_TYPE_IN_GENERIC_MIC, /*_assocTerm*/ 0x03, /*_clkid*/ 0x04, /*_nchannelslogical*/ 0x01, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_idxchannelnames*/ 0x00, /*_ctrl*/ AUDIO_CTRL_R << AUDIO_IN_TERM_CTRL_CONNECTOR_POS, /*_stridx*/ 0x00),\
455 /* Output Terminal Descriptor(4.7.2.5) */\
456 TUD_AUDIO_DESC_OUTPUT_TERM(/*_termid*/ 0x03, /*_termtype*/ AUDIO_TERM_TYPE_USB_STREAMING, /*_assocTerm*/ 0x01, /*_srcid*/ 0x02, /*_clkid*/ 0x04, /*_ctrl*/ 0x0000, /*_stridx*/ 0x00),\
457 /* Feature Unit Descriptor(4.7.2.8) */\
458 TUD_AUDIO_DESC_FEATURE_UNIT_ONE_CHANNEL(/*_unitid*/ 0x02, /*_srcid*/ 0x01, /*_ctrlch0master*/ AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS, /*_ctrlch1*/ AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS, /*_stridx*/ 0x00),\
459 /* Standard AS Interface Descriptor(4.9.1) */\
460 /* Interface 1, Alternate 0 - default alternate setting with 0 bandwidth */\
461 TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum)+1), /*_altset*/ 0x00, /*_nEPs*/ 0x00, /*_stridx*/ 0x00),\
462 /* Standard AS Interface Descriptor(4.9.1) */\
463 /* Interface 1, Alternate 1 - alternate interface for data streaming */\
464 TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum)+1), /*_altset*/ 0x01, /*_nEPs*/ 0x01, /*_stridx*/ 0x00),\
465 /* Class-Specific AS Interface Descriptor(4.9.2) */\
466 TUD_AUDIO_DESC_CS_AS_INT(/*_termid*/ 0x03, /*_ctrl*/ AUDIO_CTRL_NONE, /*_formattype*/ AUDIO_FORMAT_TYPE_I, /*_formats*/ AUDIO_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ 0x01, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
467 /* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
468 TUD_AUDIO_DESC_TYPE_I_FORMAT(_nBytesPerSample, _nBitsUsedPerSample),\
469 /* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
470 TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epin, /*_attr*/ (uint8_t) (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ASYNCHRONOUS | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ _epsize, /*_interval*/ TUD_OPT_HIGH_SPEED ? 0x04 : 0x01),\
471 /* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
472 TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_UNDEFINED, /*_lockdelay*/ 0x0000)
473
474// AUDIO simple descriptor (UAC2) for 4 microphone input
475// - 1 Input Terminal, 1 Feature Unit (Mute and Volume Control), 1 Output Terminal, 1 Clock Source
476
477#define TUD_AUDIO_MIC_FOUR_CH_DESC_LEN (TUD_AUDIO_DESC_IAD_LEN\
478 + TUD_AUDIO_DESC_STD_AC_LEN\
479 + TUD_AUDIO_DESC_CS_AC_LEN\
480 + TUD_AUDIO_DESC_CLK_SRC_LEN\
481 + TUD_AUDIO_DESC_INPUT_TERM_LEN\
482 + TUD_AUDIO_DESC_OUTPUT_TERM_LEN\
483 + TUD_AUDIO_DESC_FEATURE_UNIT_FOUR_CHANNEL_LEN\
484 + TUD_AUDIO_DESC_STD_AS_INT_LEN\
485 + TUD_AUDIO_DESC_STD_AS_INT_LEN\
486 + TUD_AUDIO_DESC_CS_AS_INT_LEN\
487 + TUD_AUDIO_DESC_TYPE_I_FORMAT_LEN\
488 + TUD_AUDIO_DESC_STD_AS_ISO_EP_LEN\
489 + TUD_AUDIO_DESC_CS_AS_ISO_EP_LEN)
490
491#define TUD_AUDIO_MIC_FOUR_CH_DESC_N_AS_INT 1 // Number of AS interfaces
492
493#define TUD_AUDIO_MIC_FOUR_CH_DESCRIPTOR(_itfnum, _stridx, _nBytesPerSample, _nBitsUsedPerSample, _epin, _epsize) \
494 /* Standard Interface Association Descriptor (IAD) */\
495 TUD_AUDIO_DESC_IAD(/*_firstitf*/ _itfnum, /*_nitfs*/ 0x02, /*_stridx*/ 0x00),\
496 /* Standard AC Interface Descriptor(4.7.1) */\
497 TUD_AUDIO_DESC_STD_AC(/*_itfnum*/ _itfnum, /*_nEPs*/ 0x00, /*_stridx*/ _stridx),\
498 /* Class-Specific AC Interface Header Descriptor(4.7.2) */\
499 TUD_AUDIO_DESC_CS_AC(/*_bcdADC*/ 0x0200, /*_category*/ AUDIO_FUNC_MICROPHONE, /*_totallen*/ TUD_AUDIO_DESC_CLK_SRC_LEN+TUD_AUDIO_DESC_INPUT_TERM_LEN+TUD_AUDIO_DESC_OUTPUT_TERM_LEN+TUD_AUDIO_DESC_FEATURE_UNIT_FOUR_CHANNEL_LEN, /*_ctrl*/ AUDIO_CS_AS_INTERFACE_CTRL_LATENCY_POS),\
500 /* Clock Source Descriptor(4.7.2.1) */\
501 TUD_AUDIO_DESC_CLK_SRC(/*_clkid*/ 0x04, /*_attr*/ AUDIO_CLOCK_SOURCE_ATT_INT_FIX_CLK, /*_ctrl*/ (AUDIO_CTRL_R << AUDIO_CLOCK_SOURCE_CTRL_CLK_FRQ_POS), /*_assocTerm*/ 0x01, /*_stridx*/ 0x00),\
502 /* Input Terminal Descriptor(4.7.2.4) */\
503 TUD_AUDIO_DESC_INPUT_TERM(/*_termid*/ 0x01, /*_termtype*/ AUDIO_TERM_TYPE_IN_GENERIC_MIC, /*_assocTerm*/ 0x03, /*_clkid*/ 0x04, /*_nchannelslogical*/ 0x04, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_idxchannelnames*/ 0x00, /*_ctrl*/ AUDIO_CTRL_R << AUDIO_IN_TERM_CTRL_CONNECTOR_POS, /*_stridx*/ 0x00),\
504 /* Output Terminal Descriptor(4.7.2.5) */\
505 TUD_AUDIO_DESC_OUTPUT_TERM(/*_termid*/ 0x03, /*_termtype*/ AUDIO_TERM_TYPE_USB_STREAMING, /*_assocTerm*/ 0x01, /*_srcid*/ 0x02, /*_clkid*/ 0x04, /*_ctrl*/ 0x0000, /*_stridx*/ 0x00),\
506 /* Feature Unit Descriptor(4.7.2.8) */\
507 TUD_AUDIO_DESC_FEATURE_UNIT_FOUR_CHANNEL(/*_unitid*/ 0x02, /*_srcid*/ 0x01, /*_ctrlch0master*/ AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS, /*_ctrlch1*/ AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS, /*_ctrlch2*/ AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS, /*_ctrlch3*/ AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS, /*_ctrlch4*/ AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS, /*_stridx*/ 0x00),\
508 /* Standard AS Interface Descriptor(4.9.1) */\
509 /* Interface 1, Alternate 0 - default alternate setting with 0 bandwidth */\
510 TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum)+1), /*_altset*/ 0x00, /*_nEPs*/ 0x00, /*_stridx*/ 0x00),\
511 /* Standard AS Interface Descriptor(4.9.1) */\
512 /* Interface 1, Alternate 1 - alternate interface for data streaming */\
513 TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum)+1), /*_altset*/ 0x01, /*_nEPs*/ 0x01, /*_stridx*/ 0x00),\
514 /* Class-Specific AS Interface Descriptor(4.9.2) */\
515 TUD_AUDIO_DESC_CS_AS_INT(/*_termid*/ 0x03, /*_ctrl*/ AUDIO_CTRL_NONE, /*_formattype*/ AUDIO_FORMAT_TYPE_I, /*_formats*/ AUDIO_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ 0x04, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
516 /* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
517 TUD_AUDIO_DESC_TYPE_I_FORMAT(_nBytesPerSample, _nBitsUsedPerSample),\
518 /* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
519 TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epin, /*_attr*/ (uint8_t) (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ASYNCHRONOUS | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ _epsize, /*_interval*/ TUD_OPT_HIGH_SPEED ? 0x04 : 0x01),\
520 /* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
521 TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_UNDEFINED, /*_lockdelay*/ 0x0000)
522
523// AUDIO simple descriptor (UAC2) for mono speaker
524// - 1 Input Terminal, 2 Feature Unit (Mute and Volume Control), 3 Output Terminal, 4 Clock Source
525
526#define TUD_AUDIO_SPEAKER_MONO_FB_DESC_LEN (TUD_AUDIO_DESC_IAD_LEN\
527 + TUD_AUDIO_DESC_STD_AC_LEN\
528 + TUD_AUDIO_DESC_CS_AC_LEN\
529 + TUD_AUDIO_DESC_CLK_SRC_LEN\
530 + TUD_AUDIO_DESC_INPUT_TERM_LEN\
531 + TUD_AUDIO_DESC_OUTPUT_TERM_LEN\
532 + TUD_AUDIO_DESC_FEATURE_UNIT_ONE_CHANNEL_LEN\
533 + TUD_AUDIO_DESC_STD_AS_INT_LEN\
534 + TUD_AUDIO_DESC_STD_AS_INT_LEN\
535 + TUD_AUDIO_DESC_CS_AS_INT_LEN\
536 + TUD_AUDIO_DESC_TYPE_I_FORMAT_LEN\
537 + TUD_AUDIO_DESC_STD_AS_ISO_EP_LEN\
538 + TUD_AUDIO_DESC_CS_AS_ISO_EP_LEN\
539 + TUD_AUDIO_DESC_STD_AS_ISO_FB_EP_LEN)
540
541#define TUD_AUDIO_SPEAKER_MONO_FB_DESCRIPTOR(_itfnum, _stridx, _nBytesPerSample, _nBitsUsedPerSample, _epout, _epsize, _epfb) \
542 /* Standard Interface Association Descriptor (IAD) */\
543 TUD_AUDIO_DESC_IAD(/*_firstitf*/ _itfnum, /*_nitfs*/ 0x02, /*_stridx*/ 0x00),\
544 /* Standard AC Interface Descriptor(4.7.1) */\
545 TUD_AUDIO_DESC_STD_AC(/*_itfnum*/ _itfnum, /*_nEPs*/ 0x00, /*_stridx*/ _stridx),\
546 /* Class-Specific AC Interface Header Descriptor(4.7.2) */\
547 TUD_AUDIO_DESC_CS_AC(/*_bcdADC*/ 0x0200, /*_category*/ AUDIO_FUNC_DESKTOP_SPEAKER, /*_totallen*/ TUD_AUDIO_DESC_CLK_SRC_LEN+TUD_AUDIO_DESC_INPUT_TERM_LEN+TUD_AUDIO_DESC_OUTPUT_TERM_LEN+TUD_AUDIO_DESC_FEATURE_UNIT_ONE_CHANNEL_LEN, /*_ctrl*/ AUDIO_CS_AS_INTERFACE_CTRL_LATENCY_POS),\
548 /* Clock Source Descriptor(4.7.2.1) */\
549 TUD_AUDIO_DESC_CLK_SRC(/*_clkid*/ 0x04, /*_attr*/ AUDIO_CLOCK_SOURCE_ATT_INT_FIX_CLK, /*_ctrl*/ (AUDIO_CTRL_R << AUDIO_CLOCK_SOURCE_CTRL_CLK_FRQ_POS), /*_assocTerm*/ 0x01, /*_stridx*/ 0x00),\
550 /* Input Terminal Descriptor(4.7.2.4) */\
551 TUD_AUDIO_DESC_INPUT_TERM(/*_termid*/ 0x01, /*_termtype*/ AUDIO_TERM_TYPE_USB_STREAMING, /*_assocTerm*/ 0x00, /*_clkid*/ 0x04, /*_nchannelslogical*/ 0x01, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_idxchannelnames*/ 0x00, /*_ctrl*/ 0 * (AUDIO_CTRL_R << AUDIO_IN_TERM_CTRL_CONNECTOR_POS), /*_stridx*/ 0x00),\
552 /* Output Terminal Descriptor(4.7.2.5) */\
553 TUD_AUDIO_DESC_OUTPUT_TERM(/*_termid*/ 0x03, /*_termtype*/ AUDIO_TERM_TYPE_OUT_DESKTOP_SPEAKER, /*_assocTerm*/ 0x01, /*_srcid*/ 0x02, /*_clkid*/ 0x04, /*_ctrl*/ 0x0000, /*_stridx*/ 0x00),\
554 /* Feature Unit Descriptor(4.7.2.8) */\
555 TUD_AUDIO_DESC_FEATURE_UNIT_ONE_CHANNEL(/*_unitid*/ 0x02, /*_srcid*/ 0x01, /*_ctrlch0master*/ 0 * (AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS), /*_ctrlch1*/ 0 * (AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_MUTE_POS | AUDIO_CTRL_RW << AUDIO_FEATURE_UNIT_CTRL_VOLUME_POS), /*_stridx*/ 0x00),\
556 /* Standard AS Interface Descriptor(4.9.1) */\
557 /* Interface 1, Alternate 0 - default alternate setting with 0 bandwidth */\
558 TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum) + 1), /*_altset*/ 0x00, /*_nEPs*/ 0x00, /*_stridx*/ 0x00),\
559 /* Standard AS Interface Descriptor(4.9.1) */\
560 /* Interface 1, Alternate 1 - alternate interface for data streaming */\
561 TUD_AUDIO_DESC_STD_AS_INT(/*_itfnum*/ (uint8_t)((_itfnum) + 1), /*_altset*/ 0x01, /*_nEPs*/ 0x02, /*_stridx*/ 0x00),\
562 /* Class-Specific AS Interface Descriptor(4.9.2) */\
563 TUD_AUDIO_DESC_CS_AS_INT(/*_termid*/ 0x01, /*_ctrl*/ AUDIO_CTRL_NONE, /*_formattype*/ AUDIO_FORMAT_TYPE_I, /*_formats*/ AUDIO_DATA_FORMAT_TYPE_I_PCM, /*_nchannelsphysical*/ 0x01, /*_channelcfg*/ AUDIO_CHANNEL_CONFIG_NON_PREDEFINED, /*_stridx*/ 0x00),\
564 /* Type I Format Type Descriptor(2.3.1.6 - Audio Formats) */\
565 TUD_AUDIO_DESC_TYPE_I_FORMAT(_nBytesPerSample, _nBitsUsedPerSample),\
566 /* Standard AS Isochronous Audio Data Endpoint Descriptor(4.10.1.1) */\
567 TUD_AUDIO_DESC_STD_AS_ISO_EP(/*_ep*/ _epout, /*_attr*/ (uint8_t) (TUSB_XFER_ISOCHRONOUS | TUSB_ISO_EP_ATT_ASYNCHRONOUS | TUSB_ISO_EP_ATT_DATA), /*_maxEPsize*/ _epsize, /*_interval*/ TUD_OPT_HIGH_SPEED ? 0x04 : 0x01),\
568 /* Class-Specific AS Isochronous Audio Data Endpoint Descriptor(4.10.1.2) */\
569 TUD_AUDIO_DESC_CS_AS_ISO_EP(/*_attr*/ AUDIO_CS_AS_ISO_DATA_EP_ATT_NON_MAX_PACKETS_OK, /*_ctrl*/ AUDIO_CTRL_NONE, /*_lockdelayunit*/ AUDIO_CS_AS_ISO_DATA_EP_LOCK_DELAY_UNIT_UNDEFINED, /*_lockdelay*/ 0x0000),\
570 /* Standard AS Isochronous Feedback Endpoint Descriptor(4.10.2.1) */\
571 TUD_AUDIO_DESC_STD_AS_ISO_FB_EP(/*_ep*/ _epfb, /*_interval*/ 1)\
572
573// Calculate wMaxPacketSize of Endpoints
574#define TUD_AUDIO_EP_SIZE(_maxFrequency, _nBytesPerSample, _nChannels) \
575 ((((_maxFrequency + (TUD_OPT_HIGH_SPEED ? 7999 : 999)) / (TUD_OPT_HIGH_SPEED ? 8000 : 1000)) + 1) * _nBytesPerSample * _nChannels)
576
577
578//--------------------------------------------------------------------+
579// USBTMC/USB488 Descriptor Templates
580//--------------------------------------------------------------------+
581
582#define TUD_USBTMC_APP_CLASS (TUSB_CLASS_APPLICATION_SPECIFIC)
583#define TUD_USBTMC_APP_SUBCLASS 0x03u
584
585#define TUD_USBTMC_PROTOCOL_STD 0x00u
586#define TUD_USBTMC_PROTOCOL_USB488 0x01u
587
588// Interface number, number of endpoints, EP string index, USB_TMC_PROTOCOL*, bulk-out endpoint ID,
589// bulk-in endpoint ID
590#define TUD_USBTMC_IF_DESCRIPTOR(_itfnum, _bNumEndpoints, _stridx, _itfProtocol) \
591 /* Interface */ \
592 0x09, TUSB_DESC_INTERFACE, _itfnum, 0x00, _bNumEndpoints, TUD_USBTMC_APP_CLASS, TUD_USBTMC_APP_SUBCLASS, _itfProtocol, _stridx
593
594#define TUD_USBTMC_IF_DESCRIPTOR_LEN 9u
595
596#define TUD_USBTMC_BULK_DESCRIPTORS(_epout, _epin, _bulk_epsize) \
597 /* Endpoint Out */ \
598 7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_bulk_epsize), 0u, \
599 /* Endpoint In */ \
600 7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_bulk_epsize), 0u
601
602#define TUD_USBTMC_BULK_DESCRIPTORS_LEN (7u+7u)
603
604/* optional interrupt endpoint */ \
605// _int_pollingInterval : for LS/FS, expressed in frames (1ms each). 16 may be a good number?
606#define TUD_USBTMC_INT_DESCRIPTOR(_ep_interrupt, _ep_interrupt_size, _int_pollingInterval ) \
607 7, TUSB_DESC_ENDPOINT, _ep_interrupt, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_ep_interrupt_size), _int_pollingInterval
608
609#define TUD_USBTMC_INT_DESCRIPTOR_LEN (7u)
610
611//--------------------------------------------------------------------+
612// Vendor Descriptor Templates
613//--------------------------------------------------------------------+
614
615#define TUD_VENDOR_DESC_LEN (9+7+7)
616
617// Interface number, string index, EP Out & IN address, EP size
618#define TUD_VENDOR_DESCRIPTOR(_itfnum, _stridx, _epout, _epin, _epsize) \
619 /* Interface */\
620 9, TUSB_DESC_INTERFACE, _itfnum, 0, 2, TUSB_CLASS_VENDOR_SPECIFIC, 0x00, 0x00, _stridx,\
621 /* Endpoint Out */\
622 7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\
623 /* Endpoint In */\
624 7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0
625
626//--------------------------------------------------------------------+
627// DFU Runtime Descriptor Templates
628//--------------------------------------------------------------------+
629
630#define TUD_DFU_APP_CLASS (TUSB_CLASS_APPLICATION_SPECIFIC)
631#define TUD_DFU_APP_SUBCLASS (APP_SUBCLASS_DFU_RUNTIME)
632
633// Length of template descriptr: 18 bytes
634#define TUD_DFU_RT_DESC_LEN (9 + 9)
635
636// DFU runtime descriptor
637// Interface number, string index, attributes, detach timeout, transfer size
638#define TUD_DFU_RT_DESCRIPTOR(_itfnum, _stridx, _attr, _timeout, _xfer_size) \
639 /* Interface */ \
640 9, TUSB_DESC_INTERFACE, _itfnum, 0, 0, TUD_DFU_APP_CLASS, TUD_DFU_APP_SUBCLASS, DFU_PROTOCOL_RT, _stridx, \
641 /* Function */ \
642 9, DFU_DESC_FUNCTIONAL, _attr, U16_TO_U8S_LE(_timeout), U16_TO_U8S_LE(_xfer_size), U16_TO_U8S_LE(0x0101)
643
644//--------------------------------------------------------------------+
645// DFU Descriptor Templates
646//--------------------------------------------------------------------+
647
648// Length of template descriptor: 9 bytes + number of alternatives * 9
649#define TUD_DFU_DESC_LEN(_alt_count) (9 + (_alt_count) * 9)
650
651// Interface number, Alternate count, starting string index, attributes, detach timeout, transfer size
652// Note: Alternate count must be numeric or macro, string index is increased by one for each Alt interface
653#define TUD_DFU_DESCRIPTOR(_itfnum, _alt_count, _stridx, _attr, _timeout, _xfer_size) \
654 TU_XSTRCAT(_TUD_DFU_ALT_,_alt_count)(_itfnum, 0, _stridx), \
655 /* Function */ \
656 9, DFU_DESC_FUNCTIONAL, _attr, U16_TO_U8S_LE(_timeout), U16_TO_U8S_LE(_xfer_size), U16_TO_U8S_LE(0x0101)
657
658#define _TUD_DFU_ALT(_itfnum, _alt, _stridx) \
659 /* Interface */ \
660 9, TUSB_DESC_INTERFACE, _itfnum, _alt, 0, TUD_DFU_APP_CLASS, TUD_DFU_APP_SUBCLASS, DFU_PROTOCOL_DFU, _stridx
661
662#define _TUD_DFU_ALT_1(_itfnum, _alt_count, _stridx) \
663 _TUD_DFU_ALT(_itfnum, _alt_count, _stridx)
664
665#define _TUD_DFU_ALT_2(_itfnum, _alt_count, _stridx) \
666 _TUD_DFU_ALT(_itfnum, _alt_count, _stridx), \
667 _TUD_DFU_ALT_1(_itfnum, _alt_count+1, _stridx+1)
668
669#define _TUD_DFU_ALT_3(_itfnum, _alt_count, _stridx) \
670 _TUD_DFU_ALT(_itfnum, _alt_count, _stridx), \
671 _TUD_DFU_ALT_2(_itfnum, _alt_count+1, _stridx+1)
672
673#define _TUD_DFU_ALT_4(_itfnum, _alt_count, _stridx) \
674 _TUD_DFU_ALT(_itfnum, _alt_count, _stridx), \
675 _TUD_DFU_ALT_3(_itfnum, _alt_count+1, _stridx+1)
676
677#define _TUD_DFU_ALT_5(_itfnum, _alt_count, _stridx) \
678 _TUD_DFU_ALT(_itfnum, _alt_count, _stridx), \
679 _TUD_DFU_ALT_4(_itfnum, _alt_count+1, _stridx+1)
680
681#define _TUD_DFU_ALT_6(_itfnum, _alt_count, _stridx) \
682 _TUD_DFU_ALT(_itfnum, _alt_count, _stridx), \
683 _TUD_DFU_ALT_5(_itfnum, _alt_count+1, _stridx+1)
684
685#define _TUD_DFU_ALT_7(_itfnum, _alt_count, _stridx) \
686 _TUD_DFU_ALT(_itfnum, _alt_count, _stridx), \
687 _TUD_DFU_ALT_6(_itfnum, _alt_count+1, _stridx+1)
688
689#define _TUD_DFU_ALT_8(_itfnum, _alt_count, _stridx) \
690 _TUD_DFU_ALT(_itfnum, _alt_count, _stridx), \
691 _TUD_DFU_ALT_7(_itfnum, _alt_count+1, _stridx+1)
692
693//--------------------------------------------------------------------+
694// CDC-ECM Descriptor Templates
695//--------------------------------------------------------------------+
696
697// Length of template descriptor: 71 bytes
698#define TUD_CDC_ECM_DESC_LEN (8+9+5+5+13+7+9+9+7+7)
699
700// CDC-ECM Descriptor Template
701// Interface number, description string index, MAC address string index, EP notification address and size, EP data address (out, in), and size, max segment size.
702#define TUD_CDC_ECM_DESCRIPTOR(_itfnum, _desc_stridx, _mac_stridx, _ep_notif, _ep_notif_size, _epout, _epin, _epsize, _maxsegmentsize) \
703 /* Interface Association */\
704 8, TUSB_DESC_INTERFACE_ASSOCIATION, _itfnum, 2, TUSB_CLASS_CDC, CDC_COMM_SUBCLASS_ETHERNET_CONTROL_MODEL, 0, 0,\
705 /* CDC Control Interface */\
706 9, TUSB_DESC_INTERFACE, _itfnum, 0, 1, TUSB_CLASS_CDC, CDC_COMM_SUBCLASS_ETHERNET_CONTROL_MODEL, 0, _desc_stridx,\
707 /* CDC-ECM Header */\
708 5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_HEADER, U16_TO_U8S_LE(0x0120),\
709 /* CDC-ECM Union */\
710 5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_UNION, _itfnum, (uint8_t)((_itfnum) + 1),\
711 /* CDC-ECM Functional Descriptor */\
712 13, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_ETHERNET_NETWORKING, _mac_stridx, 0, 0, 0, 0, U16_TO_U8S_LE(_maxsegmentsize), U16_TO_U8S_LE(0), 0,\
713 /* Endpoint Notification */\
714 7, TUSB_DESC_ENDPOINT, _ep_notif, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_ep_notif_size), 1,\
715 /* CDC Data Interface (default inactive) */\
716 9, TUSB_DESC_INTERFACE, (uint8_t)((_itfnum)+1), 0, 0, TUSB_CLASS_CDC_DATA, 0, 0, 0,\
717 /* CDC Data Interface (alternative active) */\
718 9, TUSB_DESC_INTERFACE, (uint8_t)((_itfnum)+1), 1, 2, TUSB_CLASS_CDC_DATA, 0, 0, 0,\
719 /* Endpoint In */\
720 7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\
721 /* Endpoint Out */\
722 7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0
723
724//--------------------------------------------------------------------+
725// RNDIS Descriptor Templates
726//--------------------------------------------------------------------+
727
728#if 0
729/* Windows XP */
730#define TUD_RNDIS_ITF_CLASS TUSB_CLASS_CDC
731#define TUD_RNDIS_ITF_SUBCLASS CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL
732#define TUD_RNDIS_ITF_PROTOCOL 0xFF /* CDC_COMM_PROTOCOL_MICROSOFT_RNDIS */
733#else
734/* Windows 7+ */
735#define TUD_RNDIS_ITF_CLASS TUSB_CLASS_WIRELESS_CONTROLLER
736#define TUD_RNDIS_ITF_SUBCLASS 0x01
737#define TUD_RNDIS_ITF_PROTOCOL 0x03
738#endif
739
740// Length of template descriptor: 66 bytes
741#define TUD_RNDIS_DESC_LEN (8+9+5+5+4+5+7+9+7+7)
742
743// RNDIS Descriptor Template
744// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
745#define TUD_RNDIS_DESCRIPTOR(_itfnum, _stridx, _ep_notif, _ep_notif_size, _epout, _epin, _epsize) \
746 /* Interface Association */\
747 8, TUSB_DESC_INTERFACE_ASSOCIATION, _itfnum, 2, TUD_RNDIS_ITF_CLASS, TUD_RNDIS_ITF_SUBCLASS, TUD_RNDIS_ITF_PROTOCOL, 0,\
748 /* CDC Control Interface */\
749 9, TUSB_DESC_INTERFACE, _itfnum, 0, 1, TUD_RNDIS_ITF_CLASS, TUD_RNDIS_ITF_SUBCLASS, TUD_RNDIS_ITF_PROTOCOL, _stridx,\
750 /* CDC-ACM Header */\
751 5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_HEADER, U16_TO_U8S_LE(0x0110),\
752 /* CDC Call Management */\
753 5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_CALL_MANAGEMENT, 0, (uint8_t)((_itfnum) + 1),\
754 /* ACM */\
755 4, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT, 0,\
756 /* CDC Union */\
757 5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_UNION, _itfnum, (uint8_t)((_itfnum) + 1),\
758 /* Endpoint Notification */\
759 7, TUSB_DESC_ENDPOINT, _ep_notif, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_ep_notif_size), 1,\
760 /* CDC Data Interface */\
761 9, TUSB_DESC_INTERFACE, (uint8_t)((_itfnum)+1), 0, 2, TUSB_CLASS_CDC_DATA, 0, 0, 0,\
762 /* Endpoint In */\
763 7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\
764 /* Endpoint Out */\
765 7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0
766
767//--------------------------------------------------------------------+
768// Bluetooth Radio Descriptor Templates
769//--------------------------------------------------------------------+
770
771#define TUD_BT_APP_CLASS (TUSB_CLASS_WIRELESS_CONTROLLER)
772#define TUD_BT_APP_SUBCLASS 0x01
773#define TUD_BT_PROTOCOL_PRIMARY_CONTROLLER 0x01
774#define TUD_BT_PROTOCOL_AMP_CONTROLLER 0x02
775
776#ifndef CFG_TUD_BTH_ISO_ALT_COUNT
777#define CFG_TUD_BTH_ISO_ALT_COUNT 0
778#endif
779
780// Length of template descriptor: 38 bytes + number of ISO alternatives * 23
781#define TUD_BTH_DESC_LEN (8 + 9 + 7 + 7 + 7 + (CFG_TUD_BTH_ISO_ALT_COUNT) * (9 + 7 + 7))
782
783/* Primary Interface */
784#define TUD_BTH_PRI_ITF(_itfnum, _stridx, _ep_evt, _ep_evt_size, _ep_evt_interval, _ep_in, _ep_out, _ep_size) \
785 9, TUSB_DESC_INTERFACE, _itfnum, 0, 3, TUD_BT_APP_CLASS, TUD_BT_APP_SUBCLASS, TUD_BT_PROTOCOL_PRIMARY_CONTROLLER, _stridx, \
786 /* Endpoint In for events */ \
787 7, TUSB_DESC_ENDPOINT, _ep_evt, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_ep_evt_size), _ep_evt_interval, \
788 /* Endpoint In for ACL data */ \
789 7, TUSB_DESC_ENDPOINT, _ep_in, TUSB_XFER_BULK, U16_TO_U8S_LE(_ep_size), 1, \
790 /* Endpoint Out for ACL data */ \
791 7, TUSB_DESC_ENDPOINT, _ep_out, TUSB_XFER_BULK, U16_TO_U8S_LE(_ep_size), 1
792
793#define TUD_BTH_ISO_ITF(_itfnum, _alt, _ep_in, _ep_out, _n) ,\
794 /* Interface with 2 endpoints */ \
795 9, TUSB_DESC_INTERFACE, _itfnum, _alt, 2, TUD_BT_APP_CLASS, TUD_BT_APP_SUBCLASS, TUD_BT_PROTOCOL_PRIMARY_CONTROLLER, 0, \
796 /* Isochronous endpoints */ \
797 7, TUSB_DESC_ENDPOINT, _ep_in, TUSB_XFER_ISOCHRONOUS, U16_TO_U8S_LE(_n), 1, \
798 7, TUSB_DESC_ENDPOINT, _ep_out, TUSB_XFER_ISOCHRONOUS, U16_TO_U8S_LE(_n), 1
799
800#define _FIRST(a, ...) a
801#define _REST(a, ...) __VA_ARGS__
802
803#define TUD_BTH_ISO_ITF_0(_itfnum, ...)
804#define TUD_BTH_ISO_ITF_1(_itfnum, _ep_in, _ep_out, ...) TUD_BTH_ISO_ITF(_itfnum, (CFG_TUD_BTH_ISO_ALT_COUNT) - 1, _ep_in, _ep_out, _FIRST(__VA_ARGS__))
805#define TUD_BTH_ISO_ITF_2(_itfnum, _ep_in, _ep_out, ...) TUD_BTH_ISO_ITF(_itfnum, (CFG_TUD_BTH_ISO_ALT_COUNT) - 2, _ep_in, _ep_out, _FIRST(__VA_ARGS__)) \
806 TUD_BTH_ISO_ITF_1(_itfnum, _ep_in, _ep_out, _REST(__VA_ARGS__))
807#define TUD_BTH_ISO_ITF_3(_itfnum, _ep_in, _ep_out, ...) TUD_BTH_ISO_ITF(_itfnum, (CFG_TUD_BTH_ISO_ALT_COUNT) - 3, _ep_in, _ep_out, _FIRST(__VA_ARGS__)) \
808 TUD_BTH_ISO_ITF_2(_itfnum, _ep_in, _ep_out, _REST(__VA_ARGS__))
809#define TUD_BTH_ISO_ITF_4(_itfnum, _ep_in, _ep_out, ...) TUD_BTH_ISO_ITF(_itfnum, (CFG_TUD_BTH_ISO_ALT_COUNT) - 4, _ep_in, _ep_out, _FIRST(__VA_ARGS__)) \
810 TUD_BTH_ISO_ITF_3(_itfnum, _ep_in, _ep_out, _REST(__VA_ARGS__))
811#define TUD_BTH_ISO_ITF_5(_itfnum, _ep_in, _ep_out, ...) TUD_BTH_ISO_ITF(_itfnum, (CFG_TUD_BTH_ISO_ALT_COUNT) - 5, _ep_in, _ep_out, _FIRST(__VA_ARGS__)) \
812 TUD_BTH_ISO_ITF_4(_itfnum, _ep_in, _ep_out, _REST(__VA_ARGS__))
813#define TUD_BTH_ISO_ITF_6(_itfnum, _ep_in, _ep_out, ...) TUD_BTH_ISO_ITF(_itfnum, (CFG_TUD_BTH_ISO_ALT_COUNT) - 6, _ep_in, _ep_out, _FIRST(__VA_ARGS__)) \
814 TUD_BTH_ISO_ITF_5(_itfnum, _ep_in, _ep_out, _REST(__VA_ARGS__))
815
816#define TUD_BTH_ISO_ITFS(_itfnum, _ep_in, _ep_out, ...) \
817 TU_XSTRCAT(TUD_BTH_ISO_ITF_, CFG_TUD_BTH_ISO_ALT_COUNT)(_itfnum, _ep_in, _ep_out, __VA_ARGS__)
818
819// BT Primary controller descriptor
820// Interface number, string index, attributes, event endpoint, event endpoint size, interval, data in, data out, data endpoint size, iso endpoint sizes
821// TODO BTH should also use IAD like CDC for composite device
822#define TUD_BTH_DESCRIPTOR(_itfnum, _stridx, _ep_evt, _ep_evt_size, _ep_evt_interval, _ep_in, _ep_out, _ep_size,...) \
823 /* Interface Associate */\
824 8, TUSB_DESC_INTERFACE_ASSOCIATION, _itfnum, 2, TUD_BT_APP_CLASS, TUD_BT_APP_SUBCLASS, TUD_BT_PROTOCOL_PRIMARY_CONTROLLER, 0,\
825 TUD_BTH_PRI_ITF(_itfnum, _stridx, _ep_evt, _ep_evt_size, _ep_evt_interval, _ep_in, _ep_out, _ep_size) \
826 TUD_BTH_ISO_ITFS(_itfnum + 1, _ep_in + 1, _ep_out + 1, __VA_ARGS__)
827
828//--------------------------------------------------------------------+
829// CDC-NCM Descriptor Templates
830//--------------------------------------------------------------------+
831
832// Length of template descriptor
833#define TUD_CDC_NCM_DESC_LEN (8+9+5+5+13+6+7+9+9+7+7)
834
835// CDC-ECM Descriptor Template
836// Interface number, description string index, MAC address string index, EP notification address and size, EP data address (out, in), and size, max segment size.
837#define TUD_CDC_NCM_DESCRIPTOR(_itfnum, _desc_stridx, _mac_stridx, _ep_notif, _ep_notif_size, _epout, _epin, _epsize, _maxsegmentsize) \
838 /* Interface Association */\
839 8, TUSB_DESC_INTERFACE_ASSOCIATION, _itfnum, 2, TUSB_CLASS_CDC, CDC_COMM_SUBCLASS_NETWORK_CONTROL_MODEL, 0, 0,\
840 /* CDC Control Interface */\
841 9, TUSB_DESC_INTERFACE, _itfnum, 0, 1, TUSB_CLASS_CDC, CDC_COMM_SUBCLASS_NETWORK_CONTROL_MODEL, 0, _desc_stridx,\
842 /* CDC-NCM Header */\
843 5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_HEADER, U16_TO_U8S_LE(0x0110),\
844 /* CDC-NCM Union */\
845 5, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_UNION, _itfnum, (uint8_t)((_itfnum) + 1),\
846 /* CDC-NCM Functional Descriptor */\
847 13, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_ETHERNET_NETWORKING, _mac_stridx, 0, 0, 0, 0, U16_TO_U8S_LE(_maxsegmentsize), U16_TO_U8S_LE(0), 0, \
848 /* CDC-NCM Functional Descriptor */\
849 6, TUSB_DESC_CS_INTERFACE, CDC_FUNC_DESC_NCM, U16_TO_U8S_LE(0x0100), 0, \
850 /* Endpoint Notification */\
851 7, TUSB_DESC_ENDPOINT, _ep_notif, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_ep_notif_size), 50,\
852 /* CDC Data Interface (default inactive) */\
853 9, TUSB_DESC_INTERFACE, (uint8_t)((_itfnum)+1), 0, 0, TUSB_CLASS_CDC_DATA, 0, NCM_DATA_PROTOCOL_NETWORK_TRANSFER_BLOCK, 0,\
854 /* CDC Data Interface (alternative active) */\
855 9, TUSB_DESC_INTERFACE, (uint8_t)((_itfnum)+1), 1, 2, TUSB_CLASS_CDC_DATA, 0, NCM_DATA_PROTOCOL_NETWORK_TRANSFER_BLOCK, 0,\
856 /* Endpoint In */\
857 7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0,\
858 /* Endpoint Out */\
859 7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_epsize), 0
860
861#ifdef __cplusplus
862}
863#endif
864
865#endif /* _TUSB_USBD_H_ */
866
tusb_speed_t
defined base on EHCI specs value for Endpoint Speed
Definition tusb_types.h:48
AUDIO Channel Cluster Descriptor (4.1)
Definition audio.h:647