1use crate::bitmask::BitMask;
4use crate::SamplingRate;
5
6pub struct UsbNormal<'a> {
7 index: u16,
8 bitmask: BitMask<'a>,
9}
10
11impl<'a> UsbNormal<'a> {
12 pub fn new(index: u16, data: &'a mut u16) -> Self {
13 let bitmask = BitMask::new(data);
14
15 UsbNormal { index, bitmask }
16 }
17
18 pub fn usb(&mut self) {
19 self.bitmask.set(self.index);
20 }
21
22 pub fn normal(&mut self) {
23 self.bitmask.unset(self.index);
24 }
25}
26
27pub struct ClockDivider<'a> {
28 index: u16,
29 bitmask: BitMask<'a>,
30}
31
32impl<'a> ClockDivider<'a> {
33 pub fn new(index: u16, data: &'a mut u16) -> Self {
34 let bitmask = BitMask::new(data);
35
36 ClockDivider { index, bitmask }
37 }
38
39 pub fn divided_by_two(&mut self) {
40 self.bitmask.set(self.index);
41 }
42
43 pub fn normal(&mut self) {
44 self.bitmask.unset(self.index);
45 }
46}
47
48pub struct Oversampling<'a> {
49 index: u16,
50 bitmask: BitMask<'a>,
51}
52
53impl<'a> Oversampling<'a> {
54 pub fn new(index: u16, data: &'a mut u16) -> Self {
55 let bitmask = BitMask::new(data);
56
57 Oversampling { index, bitmask }
58 }
59
60 pub fn usb_272(&mut self) {
61 self.bitmask.set(self.index);
62 }
63
64 pub fn usb_250(&mut self) {
65 self.bitmask.unset(self.index);
66 }
67
68 pub fn normal_384(&mut self) {
69 self.bitmask.set(self.index);
70 }
71
72 pub fn normal_256(&mut self) {
73 self.bitmask.unset(self.index);
74 }
75}
76
77#[derive(Debug, Copy, Clone)]
78pub struct Sampling {
79 pub(crate) data: u16,
80}
81
82impl Sampling {
83 pub fn new() -> Self {
84 Sampling {
85 data: 0b0_0000_0000,
86 }
87 }
88
89 pub fn usb_normal(&mut self) -> UsbNormal {
91 UsbNormal::new(0, &mut self.data)
92 }
93
94 pub fn base_oversampling_rate(&mut self) -> Oversampling {
96 Oversampling::new(1, &mut self.data)
97 }
98
99 pub fn sample_rate(&mut self) -> SamplingRate {
101 SamplingRate::new(2, &mut self.data)
102 }
103
104 pub fn core_clock_divider_select(&mut self) -> ClockDivider {
106 ClockDivider::new(6, &mut self.data)
107 }
108
109 pub fn clock_out_divider_select(&mut self) -> ClockDivider {
111 ClockDivider::new(7, &mut self.data)
112 }
113}