usbdac_core/descriptors/
builders.rs1use super::types::{FeatureUnit, FormatTypeI, FormatTypeII};
2
3pub struct FeatureUnitBuilder {
4 b_unit_id: u8,
5 b_source_id: u8,
6 b_control_size: u8,
7 bma_controls: Vec<u32>,
8}
9
10impl FeatureUnitBuilder {
11 pub fn new(b_unit_id: u8, b_source_id: u8) -> Self {
12 Self {
13 b_unit_id,
14 b_source_id,
15 b_control_size: 4,
16 bma_controls: Vec::new(),
17 }
18 }
19
20 pub fn bma_controls(mut self, controls: Vec<u32>) -> Self {
21 self.bma_controls = controls;
22 self
23 }
24
25 pub fn build(self) -> FeatureUnit {
26 FeatureUnit {
27 b_unit_id: self.b_unit_id,
28 b_source_id: self.b_source_id,
29 b_control_size: self.b_control_size,
30 bma_controls: self.bma_controls,
31 }
32 }
33}
34
35pub struct FormatTypeIBuilder {
36 b_subslot_size: u8,
37 b_bit_resolution: u8,
38 b_sam_freq_type: u8,
39 sample_rates: Vec<u32>,
40}
41
42impl FormatTypeIBuilder {
43 pub fn new(b_subslot_size: u8, b_bit_resolution: u8) -> Self {
44 Self {
45 b_subslot_size,
46 b_bit_resolution,
47 b_sam_freq_type: 0,
48 sample_rates: Vec::new(),
49 }
50 }
51
52 pub fn continuous_sample_rate(mut self, rate: u32) -> Self {
53 self.b_sam_freq_type = 0;
54 self.sample_rates = vec![rate];
55 self
56 }
57
58 pub fn discrete_sample_rates(mut self, rates: Vec<u32>) -> Self {
59 self.b_sam_freq_type = rates.len() as u8;
60 self.sample_rates = rates;
61 self
62 }
63
64 pub fn build(self) -> FormatTypeI {
65 FormatTypeI {
66 b_subslot_size: self.b_subslot_size,
67 b_bit_resolution: self.b_bit_resolution,
68 b_sam_freq_type: self.b_sam_freq_type,
69 sample_rates: self.sample_rates,
70 }
71 }
72}
73
74pub struct FormatTypeIIBuilder {
75 w_max_bit_rate: u16,
76 w_samples_per_frame: u16,
77 b_sam_freq_type: u8,
78 sample_rates: Vec<u32>,
79}
80
81impl FormatTypeIIBuilder {
82 pub fn new(w_max_bit_rate: u16, w_samples_per_frame: u16) -> Self {
83 Self {
84 w_max_bit_rate,
85 w_samples_per_frame,
86 b_sam_freq_type: 0,
87 sample_rates: Vec::new(),
88 }
89 }
90
91 pub fn continuous_sample_rate(mut self, rate: u32) -> Self {
92 self.b_sam_freq_type = 0;
93 self.sample_rates = vec![rate];
94 self
95 }
96
97 pub fn discrete_sample_rates(mut self, rates: Vec<u32>) -> Self {
98 self.b_sam_freq_type = rates.len() as u8;
99 self.sample_rates = rates;
100 self
101 }
102
103 pub fn build(self) -> FormatTypeII {
104 FormatTypeII {
105 w_max_bit_rate: self.w_max_bit_rate,
106 w_samples_per_frame: self.w_samples_per_frame,
107 b_sam_freq_type: self.b_sam_freq_type,
108 sample_rates: self.sample_rates,
109 }
110 }
111}