|
Embedded Artistry Framework
Embedded Systems C++ Framework
|
This class provides the SPI master interface definition. More...
#include <spi.hpp>

Public Member Functions | |
| virtual void | configure (spi::baud_t baud) noexcept |
| Configure the SPI bus. More... | |
| spi::mode | mode () const noexcept |
| Get the current SPI bus mode. More... | |
| spi::mode | mode (spi::mode mode) noexcept |
| Set the SPI bus mode. More... | |
| spi::order | order () const noexcept |
| Get the current SPI bus byte order. More... | |
| spi::order | order (spi::order order) noexcept |
| Set the SPI bus byte order. More... | |
| void | start () noexcept |
| Start the driver. More... | |
| void | stop () noexcept |
| Stop the driver. More... | |
| void | restart () noexcept |
| Restart the driver. More... | |
| type_safe::boolean | started () const noexcept |
| Check if the driver has been started. More... | |
| constexpr embvm::DriverType_t | DriverType () const noexcept |
| Returns the registered type ID of the driver. More... | |
| constexpr const std::string_view & | name () const noexcept |
| Provides a string_view reference of the driver name. More... | |
| constexpr const char * | name_cstr () const noexcept |
| Provides a c-string version of the driver name. More... | |
| virtual DriverBase & | operator++ () noexcept |
| Increment operator is a no-op, but is used for iterator compatibility. More... | |
Static Public Member Functions | |
| static constexpr embvm::DriverType | type () noexcept |
| SPI Driver Type ID. More... | |
Protected Member Functions | |
| master (const spi::commBus::DispatcherFunc &dispatcher=nullptr) noexcept | |
| Default constructor. More... | |
| master (const char *name, const spi::commBus::DispatcherFunc &dispatcher=nullptr) noexcept | |
| Construct a SPI master with a C-string name. More... | |
| master (const std::string &name, const spi::commBus::DispatcherFunc &dispatcher=nullptr) noexcept | |
| Construct a SPI master with a std::string name. More... | |
| master (const std::string_view &name, const spi::commBus::DispatcherFunc &dispatcher=nullptr) noexcept | |
| Construct a SPI master with a std::string_view name. More... | |
| ~master () noexcept override | |
| Default destructor. More... | |
| virtual void | setMode_ (spi::mode mode) noexcept=0 |
| Set the SPI bus mode. More... | |
| virtual void | setOrder_ (spi::order order) noexcept=0 |
| Set the SPI bus byte order. More... | |
| virtual void | configure_ () noexcept=0 |
| Configure the SPI bus for operation. More... | |
| void | start_ () noexcept override=0 |
| Derived classes override the start_ method to control driver-specific startup behavior. More... | |
| void | stop_ () noexcept override=0 |
| Derived classes override the start_ method to control driver-specific startup behavior. More... | |
| spi::baud_t | baudrate_ (spi::baud_t baud) noexcept override=0 |
| embvm::comm::status | transfer_ (const spi::op_t &op, const cb_t &cb) noexcept override=0 |
Protected Attributes | |
| spi::mode | mode_ = spi::mode::mode0 |
| Stores the active SPI mode configuration. More... | |
| spi::order | order_ = spi::order::msbFirst |
| Stores the active SPI byte ordering. More... | |
| type_safe::boolean | started_ = false |
| Tracks the driver state. More... | |
| const std::string_view | name_ |
| Name of the driver instance. More... | |
| const embvm::DriverType_t | type_ |
| Type ID of the driver instance. More... | |
This class provides the SPI master interface definition.
This class defines common interfaces and types for SPI master devices.
To implement your own SPI master device, simply inherit from this class type:
Derived classes must imlement the following pure virtual functions to complete SPI master behavior:
Derived classes must also implement pure virtual functions required by the comm bus, such as:
spi::master usage follows this general pattern:
Derived classes will have their own specific constructor schemes. In all cases you will use a derived class for the declaration.
After the device has been declared, the object can be used to configure the SPI bus. Initial configuration will happen with the configure() function, which sets up the SPI device with the target baudrate.
The mode() function is used to change the SPI bus mode (spi::mode). The order() function can be used to change the order bytes are sent over the bus (spi::order).
All transfers require an op structure instance with the proper settings:
You should also prepare a callback function to handle the transfer completion:
To initiate a transfer, call transfer() with the op and callback:
When the transfer completes, the callback function will be called with a copy of the op struct and the result of the transfer.
commBus devices support dispatching callbacks. You can construct a spi::master instance with a dispatcher function:
If a dispatcher has been configured, callbacks will be invoked on the dispatch thread instead of the spi::master's local thread. We recommend using dispatchers when possible for improved responsiveness.
|
inlineexplicitprotectednoexcept |
Default constructor.
Initializes the spi::master device with a generic name and optional dispatcher.
| dispatcher | The functor which callbacks will be dispatched to. This will often be paired with a dispatch queue. Example: |
|
inlineexplicitprotectednoexcept |
Construct a SPI master with a C-string name.
Initializes the spi::master instance with a name and optional dispatcher.
| name | C-string name for the SPI master instance. |
| dispatcher | The functor which callbacks will be dispatched to. This will often be paired with a dispatch queue. Example: |
|
inlineexplicitprotectednoexcept |
Construct a SPI master with a std::string name.
Initializes the spi::master instance with a name and optional dispatcher.
| name | std::string name for the SPI master instance. Note: spi::master() uses a std::string_view, so the std::string must remain valid |
| dispatcher | The functor which callbacks will be dispatched to. This will often be paired with a dispatch queue. Example: |
|
inlineexplicitprotectednoexcept |
Construct a SPI master with a std::string_view name.
Initializes the spi::master instance with a name and optional dispatcher.
| name | std::string_view name for the SPI master instance. Note: spi::master() uses a std::string_view, so the original string must remain valid |
| dispatcher | The functor which callbacks will be dispatched to. This will often be paired with a dispatch queue. Example: |
|
overrideprotecteddefaultnoexcept |
Default destructor.
|
overrideprotectedpure virtualnoexcept |
Implemented in test::spiTestDriver, embvm::spi::activeMaster< TQueueSize, TLock, TCond >, and embdrv::aardvarkSPIMaster.
|
inlinevirtualnoexcept |
Configure the SPI bus.
Configures the SPI bus for operation and sets the target baud rate.
Derived classes must implement the configure_() function to set up the target hardware.
| baud | The target baudrate, in Hz. TODO: Tolerance - allowed relative tolerance for the resulting baudrate |
References configure_().
|
protectedpure virtualnoexcept |
Configure the SPI bus for operation.
This function is implemented by the derived class. It is responsible for configuring the target hardware for operation.
Implemented in test::spiTestDriver, embdrv::aardvarkSPIMaster, and embvm::spi::activeMaster< TQueueSize, TLock, TCond >.
Referenced by configure().
|
inlinenoexceptinherited |
Returns the registered type ID of the driver.
When using DriverBase interfaces, clients can retrieve the registered driver type in order to up-cast to the correct interface.
The type is returned as a embvm::DriverType_t rather than a embvm::DriverType enum to work with custom user-defined types. Enforcing a embvm::DriverType return value would prevent clients from defining and using their own custom types.
References embvm::DriverBase::type_.
|
inlinenoexcept |
Get the current SPI bus mode.
References mode_.
Referenced by mode(), and embvm::spi::activeMaster< TQueueSize, TLock, TCond >::setMode_().
Set the SPI bus mode.
Derived classes must implement the setMode_() function, which is reponsible for configuring the target hardware.
| mode | The desired SPI bus mode. |
References mode(), mode_, and setMode_().
|
inlinenoexceptinherited |
Provides a string_view reference of the driver name.
std::string_view ref containing the driver name. References embvm::DriverBase::name_.
|
inlinenoexceptinherited |
Provides a c-string version of the driver name.
References embvm::DriverBase::name_.
|
inlinevirtualnoexceptinherited |
Increment operator is a no-op, but is used for iterator compatibility.
|
inlinenoexcept |
Get the current SPI bus byte order.
References order_.
Referenced by order(), and embvm::spi::activeMaster< TQueueSize, TLock, TCond >::setOrder_().
|
inlinenoexcept |
Set the SPI bus byte order.
Derived classes must implement the setOrder_() function, which is reponsible for configuring the target hardware.
| order | The desired byte ordering. |
References order(), order_, and setOrder_().
|
inlinenoexceptinherited |
Restart the driver.
Calls stop() and then start() on the driver. If the driver is not started, then it will be started after the start() function is invoked.
References embvm::DriverBase::start(), and embvm::DriverBase::stop().
|
protectedpure virtualnoexcept |
Set the SPI bus mode.
This function is implemented by the derived class. It is responsible for configuring the target hardware to use the new mode.
| mode | The desired byte ordering. |
Implemented in test::spiTestDriver, embdrv::aardvarkSPIMaster, and embvm::spi::activeMaster< TQueueSize, TLock, TCond >.
Referenced by mode().
|
protectedpure virtualnoexcept |
Set the SPI bus byte order.
This function is implemented by the derived class. It is responsible for configuring the target hardware to use the new byte ordering.
| order | The desired byte ordering. |
Implemented in test::spiTestDriver, embdrv::aardvarkSPIMaster, and embvm::spi::activeMaster< TQueueSize, TLock, TCond >.
Referenced by order().
|
inlinenoexceptinherited |
Start the driver.
If the driver is not started, call the start_() function defined by the derived class. (Template Method Pattern)
References embvm::DriverBase::start_(), and embvm::DriverBase::started_.
Referenced by NRF52DongleHWPlatform::init_(), NRF52DKHWPlatform::init_(), BlinkySimulatorHWPlatform::init_(), FWDemoSimulatorHWPlatform::init_(), FrameworkDemoSimPlatform::initHWPlatform_(), embvm::DriverBase::restart(), embvm::timer::Timer::restart(), embvm::spi::activeMaster< TQueueSize, TLock, TCond >::start_(), embvm::i2c::activeMaster< 128 >::start_(), embdrv::aardvarkSPIMaster::start_(), embdrv::aardvarkI2CMaster::start_(), embdrv::aardvarkGPIOInput< 4 >::start_(), embdrv::vl53l1x::start_(), embdrv::aardvarkGPIOOutput< 5 >::start_(), BlinkySimulatorHWPlatform::startBlink(), and FWDemoSimulatorHWPlatform::startLEDTimer().
|
overrideprotectedpure virtualnoexcept |
Derived classes override the start_ method to control driver-specific startup behavior.
(Template Method Pattern)
Implements embvm::DriverBase.
Implemented in test::spiTestDriver, embdrv::aardvarkSPIMaster, and embvm::spi::activeMaster< TQueueSize, TLock, TCond >.
|
inlinenoexceptinherited |
Check if the driver has been started.
true if the driver is running (started), false if not running (stopped). References embvm::DriverBase::started_.
Referenced by embdrv::aardvarkSPIMaster::configure_(), embdrv::aardvarkGPIOInput< 4 >::get(), embdrv::aardvarkGPIOOutput< 5 >::set(), embdrv::vl53l1x::start_(), embdrv::aardvarkAdapter::start_(), and embdrv::aardvarkAdapter::stop_().
|
inlinenoexceptinherited |
Stop the driver.
If the driver has been started, call the stop_() function defined by the derived class. (Template Method Pattern)
References embvm::DriverBase::started_, and embvm::DriverBase::stop_().
Referenced by embvm::DriverBase::restart(), embvm::timer::Timer::restart(), embvm::spi::activeMaster< TQueueSize, TLock, TCond >::stop_(), embvm::i2c::activeMaster< 128 >::stop_(), embdrv::aardvarkSPIMaster::stop_(), embdrv::aardvarkI2CMaster::stop_(), embdrv::aardvarkGPIOInput< 4 >::stop_(), embdrv::aardvarkGPIOOutput< 5 >::stop_(), FWDemoSimulatorHWPlatform::~FWDemoSimulatorHWPlatform(), and embdrv::SimulatorTimer::~SimulatorTimer().
|
overrideprotectedpure virtualnoexcept |
Derived classes override the start_ method to control driver-specific startup behavior.
(Template Method Pattern)
Implements embvm::DriverBase.
Implemented in test::spiTestDriver, embdrv::aardvarkSPIMaster, and embvm::spi::activeMaster< TQueueSize, TLock, TCond >.
|
overrideprotectedpure virtualnoexcept |
|
inlinestaticnoexcept |
|
protected |
Stores the active SPI mode configuration.
Referenced by embdrv::aardvarkSPIMaster::configure_(), and mode().
|
protectedinherited |
Name of the driver instance.
Referenced by embvm::DriverBase::name(), and embvm::DriverBase::name_cstr().
|
protected |
Stores the active SPI byte ordering.
Referenced by embdrv::aardvarkSPIMaster::configure_(), and order().
|
protectedinherited |
Tracks the driver state.
True if the driver has been started, false if it has been stopped or not yet started.
Referenced by embvm::DriverBase::start(), embvm::DriverBase::started(), and embvm::DriverBase::stop().
|
protectedinherited |
Type ID of the driver instance.
Referenced by embvm::DriverBase::DriverType().
1.8.15