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.

Disable the SPI peripheral and return the Config struct

Reset the internal state tracking serial Read transactions

See the implementation of Read for more details.

Trait Implementations

Performs the conversion.

Performs the conversion.

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.

An enumeration of SPI errors

Reads the word stored in the shift register Read more

Sends a word to the slave

Implement Read for Slave OpMode

Read is only implemented when the Pads are Rx but NotTx. If the Pads are both Rx and Tx, then use FullDuplex.

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.

Wait for an RXC flag, then read the word

Read error

Implement Read for MasterModes

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.

Read error

Implement Write for Spi

Write is only implemented when the Pads are Tx but NotRx. If the Pads are both Tx and Rx, then use FullDuplex.

Because Write is only implemented when the Pads are NotRx, this implementation never reads the DATA register and ignores all buffer overflow errors.

Wait for a DRE flag, then write a word

Wait for a TXC flag

Write error

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Spi transaction length Read more

Return the Spi transaction length Read more

Step size through the SpiFuture buffer Read more

Return the step size through the SpiFuture buffer Read more

Check that the buffer has a valid length Read more

Performs the conversion.

Performs the conversion.

Should always be Self

Error type

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Error type

Sends words to the slave, ignoring all the incoming words

The type of error that can occur when writing

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

Block until the serial interface has sent all buffered words