esp_hal::spi::master

Struct Spi

Source
pub struct Spi<'d, M, T = AnySpi> { /* private fields */ }
Expand description

SPI peripheral driver

Implementations§

Source§

impl<'d, M, T> Spi<'d, M, T>
where M: Mode, T: Instance,

Source

pub fn with_dma<CH, DM>(self, channel: Channel<'d, DM, CH>) -> SpiDma<'d, M, T>
where CH: DmaChannelConvert<T::Dma>, DM: Mode, Channel<'d, M, CH>: From<Channel<'d, DM, CH>>,

Configures the SPI instance to use DMA with the specified channel.

This method prepares the SPI instance for DMA transfers using SPI and returns an instance of SpiDma that supports DMA operations.

Source§

impl<M, T> Spi<'_, M, T>
where T: Instance,

Source

pub fn read_byte(&mut self) -> Result<u8, Error>

Read a byte from SPI.

Sends out a stuffing byte for every byte to read. This function doesn’t perform flushing. If you want to read the response to something you have written before, consider using Self::transfer instead.

Source

pub fn write_byte(&mut self, word: u8) -> Result<(), Error>

Write a byte to SPI.

Source

pub fn write_bytes(&mut self, words: &[u8]) -> Result<(), Error>

Write bytes to SPI.

Copies the content of words in chunks of 64 bytes into the SPI transmission FIFO. If words is longer than 64 bytes, multiple sequential transfers are performed.

Source

pub fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Error>

Sends words to the slave. Returns the words received from the slave

Source§

impl<'d> Spi<'d, Blocking>

Source

pub fn new(spi: impl Peripheral<P = impl Instance> + 'd) -> Spi<'d, Blocking>

Constructs an SPI instance in 8bit dataframe mode.

Source

pub fn new_with_config( spi: impl Peripheral<P = impl Instance> + 'd, config: Config, ) -> Spi<'d, Blocking>

Constructs an SPI instance in 8bit dataframe mode.

Source

pub fn into_async(self) -> Spi<'d, Async>

Converts the SPI instance into async mode.

Source§

impl<'d> Spi<'d, Async>

Source

pub fn into_blocking(self) -> Spi<'d, Blocking>

Converts the SPI instance into blocking mode.

Source§

impl<'d, M, T> Spi<'d, M, T>
where T: Instance,

Source

pub fn new_typed(spi: impl Peripheral<P = T> + 'd) -> Spi<'d, M, T>

Constructs an SPI instance in 8bit dataframe mode.

Source

pub fn new_typed_with_config( spi: impl Peripheral<P = T> + 'd, config: Config, ) -> Spi<'d, M, T>

Constructs an SPI instance in 8bit dataframe mode.

Source

pub fn with_mosi<MOSI: PeripheralOutput>( self, mosi: impl Peripheral<P = MOSI> + 'd, ) -> Self

Assign the MOSI (Master Out Slave In) pin for the SPI instance.

Enables both input and output functionality for the pin, and connects it to the MOSI signal and SIO0 input signal.

Source

pub fn with_miso<MISO: PeripheralOutput>( self, miso: impl Peripheral<P = MISO> + 'd, ) -> Self

Assign the MISO (Master In Slave Out) pin for the SPI instance.

Enables both input and output functionality for the pin, and connects it to the MISO signal and SIO1 input signal.

Source

pub fn with_sck<SCK: PeripheralOutput>( self, sclk: impl Peripheral<P = SCK> + 'd, ) -> Self

Assign the SCK (Serial Clock) pin for the SPI instance.

Sets the specified pin to push-pull output and connects it to the SPI clock signal.

Source

pub fn with_cs<CS: PeripheralOutput>( self, cs: impl Peripheral<P = CS> + 'd, ) -> Self

Assign the CS (Chip Select) pin for the SPI instance.

Sets the specified pin to push-pull output and connects it to the SPI CS signal.

Source

pub fn apply_config(&mut self, config: &Config) -> Result<(), ConfigError>

Change the bus configuration.

Source§

impl<'d, M, T> Spi<'d, M, T>
where T: QspiInstance,

Source

pub fn with_sio2<SIO2: PeripheralOutput>( self, sio2: impl Peripheral<P = SIO2> + 'd, ) -> Self
where T: QspiInstance,

Assign the SIO2 pin for the SPI instance.

Enables both input and output functionality for the pin, and connects it to the SIO2 output and input signals.

Source

pub fn with_sio3<SIO3: PeripheralOutput>( self, sio3: impl Peripheral<P = SIO3> + 'd, ) -> Self
where T: QspiInstance,

Assign the SIO3 pin for the SPI instance.

Enables both input and output functionality for the pin, and connects it to the SIO3 output and input signals.

Source§

impl<M, T> Spi<'_, M, T>
where T: Instance,

Source

pub fn half_duplex_read( &mut self, data_mode: SpiDataMode, cmd: Command, address: Address, dummy: u8, buffer: &mut [u8], ) -> Result<(), Error>

Half-duplex read.

Source

pub fn half_duplex_write( &mut self, data_mode: SpiDataMode, cmd: Command, address: Address, dummy: u8, buffer: &[u8], ) -> Result<(), Error>

Half-duplex write.

Trait Implementations§

Source§

impl<M, T> ErrorType for Spi<'_, M, T>

Source§

type Error = Error

Error type.
Source§

impl<M, T> FullDuplex for Spi<'_, M, T>
where T: Instance,

Source§

fn read(&mut self) -> Result<u8, Self::Error>

Reads the word stored in the shift register Read more
Source§

fn write(&mut self, word: u8) -> Result<(), Self::Error>

Writes a word to the slave
Source§

impl<M, T> SetConfig for Spi<'_, M, T>
where T: Instance, M: Mode,

Source§

type Config = Config

The configuration type used by this driver.
Source§

type ConfigError = ConfigError

The error type that can occur if set_config fails.
Source§

fn set_config(&mut self, config: &Self::Config) -> Result<(), Self::ConfigError>

Set the configuration of the driver.
Source§

impl<M, T> SpiBus for Spi<'_, M, T>
where T: Instance,

Source§

fn read(&mut self, words: &mut [u8]) -> Result<(), Self::Error>

Read words from the slave. Read more
Source§

fn write(&mut self, words: &[u8]) -> Result<(), Self::Error>

Write words to the slave, ignoring all the incoming words. Read more
Source§

fn transfer(&mut self, read: &mut [u8], write: &[u8]) -> Result<(), Self::Error>

Write and read simultaneously. write is written to the slave on MOSI and words received on MISO are stored in read. Read more
Source§

fn transfer_in_place(&mut self, words: &mut [u8]) -> Result<(), Self::Error>

Write and read simultaneously. The contents of words are written to the slave, and the received words are stored into the same words buffer, overwriting it. Read more
Source§

fn flush(&mut self) -> Result<(), Self::Error>

Wait until all operations have completed and the bus is idle. Read more
Source§

impl<M, T> Transfer<u8> for Spi<'_, M, T>
where T: Instance,

Source§

type Error = Error

Error type
Source§

fn transfer<'w>(&mut self, words: &'w mut [u8]) -> Result<&'w [u8], Self::Error>

Sends words to the slave. Returns the words received from the slave
Source§

impl<M, T> Write<u8> for Spi<'_, M, T>
where T: Instance,

Source§

type Error = Error

Error type
Source§

fn write(&mut self, words: &[u8]) -> Result<(), Self::Error>

Sends words to the slave, ignoring all the incoming words
Source§

impl<M, T> FullDuplex<u8> for Spi<'_, M, T>
where T: Instance,

Source§

type Error = Error

An enumeration of SPI errors
Source§

fn read(&mut self) -> Result<u8, Self::Error>

Reads the word stored in the shift register Read more
Source§

fn send(&mut self, word: u8) -> Result<(), Self::Error>

Sends a word to the slave

Auto Trait Implementations§

§

impl<'d, M, T> Freeze for Spi<'d, M, T>
where T: Freeze,

§

impl<'d, M, T> RefUnwindSafe for Spi<'d, M, T>

§

impl<'d, M, T> Send for Spi<'d, M, T>
where T: Send, M: Send,

§

impl<'d, M, T> Sync for Spi<'d, M, T>
where T: Sync, M: Sync,

§

impl<'d, M, T> Unpin for Spi<'d, M, T>
where T: Unpin, M: Unpin,

§

impl<'d, M, T = AnySpi> !UnwindSafe for Spi<'d, M, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.