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