stm32_rust_template/driver/sai/
mod.rs1#![allow(dead_code)]
2
3use bitflags::bitflags;
4use core::ops::FnMut;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum Protocol {
9 UserDefined,
10 I2S,
11 MsbJustified,
12 LsbJustified,
13 PcmShort,
14 PcmLong,
15 Ac97,
16}
17
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
20pub enum Companding {
21 None,
22 ALaw,
23 ULaw,
24}
25
26#[derive(Debug, Clone, Copy, PartialEq, Eq)]
28pub enum BitOrder {
29 MsbFirst,
30 LsbFirst,
31}
32
33#[derive(Debug, Clone, Copy, PartialEq, Eq)]
35pub enum ClockPolarity {
36 FallingEdgeDrive,
37 RisingEdgeDrive,
38}
39
40#[derive(Debug, Clone, Copy, PartialEq, Eq)]
42pub enum Mode {
43 Master,
44 Slave,
45}
46
47#[derive(Debug, Clone, Copy, PartialEq, Eq)]
49pub enum Synchronization {
50 Asynchronous,
51 Synchronous,
52}
53
54#[derive(Debug, Clone, Copy, PartialEq, Eq)]
56pub enum PowerState {
57 Off,
58 Low,
59 Full,
60}
61
62#[derive(Debug, Clone, Copy, PartialEq, Eq)]
64pub struct Status {
65 pub tx_busy: bool,
66 pub rx_busy: bool,
67 pub tx_underflow: bool,
68 pub rx_overflow: bool,
69 pub frame_error: bool,
70}
71
72#[derive(Debug, Clone, Copy, PartialEq, Eq)]
74pub struct Capabilities {
75 pub asynchronous: bool,
76 pub synchronous: bool,
77 pub protocol_user: bool,
78 pub protocol_i2s: bool,
79 pub protocol_justified: bool,
80 pub protocol_pcm: bool,
81 pub protocol_ac97: bool,
82 pub mono_mode: bool,
83 pub companding: bool,
84 pub mclk_pin: bool,
85 pub event_frame_error: bool,
86}
87
88bitflags! {
89 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
91 pub struct Event: u32 {
92 const SEND_COMPLETE = 1 << 0;
93 const RECEIVE_COMPLETE = 1 << 1;
94 const TX_UNDERFLOW = 1 << 2;
95 const RX_OVERFLOW = 1 << 3;
96 const FRAME_ERROR = 1 << 4;
97 }
98}
99
100pub type Error = i32;
102
103pub type Result<T> = core::result::Result<T, Error>;
105
106pub trait Sai<'a> {
108 fn initialize(&mut self, callback: impl FnMut(Event) + 'a) -> Result<()>;
110
111 fn uninitialize(&mut self) -> Result<()>;
113
114 fn power_control(&mut self, state: PowerState) -> Result<()>;
116
117 fn send(&mut self, data: &[u8]) -> Result<()>;
119
120 fn receive(&mut self, buffer: &mut [u8]) -> Result<()>;
122
123 fn get_tx_count(&self) -> u32;
125
126 fn get_rx_count(&self) -> u32;
128
129 fn control(&mut self, control: u32, arg1: u32, arg2: u32) -> Result<()>;
133
134 fn get_status(&self) -> Status;
136}