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
sourceimpl<C, A> Spi<C, A>where
C: ValidConfig,
A: Capability,
impl<C, A> Spi<C, A>where
C: ValidConfig,
A: Capability,
sourcepub fn reconfigure(&mut self, update: impl FnOnce(&mut SpecificConfig<C>))
pub fn reconfigure(&mut self, update: impl FnOnce(&mut SpecificConfig<C>))
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.
sourcepub fn enable_interrupts(&mut self, flags: Flags)
pub fn enable_interrupts(&mut self, flags: Flags)
Enable interrupts for the specified flags
sourcepub fn disable_interrupts(&mut self, flags: Flags)
pub fn disable_interrupts(&mut self, flags: Flags)
Disable interrupts for the specified flags
sourcepub fn read_flags(&self) -> Flags
pub fn read_flags(&self) -> Flags
Read the interrupt flags
sourcepub fn clear_flags(&mut self, flags: Flags)
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.
sourcepub fn read_status(&self) -> Status
pub fn read_status(&self) -> Status
Read the error status flags
sourcepub fn clear_status(&mut self, status: Status)
pub fn clear_status(&mut self, status: Status)
Clear the corresponding error status flags
sourcepub fn read_flags_errors(&self) -> Result<Flags, Error>
pub fn read_flags_errors(&self) -> Result<Flags, Error>
Try to read the interrupt flags, but first check the error status flags.
sourcepub unsafe fn read_data(&mut self) -> DataWidth
pub unsafe fn read_data(&mut self) -> DataWidth
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.
sourcepub unsafe fn write_data(&mut self, data: DataWidth)
pub unsafe fn write_data(&mut self, data: DataWidth)
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.
Trait Implementations
sourceimpl<C, A> AnySpi for Spi<C, A>where
C: ValidConfig,
A: Capability,
impl<C, A> AnySpi for Spi<C, A>where
C: ValidConfig,
A: Capability,
sourceimpl<C, A> AsMut<Spi<C, A>> for Spi<C, A>where
C: ValidConfig,
A: Capability,
impl<C, A> AsMut<Spi<C, A>> for Spi<C, A>where
C: ValidConfig,
A: Capability,
sourceimpl<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,
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
sourcefn as_ref(&self) -> &SpecificConfig<C>
fn as_ref(&self) -> &SpecificConfig<C>
sourceimpl<C, A> AsRef<Spi<C, A>> for Spi<C, A>where
C: ValidConfig,
A: Capability,
impl<C, A> AsRef<Spi<C, A>> for Spi<C, A>where
C: ValidConfig,
A: Capability,
sourceimpl<C> FullDuplex<<C as AnyConfig>::Word> for Spi<C, Duplex>where
C: ValidConfig,
C::Word: PrimInt + AsPrimitive<u16>,
u16: AsPrimitive<C::Word>,
impl<C> FullDuplex<<C as AnyConfig>::Word> for Spi<C, Duplex>where
C: ValidConfig,
C::Word: PrimInt + AsPrimitive<u16>,
u16: AsPrimitive<C::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
.
sourceimpl<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::Word: PrimInt,
u16: AsPrimitive<C::Word>,
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::Word: PrimInt,
u16: AsPrimitive<C::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
.
sourceimpl<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::Word: PrimInt,
u16: AsPrimitive<C::Word>,
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::Word: PrimInt,
u16: AsPrimitive<C::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
.
sourceimpl<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,
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,
sourceimpl<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,
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,
sourceimpl<C> Write<<C as AnyConfig>::Word> for Spi<C, Tx>where
C: ValidConfig,
C::Word: PrimInt + AsPrimitive<u16>,
impl<C> Write<<C as AnyConfig>::Word> for Spi<C, Tx>where
C: ValidConfig,
C::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.
sourceimpl<P, M> Write<<EightBit as CharSize>::Word> for Spi<Config<P, M, EightBit>, Duplex>where
Config<P, M, EightBit>: ValidConfig,
P: ValidPads,
M: OpMode,
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
).
sourceimpl<P, M> Write<<EightBit as CharSize>::Word> for Spi<Config<P, M, EightBit>, Tx>where
Config<P, M, EightBit>: ValidConfig,
P: ValidPads,
M: OpMode,
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.
sourceimpl<P, M> Write<<NineBit as CharSize>::Word> for Spi<Config<P, M, NineBit>, Duplex>where
Config<P, M, NineBit>: ValidConfig,
P: ValidPads,
M: OpMode,
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
).
sourceimpl<P, M> Write<<NineBit as CharSize>::Word> for Spi<Config<P, M, NineBit>, Tx>where
Config<P, M, NineBit>: ValidConfig,
P: ValidPads,
M: OpMode,
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.
sourceimpl<P, M> WriteIter<<EightBit as CharSize>::Word> for Spi<Config<P, M, EightBit>, Duplex>where
Config<P, M, EightBit>: ValidConfig,
P: ValidPads,
M: OpMode,
impl<P, M> WriteIter<<EightBit as CharSize>::Word> for Spi<Config<P, M, EightBit>, Duplex>where
Config<P, M, EightBit>: ValidConfig,
P: ValidPads,
M: OpMode,
Implement WriteIter
for Spi
structs with Duplex
Capability
The transfer accepts a slice of primitive integers, depending on
the CharSize
(u8
or u16
).
sourcefn write_iter<WI>(&mut self, words: WI) -> Result<(), Error>where
WI: IntoIterator<Item = Word<EightBit>>,
fn write_iter<WI>(&mut self, words: WI) -> Result<(), Error>where
WI: IntoIterator<Item = Word<EightBit>>,
words
to the slave, ignoring all the incoming wordssourceimpl<P, M> WriteIter<<EightBit as CharSize>::Word> for Spi<Config<P, M, EightBit>, Tx>where
Config<P, M, EightBit>: ValidConfig,
P: ValidPads,
M: OpMode,
impl<P, M> WriteIter<<EightBit as CharSize>::Word> for Spi<Config<P, M, EightBit>, Tx>where
Config<P, M, EightBit>: ValidConfig,
P: ValidPads,
M: OpMode,
Implement WriteIter
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.
sourcefn write_iter<WI>(&mut self, words: WI) -> Result<(), Error>where
WI: IntoIterator<Item = Word<EightBit>>,
fn write_iter<WI>(&mut self, words: WI) -> Result<(), Error>where
WI: IntoIterator<Item = Word<EightBit>>,
words
to the slave, ignoring all the incoming wordssourceimpl<P, M> WriteIter<<NineBit as CharSize>::Word> for Spi<Config<P, M, NineBit>, Duplex>where
Config<P, M, NineBit>: ValidConfig,
P: ValidPads,
M: OpMode,
impl<P, M> WriteIter<<NineBit as CharSize>::Word> for Spi<Config<P, M, NineBit>, Duplex>where
Config<P, M, NineBit>: ValidConfig,
P: ValidPads,
M: OpMode,
Implement WriteIter
for Spi
structs with Duplex
Capability
The transfer accepts a slice of primitive integers, depending on
the CharSize
(u8
or u16
).
sourcefn write_iter<WI>(&mut self, words: WI) -> Result<(), Error>where
WI: IntoIterator<Item = Word<NineBit>>,
fn write_iter<WI>(&mut self, words: WI) -> Result<(), Error>where
WI: IntoIterator<Item = Word<NineBit>>,
words
to the slave, ignoring all the incoming wordssourceimpl<P, M> WriteIter<<NineBit as CharSize>::Word> for Spi<Config<P, M, NineBit>, Tx>where
Config<P, M, NineBit>: ValidConfig,
P: ValidPads,
M: OpMode,
impl<P, M> WriteIter<<NineBit as CharSize>::Word> for Spi<Config<P, M, NineBit>, Tx>where
Config<P, M, NineBit>: ValidConfig,
P: ValidPads,
M: OpMode,
Implement WriteIter
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.
sourcefn write_iter<WI>(&mut self, words: WI) -> Result<(), Error>where
WI: IntoIterator<Item = Word<NineBit>>,
fn write_iter<WI>(&mut self, words: WI) -> Result<(), Error>where
WI: IntoIterator<Item = Word<NineBit>>,
words
to the slave, ignoring all the incoming words