Skip to content

Commit

Permalink
SNS - Create HypedSpi trait (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbeechey authored and SinY-Over-CosY committed Nov 6, 2024
1 parent 2d4a56a commit 0db24f5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
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 {
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>;
/// Write data from `words` to the SPI sensor
fn write(&mut self, words: &[WordSize]) -> Result<(), SpiError>;
}

0 comments on commit 0db24f5

Please sign in to comment.