Skip to main content

embassy_usb_host/class/uac/
codes.rs

1//! USB Audio Device Class constants from UAC2 specification
2//! Based on USB Device Class Definition for Audio Devices, Release 2.0 (May 31, 2006)
3
4/// Audio Function Class Code
5pub const AUDIO_FUNCTION: u8 = 0x01;
6
7/// Audio Function Subclass Codes
8pub const FUNCTION_SUBCLASS_UNDEFINED: u8 = 0x00;
9
10/// Audio Function Protocol Codes
11pub mod function_protocol {
12    pub const UNDEFINED: u8 = 0x00;
13    pub const AF_VERSION_02_00: u8 = 0x20;
14}
15
16/// Audio Interface Class/Subclass Codes
17pub mod interface {
18    pub const AUDIO: u8 = 0x01;
19
20    pub mod subclass {
21        pub const UNDEFINED: u8 = 0x00;
22        pub const AUDIOCONTROL: u8 = 0x01;
23        pub const AUDIOSTREAMING: u8 = 0x02;
24        pub const MIDISTREAMING: u8 = 0x03;
25    }
26
27    pub mod protocol {
28        pub const UNDEFINED: u8 = 0x00;
29        pub const IP_VERSION_02_00: u8 = 0x20;
30    }
31}
32
33/// Audio Function Category Codes
34pub mod function_category {
35    pub const UNDEFINED: u8 = 0x00;
36    pub const DESKTOP_SPEAKER: u8 = 0x01;
37    pub const HOME_THEATER: u8 = 0x02;
38    pub const MICROPHONE: u8 = 0x03;
39    pub const HEADSET: u8 = 0x04;
40    pub const TELEPHONE: u8 = 0x05;
41    pub const CONVERTER: u8 = 0x06;
42    pub const VOICE_SOUND_RECORDER: u8 = 0x07;
43    pub const IO_BOX: u8 = 0x08;
44    pub const MUSICAL_INSTRUMENT: u8 = 0x09;
45    pub const PRO_AUDIO: u8 = 0x0A;
46    pub const AUDIO_VIDEO: u8 = 0x0B;
47    pub const CONTROL_PANEL: u8 = 0x0C;
48    pub const OTHER: u8 = 0xFF;
49}
50
51/// Audio Class-Specific Descriptor Types
52pub mod descriptor_type {
53    pub const CS_UNDEFINED: u8 = 0x20;
54    pub const CS_DEVICE: u8 = 0x21;
55    pub const CS_CONFIGURATION: u8 = 0x22;
56    pub const CS_STRING: u8 = 0x23;
57    pub const CS_INTERFACE: u8 = 0x24;
58    pub const CS_ENDPOINT: u8 = 0x25;
59}
60
61/// Audio Class-Specific AC Interface Descriptor Subtypes
62pub mod ac_descriptor {
63    pub const UNDEFINED: u8 = 0x00;
64    pub const HEADER: u8 = 0x01;
65    pub const INPUT_TERMINAL: u8 = 0x02;
66    pub const OUTPUT_TERMINAL: u8 = 0x03;
67    pub const MIXER_UNIT: u8 = 0x04;
68    pub const SELECTOR_UNIT: u8 = 0x05;
69    pub const FEATURE_UNIT: u8 = 0x06;
70    pub const EFFECT_UNIT: u8 = 0x07;
71    pub const PROCESSING_UNIT: u8 = 0x08;
72    pub const EXTENSION_UNIT: u8 = 0x09;
73    pub const CLOCK_SOURCE: u8 = 0x0A;
74    pub const CLOCK_SELECTOR: u8 = 0x0B;
75    pub const CLOCK_MULTIPLIER: u8 = 0x0C;
76    pub const SAMPLE_RATE_CONVERTER: u8 = 0x0D;
77}
78
79/// Audio Class-Specific AS Interface Descriptor Subtypes
80pub mod as_descriptor {
81    pub const UNDEFINED: u8 = 0x00;
82    pub const GENERAL: u8 = 0x01;
83    pub const FORMAT_TYPE: u8 = 0x02;
84    pub const ENCODER: u8 = 0x03;
85    pub const DECODER: u8 = 0x04;
86}
87
88/// Effect Unit Effect Types
89pub mod effect_type {
90    pub const UNDEFINED: u8 = 0x00;
91    pub const PARAM_EQ_SECTION_EFFECT: u8 = 0x01;
92    pub const REVERBERATION_EFFECT: u8 = 0x02;
93    pub const MOD_DELAY_EFFECT: u8 = 0x03;
94    pub const DYN_RANGE_COMP_EFFECT: u8 = 0x04;
95}
96
97/// Processing Unit Process Types
98pub mod process_type {
99    pub const UNDEFINED: u8 = 0x00;
100    pub const UP_DOWNMIX_PROCESS: u8 = 0x01;
101    pub const DOLBY_PROLOGIC_PROCESS: u8 = 0x02;
102    pub const STEREO_EXTENDER_PROCESS: u8 = 0x03;
103}
104
105/// Audio Class-Specific Endpoint Descriptor Subtypes
106pub mod endpoint_descriptor {
107    pub const UNDEFINED: u8 = 0x00;
108    pub const EP_GENERAL: u8 = 0x01;
109}
110
111/// Audio Class-Specific Request Codes
112pub mod request_code {
113    pub const UNDEFINED: u8 = 0x00;
114    pub const CUR: u8 = 0x01;
115    pub const RANGE: u8 = 0x02;
116    pub const MEM: u8 = 0x03;
117}
118
119/// Encoder Type Codes
120pub mod encoder_type {
121    pub const UNDEFINED: u8 = 0x00;
122    pub const OTHER_ENCODER: u8 = 0x01;
123    pub const MPEG_ENCODER: u8 = 0x02;
124    pub const AC_3_ENCODER: u8 = 0x03;
125    pub const WMA_ENCODER: u8 = 0x04;
126    pub const DTS_ENCODER: u8 = 0x05;
127}
128
129/// Decoder Type Codes
130pub mod decoder_type {
131    pub const UNDEFINED: u8 = 0x00;
132    pub const OTHER_DECODER: u8 = 0x01;
133    pub const MPEG_DECODER: u8 = 0x02;
134    pub const AC_3_DECODER: u8 = 0x03;
135    pub const WMA_DECODER: u8 = 0x04;
136    pub const DTS_DECODER: u8 = 0x05;
137}
138
139/// Control Selector Codes
140pub mod control_selector {
141    /// Clock Source Control Selectors
142    pub mod clock_source {
143        pub const UNDEFINED: u16 = 0x00 << 8;
144        pub const SAMPLING_FREQ_CONTROL: u16 = 0x01 << 8;
145        pub const CLOCK_VALID_CONTROL: u16 = 0x02 << 8;
146    }
147
148    /// Clock Selector Control Selectors
149    pub mod clock_selector {
150        pub const UNDEFINED: u16 = 0x00 << 8;
151        pub const CLOCK_SELECTOR_CONTROL: u16 = 0x01 << 8;
152    }
153
154    /// Clock Multiplier Control Selectors
155    pub mod clock_multiplier {
156        pub const UNDEFINED: u16 = 0x00 << 8;
157        pub const NUMERATOR_CONTROL: u16 = 0x01 << 8;
158        pub const DENOMINATOR_CONTROL: u16 = 0x02 << 8;
159    }
160
161    /// Terminal Control Selectors
162    pub mod terminal {
163        pub const UNDEFINED: u16 = 0x00 << 8;
164        pub const COPY_PROTECT_CONTROL: u16 = 0x01 << 8;
165        pub const CONNECTOR_CONTROL: u16 = 0x02 << 8;
166        pub const OVERLOAD_CONTROL: u16 = 0x03 << 8;
167        pub const CLUSTER_CONTROL: u16 = 0x04 << 8;
168        pub const UNDERFLOW_CONTROL: u16 = 0x05 << 8;
169        pub const OVERFLOW_CONTROL: u16 = 0x06 << 8;
170        pub const LATENCY_CONTROL: u16 = 0x07 << 8;
171    }
172
173    /// Mixer Control Selectors
174    pub mod mixer {
175        pub const UNDEFINED: u16 = 0x00 << 8;
176        pub const MIXER_CONTROL: u16 = 0x01 << 8;
177        pub const CLUSTER_CONTROL: u16 = 0x02 << 8;
178        pub const UNDERFLOW_CONTROL: u16 = 0x03 << 8;
179        pub const OVERFLOW_CONTROL: u16 = 0x04 << 8;
180        pub const LATENCY_CONTROL: u16 = 0x05 << 8;
181    }
182
183    /// Selector Control Selectors
184    pub mod selector {
185        pub const UNDEFINED: u16 = 0x00 << 8;
186        pub const SELECTOR_CONTROL: u16 = 0x01 << 8;
187        pub const LATENCY_CONTROL: u16 = 0x02 << 8;
188    }
189
190    /// Feature Unit Control Selectors
191    pub mod feature_unit {
192        pub const UNDEFINED: u16 = 0x00 << 8;
193        pub const MUTE_CONTROL: u16 = 0x01 << 8;
194        pub const VOLUME_CONTROL: u16 = 0x02 << 8;
195        pub const BASS_CONTROL: u16 = 0x03 << 8;
196        pub const MID_CONTROL: u16 = 0x04 << 8;
197        pub const TREBLE_CONTROL: u16 = 0x05 << 8;
198        pub const GRAPHIC_EQUALIZER_CONTROL: u8 = 0x06;
199        pub const AUTOMATIC_GAIN_CONTROL: u16 = 0x07 << 8;
200        pub const DELAY_CONTROL: u16 = 0x08 << 8;
201        pub const BASS_BOOST_CONTROL: u16 = 0x09 << 8;
202        pub const LOUDNESS_CONTROL: u16 = 0x0A << 8;
203        pub const INPUT_GAIN_CONTROL: u16 = 0x0B << 8;
204        pub const INPUT_GAIN_PAD_CONTROL: u16 = 0x0C << 8;
205        pub const PHASE_INVERTER_CONTROL: u16 = 0x0D << 8;
206        pub const UNDERFLOW_CONTROL: u16 = 0x0E << 8;
207        pub const OVERFLOW_CONTROL: u16 = 0x0F << 8;
208        pub const LATENCY_CONTROL: u16 = 0x10 << 8;
209    }
210
211    /// Effect Unit Control Selectors
212    pub mod effect_unit {
213        /// Parametric Equalizer Section Effect Unit Control Selectors
214        pub mod parametric_equalizer {
215            pub const UNDEFINED: u16 = 0x00 << 8;
216            pub const ENABLE_CONTROL: u16 = 0x01 << 8;
217            pub const CENTERFREQ_CONTROL: u16 = 0x02 << 8;
218            pub const QFACTOR_CONTROL: u16 = 0x03 << 8;
219            pub const GAIN_CONTROL: u16 = 0x04 << 8;
220            pub const UNDERFLOW_CONTROL: u16 = 0x05 << 8;
221            pub const OVERFLOW_CONTROL: u16 = 0x06 << 8;
222            pub const LATENCY_CONTROL: u16 = 0x07 << 8;
223        }
224
225        /// Reverberation Effect Unit Control Selectors
226        pub mod reverberation {
227            pub const UNDEFINED: u16 = 0x00 << 8;
228            pub const ENABLE_CONTROL: u16 = 0x01 << 8;
229            pub const TYPE_CONTROL: u16 = 0x02 << 8;
230            pub const LEVEL_CONTROL: u16 = 0x03 << 8;
231            pub const TIME_CONTROL: u16 = 0x04 << 8;
232            pub const FEEDBACK_CONTROL: u16 = 0x05 << 8;
233            pub const PREDELAY_CONTROL: u16 = 0x06 << 8;
234            pub const DENSITY_CONTROL: u16 = 0x07 << 8;
235            pub const HIFREQ_ROLLOFF_CONTROL: u16 = 0x08 << 8;
236            pub const UNDERFLOW_CONTROL: u16 = 0x09 << 8;
237            pub const OVERFLOW_CONTROL: u16 = 0x0A << 8;
238            pub const LATENCY_CONTROL: u16 = 0x0B << 8;
239        }
240
241        /// Modulation Delay Effect Unit Control Selectors
242        pub mod modulation_delay {
243            pub const UNDEFINED: u16 = 0x00 << 8;
244            pub const ENABLE_CONTROL: u16 = 0x01 << 8;
245            pub const BALANCE_CONTROL: u16 = 0x02 << 8;
246            pub const RATE_CONTROL: u16 = 0x03 << 8;
247            pub const DEPTH_CONTROL: u16 = 0x04 << 8;
248            pub const TIME_CONTROL: u16 = 0x05 << 8;
249            pub const FEEDBACK_CONTROL: u16 = 0x06 << 8;
250            pub const UNDERFLOW_CONTROL: u16 = 0x07 << 8;
251            pub const OVERFLOW_CONTROL: u16 = 0x08 << 8;
252            pub const LATENCY_CONTROL: u16 = 0x09 << 8;
253        }
254
255        /// Dynamic Range Compressor Effect Unit Control Selectors
256        pub mod dynamic_range_compressor {
257            pub const UNDEFINED: u16 = 0x00 << 8;
258            pub const ENABLE_CONTROL: u16 = 0x01 << 8;
259            pub const COMPRESSION_RATE_CONTROL: u16 = 0x02 << 8;
260            pub const MAXAMPL_CONTROL: u16 = 0x03 << 8;
261            pub const THRESHOLD_CONTROL: u16 = 0x04 << 8;
262            pub const ATTACK_TIME_CONTROL: u16 = 0x05 << 8;
263            pub const RELEASE_TIME_CONTROL: u16 = 0x06 << 8;
264            pub const UNDERFLOW_CONTROL: u16 = 0x07 << 8;
265            pub const OVERFLOW_CONTROL: u16 = 0x08 << 8;
266            pub const LATENCY_CONTROL: u16 = 0x09 << 8;
267        }
268    }
269
270    /// Processing Unit Control Selectors
271    pub mod processing_unit {
272        /// Up/Down-mix Processing Unit Control Selectors
273        pub mod up_downmix {
274            pub const UNDEFINED: u16 = 0x00 << 8;
275            pub const ENABLE_CONTROL: u16 = 0x01 << 8;
276            pub const MODE_SELECT_CONTROL: u16 = 0x02 << 8;
277            pub const CLUSTER_CONTROL: u16 = 0x03 << 8;
278            pub const UNDERFLOW_CONTROL: u16 = 0x04 << 8;
279            pub const OVERFLOW_CONTROL: u16 = 0x05 << 8;
280            pub const LATENCY_CONTROL: u16 = 0x06 << 8;
281        }
282
283        /// Dolby Prologic Processing Unit Control Selectors
284        pub mod dolby_prologic {
285            pub const UNDEFINED: u16 = 0x00 << 8;
286            pub const ENABLE_CONTROL: u16 = 0x01 << 8;
287            pub const MODE_SELECT_CONTROL: u16 = 0x02 << 8;
288            pub const CLUSTER_CONTROL: u16 = 0x03 << 8;
289            pub const UNDERFLOW_CONTROL: u16 = 0x04 << 8;
290            pub const OVERFLOW_CONTROL: u16 = 0x05 << 8;
291            pub const LATENCY_CONTROL: u16 = 0x06 << 8;
292        }
293
294        /// Stereo Extender Processing Unit Control Selectors
295        pub mod stereo_extender {
296            pub const UNDEFINED: u16 = 0x00 << 8;
297            pub const ENABLE_CONTROL: u16 = 0x01 << 8;
298            pub const WIDTH_CONTROL: u16 = 0x02 << 8;
299            pub const UNDERFLOW_CONTROL: u16 = 0x03 << 8;
300            pub const OVERFLOW_CONTROL: u16 = 0x04 << 8;
301            pub const LATENCY_CONTROL: u16 = 0x05 << 8;
302        }
303    }
304
305    /// Extension Unit Control Selectors
306    pub mod extension_unit {
307        pub const UNDEFINED: u16 = 0x00 << 8;
308        pub const ENABLE_CONTROL: u16 = 0x01 << 8;
309        pub const CLUSTER_CONTROL: u16 = 0x02 << 8;
310        pub const UNDERFLOW_CONTROL: u16 = 0x03 << 8;
311        pub const OVERFLOW_CONTROL: u16 = 0x04 << 8;
312        pub const LATENCY_CONTROL: u16 = 0x05 << 8;
313    }
314
315    /// AudioStreaming Interface Control Selectors
316    pub mod audio_streaming {
317        pub const UNDEFINED: u16 = 0x00 << 8;
318        pub const ACT_ALT_SETTING_CONTROL: u16 = 0x01 << 8;
319        pub const VAL_ALT_SETTINGS_CONTROL: u16 = 0x02 << 8;
320        pub const AUDIO_DATA_FORMAT_CONTROL: u16 = 0x03 << 8;
321    }
322
323    /// Encoder Control Selectors
324    pub mod encoder {
325        pub const UNDEFINED: u16 = 0x00 << 8;
326        pub const BIT_RATE_CONTROL: u16 = 0x01 << 8;
327        pub const QUALITY_CONTROL: u16 = 0x02 << 8;
328        pub const VBR_CONTROL: u16 = 0x03 << 8;
329        pub const TYPE_CONTROL: u16 = 0x04 << 8;
330        pub const UNDERFLOW_CONTROL: u16 = 0x05 << 8;
331        pub const OVERFLOW_CONTROL: u16 = 0x06 << 8;
332        pub const ENCODER_ERROR_CONTROL: u16 = 0x07 << 8;
333        pub const PARAM1_CONTROL: u16 = 0x08 << 8;
334        pub const PARAM2_CONTROL: u16 = 0x09 << 8;
335        pub const PARAM3_CONTROL: u16 = 0x0A << 8;
336        pub const PARAM4_CONTROL: u16 = 0x0B << 8;
337        pub const PARAM5_CONTROL: u16 = 0x0C << 8;
338        pub const PARAM6_CONTROL: u16 = 0x0D << 8;
339        pub const PARAM7_CONTROL: u16 = 0x0E << 8;
340        pub const PARAM8_CONTROL: u16 = 0x0F << 8;
341    }
342
343    /// Decoder Control Selectors
344    pub mod decoder {
345        /// MPEG Decoder Control Selectors
346        pub mod mpeg {
347            pub const UNDEFINED: u16 = 0x00 << 8;
348            pub const DUAL_CHANNEL_CONTROL: u16 = 0x01 << 8;
349            pub const SECOND_STEREO_CONTROL: u16 = 0x02 << 8;
350            pub const MULTILINGUAL_CONTROL: u16 = 0x03 << 8;
351            pub const DYN_RANGE_CONTROL: u16 = 0x04 << 8;
352            pub const SCALING_CONTROL: u16 = 0x05 << 8;
353            pub const HILO_SCALING_CONTROL: u16 = 0x06 << 8;
354            pub const UNDERFLOW_CONTROL: u16 = 0x07 << 8;
355            pub const OVERFLOW_CONTROL: u16 = 0x08 << 8;
356            pub const DECODER_ERROR_CONTROL: u16 = 0x09 << 8;
357        }
358
359        /// AC-3 Decoder Control Selectors
360        pub mod ac_3 {
361            pub const UNDEFINED: u16 = 0x00 << 8;
362            pub const MODE_CONTROL: u16 = 0x01 << 8;
363            pub const DYN_RANGE_CONTROL: u16 = 0x02 << 8;
364            pub const SCALING_CONTROL: u16 = 0x03 << 8;
365            pub const HILO_SCALING_CONTROL: u16 = 0x04 << 8;
366            pub const UNDERFLOW_CONTROL: u16 = 0x05 << 8;
367            pub const OVERFLOW_CONTROL: u16 = 0x06 << 8;
368            pub const DECODER_ERROR_CONTROL: u16 = 0x07 << 8;
369        }
370
371        /// WMA Decoder Control Selectors
372        pub mod wma {
373            pub const UNDEFINED: u16 = 0x00 << 8;
374            pub const UNDERFLOW_CONTROL: u16 = 0x01 << 8;
375            pub const OVERFLOW_CONTROL: u16 = 0x02 << 8;
376            pub const DECODER_ERROR_CONTROL: u16 = 0x03 << 8;
377        }
378
379        /// DTS Decoder Control Selectors
380        pub mod dts {
381            pub const UNDEFINED: u16 = 0x00 << 8;
382            pub const UNDERFLOW_CONTROL: u16 = 0x01 << 8;
383            pub const OVERFLOW_CONTROL: u16 = 0x02 << 8;
384            pub const DECODER_ERROR_CONTROL: u16 = 0x03 << 8;
385        }
386    }
387
388    /// Endpoint Control Selectors
389    pub mod endpoint {
390        pub const UNDEFINED: u16 = 0x00 << 8;
391        pub const PITCH_CONTROL: u16 = 0x01 << 8;
392        pub const DATA_OVERRUN_CONTROL: u16 = 0x02 << 8;
393        pub const DATA_UNDERRUN_CONTROL: u16 = 0x03 << 8;
394    }
395}
396
397pub mod format_type {
398
399    macro_rules! bitflags {
400        ($($tt:tt)*) => {
401            #[cfg(feature = "defmt")]
402            defmt::bitflags! { $($tt)* }
403            #[cfg(not(feature = "defmt"))]
404            bitflags::bitflags! { #[derive(Debug, Clone, PartialEq)] $($tt)* }
405        };
406    }
407
408    pub const UNDEFINED: u8 = 0x00;
409    pub const I: u8 = 0x01;
410    pub const II: u8 = 0x02;
411    pub const III: u8 = 0x03;
412    pub const IV: u8 = 0x04;
413    pub const EXT_I: u8 = 0x81;
414    pub const EXT_II: u8 = 0x82;
415    pub const EXT_III: u8 = 0x83;
416
417    bitflags! {
418        pub struct Type1: u32 {
419            const PCM = 1 << 0;
420            const PCM8 = 1 << 1;
421            const IEEE_FLOAT = 1 << 2;
422            const ALAW = 1 << 3;
423            const MULAW = 1 << 4;
424            // Reserved. Must be set to 0. D30..D5
425            const TYPE_I_RAW_DATA = 1 << 31;
426        }
427    }
428    bitflags! {
429
430        pub struct Type2: u32 {
431            const MPEG = 1 << 0;
432            const AC_3 = 1 << 1;
433            const WMA = 1 << 2;
434            const DTS = 1 << 3;
435            // Reserved. Must be set to 0. D30..D4
436            const TYPE_II_RAW_DATA = 1 << 31;
437        }
438    }
439
440    bitflags! {
441        pub struct Type3: u32 {
442            const IEC61937_AC_3 = 1 << 0;
443            const IEC61937_MPEG_1_LAYER1 = 1 << 1;
444            const IEC61937_MPEG_1_LAYER2_3 = 1 << 2;
445            const IEC61937_MPEG_2_NOEXT = 1 << 2;
446            const IEC61937_MPEG_2_EXT = 1 << 3;
447            const IEC61937_MPEG_2_AAC_ADTS = 1 << 4;
448            const IEC61937_MPEG_2_LAYER1_LS = 1 << 5;
449            const IEC61937_MPEG_2_LAYER2_3_LS = 1 << 6;
450            const IEC61937_DTS_I = 1 << 7;
451            const IEC61937_DTS_II = 1 << 8;
452            const IEC61937_DTS_III = 1 << 9;
453            const IEC61937_ATRAC = 1 << 10;
454            const IEC61937_ATRAC2_3 = 1 << 11;
455            const TYPE_III_WMA = 1 << 12;
456            // Reserved. Must be set to 0. D31..D13
457        }
458    }
459
460    bitflags! {
461        pub struct Type4: u32 {
462            const PCM = 1 << 0;
463            const PCM8 = 1 << 1;
464            const IEEE_FLOAT = 1 << 2;
465            const ALAW = 1 << 3;
466            const MULAW = 1 << 4;
467            const MPEG = 1 << 5;
468            const AC_3 = 1 << 6;
469            const WMA = 1 << 7;
470            const IEC61937_AC_3 = 1 << 8;
471            const IEC61937_MPEG_1_LAYER1 = 1 << 9;
472            const IEC61937_MPEG_1_LAYER2_3 = 1 << 10;
473            const IEC61937_MPEG_2_NOEXT = 1 << 10;
474            const IEC61937_MPEG_2_EXT = 1 << 11;
475            const IEC61937_MPEG_2_AAC_ADTS = 1 << 12;
476            const IEC61937_MPEG_2_LAYER1_LS = 1 << 13;
477            const IEC61937_MPEG_2_LAYER2_3_LS = 1 << 14;
478            const IEC61937_DTS_I = 1 << 15;
479            const IEC61937_DTS_II = 1 << 16;
480            const IEC61937_DTS_III = 1 << 17;
481            const IEC61937_ATRAC = 1 << 18;
482            const IEC61937_ATRAC2_3 = 1 << 19;
483            const TYPE_III_WMA = 1 << 20;
484            const IEC60958_PCM = 1 << 21;
485            // Reserved. Must be set to 0. D31..D22
486        }
487    }
488
489    #[derive(Debug, Clone, PartialEq)]
490    #[cfg_attr(feature = "defmt", derive(defmt::Format))]
491    pub enum Format {
492        Type1(Type1),
493        Type2(Type2),
494        Type3(Type3),
495        Type4(Type4),
496        Type1Extended(Type1),
497        Type2Extended(Type2),
498        Type3Extended(Type3),
499    }
500
501    impl Format {
502        pub fn from_u32(format_type: u8, bitmap: u32) -> Option<Self> {
503            match format_type {
504                I => Some(Self::Type1(Type1::from_bits_truncate(bitmap))),
505                II => Some(Self::Type2(Type2::from_bits_truncate(bitmap))),
506                III => Some(Self::Type3(Type3::from_bits_truncate(bitmap))),
507                IV => Some(Self::Type4(Type4::from_bits_truncate(bitmap))),
508                EXT_I => Some(Self::Type1Extended(Type1::from_bits_truncate(bitmap))),
509                EXT_II => Some(Self::Type2Extended(Type2::from_bits_truncate(bitmap))),
510                EXT_III => Some(Self::Type3Extended(Type3::from_bits_truncate(bitmap))),
511                _ => None,
512            }
513        }
514    }
515}
516
517pub mod terminal_type {
518    // USB Terminal Types (0x01xx)
519    pub mod usb {
520        pub const UNDEFINED: u16 = 0x0100;
521        pub const STREAMING: u16 = 0x0101;
522        pub const VENDOR_SPECIFIC: u16 = 0x01FF;
523    }
524
525    // Input Terminal Types (0x02xx)
526    pub mod input {
527        pub const UNDEFINED: u16 = 0x0200;
528        pub const MICROPHONE: u16 = 0x0201;
529        pub const DESKTOP_MICROPHONE: u16 = 0x0202;
530        pub const PERSONAL_MICROPHONE: u16 = 0x0203;
531        pub const OMNI_DIRECTIONAL_MICROPHONE: u16 = 0x0204;
532        pub const MICROPHONE_ARRAY: u16 = 0x0205;
533        pub const PROCESSING_MICROPHONE_ARRAY: u16 = 0x0206;
534    }
535
536    // Output Terminal Types (0x03xx)
537    pub mod output {
538        pub const UNDEFINED: u16 = 0x0300;
539        pub const SPEAKER: u16 = 0x0301;
540        pub const HEADPHONES: u16 = 0x0302;
541        pub const HEAD_MOUNTED_DISPLAY_AUDIO: u16 = 0x0303;
542        pub const DESKTOP_SPEAKER: u16 = 0x0304;
543        pub const ROOM_SPEAKER: u16 = 0x0305;
544        pub const COMMUNICATION_SPEAKER: u16 = 0x0306;
545        pub const LOW_FREQUENCY_EFFECTS_SPEAKER: u16 = 0x0307;
546    }
547
548    // Bi-directional Terminal Types (0x04xx)
549    pub mod bidirectional {
550        pub const UNDEFINED: u16 = 0x0400;
551        pub const HANDSET: u16 = 0x0401;
552        pub const HEADSET: u16 = 0x0402;
553        pub const SPEAKERPHONE_NO_ECHO: u16 = 0x0403;
554        pub const ECHO_SUPPRESSING_SPEAKERPHONE: u16 = 0x0404;
555        pub const ECHO_CANCELING_SPEAKERPHONE: u16 = 0x0405;
556    }
557
558    // Telephony Terminal Types (0x05xx)
559    pub mod telephony {
560        pub const UNDEFINED: u16 = 0x0500;
561        pub const PHONE_LINE: u16 = 0x0501;
562        pub const TELEPHONE: u16 = 0x0502;
563        pub const DOWN_LINE_PHONE: u16 = 0x0503;
564    }
565
566    // External Terminal Types (0x06xx)
567    pub mod external {
568        pub const UNDEFINED: u16 = 0x0600;
569        pub const ANALOG_CONNECTOR: u16 = 0x0601;
570        pub const DIGITAL_AUDIO_INTERFACE: u16 = 0x0602;
571        pub const LINE_CONNECTOR: u16 = 0x0603;
572        pub const LEGACY_AUDIO_CONNECTOR: u16 = 0x0604;
573        pub const SPDIF_INTERFACE: u16 = 0x0605;
574        pub const DA_STREAM_1394: u16 = 0x0606;
575        pub const DV_STREAM_SOUNDTRACK_1394: u16 = 0x0607;
576        pub const ADAT_LIGHTPIPE: u16 = 0x0608;
577        pub const TDIF: u16 = 0x0609;
578        pub const MADI: u16 = 0x060A;
579    }
580
581    // Embedded Function Terminal Types (0x07xx)
582    pub mod embedded {
583        pub const UNDEFINED: u16 = 0x0700;
584        pub const LEVEL_CALIBRATION_NOISE_SOURCE: u16 = 0x0701;
585        pub const EQUALIZATION_NOISE: u16 = 0x0702;
586        pub const CD_PLAYER: u16 = 0x0703;
587        pub const DAT: u16 = 0x0704;
588        pub const DCC: u16 = 0x0705;
589        pub const COMPRESSED_AUDIO_PLAYER: u16 = 0x0706;
590        pub const ANALOG_TAPE: u16 = 0x0707;
591        pub const PHONOGRAPH: u16 = 0x0708;
592        pub const VCR_AUDIO: u16 = 0x0709;
593        pub const VIDEO_DISC_AUDIO: u16 = 0x070A;
594        pub const DVD_AUDIO: u16 = 0x070B;
595        pub const TV_TUNER_AUDIO: u16 = 0x070C;
596        pub const SATELLITE_RECEIVER_AUDIO: u16 = 0x070D;
597        pub const CABLE_TUNER_AUDIO: u16 = 0x070E;
598        pub const DSS_AUDIO: u16 = 0x070F;
599        pub const RADIO_RECEIVER: u16 = 0x0710;
600        pub const RADIO_TRANSMITTER: u16 = 0x0711;
601        pub const MULTI_TRACK_RECORDER: u16 = 0x0712;
602        pub const SYNTHESIZER: u16 = 0x0713;
603        pub const PIANO: u16 = 0x0714;
604        pub const GUITAR: u16 = 0x0715;
605        pub const DRUMS_RHYTHM: u16 = 0x0716;
606        pub const OTHER_MUSICAL_INSTRUMENT: u16 = 0x0717;
607    }
608}