modm API documentation
modm::platform::UartSpiMaster5 Class Reference

#include <modm/platform/spi/uart_spi_master_5.hpp>

Inheritance diagram for modm::platform::UartSpiMaster5:
modm::SpiMaster modm::platform::UartBase modm::SpiLock< UartSpiMaster5 > modm::PeripheralDriver modm::Spi

Public Typedefs

using ConfigurationHandler = void (*)()
 The signature of the configuration function.
 

Public Types

enum  DataMode : uint32_t { DataMode::Mode0 = 0b00, DataMode::Mode1 = USART_CR2_CPHA, DataMode::Mode2 = USART_CR2_CPOL, DataMode::Mode3 = USART_CR2_CPOL | USART_CR2_CPHA }
 
enum  DataMode : uint8_t { DataMode::Mode0 = 0b00, DataMode::Mode1 = 0b01, DataMode::Mode2 = 0b10, DataMode::Mode3 = 0b11 }
 Spi Data Mode, Mode0 is the most common mode. More...
 
enum  DataOrder : uint8_t { MsbFirst = 0b0, LsbFirst = 0b1 }
 Spi Data Order, MsbFirst is the most common mode.
 
enum  Interrupt : uint32_t {
  Interrupt::CharacterMatch = USART_CR1_CMIE, Interrupt::ParityError = USART_CR1_PEIE, Interrupt::TxEmpty = USART_CR1_TXEIE, Interrupt::TxComplete = USART_CR1_TCIE,
  Interrupt::RxNotEmpty = USART_CR1_RXNEIE
}
 
enum  InterruptFlag : uint32_t {
  InterruptFlag::CharacterMatch = USART_ISR_CMF, InterruptFlag::TxEmpty = USART_ISR_TXE, InterruptFlag::TxComplete = USART_ISR_TC, InterruptFlag::RxNotEmpty = USART_ISR_RXNE,
  InterruptFlag::OverrunError = USART_ISR_ORE, InterruptFlag::FramingError = USART_ISR_FE, InterruptFlag::ParityError = USART_ISR_PE
}
 
enum  LastBitClockPulse : uint32_t { DoNotOutput = 0b0, Output = USART_CR2_LBCL }
 
enum  Parity : uint32_t { Disabled = 0, Even = USART_CR1_PCE, Odd = USART_CR1_PCE | USART_CR1_PS }
 
enum  SpiClock : uint32_t { Disabled = 0b0, Enabled = USART_CR2_CLKEN }
 
enum  SpiDataMode : uint32_t { Mode0 = 0b00, Mode1 = USART_CR2_CPHA, Mode2 = USART_CR2_CPOL, Mode3 = USART_CR2_CPOL | USART_CR2_CPHA }
 
enum  WordLength : uint32_t { Bit8 = 0, Bit9 = USART_CR1_M }
 

Public Member Functions

 MODM_FLAGS32 (Interrupt)
 
 MODM_FLAGS32 (InterruptFlag)
 

Static Public Member Functions

template<class... Signals>
static void connect ()
 
template<class SystemClock , baudrate_t baudrate, percent_t tolerance = pct(5)>
static void initialize ()
 
static void setDataMode (DataMode mode)
 
static void setDataOrder (DataOrder order)
 
static uint8_t transferBlocking (uint8_t data)
 
static void transferBlocking (const uint8_t *tx, uint8_t *rx, std::size_t length)
 
static modm::ResumableResult< uint8_t > transfer (uint8_t data)
 
static modm::ResumableResult< void > transfer (const uint8_t *tx, uint8_t *rx, std::size_t length)
 
static void acknowledgeInterruptFlag ()
 
static uint8_t acquire (void *ctx, ConfigurationHandler handler=nullptr)
 
template<uint64_t available, uint64_t requested, percent_t tolerance>
static void assertBaudrateInTolerance ()
 
template<double available, double requested, percent_t tolerance>
static void assertDurationInTolerance ()
 
static void configurePurpose ()
 configures a peripheral for a specific purpose
 
template<class... Signals>
static void connect ()
 
static bool getInterruptFlag ()
 Read an interrupt flag.
 
static void getParameter ()
 returns a parameter
 
template<class SystemClock , baudrate_t baudrate, percent_t tolerance = 5_pct>
static void initialize ()
 
static void initialize ()
 initializes the peripheral, must be called before use.
 
static uint8_t release (void *ctx)
 
static void setDataMode (DataMode mode)
 Sets a new data mode.
 
static void setDataOrder (DataOrder order)
 Sets a new data order.
 
static void setParameter ()
 sets a parameter
 
static modm::ResumableResult< uint8_t > transfer (uint8_t data)
 
static modm::ResumableResult< void > transfer (const uint8_t *tx, uint8_t *rx, std::size_t length)
 
static uint8_t transferBlocking (uint8_t data)
 
static void transferBlocking (const uint8_t *tx, uint8_t *rx, std::size_t length)
 
static uint8_t acquire (void *ctx, Spi::ConfigurationHandler handler)
 
static uint8_t release (void *ctx)
 

Detailed Description

Serial Peripheral Interface of the Uart module.

Warning
Be aware, that the UART module can send bytes only LSB first. Therefore the data is bit reversed in software for DataOrder::MsbFirst.
Author
Niklas Hauser

Member Enumeration Documentation

enum modm::Spi::DataMode : uint8_t
inheritedstrong

Spi Data Mode, Mode0 is the most common mode.

Enum ValuesDocumentation
Mode0 

clock normal, sample on rising edge

Mode1 

clock normal, sample on falling edge

Mode2 

clock inverted, sample on falling edge

Mode3 

clock inverted, sample on rising edge

Enum ValuesDocumentation
Mode0 

clock normal, sample on rising edge

Mode1 

clock normal, sample on falling edge

Mode2 

clock inverted, sample on falling edge

Mode3 

clock inverted, sample on rising edge

enum modm::platform::UartBase::Interrupt : uint32_t
inheritedstrong
Enum ValuesDocumentation
CharacterMatch 

A USART interrupt is generated when match character is received.

ParityError 

Call interrupt when a parity error occurred.

TxEmpty 

Call interrupt when transmit register is empty (i.e. the byte has been transfered to the shift out register.

TxComplete 

Called when the byte was completely transmitted.

RxNotEmpty 

Call interrupt when char received (RXNE) or overrun occurred (ORE)

enum modm::platform::UartBase::InterruptFlag : uint32_t
inheritedstrong
Enum ValuesDocumentation
CharacterMatch 

Set if match character is received.

TxEmpty 

Set if the transmit data register is empty.

TxComplete 

Set if the transmission is complete.

RxNotEmpty 

Set if the receive data register is not empty.

OverrunError 

Set if receive register was not cleared.

FramingError 

Set if a de-synchronization, excessive noise or a break character is detected.

ParityError 

Set if a parity error was detected.

Member Function Documentation

static void modm::PeripheralDriver::acknowledgeInterruptFlag ( )
inheritedstatic

Acknowledge an interrupt flag.

We use acknowledge here, since it describes the intention rather than the actual implementation.

static uint8_t modm::SpiMaster::acquire ( void *  ctx,
ConfigurationHandler  handler = nullptr 
)
inheritedstatic

Request access to the spi master within a context. You may acquire the spi master multiple times within the same context.

The configuration handler will only be called when aquiring the spi master for the first time (if it is not a nullptr).

Warning
Aquires must be balanced with releases of the same context!
Aquires are persistent even after calling initialize()!
Returns
0 if another context is using the spi master, otherwise >0 as the number of times this context acquired the master.
template<uint64_t available, uint64_t requested, percent_t tolerance>
static void modm::PeripheralDriver::assertBaudrateInTolerance ( )
inheritedinlinestatic

Since baudrates are usually generated by prescaling a system clock, only several distinct values can be generated. This method checks if the user requested baudrate is within error tolerance of the system achievable baudrate.

template<class... Signals>
static void modm::SpiMaster::connect ( )
inheritedstatic

Connect GPIOs to the peripheral and configure them.

This configures the Sck, Mosi and Miso signals and connects them.

Template Parameters
SignalsOne Scl and one Mosi signal are required (one Miso signal is optional) and can be passed out-of-order.
template<class SystemClock , baudrate_t baudrate, percent_t tolerance = 5_pct>
static void modm::SpiMaster::initialize ( )
inheritedstatic

Initializes the hardware and sets the baudrate.

Template Parameters
SystemClockthe currently active system clock
baudratethe desired baudrate in Hz
tolerancethe allowed relative tolerance for the resulting baudrate
static uint8_t modm::SpiMaster::release ( void *  ctx)
inheritedstatic

Release access to the spi master within a context.

Warning
Releases must be balanced with acquires of the same context!
Releases are persistent even after calling initialize()!
Returns
0 if nothing can be released anymore (for any context) >0 as the number of times this context can still release the master.
static void modm::platform::UartSpiMaster5::setDataOrder ( DataOrder  order)
inlinestatic
Warning
On this target, only DataOrder::LsbFirst is natively supported! DataOrder::MsbFirst is reimplemented in software using modm::bitReverse(), which adds some overhead.
See also
modm::bitReverse()
static modm::ResumableResult<void> modm::SpiMaster::transfer ( const uint8_t *  tx,
uint8_t *  rx,
std::size_t  length 
)
inheritedstatic

Set the data buffers and length with options and starts a non-blocking transfer. This may be hardware accelerated (DMA or Interrupt), but not guaranteed.

You must call this inside a Protothread or Resumable using PT_CALL or RF_CALL respectively.

Warning
These methods differ from Resumables by lacking context protection! You must ensure that only one driver is accessing this resumable function by using acquire(ctx) and release(ctx).
Parameters
[in]txpointer to transmit buffer, set to nullptr to send dummy bytes
[out]rxpointer to receive buffer, set to nullptr to discard received bytes
lengthnumber of bytes to be shifted out
static modm::ResumableResult<uint8_t> modm::SpiMaster::transfer ( uint8_t  data)
inheritedstatic

Swap a single byte and wait for completion non-blocking!.

You must call this inside a Protothread or Resumable using PT_CALL or RF_CALL respectively.

Warning
These methods differ from Resumables by lacking context protection! You must ensure that only one driver is accessing this resumable function by using acquire(ctx) and release(ctx).
Parameters
datadata to be sent
Returns
received data
static void modm::SpiMaster::transferBlocking ( const uint8_t *  tx,
uint8_t *  rx,
std::size_t  length 
)
inheritedstatic

Set the data buffers and length with options and starts a transfer. This may be hardware accelerated (DMA or Interrupt), but not guaranteed.

Parameters
[in]txpointer to transmit buffer, set to nullptr to send dummy bytes
[out]rxpointer to receive buffer, set to nullptr to discard received bytes
lengthnumber of bytes to be shifted out
static uint8_t modm::SpiMaster::transferBlocking ( uint8_t  data)
inheritedstatic

Swap a single byte and wait for completion.

Parameters
datadata to be sent
Returns
received data

The documentation for this class was generated from the following files: