diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cirque.rs | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/src/cirque.rs b/src/cirque.rs index c026ea4..5e48269 100644 --- a/src/cirque.rs +++ b/src/cirque.rs @@ -68,8 +68,8 @@ enum RAPAddress { } trait SPIWriter<Word>: spi::FullDuplex<Word> { - fn write(&mut self, buf: &[Word]) -> Result<(), Self::Error>; - fn transfer(&mut self, buf: &mut [Word]) -> Result<(), Self::Error>; + fn write(&mut self, buf: &[Word]) -> nb::Result<(), Self::Error>; + fn transfer(&mut self, buf: &mut [Word]) -> nb::Result<(), Self::Error>; } impl<T, Word> SPIWriter<Word> for T @@ -77,21 +77,17 @@ where T: spi::FullDuplex<Word>, Word: Copy, { - fn write(&mut self, buf: &[Word]) -> Result<(), Self::Error> { + fn write(&mut self, buf: &[Word]) -> nb::Result<(), Self::Error> { for i in buf { - // TODO: figure out why the ? operator doesn't work here. - self.send(*i); + self.send(*i)?; } Ok(()) } - fn transfer(&mut self, buf: &mut [Word]) -> Result<(), Self::Error> { + fn transfer(&mut self, buf: &mut [Word]) -> nb::Result<(), Self::Error> { for i in buf.iter_mut() { - // TODO: figure out why the ? operator doesn't work here. - self.send(*i); - if let Ok(v) = self.read() { - *i = v; - } + self.send(*i)?; + *i = self.read()?; } Ok(()) } @@ -141,12 +137,7 @@ where C: OutputPin, D: InputPin, { - pub fn new<S>( - cs_pin: C, - dr_pin: D, - spi: &mut S, - clocks: Clocks, - ) -> nb::Result<Self, S::Error> + pub fn new<S>(cs_pin: C, dr_pin: D, spi: &mut S, clocks: Clocks) -> nb::Result<Self, S::Error> where S: embedded_hal::spi::FullDuplex<u8>, { @@ -227,7 +218,7 @@ where }) } - fn rd<S>(&mut self, spi: &mut S, cmd: u8, buf: &mut [u8]) -> Result<(), S::Error> + fn rd<S>(&mut self, spi: &mut S, cmd: u8, buf: &mut [u8]) -> nb::Result<(), S::Error> where S: embedded_hal::spi::FullDuplex<u8>, { @@ -241,7 +232,7 @@ where res } - fn wr<S>(&mut self, spi: &mut S, addr: u8, data: u8) -> Result<(), S::Error> + fn wr<S>(&mut self, spi: &mut S, addr: u8, data: u8) -> nb::Result<(), S::Error> where S: embedded_hal::spi::FullDuplex<u8>, { |