Embedded Artistry Framework
Embedded Systems C++ Framework
Classes | Enumerations | Variables
Aardvark Adapter Drivers

Aardvark Adapter drivers, usable for Simulator applications. More...

Collaboration diagram for Aardvark Adapter Drivers:

Classes

class  embdrv::aardvarkAdapter
 Driver to control the Aardvark Adapter. More...
 
class  embdrv::aardvarkGPIOInput< TPinID, TPull >
 Aardvark GPIO Input driver. More...
 
class  embdrv::aardvarkGPIOOutput< TPinID >
 Aardvark GPIO Output driver. More...
 
class  embdrv::aardvarkI2CMaster
 Create an Aardvark I2C Master Driver. More...
 
class  embdrv::aardvarkSPIMaster
 Create an Aardvark SPI Master Driver. More...
 

Enumerations

enum  embdrv::aardvarkMode {
  embdrv::aardvarkMode::GpioOnly = 0x0, embdrv::aardvarkMode::SpiGpio = 0x01, embdrv::aardvarkMode::GpioI2C = 0x02, embdrv::aardvarkMode::SpiI2C = 0x03,
  embdrv::aardvarkMode::Query = 0x80
}
 Aardvark master operational modes. More...
 

Variables

constexpr size_t embdrv::AARDVARK_IO_COUNT = 6
 The number of IO pins supported by the AARDVARK sensor. More...
 
static constexpr std::array< uint8_t, AARDVARK_IO_COUNTembdrv::aardvarkIO
 aardvark IO pin IDs More...
 

Detailed Description

Aardvark Adapter drivers, usable for Simulator applications.


Class Documentation

◆ embdrv::aardvarkAdapter

class embdrv::aardvarkAdapter

Driver to control the Aardvark Adapter.

This class must always be declared for use with Aardvark drivers. The aardvarkAdapter is used to set the operational mode and configure the device hardware.

The aardvarkAdapter instance is then passed to the aardvark drivers:

Inheritance diagram for embdrv::aardvarkAdapter:
Inheritance graph

Public Member Functions

 aardvarkAdapter (aardvarkMode m=aardvarkMode::SpiI2C, uint8_t USBPort=0) noexcept
 Create a generic aardvark Adapter. More...
 
 aardvarkAdapter (const char *name, aardvarkMode m=aardvarkMode::SpiI2C, uint8_t USBPort=0) noexcept
 Create an aardvarkAdapter with a name. More...
 
 aardvarkAdapter (const std::string &name, aardvarkMode m=aardvarkMode::SpiI2C, uint8_t USBPort=0) noexcept
 
 aardvarkAdapter (const std::string_view &name, aardvarkMode m=aardvarkMode::SpiI2C, uint8_t USBPort=0) noexcept
 
 ~aardvarkAdapter () noexcept override=default
 Default destructor. More...
 
aardvarkMode mode (aardvarkMode m) noexcept
 Change the Aardvark Adapter's operational mode. More...
 
aardvarkMode mode () const noexcept
 Get the current mode setting This function does not query the device, it returns the cached mode. More...
 
int handle () const noexcept
 Get the handle for the Aardvark Master The handle is used by related drivers to work with the Aardvark library APIs. More...
 
void lock () noexcept
 Lock the Aardvark master - used by other Aardvark driver types to ensure exclusion. More...
 
void unlock () noexcept
 Unlock the Aardvark Master. More...
 
bool i2cPullups () noexcept
 Query the current i2c pullup setting. More...
 
bool i2cPullups (bool en) noexcept
 Enable/Disable the i2c pullup setting. More...
 
bool targetPower () noexcept
 Query the current 5V target power setting. More...
 
bool targetPower (bool en) noexcept
 Enable/Disable 5V target power output. More...
 
void pullup (uint8_t id, bool en) noexcept
 Set a pullup for GPIO. 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 DriverBaseoperator++ () noexcept
 Increment operator is a no-op, but is used for iterator compatibility. More...
 

Protected Attributes

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...
 

Private Member Functions

void start_ () noexcept final
 Derived classes override the start_ method to control driver-specific startup behavior. More...
 
void stop_ () noexcept final
 Derived classes override the start_ method to control driver-specific startup behavior. More...
 

Private Attributes

std::mutex lock_ {}
 The aardvark adapter lock. More...
 
uint8_t port_
 The USB port the adapter is connected to. More...
 
uint8_t pullup_mask_ = 0
 Mask representing the pullups currently enabled. More...
 
int handle_ = 0
 The handle for the aardvark Adapter (provided by the aardvark API). More...
 
aardvarkMode mode_
 The currently configured Aardvark Adapter mode. More...
 
std::atomic< int > started_refcnt_ = 0
 Reference count for the number of times this driver has been started. More...
 

Constructor & Destructor Documentation

◆ aardvarkAdapter() [1/4]

embdrv::aardvarkAdapter::aardvarkAdapter ( aardvarkMode  m = aardvarkMode::SpiI2C,
uint8_t  USBPort = 0 
)
inlineexplicitnoexcept

Create a generic aardvark Adapter.

Parameters
mThe aardvark adapter mode.
USBPortThe id of the USB port the aardvarkAdapter is connected to.

◆ aardvarkAdapter() [2/4]

embdrv::aardvarkAdapter::aardvarkAdapter ( const char *  name,
aardvarkMode  m = aardvarkMode::SpiI2C,
uint8_t  USBPort = 0 
)
inlineexplicitnoexcept

Create an aardvarkAdapter with a name.

Parameters
nameThe name for the aardvarkAdapter driver.
mThe aardvark adapter mode.
USBPortThe id of the USB port the aardvarkAdapter is connected to.

◆ aardvarkAdapter() [3/4]

embdrv::aardvarkAdapter::aardvarkAdapter ( const std::string &  name,
aardvarkMode  m = aardvarkMode::SpiI2C,
uint8_t  USBPort = 0 
)
inlineexplicitnoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ aardvarkAdapter() [4/4]

embdrv::aardvarkAdapter::aardvarkAdapter ( const std::string_view &  name,
aardvarkMode  m = aardvarkMode::SpiI2C,
uint8_t  USBPort = 0 
)
inlineexplicitnoexcept

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

◆ ~aardvarkAdapter()

embdrv::aardvarkAdapter::~aardvarkAdapter ( )
overridedefaultnoexcept

Default destructor.

Member Function Documentation

◆ DriverType()

constexpr embvm::DriverType_t embvm::DriverBase::DriverType ( ) const
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.

Returns
the registered driver type as a embvm::DriverType_t value

References embvm::DriverBase::type_.

◆ handle()

int embdrv::aardvarkAdapter::handle ( ) const
inlinenoexcept

Get the handle for the Aardvark Master The handle is used by related drivers to work with the Aardvark library APIs.

Returns
the Aardvark master handle.

References handle_.

Referenced by embdrv::aardvarkSPIMaster::configure_(), embdrv::aardvarkGPIOInput< 4 >::get(), embdrv::aardvarkGPIOOutput< 5 >::set(), and embdrv::aardvarkGPIOOutput< 5 >::start_().

◆ i2cPullups() [1/2]

bool aardvarkAdapter::i2cPullups ( )
noexcept

Query the current i2c pullup setting.

Returns
true if I2C pullups are enabled, false if disabled.

References aa_i2c_pullup(), AA_I2C_PULLUP_QUERY, handle_, lock(), r, and unlock().

Referenced by embdrv::aardvarkGPIOInput< 4 >::start_().

◆ i2cPullups() [2/2]

bool aardvarkAdapter::i2cPullups ( bool  en)
noexcept

Enable/Disable the i2c pullup setting.

Parameters
enTrue enables I2C pullups, false disables them.
Returns
true if I2C pullups are enabled, false if disabled.

References aa_i2c_pullup(), AA_I2C_PULLUP_BOTH, and AA_I2C_PULLUP_NONE.

◆ lock()

void embdrv::aardvarkAdapter::lock ( )
inlinenoexcept

Lock the Aardvark master - used by other Aardvark driver types to ensure exclusion.

Postcondition
The aardvarkAdapter is locked for the client's exclusive use.

References lock_.

Referenced by embdrv::aardvarkSPIMaster::configure_(), embdrv::aardvarkGPIOInput< 4 >::get(), i2cPullups(), embdrv::aardvarkGPIOOutput< 5 >::set(), embdrv::aardvarkGPIOOutput< 5 >::start_(), and targetPower().

◆ mode() [1/2]

aardvarkMode aardvarkAdapter::mode ( aardvarkMode  m)
noexcept

Change the Aardvark Adapter's operational mode.

Parameters
mThe desired aardvark operational mode.
Returns
the configured aardvark operational mode.

References aa_configure().

Referenced by embdrv::aardvarkGPIOInput< 4 >::start_().

◆ mode() [2/2]

aardvarkMode embdrv::aardvarkAdapter::mode ( ) const
inlinenoexcept

Get the current mode setting This function does not query the device, it returns the cached mode.

Returns
the configured aardvark operational mode.

References mode_.

Referenced by start_().

◆ name()

constexpr const std::string_view& embvm::DriverBase::name ( ) const
inlinenoexceptinherited

Provides a string_view reference of the driver name.

Returns
std::string_view ref containing the driver name.

References embvm::DriverBase::name_.

◆ name_cstr()

constexpr const char* embvm::DriverBase::name_cstr ( ) const
inlinenoexceptinherited

Provides a c-string version of the driver name.

Returns
c-string containing the driver name

References embvm::DriverBase::name_.

◆ operator++()

virtual DriverBase& embvm::DriverBase::operator++ ( )
inlinevirtualnoexceptinherited

Increment operator is a no-op, but is used for iterator compatibility.

◆ pullup()

void aardvarkAdapter::pullup ( uint8_t  id,
bool  en 
)
noexcept

Set a pullup for GPIO.

Parameters
idThe GPIO Id to enable the pullup for
enTrue enables a pullup, false disables it.

References aa_gpio_pullup(), AA_OK, embdrv::aardvarkIO, assert, and r.

Referenced by embdrv::aardvarkGPIOInput< 4 >::pull_().

◆ restart()

void embvm::DriverBase::restart ( )
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().

◆ start()

◆ start_()

void aardvarkAdapter::start_ ( )
finalprivatevirtualnoexcept

Derived classes override the start_ method to control driver-specific startup behavior.

(Template Method Pattern)

Implements embvm::DriverBase.

References aa_open(), assert, handle_, mode(), mode_, port_, embvm::DriverBase::started(), and started_refcnt_.

◆ started()

type_safe::boolean embvm::DriverBase::started ( ) const
inlinenoexceptinherited

Check if the driver has been started.

Returns
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_(), start_(), and stop_().

◆ stop()

◆ stop_()

void aardvarkAdapter::stop_ ( )
finalprivatevirtualnoexcept

Derived classes override the start_ method to control driver-specific startup behavior.

(Template Method Pattern)

Implements embvm::DriverBase.

References aa_close(), handle_, embvm::DriverBase::started(), and started_refcnt_.

◆ targetPower() [1/2]

bool aardvarkAdapter::targetPower ( )
noexcept

Query the current 5V target power setting.

Returns
true if 5V target power is enabled, false if disabled.

References aa_target_power(), AA_TARGET_POWER_QUERY, handle_, lock(), r, and unlock().

◆ targetPower() [2/2]

bool aardvarkAdapter::targetPower ( bool  en)
noexcept

Enable/Disable 5V target power output.

Parameters
enTrue enables 5V target power output, false disables it.
Returns
true if 5V target power is enabled, false if disabled.

References aa_i2c_pullup(), AA_TARGET_POWER_BOTH, and AA_TARGET_POWER_NONE.

◆ unlock()

void embdrv::aardvarkAdapter::unlock ( )
inlinenoexcept

Member Data Documentation

◆ handle_

int embdrv::aardvarkAdapter::handle_ = 0
private

The handle for the aardvark Adapter (provided by the aardvark API).

Referenced by handle(), i2cPullups(), start_(), stop_(), and targetPower().

◆ lock_

std::mutex embdrv::aardvarkAdapter::lock_ {}
private

The aardvark adapter lock.

Referenced by lock(), and unlock().

◆ mode_

aardvarkMode embdrv::aardvarkAdapter::mode_
private

The currently configured Aardvark Adapter mode.

Referenced by mode(), and start_().

◆ name_

const std::string_view embvm::DriverBase::name_
protectedinherited

Name of the driver instance.

Referenced by embvm::DriverBase::name(), and embvm::DriverBase::name_cstr().

◆ port_

uint8_t embdrv::aardvarkAdapter::port_
private

The USB port the adapter is connected to.

Referenced by start_().

◆ pullup_mask_

uint8_t embdrv::aardvarkAdapter::pullup_mask_ = 0
private

Mask representing the pullups currently enabled.

◆ started_

type_safe::boolean embvm::DriverBase::started_ = false
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().

◆ started_refcnt_

std::atomic<int> embdrv::aardvarkAdapter::started_refcnt_ = 0
private

Reference count for the number of times this driver has been started.

Since multiple client drivers can be created, we don't want to stop the aardvarkAdapter base until all client drivers have been stopped.

Referenced by start_(), and stop_().

◆ type_

const embvm::DriverType_t embvm::DriverBase::type_
protectedinherited

Type ID of the driver instance.

Referenced by embvm::DriverBase::DriverType().

◆ embdrv::aardvarkGPIOInput

class embdrv::aardvarkGPIOInput

template<uint8_t TPinID, embvm::gpio::pull TPull = embvm::gpio::pull::none>
class embdrv::aardvarkGPIOInput< TPinID, TPull >

Aardvark GPIO Input driver.

Create a GPIO input driver using the Aardvark adapter.

This driver requires an aardvarkAdapter to work. The aardvark adapter must be configured with aardvarkMode::GpioI2C, aardvarkMode::SpiGpio, or aardvarkMode::GpioOnly.

Template Parameters
TPinIDThe aardvark pin ID to use as a GPIO Input. Must be less than AARDVARK_IO_COUNT.
TPullThe pull setting to use with this GPIO.
Inheritance diagram for embdrv::aardvarkGPIOInput< TPinID, TPull >:
Inheritance graph

Public Member Functions

 aardvarkGPIOInput (aardvarkAdapter &master) noexcept
 Construct a generic GPIO input. More...
 
 aardvarkGPIOInput (aardvarkAdapter &master, const char *name) noexcept
 Construct a named GPIO Input. More...
 
 ~aardvarkGPIOInput () noexcept final=default
 Default Destructor. More...
 
bool get () noexcept final
 Get the current GPIO pin state. More...
 
gpio::pull pull () const noexcept
 Get the current pull configuration. More...
 
gpio::direction direction () const noexcept
 Check the direction of the GPIO pin. 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 DriverBaseoperator++ () noexcept
 Increment operator is a no-op, but is used for iterator compatibility. More...
 

Static Public Member Functions

static constexpr embvm::DriverType type () noexcept
 GPIO Driver Type ID. More...
 

Protected Attributes

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...
 

Private Member Functions

void start_ () noexcept final
 Derived classes override the start_ method to control driver-specific startup behavior. More...
 
void stop_ () noexcept final
 Derived classes override the start_ method to control driver-specific startup behavior. More...
 
embvm::gpio::pull pull_ (embvm::gpio::pull p) noexcept final
 Set the pull configuration in hardware. More...
 

Private Attributes

aardvarkAdaptermaster_
 The aardvarkAdapter instance associated with this GPIO input. More...
 

Constructor & Destructor Documentation

◆ aardvarkGPIOInput() [1/2]

template<uint8_t TPinID, embvm::gpio::pull TPull = embvm::gpio::pull::none>
embdrv::aardvarkGPIOInput< TPinID, TPull >::aardvarkGPIOInput ( aardvarkAdapter master)
inlineexplicitnoexcept

Construct a generic GPIO input.

Parameters
masterThe aardvarkAdapter instance associated with this GPIO pin.

◆ aardvarkGPIOInput() [2/2]

template<uint8_t TPinID, embvm::gpio::pull TPull = embvm::gpio::pull::none>
embdrv::aardvarkGPIOInput< TPinID, TPull >::aardvarkGPIOInput ( aardvarkAdapter master,
const char *  name 
)
inlineexplicitnoexcept

Construct a named GPIO Input.

Parameters
masterThe aardvarkAdapter instance associated with this GPIO pin.
nameThe name of the GPIO pin

◆ ~aardvarkGPIOInput()

template<uint8_t TPinID, embvm::gpio::pull TPull = embvm::gpio::pull::none>
embdrv::aardvarkGPIOInput< TPinID, TPull >::~aardvarkGPIOInput ( )
finaldefaultnoexcept

Default Destructor.

Member Function Documentation

◆ direction()

gpio::direction embvm::gpio::base< TDir >::direction ( ) const
inlinenoexceptinherited

Check the direction of the GPIO pin.

Returns
The configured direction of this GPIO pin.

◆ DriverType()

constexpr embvm::DriverType_t embvm::DriverBase::DriverType ( ) const
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.

Returns
the registered driver type as a embvm::DriverType_t value

References embvm::DriverBase::type_.

◆ get()

template<uint8_t TPinID, embvm::gpio::pull TPull = embvm::gpio::pull::none>
bool embdrv::aardvarkGPIOInput< TPinID, TPull >::get ( )
inlinefinalvirtualnoexcept

Get the current GPIO pin state.

Derived classes must implement the get() function.

Returns
true if the GPIO is set (logic 1), false otherwise (logic 0).

Implements embvm::gpio::input< TPull >.

Referenced by FWDemoSimulatorHWPlatform::readAndSetToFMode().

◆ name()

constexpr const std::string_view& embvm::DriverBase::name ( ) const
inlinenoexceptinherited

Provides a string_view reference of the driver name.

Returns
std::string_view ref containing the driver name.

References embvm::DriverBase::name_.

◆ name_cstr()

constexpr const char* embvm::DriverBase::name_cstr ( ) const
inlinenoexceptinherited

Provides a c-string version of the driver name.

Returns
c-string containing the driver name

References embvm::DriverBase::name_.

◆ operator++()

virtual DriverBase& embvm::DriverBase::operator++ ( )
inlinevirtualnoexceptinherited

Increment operator is a no-op, but is used for iterator compatibility.

◆ pull()

template<gpio::pull TPull = gpio::pull::none>
gpio::pull embvm::gpio::input< TPull >::pull ( ) const
inlinenoexceptinherited

Get the current pull configuration.

Returns
The currently configured GPIO pull setting.

◆ pull_()

template<uint8_t TPinID, embvm::gpio::pull TPull = embvm::gpio::pull::none>
embvm::gpio::pull embdrv::aardvarkGPIOInput< TPinID, TPull >::pull_ ( embvm::gpio::pull  p)
inlinefinalprivatevirtualnoexcept

Set the pull configuration in hardware.

Derived classes must implement the pull_(gpio::pull p) function.

Returns
The currently configured GPIO pull setting.

Implements embvm::gpio::input< TPull >.

Referenced by embdrv::aardvarkGPIOInput< 4 >::start_().

◆ restart()

void embvm::DriverBase::restart ( )
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().

◆ start()

◆ start_()

template<uint8_t TPinID, embvm::gpio::pull TPull = embvm::gpio::pull::none>
void embdrv::aardvarkGPIOInput< TPinID, TPull >::start_ ( )
inlinefinalprivatevirtualnoexcept

Derived classes override the start_ method to control driver-specific startup behavior.

(Template Method Pattern)

Implements embvm::gpio::input< TPull >.

◆ started()

type_safe::boolean embvm::DriverBase::started ( ) const
inlinenoexceptinherited

Check if the driver has been started.

Returns
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_().

◆ stop()

◆ stop_()

template<uint8_t TPinID, embvm::gpio::pull TPull = embvm::gpio::pull::none>
void embdrv::aardvarkGPIOInput< TPinID, TPull >::stop_ ( )
inlinefinalprivatevirtualnoexcept

Derived classes override the start_ method to control driver-specific startup behavior.

(Template Method Pattern)

Implements embvm::gpio::input< TPull >.

◆ type()

static constexpr embvm::DriverType embvm::gpio::base< TDir >::type ( )
inlinestaticnoexceptinherited

GPIO Driver Type ID.

Returns
GPIO type ID.

Member Data Documentation

◆ master_

template<uint8_t TPinID, embvm::gpio::pull TPull = embvm::gpio::pull::none>
aardvarkAdapter& embdrv::aardvarkGPIOInput< TPinID, TPull >::master_
private

◆ name_

const std::string_view embvm::DriverBase::name_
protectedinherited

Name of the driver instance.

Referenced by embvm::DriverBase::name(), and embvm::DriverBase::name_cstr().

◆ started_

type_safe::boolean embvm::DriverBase::started_ = false
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().

◆ type_

const embvm::DriverType_t embvm::DriverBase::type_
protectedinherited

Type ID of the driver instance.

Referenced by embvm::DriverBase::DriverType().

◆ embdrv::aardvarkGPIOOutput

class embdrv::aardvarkGPIOOutput

template<uint8_t TPinID>
class embdrv::aardvarkGPIOOutput< TPinID >

Aardvark GPIO Output driver.

Create a GPIO output driver using the Aardvark adapter.

This driver requires an aardvarkAdapter to work. The aardvark adapter must be configured with aardvarkMode::GpioI2C, aardvarkMode::SpiGpio, or aardvarkMode::GpioOnly.

Template Parameters
TPinIDThe aardvark pin ID to use as a GPIO output. Must be less than AARDVARK_IO_COUNT.
Inheritance diagram for embdrv::aardvarkGPIOOutput< TPinID >:
Inheritance graph

Public Member Functions

 aardvarkGPIOOutput (aardvarkAdapter &master) noexcept
 Construct a generic GPIO output. More...
 
 aardvarkGPIOOutput (aardvarkAdapter &master, const char *name) noexcept
 Construct a named GPIO output. More...
 
 ~aardvarkGPIOOutput () noexcept final=default
 Default destructor. More...
 
void set (bool v) noexcept final
 Set the current GPIO pin state. More...
 
gpio::direction direction () const noexcept
 Check the direction of the GPIO pin. 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 DriverBaseoperator++ () noexcept
 Increment operator is a no-op, but is used for iterator compatibility. More...
 

Static Public Member Functions

static constexpr embvm::DriverType type () noexcept
 GPIO Driver Type ID. More...
 

Protected Attributes

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...
 

Private Member Functions

void start_ () noexcept final
 Derived classes override the start_ method to control driver-specific startup behavior. More...
 
void stop_ () noexcept final
 Derived classes override the start_ method to control driver-specific startup behavior. More...
 

Private Attributes

aardvarkAdaptermaster_
 The aardvarkAdapter instance associated with this GPIO output. More...
 

Constructor & Destructor Documentation

◆ aardvarkGPIOOutput() [1/2]

template<uint8_t TPinID>
embdrv::aardvarkGPIOOutput< TPinID >::aardvarkGPIOOutput ( aardvarkAdapter master)
inlineexplicitnoexcept

Construct a generic GPIO output.

Parameters
masterThe aardvarkAdapter instance associated with this GPIO pin.

◆ aardvarkGPIOOutput() [2/2]

template<uint8_t TPinID>
embdrv::aardvarkGPIOOutput< TPinID >::aardvarkGPIOOutput ( aardvarkAdapter master,
const char *  name 
)
inlineexplicitnoexcept

Construct a named GPIO output.

Parameters
masterThe aardvarkAdapter instance associated with this GPIO pin.
nameThe name of the GPIO pin

◆ ~aardvarkGPIOOutput()

template<uint8_t TPinID>
embdrv::aardvarkGPIOOutput< TPinID >::~aardvarkGPIOOutput ( )
finaldefaultnoexcept

Default destructor.

Member Function Documentation

◆ direction()

gpio::direction embvm::gpio::base< TDir >::direction ( ) const
inlinenoexceptinherited

Check the direction of the GPIO pin.

Returns
The configured direction of this GPIO pin.

◆ DriverType()

constexpr embvm::DriverType_t embvm::DriverBase::DriverType ( ) const
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.

Returns
the registered driver type as a embvm::DriverType_t value

References embvm::DriverBase::type_.

◆ name()

constexpr const std::string_view& embvm::DriverBase::name ( ) const
inlinenoexceptinherited

Provides a string_view reference of the driver name.

Returns
std::string_view ref containing the driver name.

References embvm::DriverBase::name_.

◆ name_cstr()

constexpr const char* embvm::DriverBase::name_cstr ( ) const
inlinenoexceptinherited

Provides a c-string version of the driver name.

Returns
c-string containing the driver name

References embvm::DriverBase::name_.

◆ operator++()

virtual DriverBase& embvm::DriverBase::operator++ ( )
inlinevirtualnoexceptinherited

Increment operator is a no-op, but is used for iterator compatibility.

◆ restart()

void embvm::DriverBase::restart ( )
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().

◆ set()

template<uint8_t TPinID>
void embdrv::aardvarkGPIOOutput< TPinID >::set ( bool  v)
inlinefinalvirtualnoexcept

Set the current GPIO pin state.

Derived classes must implement the set() function.

Parameters
vThe desired GPIO state. True for logic 1, false for logic 0.

Implements embvm::gpio::output.

◆ start()

◆ start_()

template<uint8_t TPinID>
void embdrv::aardvarkGPIOOutput< TPinID >::start_ ( )
inlinefinalprivatevirtualnoexcept

Derived classes override the start_ method to control driver-specific startup behavior.

(Template Method Pattern)

Implements embvm::gpio::output.

◆ started()

type_safe::boolean embvm::DriverBase::started ( ) const
inlinenoexceptinherited

Check if the driver has been started.

Returns
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_().

◆ stop()

◆ stop_()

template<uint8_t TPinID>
void embdrv::aardvarkGPIOOutput< TPinID >::stop_ ( )
inlinefinalprivatevirtualnoexcept

Derived classes override the start_ method to control driver-specific startup behavior.

(Template Method Pattern)

Implements embvm::gpio::output.

◆ type()

static constexpr embvm::DriverType embvm::gpio::base< TDir >::type ( )
inlinestaticnoexceptinherited

GPIO Driver Type ID.

Returns
GPIO type ID.

Member Data Documentation

◆ master_

template<uint8_t TPinID>
aardvarkAdapter& embdrv::aardvarkGPIOOutput< TPinID >::master_
private

◆ name_

const std::string_view embvm::DriverBase::name_
protectedinherited

Name of the driver instance.

Referenced by embvm::DriverBase::name(), and embvm::DriverBase::name_cstr().

◆ started_

type_safe::boolean embvm::DriverBase::started_ = false
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().

◆ type_

const embvm::DriverType_t embvm::DriverBase::type_
protectedinherited

Type ID of the driver instance.

Referenced by embvm::DriverBase::DriverType().

◆ embdrv::aardvarkI2CMaster

class embdrv::aardvarkI2CMaster

Create an Aardvark I2C Master Driver.

This driver requires an aardvarkAdapter to work. The aardvark adapter must be configured with aardvarkMode::GpioI2C or aardvarkMode::SpiI2C.

This is an active object: it has its own thread of control.

Inheritance diagram for embdrv::aardvarkI2CMaster:
Inheritance graph

Public Types

using cb_t = stdext::inplace_function< void(i2c::op_t, i2c::status)>
 Represents the type of the callback operation. More...
 
using sweep_list_t = etl::vector< uint8_t, 128 >
 
using sweep_cb_t = stdext::inplace_function< void(void)>
 

Public Member Functions

 aardvarkI2CMaster (aardvarkAdapter &master) noexcept
 Construct a generic I2C master. More...
 
 aardvarkI2CMaster (aardvarkAdapter &master, const char *name) noexcept
 Construct a named I2C master. More...
 
 ~aardvarkI2CMaster () noexcept final
 Default destructor. More...
 
void process_ (const storagePair_t &op) noexcept
 Active object process function. More...
 
virtual void configure (i2c::baud baud, i2c::pullups pull=i2c::pullups::external) noexcept
 Configure the I2C bus. More...
 
i2c::state state () const noexcept
 Check the I2C bus status. More...
 
i2c::pullups pullups (i2c::pullups pullups) noexcept
 Configure pull-ups. More...
 
i2c::pullups pullups () const noexcept
 Check the pull-up configuration. More...
 
void sweep (sweep_list_t &found_list, const sweep_cb_t &cb) noexcept
 Perform an I2C bus sweep to identify active devices. 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 DriverBaseoperator++ () noexcept
 Increment operator is a no-op, but is used for iterator compatibility. More...
 
size_t queuedCount () const noexcept
 Get the number of operations in the queue. More...
 
bool enqueue (std::pair< embvm::i2c::op_t, const embvm::i2c::master::cb_t > t) noexcept
 Add an operation to the queue. More...
 
void shutdown () noexcept
 Shutdown the active object. More...
 

Static Public Member Functions

static constexpr embvm::DriverType type () noexcept
 I2C Driver Type ID. More...
 

Protected Attributes

i2c::pullups pullups_ = i2c::pullups::external
 Tracks the active pull-up configuration. More...
 
i2c::state state_ = i2c::state::idle
 Tracks the status of the I2C bus. 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...
 

Private Types

using storagePair_t = std::pair< embvm::i2c::op_t, const embvm::i2c::master::cb_t >
 The storage type that the active object stores. More...
 

Private Member Functions

void configure_ (embvm::i2c::pullups pullup) noexcept final
 Configure the I2C bus for operation. More...
 
embvm::i2c::status transfer_ (const embvm::i2c::op_t &op, const embvm::i2c::master::cb_t &cb) noexcept final
 
embvm::i2c::baud baudrate_ (embvm::i2c::baud baud) noexcept final
 
embvm::i2c::pullups setPullups_ (embvm::i2c::pullups pullups) noexcept final
 Configure pull-ups. More...
 
void start_ () noexcept final
 Derived classes override the start_ method to control driver-specific startup behavior. More...
 
void stop_ () noexcept final
 Derived classes override the start_ method to control driver-specific startup behavior. More...
 

Private Attributes

aardvarkAdaptermaster_
 The aardvarkAdapter instance associated with this driver. More...
 

Member Typedef Documentation

◆ cb_t

using embvm::i2c::master::cb_t = stdext::inplace_function<void(i2c::op_t, i2c::status)>
inherited

Represents the type of the callback operation.

◆ storagePair_t

The storage type that the active object stores.

◆ sweep_cb_t

using embvm::i2c::master::sweep_cb_t = stdext::inplace_function<void(void)>
inherited

◆ sweep_list_t

using embvm::i2c::master::sweep_list_t = etl::vector<uint8_t, 128>
inherited

Constructor & Destructor Documentation

◆ aardvarkI2CMaster() [1/2]

embdrv::aardvarkI2CMaster::aardvarkI2CMaster ( aardvarkAdapter master)
inlineexplicitnoexcept

Construct a generic I2C master.

Parameters
masterThe aardvarkAdapter instance associated with this driver.

◆ aardvarkI2CMaster() [2/2]

embdrv::aardvarkI2CMaster::aardvarkI2CMaster ( aardvarkAdapter master,
const char *  name 
)
inlineexplicitnoexcept

Construct a named I2C master.

Parameters
masterThe aardvarkAdapter instance associated with this driver.
nameThe name of the driver.

◆ ~aardvarkI2CMaster()

aardvarkI2CMaster::~aardvarkI2CMaster ( )
finaldefaultnoexcept

Default destructor.

Member Function Documentation

◆ baudrate_()

embvm::i2c::baud aardvarkI2CMaster::baudrate_ ( embvm::i2c::baud  baud)
finalprivatevirtualnoexcept

◆ configure()

virtual void embvm::i2c::master::configure ( i2c::baud  baud,
i2c::pullups  pull = i2c::pullups::external 
)
inlinevirtualnoexceptinherited

Configure the I2C bus.

Configures the I2C bus for operation and sets the target baud rate and pull-ups.

Derived classes must implement the configure_() function to set up the target hardware.

Parameters
baudThe target baudrate (as an i2c::baud enumeration rather than integral Hz). TODO: Tolerance - allowed relative tolerance for the resulting baudrate
pullThe pullup setting, which defaults to external pull-ups (in hardware).

References embvm::i2c::master::configure_(), and embvm::i2c::master::pullups().

Referenced by embvm::i2c::activeMaster< 128 >::configure_(), and FWDemoSimulatorHWPlatform::init_().

◆ configure_()

void aardvarkI2CMaster::configure_ ( embvm::i2c::pullups  pullups)
finalprivatevirtualnoexcept

Configure the I2C bus for operation.

This function is implemented by the derived class. It is responsible for configuring the target hardware for operation.

Parameters
pullupsThe target pull-up configuration.

Implements embvm::i2c::master.

References aa_i2c_bus_timeout(), assert, and bus_timeout_ms.

◆ DriverType()

constexpr embvm::DriverType_t embvm::DriverBase::DriverType ( ) const
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.

Returns
the registered driver type as a embvm::DriverType_t value

References embvm::DriverBase::type_.

◆ enqueue()

bool embutil::activeObject< aardvarkI2CMaster , std::pair< embvm::i2c::op_t, const embvm::i2c::master::cb_t > , 0 , std::mutex , std::condition_variable >::enqueue ( std::pair< embvm::i2c::op_t, const embvm::i2c::master::cb_t t)
inlinenoexceptinherited

Add an operation to the queue.

This function can be called directly, or by functions internal to the activeObject. For example, the "transfer" API enqueues transfer operations.

This function is marked noexcept because we want the program to terminate if an exception results from this call. For example, the underlying queue may throw on push.

Parameters
tThe operation data object to enqueue for later processing.

◆ name()

constexpr const std::string_view& embvm::DriverBase::name ( ) const
inlinenoexceptinherited

Provides a string_view reference of the driver name.

Returns
std::string_view ref containing the driver name.

References embvm::DriverBase::name_.

◆ name_cstr()

constexpr const char* embvm::DriverBase::name_cstr ( ) const
inlinenoexceptinherited

Provides a c-string version of the driver name.

Returns
c-string containing the driver name

References embvm::DriverBase::name_.

◆ operator++()

virtual DriverBase& embvm::DriverBase::operator++ ( )
inlinevirtualnoexceptinherited

Increment operator is a no-op, but is used for iterator compatibility.

◆ process_()

◆ pullups() [1/2]

i2c::pullups embvm::i2c::master::pullups ( i2c::pullups  pullups)
inlinenoexceptinherited

Configure pull-ups.

Parameters
pullupsThe target pull-up setting.
Returns
The configured pull-up setting.

References embvm::i2c::master::pullups_, and embvm::i2c::master::setPullups_().

Referenced by embvm::i2c::activeMaster< 128 >::setPullups_().

◆ pullups() [2/2]

i2c::pullups embvm::i2c::master::pullups ( ) const
inlinenoexceptinherited

◆ queuedCount()

size_t embutil::activeObject< aardvarkI2CMaster , std::pair< embvm::i2c::op_t, const embvm::i2c::master::cb_t > , 0 , std::mutex , std::condition_variable >::queuedCount ( ) const
inlinenoexceptinherited

Get the number of operations in the queue.

Returns
the number of queued operations.

◆ restart()

void embvm::DriverBase::restart ( )
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().

◆ setPullups_()

embvm::i2c::pullups aardvarkI2CMaster::setPullups_ ( embvm::i2c::pullups  pullups)
finalprivatevirtualnoexcept

Configure pull-ups.

This function is implemented by the derived class. It is responsible for configuring the target hardware to use the requested pullup setting.

Parameters
pullupsThe target pull-up setting.
Returns
The configured pull-up setting.

Implements embvm::i2c::master.

References assert, and embvm::i2c::external.

◆ shutdown()

void embutil::activeObject< aardvarkI2CMaster , std::pair< embvm::i2c::op_t, const embvm::i2c::master::cb_t > , 0 , std::mutex , std::condition_variable >::shutdown ( )
inlinenoexceptinherited

Shutdown the active object.

Call this function in the parent class destructor to stop the AO thread operation before destroying the parent class. This will prevent memory access problems due to race conidtions during destruction.

This function is marked noexcept because we want the program to terminate if an exception results from this call.

The shutdown process is permanent and cannot be reversed without recreating the object.

◆ start()

◆ start_()

void aardvarkI2CMaster::start_ ( )
finalprivatevirtualnoexcept

Derived classes override the start_ method to control driver-specific startup behavior.

(Template Method Pattern)

Implements embvm::i2c::master.

References embvm::DriverBase::start().

◆ started()

type_safe::boolean embvm::DriverBase::started ( ) const
inlinenoexceptinherited

Check if the driver has been started.

Returns
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_().

◆ state()

i2c::state embvm::i2c::master::state ( ) const
inlinenoexceptinherited

Check the I2C bus status.

Returns
the status of the I2C bus as an i2c::state enumeration.

References embvm::i2c::master::state_.

◆ stop()

◆ stop_()

void aardvarkI2CMaster::stop_ ( )
finalprivatevirtualnoexcept

Derived classes override the start_ method to control driver-specific startup behavior.

(Template Method Pattern)

Implements embvm::i2c::master.

References master_, and embvm::DriverBase::stop().

◆ sweep()

void embvm::i2c::master::sweep ( sweep_list_t found_list,
const sweep_cb_t cb 
)
noexceptinherited

Perform an I2C bus sweep to identify active devices.

The sweep function pings all I2C addresses. Devices which ACK are stored in a list and returned via callback.

Parameters
[in,out]found_listCaller's memory which will contain the successfully found ping addresses
[in]cbThe callback which will be called to indicate that the sweep is complete. After the cb is called, found_list is valid and can be used by the caller.

References embvm::i2c::op_t::address, embvm::i2c::busy, I2C_ADDR_MAX, and embvm::i2c::op_t::op.

◆ transfer_()

embvm::i2c::status aardvarkI2CMaster::transfer_ ( const embvm::i2c::op_t op,
const embvm::i2c::master::cb_t cb 
)
finalprivatevirtualnoexcept

Implements embvm::i2c::master.

References embvm::i2c::enqueued.

◆ type()

static constexpr embvm::DriverType embvm::i2c::master::type ( )
inlinestaticnoexceptinherited

I2C Driver Type ID.

Returns
I2C type ID.

References embvm::I2C.

Member Data Documentation

◆ master_

aardvarkAdapter& embdrv::aardvarkI2CMaster::master_
private

The aardvarkAdapter instance associated with this driver.

Referenced by stop_().

◆ name_

const std::string_view embvm::DriverBase::name_
protectedinherited

Name of the driver instance.

Referenced by embvm::DriverBase::name(), and embvm::DriverBase::name_cstr().

◆ pullups_

i2c::pullups embvm::i2c::master::pullups_ = i2c::pullups::external
protectedinherited

Tracks the active pull-up configuration.

Referenced by embvm::i2c::master::pullups().

◆ started_

type_safe::boolean embvm::DriverBase::started_ = false
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().

◆ state_

i2c::state embvm::i2c::master::state_ = i2c::state::idle
protectedinherited

Tracks the status of the I2C bus.

Referenced by embvm::i2c::master::state().

◆ type_

const embvm::DriverType_t embvm::DriverBase::type_
protectedinherited

Type ID of the driver instance.

Referenced by embvm::DriverBase::DriverType().

◆ embdrv::aardvarkSPIMaster

class embdrv::aardvarkSPIMaster

Create an Aardvark SPI Master Driver.

This driver requires an aardvarkAdapter to work. The aardvark adapter must be configured with aardvarkMode::SpiGpio or aardvarkMode::SpiI2C.

This is an active object: it has its own thread of control.

Inheritance diagram for embdrv::aardvarkSPIMaster:
Inheritance graph

Public Member Functions

 aardvarkSPIMaster (aardvarkAdapter &master) noexcept
 Construct a generic SPI master. More...
 
 aardvarkSPIMaster (aardvarkAdapter &master, const char *name) noexcept
 Construct a named SPI master. More...
 
 ~aardvarkSPIMaster () noexcept final
 Default destructor. More...
 
void process_ (const storagePair_t &op) noexcept
 Active object process function. More...
 
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 DriverBaseoperator++ () noexcept
 Increment operator is a no-op, but is used for iterator compatibility. More...
 
size_t queuedCount () const noexcept
 Get the number of operations in the queue. More...
 
bool enqueue (std::pair< embvm::spi::op_t, const embvm::spi::master::cb_t > t) noexcept
 Add an operation to the queue. More...
 
void shutdown () noexcept
 Shutdown the active object. More...
 

Static Public Member Functions

static constexpr embvm::DriverType type () noexcept
 SPI Driver Type ID. More...
 

Protected Member Functions

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...
 

Private Types

using storagePair_t = std::pair< embvm::spi::op_t, const embvm::spi::master::cb_t >
 The storage type that the active object stores. More...
 

Private Member Functions

void start_ () noexcept final
 Derived classes override the start_ method to control driver-specific startup behavior. More...
 
void stop_ () noexcept final
 Derived classes override the start_ method to control driver-specific startup behavior. More...
 
void configure_ () noexcept final
 Configure the SPI bus for operation. More...
 
uint32_t baudrate_ (uint32_t baud) noexcept final
 
embvm::comm::status transfer_ (const embvm::spi::op_t &op, const embvm::spi::master::cb_t &cb) noexcept final
 
void setMode_ (embvm::spi::mode mode) noexcept final
 Set the SPI bus mode. More...
 
void setOrder_ (embvm::spi::order order) noexcept final
 Set the SPI bus byte order. More...
 

Private Attributes

aardvarkAdaptermaster_
 The aardvarkAdapter instance associated with this driver. More...
 

Member Typedef Documentation

◆ storagePair_t

using embdrv::aardvarkSPIMaster::storagePair_t = std::pair<embvm::spi::op_t, const embvm::spi::master::cb_t>
private

The storage type that the active object stores.

Constructor & Destructor Documentation

◆ aardvarkSPIMaster() [1/2]

embdrv::aardvarkSPIMaster::aardvarkSPIMaster ( aardvarkAdapter master)
inlineexplicitnoexcept

Construct a generic SPI master.

Parameters
masterThe aardvarkAdapter instance associated with this driver.

◆ aardvarkSPIMaster() [2/2]

embdrv::aardvarkSPIMaster::aardvarkSPIMaster ( aardvarkAdapter master,
const char *  name 
)
inlineexplicitnoexcept

Construct a named SPI master.

Parameters
masterThe aardvarkAdapter instance associated with this driver.
nameThe name of the driver.

◆ ~aardvarkSPIMaster()

aardvarkSPIMaster::~aardvarkSPIMaster ( )
finaldefaultnoexcept

Default destructor.

Member Function Documentation

◆ baudrate_()

uint32_t aardvarkSPIMaster::baudrate_ ( uint32_t  baud)
finalprivatevirtualnoexcept

◆ configure()

virtual void embvm::spi::master::configure ( spi::baud_t  baud)
inlinevirtualnoexceptinherited

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.

Parameters
baudThe target baudrate, in Hz. TODO: Tolerance - allowed relative tolerance for the resulting baudrate

References embvm::spi::master::configure_().

◆ configure_()

void aardvarkSPIMaster::configure_ ( )
finalprivatevirtualnoexcept

Configure the SPI bus for operation.

This function is implemented by the derived class. It is responsible for configuring the target hardware for operation.

Implements embvm::spi::master.

References AA_SPI_BITORDER_LSB, AA_SPI_BITORDER_MSB, aa_spi_configure(), embdrv::aardvarkAdapter::handle(), embdrv::aardvarkAdapter::lock(), master_, embvm::spi::master::mode_, embvm::spi::msbFirst, embvm::spi::master::order_, embvm::DriverBase::started(), and embdrv::aardvarkAdapter::unlock().

◆ DriverType()

constexpr embvm::DriverType_t embvm::DriverBase::DriverType ( ) const
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.

Returns
the registered driver type as a embvm::DriverType_t value

References embvm::DriverBase::type_.

◆ enqueue()

bool embutil::activeObject< aardvarkSPIMaster , std::pair< embvm::spi::op_t, const embvm::spi::master::cb_t > , 0 , std::mutex , std::condition_variable >::enqueue ( std::pair< embvm::spi::op_t, const embvm::spi::master::cb_t >  t)
inlinenoexceptinherited

Add an operation to the queue.

This function can be called directly, or by functions internal to the activeObject. For example, the "transfer" API enqueues transfer operations.

This function is marked noexcept because we want the program to terminate if an exception results from this call. For example, the underlying queue may throw on push.

Parameters
tThe operation data object to enqueue for later processing.

◆ mode() [1/2]

spi::mode embvm::spi::master::mode ( ) const
inlinenoexceptinherited

Get the current SPI bus mode.

Returns
The currently configured mode.

References embvm::spi::master::mode_.

Referenced by embvm::spi::master::mode(), and embvm::spi::activeMaster< TQueueSize, TLock, TCond >::setMode_().

◆ mode() [2/2]

spi::mode embvm::spi::master::mode ( spi::mode  mode)
inlinenoexceptinherited

Set the SPI bus mode.

Derived classes must implement the setMode_() function, which is reponsible for configuring the target hardware.

Parameters
modeThe desired SPI bus mode.
Returns
The new SPI bus mode.

References embvm::spi::master::mode(), embvm::spi::master::mode_, and embvm::spi::master::setMode_().

◆ name()

constexpr const std::string_view& embvm::DriverBase::name ( ) const
inlinenoexceptinherited

Provides a string_view reference of the driver name.

Returns
std::string_view ref containing the driver name.

References embvm::DriverBase::name_.

◆ name_cstr()

constexpr const char* embvm::DriverBase::name_cstr ( ) const
inlinenoexceptinherited

Provides a c-string version of the driver name.

Returns
c-string containing the driver name

References embvm::DriverBase::name_.

◆ operator++()

virtual DriverBase& embvm::DriverBase::operator++ ( )
inlinevirtualnoexceptinherited

Increment operator is a no-op, but is used for iterator compatibility.

◆ order() [1/2]

spi::order embvm::spi::master::order ( ) const
inlinenoexceptinherited

Get the current SPI bus byte order.

Returns
The currently configured byte order.

References embvm::spi::master::order_.

Referenced by embvm::spi::master::order(), and embvm::spi::activeMaster< TQueueSize, TLock, TCond >::setOrder_().

◆ order() [2/2]

spi::order embvm::spi::master::order ( spi::order  order)
inlinenoexceptinherited

Set the SPI bus byte order.

Derived classes must implement the setOrder_() function, which is reponsible for configuring the target hardware.

Parameters
orderThe desired byte ordering.
Returns
The new byte ordering.

References embvm::spi::master::order(), embvm::spi::master::order_, and embvm::spi::master::setOrder_().

◆ process_()

◆ queuedCount()

size_t embutil::activeObject< aardvarkSPIMaster , std::pair< embvm::spi::op_t, const embvm::spi::master::cb_t > , 0 , std::mutex , std::condition_variable >::queuedCount ( ) const
inlinenoexceptinherited

Get the number of operations in the queue.

Returns
the number of queued operations.

◆ restart()

void embvm::DriverBase::restart ( )
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().

◆ setMode_()

void aardvarkSPIMaster::setMode_ ( embvm::spi::mode  mode)
finalprivatevirtualnoexcept

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.

Parameters
modeThe desired byte ordering.

Implements embvm::spi::master.

References assert, embvm::spi::mode0, and embvm::spi::mode3.

◆ setOrder_()

void aardvarkSPIMaster::setOrder_ ( embvm::spi::order  order)
finalprivatevirtualnoexcept

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.

Parameters
orderThe desired byte ordering.

Implements embvm::spi::master.

◆ shutdown()

void embutil::activeObject< aardvarkSPIMaster , std::pair< embvm::spi::op_t, const embvm::spi::master::cb_t > , 0 , std::mutex , std::condition_variable >::shutdown ( )
inlinenoexceptinherited

Shutdown the active object.

Call this function in the parent class destructor to stop the AO thread operation before destroying the parent class. This will prevent memory access problems due to race conidtions during destruction.

This function is marked noexcept because we want the program to terminate if an exception results from this call.

The shutdown process is permanent and cannot be reversed without recreating the object.

◆ start()

◆ start_()

void aardvarkSPIMaster::start_ ( )
finalprivatevirtualnoexcept

Derived classes override the start_ method to control driver-specific startup behavior.

(Template Method Pattern)

Implements embvm::spi::master.

References embvm::DriverBase::start().

◆ started()

type_safe::boolean embvm::DriverBase::started ( ) const
inlinenoexceptinherited

Check if the driver has been started.

Returns
true if the driver is running (started), false if not running (stopped).

References embvm::DriverBase::started_.

Referenced by configure_(), embdrv::aardvarkGPIOInput< 4 >::get(), embdrv::aardvarkGPIOOutput< 5 >::set(), embdrv::vl53l1x::start_(), embdrv::aardvarkAdapter::start_(), and embdrv::aardvarkAdapter::stop_().

◆ stop()

◆ stop_()

void aardvarkSPIMaster::stop_ ( )
finalprivatevirtualnoexcept

Derived classes override the start_ method to control driver-specific startup behavior.

(Template Method Pattern)

Implements embvm::spi::master.

References master_, and embvm::DriverBase::stop().

◆ transfer_() [1/2]

embvm::comm::status aardvarkSPIMaster::transfer_ ( const embvm::spi::op_t op,
const embvm::spi::master::cb_t &  cb 
)
finalprivatenoexcept

References embvm::comm::enqueued.

◆ transfer_() [2/2]

embvm::comm::status embvm::spi::master::transfer_ ( const spi::op_t op,
const cb_t &  cb 
)
overrideprotectedpure virtualnoexceptinherited

◆ type()

static constexpr embvm::DriverType embvm::spi::master::type ( )
inlinestaticnoexceptinherited

SPI Driver Type ID.

Returns
SPI type ID.

References embvm::SPI.

Member Data Documentation

◆ master_

aardvarkAdapter& embdrv::aardvarkSPIMaster::master_
private

The aardvarkAdapter instance associated with this driver.

Referenced by configure_(), and stop_().

◆ mode_

spi::mode embvm::spi::master::mode_ = spi::mode::mode0
protectedinherited

Stores the active SPI mode configuration.

Referenced by configure_(), and embvm::spi::master::mode().

◆ name_

const std::string_view embvm::DriverBase::name_
protectedinherited

Name of the driver instance.

Referenced by embvm::DriverBase::name(), and embvm::DriverBase::name_cstr().

◆ order_

spi::order embvm::spi::master::order_ = spi::order::msbFirst
protectedinherited

Stores the active SPI byte ordering.

Referenced by configure_(), and embvm::spi::master::order().

◆ started_

type_safe::boolean embvm::DriverBase::started_ = false
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().

◆ type_

const embvm::DriverType_t embvm::DriverBase::type_
protectedinherited

Type ID of the driver instance.

Referenced by embvm::DriverBase::DriverType().

Enumeration Type Documentation

◆ aardvarkMode

enum embdrv::aardvarkMode
strong

Aardvark master operational modes.

Enumerator
GpioOnly 

Aardvark Device used for GPIO.

Enables the full array of GPIO IOs for use.

SpiGpio 

Aardvark device used for SPI + GPIO.

The Non-SPI pins can be used in GPIO mode.

GpioI2C 

Aardvark device used for I2C + GPIO.

The non-I2C pins can be used in GPIO mode.

SpiI2C 

Aardvark Device used for I2C + SPI.

GPIO use is not supported

Query 

Query the current mode.

Variable Documentation

◆ AARDVARK_IO_COUNT

constexpr size_t embdrv::AARDVARK_IO_COUNT = 6
inline

The number of IO pins supported by the AARDVARK sensor.

Referenced by embdrv::aardvarkGPIOInput< 4 >::aardvarkGPIOInput(), and embdrv::aardvarkGPIOOutput< 5 >::aardvarkGPIOOutput().

◆ aardvarkIO

constexpr std::array<uint8_t, AARDVARK_IO_COUNT> embdrv::aardvarkIO
inlinestatic
Initial value:
= {
Definition: aardvark.h:660
Definition: aardvark.h:662
Definition: aardvark.h:659
Definition: aardvark.h:658
Definition: aardvark.h:657
Definition: aardvark.h:661

aardvark IO pin IDs

Referenced by embdrv::aardvarkGPIOInput< 4 >::get(), embdrv::aardvarkAdapter::pullup(), embdrv::aardvarkGPIOOutput< 5 >::set(), and embdrv::aardvarkGPIOOutput< 5 >::start_().