wm8731_another_hal/registers/
digital_audio_interface.rs1#![allow(clippy::new_without_default)]
3use crate::interface::Frame;
4
5#[derive(Debug, Eq, PartialEq, Clone, Copy)]
7pub struct DigitalAudioInterface {
8 data: u8,
9}
10
11impl Default for DigitalAudioInterface {
12 fn default() -> Self {
13 Self::new()
14 }
15}
16
17impl DigitalAudioInterface {
18 pub fn new() -> Self {
19 Self { data: 0b1010 }
20 }
21 pub fn to_frame(&self) -> Frame {
22 Frame {
23 data: 0b111 << 9 | self.data as u16,
24 }
25 }
26}
27impl DigitalAudioInterface {
28 pub fn format(&self) -> FormatV {
29 let pos = 0;
30 match (self.data & (0b11 << pos)) >> pos {
31 0b11 => FormatV::Dsp,
32 0b10 => FormatV::I2s,
33 0b01 => FormatV::LeftJustified,
34 0b00 => FormatV::RigthJustified,
35 _ => unreachable!(),
36 }
37 }
38 pub fn iwl(&self) -> IwlV {
39 let pos = 2;
40 match (self.data & (0b11 << pos)) >> pos {
41 0b11 => IwlV::Iwl32Bits,
42 0b10 => IwlV::Iwl24Bits,
43 0b01 => IwlV::Iwl20Bits,
44 0b00 => IwlV::Iwl16Bits,
45 _ => unreachable!(),
46 }
47 }
48 pub fn lrp(&self) -> bool {
49 let pos = 4;
50 self.data & (1 << pos) == 1 << pos
51 }
52 pub fn lrswap(&self) -> bool {
53 let pos = 5;
54 self.data & (1 << pos) == 1 << pos
55 }
56 pub fn ms(&self) -> MsV {
57 let pos = 6;
58 match self.data & (1 << pos) == 1 << pos {
59 true => MsV::Master,
60 false => MsV::Slave,
61 }
62 }
63 pub fn bclkinv(&self) -> bool {
64 let pos = 7;
65 self.data & (1 << pos) == 1 << pos
66 }
67
68 pub fn set_format(&mut self, value: FormatV) -> &mut Self {
69 let pos = 0;
70 self.data = self.data & !(0b11 << pos) | (value as u8) << pos;
71 self
72 }
73 pub fn set_iwl(&mut self, value: IwlV) -> &mut Self {
74 let pos = 2;
75 self.data = self.data & !(0b11 << pos) | (value as u8) << pos;
76 self
77 }
78 pub fn set_lrp(&mut self, value: bool) -> &mut Self {
79 let pos = 4;
80 self.data = self.data & !(1 << pos) | (value as u8) << pos;
81 self
82 }
83 pub fn set_lrswap(&mut self, value: bool) -> &mut Self {
84 let pos = 5;
85 self.data = self.data & !(1 << pos) | (value as u8) << pos;
86 self
87 }
88 pub fn set_ms(&mut self, value: MsV) -> &mut Self {
89 let pos = 6;
90 self.data = self.data & !(1 << pos) | (value as u8) << pos;
91 self
92 }
93 pub fn set_bclkinv(&mut self, value: bool) -> &mut Self {
94 let pos = 7;
95 self.data = self.data & !(1 << pos) | (value as u8) << pos;
96 self
97 }
98}
99
100#[derive(Debug, Eq, PartialEq, Clone, Copy)]
102pub enum FormatV {
103 Dsp = 0b11,
104 I2s = 0b10,
105 LeftJustified = 0b01,
106 RigthJustified = 0b00,
107}
108
109#[derive(Debug, Eq, PartialEq, Clone, Copy)]
111pub enum IwlV {
112 Iwl32Bits = 0b11,
113 Iwl24Bits = 0b10,
114 Iwl20Bits = 0b01,
115 Iwl16Bits = 0b00,
116}
117
118#[derive(Debug, Eq, PartialEq, Clone, Copy)]
120pub enum MsV {
121 Master = 0b1,
122 Slave = 0b0,
123}