Skip to content
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

SNS - Create HypedSpi trait #38

Merged
merged 2 commits into from
Oct 25, 2024
Merged
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 lib/io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

pub mod gpio;
pub mod i2c;
pub mod spi;
22 changes: 22 additions & 0 deletions lib/io/src/spi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/// SPI errors that can occur
/// From: https://docs.embassy.dev/embassy-stm32/git/stm32f103c8/spi/enum.Error.html
pub enum SpiError {
TomLonergan03 marked this conversation as resolved.
Show resolved Hide resolved
Framing,
Crc,
ModeFault,
Overrun,
}

/// A word is either u8 or u16
pub enum WordSize {
U8(u8),
U16(u16),
}

/// SPI trait used to abstract SPI and allow for mocking
pub trait HypedSpi {
/// Read data into `words` from the SPI sensor
fn read(&mut self, words: &mut [WordSize]) -> Result<(), SpiError>;
davidbeechey marked this conversation as resolved.
Show resolved Hide resolved
/// Write data from `words` to the SPI sensor
fn write(&mut self, words: &[WordSize]) -> Result<(), SpiError>;
}