Skip to content

Commit cb5dbf2

Browse files
committed
implement FullDuplex for Spi
1 parent e679ab1 commit cb5dbf2

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/spi.rs

+40
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,26 @@ where
454454
}
455455
}
456456

457+
impl<SPI, SCKPIN, MISOPIN, MOSIPIN> ::embedded_hal::spi::FullDuplex<u8>
458+
for Spi<SPI, SCKPIN, MISOPIN, MOSIPIN, EightBit>
459+
where
460+
SPI: Deref<Target = SpiRegisterBlock>,
461+
{
462+
type Error = Error;
463+
464+
fn read(&mut self) -> nb::Result<u8, Error> {
465+
self.check_read()?;
466+
Ok(self.read_u8())
467+
}
468+
469+
fn send(&mut self, byte: u8) -> nb::Result<(), Error> {
470+
self.check_send()?;
471+
self.send_u8(byte);
472+
self.check_send().ok();
473+
Ok(())
474+
}
475+
}
476+
457477
impl<SPI, SCKPIN, MISOPIN, MOSIPIN> ::embedded_hal::blocking::spi::Write<u8>
458478
for Spi<SPI, SCKPIN, MISOPIN, MOSIPIN, EightBit>
459479
where
@@ -487,6 +507,26 @@ where
487507
}
488508
}
489509

510+
impl<SPI, SCKPIN, MISOPIN, MOSIPIN> ::embedded_hal::spi::FullDuplex<u16>
511+
for Spi<SPI, SCKPIN, MISOPIN, MOSIPIN, SixteenBit>
512+
where
513+
SPI: Deref<Target = SpiRegisterBlock>,
514+
{
515+
type Error = Error;
516+
517+
fn read(&mut self) -> nb::Result<u16, Error> {
518+
self.check_read()?;
519+
Ok(self.read_u16())
520+
}
521+
522+
fn send(&mut self, byte: u16) -> nb::Result<(), Error> {
523+
self.check_send()?;
524+
self.send_u16(byte);
525+
self.check_send().ok();
526+
Ok(())
527+
}
528+
}
529+
490530
impl<SPI, SCKPIN, MISOPIN, MOSIPIN> ::embedded_hal::blocking::spi::Transfer<u16>
491531
for Spi<SPI, SCKPIN, MISOPIN, MOSIPIN, SixteenBit>
492532
where

0 commit comments

Comments
 (0)