Struct avr_hal_generic::spi::Spi
source · pub struct Spi<H, SPI, SCLKPIN, MOSIPIN, MISOPIN, CSPIN> { /* private fields */ }
Expand description
Behavior for a SPI interface.
Stores the SPI peripheral for register access. In addition, it takes
ownership of the MOSI and MISO pins to ensure they are in the correct mode.
Instantiate with the new
method.
This can be used both with the embedded-hal 0.2 spi::FullDuplex
trait, and
with the embedded-hal 1.0 spi::SpiBus
trait.
Implementations§
source§impl<H, SPI, SCLKPIN, MOSIPIN, MISOPIN, CSPIN> Spi<H, SPI, SCLKPIN, MOSIPIN, MISOPIN, CSPIN>
impl<H, SPI, SCLKPIN, MOSIPIN, MISOPIN, CSPIN> Spi<H, SPI, SCLKPIN, MOSIPIN, MISOPIN, CSPIN>
sourcepub fn new(
p: SPI,
sclk: Pin<Output, SCLKPIN>,
mosi: Pin<Output, MOSIPIN>,
miso: Pin<Input<PullUp>, MISOPIN>,
cs: Pin<Output, CSPIN>,
settings: Settings
) -> (Self, ChipSelectPin<CSPIN>)
pub fn new( p: SPI, sclk: Pin<Output, SCLKPIN>, mosi: Pin<Output, MOSIPIN>, miso: Pin<Input<PullUp>, MISOPIN>, cs: Pin<Output, CSPIN>, settings: Settings ) -> (Self, ChipSelectPin<CSPIN>)
Instantiate an SPI with the registers, SCLK/MOSI/MISO/CS pins, and settings, with the internal pull-up enabled on the MISO pin.
The pins are not actually used directly, but they are moved into the struct in
order to enforce that they are in the correct mode, and cannot be used by anyone
else while SPI is active. CS is placed into a ChipSelectPin
instance and given
back so that its output state can be changed as needed.
sourcepub fn with_external_pullup(
p: SPI,
sclk: Pin<Output, SCLKPIN>,
mosi: Pin<Output, MOSIPIN>,
miso: Pin<Input<Floating>, MISOPIN>,
cs: Pin<Output, CSPIN>,
settings: Settings
) -> (Self, ChipSelectPin<CSPIN>)
pub fn with_external_pullup( p: SPI, sclk: Pin<Output, SCLKPIN>, mosi: Pin<Output, MOSIPIN>, miso: Pin<Input<Floating>, MISOPIN>, cs: Pin<Output, CSPIN>, settings: Settings ) -> (Self, ChipSelectPin<CSPIN>)
Instantiate an SPI with the registers, SCLK/MOSI/MISO/CS pins, and settings, with an external pull-up on the MISO pin.
The pins are not actually used directly, but they are moved into the struct in order to enforce that they are in the correct mode, and cannot be used by anyone else while SPI is active.
sourcepub fn reconfigure(&mut self, settings: Settings) -> Result<(), Infallible>
pub fn reconfigure(&mut self, settings: Settings) -> Result<(), Infallible>
Reconfigure the SPI peripheral after initializing
Trait Implementations§
source§impl<H, SPI, SCLKPIN, MOSIPIN, MISOPIN, CSPIN> ErrorType for Spi<H, SPI, SCLKPIN, MOSIPIN, MISOPIN, CSPIN>
impl<H, SPI, SCLKPIN, MOSIPIN, MISOPIN, CSPIN> ErrorType for Spi<H, SPI, SCLKPIN, MOSIPIN, MISOPIN, CSPIN>
§type Error = Infallible
type Error = Infallible
source§impl<H, SPI, SCLKPIN, MOSIPIN, MISOPIN, CSPIN> SpiBus for Spi<H, SPI, SCLKPIN, MOSIPIN, MISOPIN, CSPIN>
impl<H, SPI, SCLKPIN, MOSIPIN, MISOPIN, CSPIN> SpiBus for Spi<H, SPI, SCLKPIN, MOSIPIN, MISOPIN, CSPIN>
source§fn flush(&mut self) -> Result<(), Self::Error>
fn flush(&mut self) -> Result<(), Self::Error>
source§fn read(&mut self, read: &mut [u8]) -> Result<(), Self::Error>
fn read(&mut self, read: &mut [u8]) -> Result<(), Self::Error>
words
from the slave. Read moresource§fn write(&mut self, write: &[u8]) -> Result<(), Self::Error>
fn write(&mut self, write: &[u8]) -> Result<(), Self::Error>
words
to the slave, ignoring all the incoming words. Read moresource§impl<H, SPI, SCLKPIN, MOSIPIN, MISOPIN, CSPIN> FullDuplex<u8> for Spi<H, SPI, SCLKPIN, MOSIPIN, MISOPIN, CSPIN>
impl<H, SPI, SCLKPIN, MOSIPIN, MISOPIN, CSPIN> FullDuplex<u8> for Spi<H, SPI, SCLKPIN, MOSIPIN, MISOPIN, CSPIN>
FullDuplex trait implementation, allowing this struct to be provided to drivers that require it for operation. Only 8-bit word size is supported for now.
impl<H, SPI, SCLKPIN, MOSIPIN, MISOPIN, CSPIN> Default<u8> for Spi<H, SPI, SCLKPIN, MOSIPIN, MISOPIN, CSPIN>
Default Write trait implementation. Only 8-bit word size is supported for now.
impl<H, SPI, SCLKPIN, MOSIPIN, MISOPIN, CSPIN> Default<u8> for Spi<H, SPI, SCLKPIN, MOSIPIN, MISOPIN, CSPIN>
Default Transfer trait implementation. Only 8-bit word size is supported for now.