embedded_audio_driver/stream/
i2s.rs

1use crate::Result;
2use crate::stream::{AudioFormat, Stream, InputStream, OutputStream};
3
4/// I2S operating modes
5#[derive(Debug, Clone, Copy)]
6pub enum I2sMode {
7    Master,  // Clock provider
8    Slave,   // Clock receiver
9}
10
11/// I2S protocol standards
12#[derive(Debug, Clone, Copy)]
13pub enum I2sStandard {
14    Philips,    // Standard I2S format
15    MSB,        // MSB justified format
16    LSB,        // LSB justified format
17    PCM,        // PCM format
18}
19
20/// I2S configuration parameters
21#[derive(Debug, Clone)]
22pub struct I2sConfig {
23    pub mode: I2sMode,
24    pub standard: I2sStandard,
25    pub format: AudioFormat,
26    /// MCLK divider ratio (optional)
27    pub mclk_div: Option<u32>,
28}
29
30/// I2S device interface
31/// 
32/// This trait defines the operations for I2S (Inter-IC Sound) devices,
33/// supporting both transmission and reception of audio data.
34pub trait I2s: Stream {
35    /// Configure the I2S interface
36    fn configure(&mut self, config: &I2sConfig) -> Result<()>;
37    
38    /// Get current I2S configuration
39    fn get_config(&self) -> Option<I2sConfig>;
40}
41
42/// I2S input device interface
43pub trait I2sInput: I2s + InputStream {}
44
45/// I2S output device interface
46pub trait I2sOutput: I2s + OutputStream {}