diff --git a/CHANGELOG.md b/CHANGELOG.md index 39584b49b..3bf7c6972 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] ### Added +- I2S (Inter-IC Sound) traits. ### Changed diff --git a/src/blocking/i2s.rs b/src/blocking/i2s.rs new file mode 100644 index 000000000..0241adf2a --- /dev/null +++ b/src/blocking/i2s.rs @@ -0,0 +1,43 @@ +//! Blocking I2S API + +/// Blocking read +pub trait Read { + /// Error type + type Error; + + /// Reads enough bytes from the slave to fill `left_words` and `right_words`. + fn try_read<'w>( + &mut self, + left_words: &'w mut [W], + right_words: &'w mut [W], + ) -> Result<(), Self::Error>; +} + +/// Blocking write +pub trait Write { + /// Error type + type Error; + + /// Sends `left_words` and `right_words` to the slave. + fn try_write<'w>( + &mut self, + left_words: &'w [W], + right_words: &'w [W], + ) -> Result<(), Self::Error>; +} + +/// Blocking write (iterator version) +pub trait WriteIter { + /// Error type + type Error; + + /// Sends `left_words` and `right_words` to the slave. + fn try_write_iter( + &mut self, + left_words: LW, + right_words: RW, + ) -> Result<(), Self::Error> + where + LW: IntoIterator, + RW: IntoIterator; +} diff --git a/src/blocking/mod.rs b/src/blocking/mod.rs index 3a050f6d2..338a8c40b 100644 --- a/src/blocking/mod.rs +++ b/src/blocking/mod.rs @@ -6,6 +6,7 @@ pub mod delay; pub mod i2c; +pub mod i2s; pub mod rng; pub mod serial; pub mod spi; diff --git a/src/i2s.rs b/src/i2s.rs new file mode 100644 index 000000000..215b84c9c --- /dev/null +++ b/src/i2s.rs @@ -0,0 +1,17 @@ +//! I2S - Inter-IC Sound Interface + +use nb; + +/// Full duplex +pub trait FullDuplex { + /// Error type + type Error; + + /// Reads the left word and right word available. + /// + /// The order is in the result is `(left_word, right_word)` + fn try_read(&mut self) -> nb::Result<(Word, Word), Self::Error>; + + /// Sends a left word and a right word to the slave. + fn try_send(&mut self, left_word: Word, right_word: Word) -> nb::Result<(), Self::Error>; +} diff --git a/src/lib.rs b/src/lib.rs index 1b869a53d..b9caccad5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -412,6 +412,7 @@ pub mod blocking; pub mod capture; pub mod digital; pub mod fmt; +pub mod i2s; pub mod prelude; pub mod pwm; pub mod qei; diff --git a/src/prelude.rs b/src/prelude.rs index 9ec6fb52d..42ddf1669 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -14,6 +14,9 @@ pub use crate::blocking::i2c::{ WriteIterRead as _embedded_hal_blocking_i2c_WriteIterRead, WriteRead as _embedded_hal_blocking_i2c_WriteRead, }; +pub use crate::blocking::i2s::{ + Read as _embedded_hal_blocking_i2s_Read, Write as _embedded_hal_blocking_i2s_Write, +}; pub use crate::blocking::rng::Read as _embedded_hal_blocking_rng_Read; pub use crate::blocking::serial::Write as _embedded_hal_blocking_serial_Write; pub use crate::blocking::spi::{ @@ -25,6 +28,7 @@ pub use crate::digital::InputPin as _embedded_hal_digital_InputPin; pub use crate::digital::OutputPin as _embedded_hal_digital_OutputPin; pub use crate::digital::StatefulOutputPin as _embedded_hal_digital_StatefulOutputPin; pub use crate::digital::ToggleableOutputPin as _embedded_hal_digital_ToggleableOutputPin; +pub use crate::i2s::FullDuplex as _embedded_hal_i2s_FullDuplex; pub use crate::pwm::Pwm as _embedded_hal_Pwm; pub use crate::pwm::PwmPin as _embedded_hal_PwmPin; pub use crate::qei::Qei as _embedded_hal_Qei;