From d7f09b1e22ced7449dbe37b848a54bbc328e92d3 Mon Sep 17 00:00:00 2001 From: Brian Cully Date: Tue, 25 Oct 2022 15:46:13 -0400 Subject: cirque: fix ? operator --- src/cirque.rs | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) (limited to 'src') 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: spi::FullDuplex { - 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 SPIWriter for T @@ -77,21 +77,17 @@ where T: spi::FullDuplex, 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( - cs_pin: C, - dr_pin: D, - spi: &mut S, - clocks: Clocks, - ) -> nb::Result + pub fn new(cs_pin: C, dr_pin: D, spi: &mut S, clocks: Clocks) -> nb::Result where S: embedded_hal::spi::FullDuplex, { @@ -227,7 +218,7 @@ where }) } - fn rd(&mut self, spi: &mut S, cmd: u8, buf: &mut [u8]) -> Result<(), S::Error> + fn rd(&mut self, spi: &mut S, cmd: u8, buf: &mut [u8]) -> nb::Result<(), S::Error> where S: embedded_hal::spi::FullDuplex, { @@ -241,7 +232,7 @@ where res } - fn wr(&mut self, spi: &mut S, addr: u8, data: u8) -> Result<(), S::Error> + fn wr(&mut self, spi: &mut S, addr: u8, data: u8) -> nb::Result<(), S::Error> where S: embedded_hal::spi::FullDuplex, { -- cgit v1.2.3