modm API documentation

#include <modm/architecture/interface/spi_master.hpp>

Inheritance diagram for modm::SpiMaster:
modm::PeripheralDriver modm::Spi modm::platform::BitBangSpiMaster< Sck, Mosi, Miso > modm_test::platform::SpiMaster

Static Public Member Functions

template<class... Signals>
static void connect ()
 
template<class SystemClock , baudrate_t baudrate, percent_t tolerance = 5_pct>
static void initialize ()
 
static void setDataMode (DataMode mode)
 Sets a new data mode.
 
static void setDataOrder (DataOrder order)
 Sets a new data order.
 
static uint8_t acquire (void *ctx, ConfigurationHandler handler=nullptr)
 
static uint8_t release (void *ctx)
 
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 Public Member Functions inherited from modm::PeripheralDriver
static void initialize ()
 initializes the peripheral, must be called before use.
 
static void configurePurpose ()
 configures a peripheral for a specific purpose
 
static void setParameter ()
 sets a parameter
 
static void getParameter ()
 returns a parameter
 
static bool getInterruptFlag ()
 Read an interrupt flag.
 
static void acknowledgeInterruptFlag ()
 
template<baudrate_t available, baudrate_t requested, percent_t tolerance>
static void assertBaudrateInTolerance ()
 

Additional Inherited Members

- Public Typedefs inherited from modm::Spi
using ConfigurationHandler = void (*)()
 The signature of the configuration function.
 
- Public Types inherited from modm::Spi
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.
 

Detailed Description

Interface for a Spi Master with resource management, which allows to synchronize multiple drivers requesting hardware access.

Author
Niklas Hauser

Member Function Documentation

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

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<class... Signals>
static void modm::SpiMaster::connect ( )
static

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 ( )
static

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)
static

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 modm::ResumableResult<void> modm::SpiMaster::transfer ( const uint8_t *  tx,
uint8_t *  rx,
std::size_t  length 
)
static

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)
static

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 
)
static

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)
static

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 file: