Struct serpente::sercom::v2::spi::Spi

source ·
pub struct Spi<C, A>where
    C: ValidConfig,
    A: Capability,{ /* private fields */ }
Expand description

An enabled SPI peripheral that can perform transactions

See the impl_ehal documentation for details on the implementations of the embedded HAL traits, which vary based on Size and Capability.

Implementations§

source§

impl<C, A> Spi<C, A>where C: ValidConfig, A: Capability,

source

pub fn reconfigure( &mut self, update: impl FnOnce(&mut Config<<C as AnyConfig>::Pads, <C as AnyConfig>::OpMode, <C as AnyConfig>::Size>) )

Update the SPI configuration.

Calling this method will temporarily disable the SERCOM peripheral, as some registers are enable-protected. This may interrupt any ongoing transactions.

source

pub fn enable_interrupts(&mut self, flags: Flags)

Enable interrupts for the specified flags

source

pub fn disable_interrupts(&mut self, flags: Flags)

Disable interrupts for the specified flags

source

pub fn read_flags(&self) -> Flags

Read the interrupt flags

source

pub fn clear_flags(&mut self, flags: Flags)

Clear the corresponding interrupt flags

Only the ERROR, SSL and TXC flags can be cleared.

Note: The implementation of of serial::Write::flush waits on and clears the TXC flag. Manually clearing this flag could cause it to hang indefinitely.

source

pub fn read_status(&self) -> Status

Read the error status flags

source

pub fn clear_status(&mut self, status: Status)

Clear the corresponding error status flags

source

pub fn read_flags_errors(&self) -> Result<Flags, Error>

Try to read the interrupt flags, but first check the error status flags.

source

pub unsafe fn read_data(&mut self) -> u16

Read from the DATA register

Reading from the data register directly is unsafe, because it will clear the RXC flag, which could break assumptions made elsewhere in this module.

source

pub unsafe fn write_data(&mut self, data: u16)

Write to the DATA register

Writing to the data register directly is unsafe, because it will clear the DRE flag, which could break assumptions made elsewhere in this module.

source

pub fn disable(self) -> C

Disable the SPI peripheral and return the Config struct

Trait Implementations§

source§

impl<C, A> AnySpi for Spi<C, A>where C: ValidConfig, A: Capability,

§

type Sercom = <C as AnyConfig>::Sercom

§

type Pads = <C as AnyConfig>::Pads

§

type Capability = A

§

type OpMode = <C as AnyConfig>::OpMode

§

type Size = <C as AnyConfig>::Size

§

type Word = <C as AnyConfig>::Word

§

type Config = C

source§

impl<C, A> AsMut<Spi<C, A>> for Spi<C, A>where C: ValidConfig, A: Capability,

source§

fn as_mut(&mut self) -> &mut Spi<C, A>

Converts this type into a mutable reference of the (usually inferred) input type.
source§

impl<C, A> AsRef<Config<<C as AnyConfig>::Pads, <C as AnyConfig>::OpMode, <C as AnyConfig>::Size>> for Spi<C, A>where C: ValidConfig, A: Capability,

Get a shared reference to the underlying Config struct

This can be used to call the various get_* functions on Config

source§

fn as_ref( &self ) -> &Config<<C as AnyConfig>::Pads, <C as AnyConfig>::OpMode, <C as AnyConfig>::Size>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<C, A> AsRef<Spi<C, A>> for Spi<C, A>where C: ValidConfig, A: Capability,

source§

fn as_ref(&self) -> &Spi<C, A>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<C> FullDuplex<<C as AnyConfig>::Word> for Spi<C, Duplex>where C: ValidConfig, <C as AnyConfig>::Word: PrimInt + AsPrimitive<u16>, u16: AsPrimitive<<C as AnyConfig>::Word>,

Implement spi::FullDuplex for Spi structs with AtomicSize

spi::FullDuplex is only implemented when the Spi struct has Duplex Capability. The Word size used in the implementation depends on the corresponding CharSize.

§

type Error = Error

An enumeration of SPI errors
source§

fn read(&mut self) -> Result<<C as AnyConfig>::Word, Error<Error>>

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

fn send(&mut self, word: <C as AnyConfig>::Word) -> Result<(), Error<Error>>

Sends a word to the slave
source§

impl<P, M, C> Read<<C as CharSize>::Word> for Spi<Config<P, M, C>, Rx>where Config<P, M, C>: ValidConfig, P: ValidPads, M: MasterMode, C: CharSize, <C as CharSize>::Word: PrimInt, u16: AsPrimitive<<C as CharSize>::Word>,

Implement serial::Read for Rx Spi structs in a MasterMode

serial::Read is only implemented for Spi structs with Rx Capability. In a MasterMode, Read has to initiate transactions, so it keeps track of the transaction state. If a transaction is in progress, it will wait on RXC. If not, it will wait on DRE, and then send 0.

§

type Error = Error

Read error
source§

fn read(&mut self) -> Result<<C as CharSize>::Word, Error<Error>>

Reads a single word from the serial interface
source§

impl<P, C> Read<<C as CharSize>::Word> for Spi<Config<P, Slave, C>, Rx>where Config<P, Slave, C>: ValidConfig, P: ValidPads, C: CharSize, <C as CharSize>::Word: PrimInt, u16: AsPrimitive<<C as CharSize>::Word>,

Implement serial::Read for Rx Spi structs in Slave OpMode

serial::Read is only implemented for Spi structs with Rx Capability. In Slave OpMode, Read does not have to initiate transactions, so it does not have to store any internal state. It only has to wait on RXC.

source§

fn read(&mut self) -> Result<<C as CharSize>::Word, Error<Error>>

Wait for an RXC flag, then read the word

§

type Error = Error

Read error
source§

impl<P, M, A> Transfer<<EightBit as CharSize>::Word> for Spi<Config<P, M, EightBit>, A>where Config<P, M, EightBit>: ValidConfig, P: ValidPads, M: OpMode, A: Receive,

Implement Transfer for Spi structs that can Receive

The transfer accepts a slice of primitive integers, depending on the CharSize (u8 or u16).

§

type Error = Error

Error type
source§

fn transfer<'w>( &mut self, words: &'w mut [<EightBit as CharSize>::Word] ) -> Result<&'w [<EightBit as CharSize>::Word], Error>

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

impl<P, M, A> Transfer<<NineBit as CharSize>::Word> for Spi<Config<P, M, NineBit>, A>where Config<P, M, NineBit>: ValidConfig, P: ValidPads, M: OpMode, A: Receive,

Implement Transfer for Spi structs that can Receive

The transfer accepts a slice of primitive integers, depending on the CharSize (u8 or u16).

§

type Error = Error

Error type
source§

fn transfer<'w>( &mut self, words: &'w mut [<NineBit as CharSize>::Word] ) -> Result<&'w [<NineBit as CharSize>::Word], Error>

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

impl<C> Write<<C as AnyConfig>::Word> for Spi<C, Tx>where C: ValidConfig, <C as AnyConfig>::Word: PrimInt + AsPrimitive<u16>,

Implement serial::Write for Tx Spi structs

serial::Write is only implemented for Spi structs with Tx Capability. Because the Capability is Tx, this implementation never reads the DATA register and ignores all buffer overflow errors.

§

type Error = Error

Write error
source§

fn write(&mut self, word: <C as AnyConfig>::Word) -> Result<(), Error<Error>>

Writes a single word to the serial interface
source§

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

Ensures that none of the previously written words are still buffered
source§

impl<P, M> Write<<EightBit as CharSize>::Word> for Spi<Config<P, M, EightBit>, Duplex>where Config<P, M, EightBit>: ValidConfig, P: ValidPads, M: OpMode,

Implement Write for Spi structs with Duplex Capability

The transfer accepts a slice of primitive integers, depending on the CharSize (u8 or u16).

§

type Error = Error

Error type
source§

fn write(&mut self, words: &[<EightBit as CharSize>::Word]) -> Result<(), Error>

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

impl<P, M> Write<<EightBit as CharSize>::Word> for Spi<Config<P, M, EightBit>, Tx>where Config<P, M, EightBit>: ValidConfig, P: ValidPads, M: OpMode,

Implement Write for Spi structs with Tx Capability

The transfer accepts a slice of primitive integers, depending on the CharSize (u8 or u16).

Because the Capability is Tx, this implementation never reads the DATA register and ignores all buffer overflow errors.

§

type Error = Error

Error type
source§

fn write(&mut self, words: &[<EightBit as CharSize>::Word]) -> Result<(), Error>

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

impl<P, M> Write<<NineBit as CharSize>::Word> for Spi<Config<P, M, NineBit>, Duplex>where Config<P, M, NineBit>: ValidConfig, P: ValidPads, M: OpMode,

Implement Write for Spi structs with Duplex Capability

The transfer accepts a slice of primitive integers, depending on the CharSize (u8 or u16).

§

type Error = Error

Error type
source§

fn write(&mut self, words: &[<NineBit as CharSize>::Word]) -> Result<(), Error>

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

impl<P, M> Write<<NineBit as CharSize>::Word> for Spi<Config<P, M, NineBit>, Tx>where Config<P, M, NineBit>: ValidConfig, P: ValidPads, M: OpMode,

Implement Write for Spi structs with Tx Capability

The transfer accepts a slice of primitive integers, depending on the CharSize (u8 or u16).

Because the Capability is Tx, this implementation never reads the DATA register and ignores all buffer overflow errors.

§

type Error = Error

Error type
source§

fn write(&mut self, words: &[<NineBit as CharSize>::Word]) -> Result<(), Error>

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

impl<C> Default<<C as AnyConfig>::Word> for Spi<C, Tx>where C: ValidConfig, Spi<C, Tx>: Write<<C as AnyConfig>::Word>,

Auto Trait Implementations§

§

impl<C, A> RefUnwindSafe for Spi<C, A>where A: RefUnwindSafe, C: RefUnwindSafe,

§

impl<C, A> Send for Spi<C, A>where A: Send, C: Send,

§

impl<C, A> Sync for Spi<C, A>where A: Sync, C: Sync,

§

impl<C, A> Unpin for Spi<C, A>where A: Unpin, C: Unpin,

§

impl<C, A> UnwindSafe for Spi<C, A>where A: UnwindSafe, C: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<S> CheckBufLen for Swhere S: AnySpi,

source§

const LEN: usize = size_of::<Self::Word>()

Spi transaction length
source§

fn len(&self) -> usize

Return the Spi transaction length Read more
source§

const STEP: usize =

Step size through the SpiFuture buffer Read more
source§

fn step(&self) -> usize

Return the step size through the SpiFuture buffer Read more
source§

fn check_buf_len(&self, buf: &impl AsRef<[u8]>)

Check that the buffer has a valid length 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 Twhere 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> Is for Twhere T: Sealed + AsRef<T> + AsMut<T>,

§

type Type = T

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
source§

impl<S, Word> Write<Word> for Swhere S: Default<Word>, Word: Clone,

§

type Error = <S as Write<Word>>::Error

The type of error that can occur when writing
source§

fn bwrite_all( &mut self, buffer: &[Word] ) -> Result<(), <S as Write<Word>>::Error>

Writes a slice, blocking until everything has been written Read more
source§

fn bflush(&mut self) -> Result<(), <S as Write<Word>>::Error>

Block until the serial interface has sent all buffered words