diff --git a/lib/io/src/lib.rs b/lib/io/src/lib.rs index 927fae6..7040188 100644 --- a/lib/io/src/lib.rs +++ b/lib/io/src/lib.rs @@ -2,3 +2,4 @@ pub mod gpio; pub mod i2c; +pub mod spi; diff --git a/lib/io/src/spi.rs b/lib/io/src/spi.rs new file mode 100644 index 0000000..479dc78 --- /dev/null +++ b/lib/io/src/spi.rs @@ -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>; +}