Skip to content

[Proposal] I2S traits #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

### Added
- I2S (Inter-IC Sound) traits.

### Changed

Expand Down
43 changes: 43 additions & 0 deletions src/blocking/i2s.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//! Blocking I2S API

/// Blocking read
pub trait Read<W> {
/// 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<W> {
/// 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<W> {
/// Error type
type Error;

/// Sends `left_words` and `right_words` to the slave.
fn try_write_iter<LW, RW>(
&mut self,
left_words: LW,
right_words: RW,
) -> Result<(), Self::Error>
where
LW: IntoIterator<Item = W>,
RW: IntoIterator<Item = W>;
}
1 change: 1 addition & 0 deletions src/blocking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

pub mod delay;
pub mod i2c;
pub mod i2s;
pub mod rng;
pub mod serial;
pub mod spi;
17 changes: 17 additions & 0 deletions src/i2s.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! I2S - Inter-IC Sound Interface

use nb;

/// Full duplex
pub trait FullDuplex<Word> {
/// 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>;
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand All @@ -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;
Expand Down