1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
use crate::bitmask::BitMask;
use crate::EnableDisable;
pub struct InputSelect<'a> {
index: u16,
bitmask: BitMask<'a>,
}
impl<'a> InputSelect<'a> {
pub fn new(index: u16, data: &'a mut u16) -> Self {
let bitmask = BitMask::new(data);
InputSelect { index, bitmask }
}
pub fn mic(&mut self) {
self.bitmask.set(self.index);
}
pub fn line_input(&mut self) {
self.bitmask.unset(self.index);
}
}
pub struct DacSelect<'a> {
index: u16,
bitmask: BitMask<'a>,
}
impl<'a> DacSelect<'a> {
pub fn new(index: u16, data: &'a mut u16) -> Self {
let bitmask = BitMask::new(data);
DacSelect { index, bitmask }
}
pub fn select(&mut self) {
self.bitmask.set(self.index);
}
pub fn deselect(&mut self) {
self.bitmask.unset(self.index);
}
}
#[derive(Debug, Copy, Clone)]
pub struct AnalogAudioPath {
pub(crate) data: u16,
}
impl AnalogAudioPath {
pub fn new() -> Self {
AnalogAudioPath {
data: 0b0_0000_0000,
}
}
pub fn mic_boost(&mut self) -> EnableDisable {
EnableDisable::new(0, &mut self.data)
}
pub fn mute_mic(&mut self) -> EnableDisable {
EnableDisable::new(1, &mut self.data)
}
pub fn input_select(&mut self) -> InputSelect {
InputSelect::new(2, &mut self.data)
}
pub fn bypass(&mut self) -> EnableDisable {
EnableDisable::new(3, &mut self.data)
}
pub fn dac_select(&mut self) -> DacSelect {
DacSelect::new(4, &mut self.data)
}
pub fn sidetone(&mut self) -> EnableDisable {
EnableDisable::new(5, &mut self.data)
}
pub fn sidetone_attenuation(&mut self) {
self.data |= 0b0_0000_0000
}
}