From 3d47e3015a3106166e0553706f5aab72e4ef55c4 Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Fri, 17 Apr 2020 10:05:56 +0200 Subject: [PATCH 1/4] Add blocking I2S traits --- src/blocking/i2s.rs | 39 +++++++++++++++++++++++++++++++++++++++ src/blocking/mod.rs | 1 + src/prelude.rs | 3 +++ 3 files changed, 43 insertions(+) create mode 100644 src/blocking/i2s.rs diff --git a/src/blocking/i2s.rs b/src/blocking/i2s.rs new file mode 100644 index 000000000..1264cc9e4 --- /dev/null +++ b/src/blocking/i2s.rs @@ -0,0 +1,39 @@ +//! 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(&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/prelude.rs b/src/prelude.rs index 9ec6fb52d..999b78428 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::{ From fcda9f2cbea44f03de732d6893536776932f8f7d Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Fri, 17 Apr 2020 10:06:14 +0200 Subject: [PATCH 2/4] Add full duplex I2S trait --- src/i2s.rs | 17 +++++++++++++++++ src/lib.rs | 1 + src/prelude.rs | 1 + 3 files changed, 19 insertions(+) create mode 100644 src/i2s.rs 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 999b78428..42ddf1669 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -28,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; From 804b4988a25df1215d8419de0b861587f900cf15 Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Sat, 23 May 2020 18:03:08 +0200 Subject: [PATCH 3/4] Rename method for consistency --- src/blocking/i2s.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/blocking/i2s.rs b/src/blocking/i2s.rs index 1264cc9e4..0241adf2a 100644 --- a/src/blocking/i2s.rs +++ b/src/blocking/i2s.rs @@ -32,7 +32,11 @@ pub trait WriteIter { type Error; /// Sends `left_words` and `right_words` to the slave. - fn try_write(&mut self, left_words: LW, right_words: RW) -> Result<(), Self::Error> + fn try_write_iter( + &mut self, + left_words: LW, + right_words: RW, + ) -> Result<(), Self::Error> where LW: IntoIterator, RW: IntoIterator; From 7c078c198d32ca8582db029bb1771d3f9788cb4e Mon Sep 17 00:00:00 2001 From: Diego Barrios Romero Date: Thu, 5 Nov 2020 16:16:30 +0100 Subject: [PATCH 4/4] Add I2S entry to changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) 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