Struct serpente::sercom::v2::spi::Spi [−][src]
pub struct Spi<C> where
C: ValidConfig, { /* fields omitted */ }
Expand description
An enabled SPI peripheral that can perform transactions using the embedded HAL traits
When an Spi
is Tx
+
Rx
, it implements FullDuplex
, with a
word type that depends on CharSize
. The word type is u8
for an
EightBit
CharSize
and u16
for a NineBit
CharSize
.
For half-duplex transactions, Spi
implements the serial
Read
and
Write
traits. They are only implemented when the Pads
are not
Tx
+
Rx
, so they don’t compete with FullDuplex
.
Spi
uses the default implementations for the blocking::spi
and
blocking::serial
traits.
For a non-blocking alternative that can be used to transfer slices, see the
SpiFuture
type.
Implementations
Obtain a reference to the PAC SERCOM
struct
Directly accessing the SERCOM
could break the invariants of the
type-level tracking in this module, so it is unsafe.
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.
Enable interrupts for the specified flags
Disable interrupts for the specified flags
Read the interrupt status flags
Clear interrupt status flags
Setting the ERROR, SSL or TXC flag will clear the interrupt. Clearing any flag will have no effect. This function has no effect on the DRE or RXC flags.
Warning: The implementation of of Write::flush
waits on and
clears the TXC
flag. Manually clearing this flag could cause it to
hang indefinitely.
Read the error status flags
Clear error status flags
Setting a flag will clear the error. Clearing any flag will have no effect.
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.
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
Perform a non-blocking, FullDuplex
trasaction
FullDuplex
is only implemented when Pads
is both Tx
and Rx
and the OpMode
is a MasterMode
. The word type is dependent on
CharSize
.
Implement Read
for MasterMode
s
Read
is only implemented when the Pads
are Rx
but NotTx
.
If the Pads
are both Rx
and Tx
, then use FullDuplex
.
In a MasterMode
, Read
has to initiate transactions and receive the
responses. To do so, it uses a static
allocation to keep 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
.
It should not be possible for the tracked state to become invalid using only
safe code. However, if using unsafe
, the state could fall out of sync. In
that case, the Spi::reset_serial_read_state
method can be used to reset
the state. After reset, a transaction is assumed to NOT be in progress.
If a transaction is already in progress, wait for an RXC
flag, then
read the word. If not, wait for a DRE
flag, then write 0
.
Track the transaction state with an internal static
. It should not be
possible for the state to get out of sync with the hardware using only
safe code. If using unsafe
and the state does get out of sync, use
Spi::reset_serial_read_state
to reset it.
impl<C> Default<<C as AnyConfig>::Word> for Spi<C> where
C: ValidConfig,
Spi<C>: FullDuplex<<C as AnyConfig>::Word>,
impl<C> Default<<C as AnyConfig>::Word> for Spi<C> where
C: ValidConfig,
Spi<C>: Write<<C as AnyConfig>::Word>,
impl<C> Default<<C as AnyConfig>::Word> for Spi<C> where
C: ValidConfig,
Spi<C>: FullDuplex<<C as AnyConfig>::Word>,
Auto Trait Implementations
impl<C> RefUnwindSafe for Spi<C> where
C: RefUnwindSafe,
impl<C> UnwindSafe for Spi<C> where
C: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
type Error = <S as FullDuplex<W>>::Error
type Error = <S as FullDuplex<W>>::Error
Error type
pub fn transfer(
&mut self,
words: &'w mut [W]
) -> Result<&'w [W], <S as FullDuplex<W>>::Error>
pub fn transfer(
&mut self,
words: &'w mut [W]
) -> Result<&'w [W], <S as FullDuplex<W>>::Error>
Sends words
to the slave. Returns the words
received from the slave
type Error = <S as FullDuplex<W>>::Error
type Error = <S as FullDuplex<W>>::Error
Error type
Writes a slice, blocking until everything has been written Read more