Embedded Artistry Framework
Embedded Systems C++ Framework
Classes
Unit Test Drivers

Drivers intended for use with unit test code. More...

Collaboration diagram for Unit Test Drivers:

Classes

class  test::TestDriverBase
 Test driver that enables testing DriverBase. More...
 
class  test::UnitTestGPIOInput
 Unit Test GPIO Input Driver. More...
 
class  test::UnitTestGPIOInputWithPullup
 Unit Test GPIO Input Driver, with a pullup. More...
 
class  test::i2cTestDriver
 I2C Master Unit Test Driver. More...
 
class  test::spiTestDriver
 SPI Master Unit Test Driver. More...
 

Detailed Description

Drivers intended for use with unit test code.


Class Documentation

◆ test::TestDriverBase

class test::TestDriverBase

Test driver that enables testing DriverBase.

Inheritance diagram for test::TestDriverBase:
Inheritance graph

Public Member Functions

 TestDriverBase (const char *name, uint32_t c=embvm::DriverType::Undefined) noexcept
 Create a driver base. More...
 
 TestDriverBase (const std::string &name, uint32_t c=embvm::DriverType::Undefined) noexcept
 
 TestDriverBase (const std::string_view &name, uint32_t c=embvm::DriverType::Undefined) noexcept
 
 ~TestDriverBase () noexcept final
 Default destructor. 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...
 

Constructor & Destructor Documentation

◆ TestDriverBase() [1/3]

test::TestDriverBase::TestDriverBase ( const char *  name,
uint32_t  c = embvm::DriverType::Undefined 
)
inlinenoexcept

Create a driver base.

Parameters
nameThe name of the driver base
Note
DriverBase() uses a std::string_view, so name input smust remain valid
Parameters
cThe type of the driver base

◆ TestDriverBase() [2/3]

test::TestDriverBase::TestDriverBase ( const std::string &  name,
uint32_t  c = embvm::DriverType::Undefined 
)
inlinenoexcept

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

◆ TestDriverBase() [3/3]

test::TestDriverBase::TestDriverBase ( const std::string_view &  name,
uint32_t  c = embvm::DriverType::Undefined 
)
inlinenoexcept

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

◆ ~TestDriverBase()

TestDriverBase::~TestDriverBase ( )
finalnoexcept

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

◆ 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().

◆ start()

◆ start_()

void TestDriverBase::start_ ( )
finalprivatevirtualnoexcept

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

(Template Method Pattern)

Implements embvm::DriverBase.

◆ 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_()

void TestDriverBase::stop_ ( )
finalprivatevirtualnoexcept

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

(Template Method Pattern)

Implements embvm::DriverBase.

Member Data Documentation

◆ 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().

◆ test::UnitTestGPIOInput

class test::UnitTestGPIOInput

Unit Test GPIO Input Driver.

Inheritance diagram for test::UnitTestGPIOInput:
Inheritance graph

Public Member Functions

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 Member Functions

embvm::gpio::pull pull_ (embvm::gpio::pull p) noexcept final
 Set the pull configuration in hardware. 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...
 

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

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

bool UnitTestGPIOInput::get ( )
finalvirtualnoexcept

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< embvm::gpio::pull::none >.

References embvm::gpio::none, embvm::gpio::input< embvm::gpio::pull::none >::pull(), embvm::gpio::pulldown, and embvm::gpio::pullup.

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

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

Get the current pull configuration.

Returns
The currently configured GPIO pull setting.

◆ pull_()

embvm::gpio::pull UnitTestGPIOInput::pull_ ( embvm::gpio::pull  p)
finalprotectedvirtualnoexcept

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< embvm::gpio::pull::none >.

References p.

◆ 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 UnitTestGPIOInput::start_ ( )
finalprotectedvirtualnoexcept

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

(Template Method Pattern)

Implements embvm::gpio::input< embvm::gpio::pull::none >.

◆ 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_()

void UnitTestGPIOInput::stop_ ( )
finalprotectedvirtualnoexcept

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

(Template Method Pattern)

Implements embvm::gpio::input< embvm::gpio::pull::none >.

◆ type()

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

GPIO Driver Type ID.

Returns
GPIO type ID.

Member Data Documentation

◆ 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().

◆ test::UnitTestGPIOInputWithPullup

class test::UnitTestGPIOInputWithPullup

Unit Test GPIO Input Driver, with a pullup.

Inheritance diagram for test::UnitTestGPIOInputWithPullup:
Inheritance graph

Public Member Functions

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 Member Functions

embvm::gpio::pull pull_ (embvm::gpio::pull p) noexcept final
 Set the pull configuration in hardware. 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...
 

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 Attributes

embvm::gpio::pull p_ = embvm::gpio::pull::pullup
 

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

bool UnitTestGPIOInputWithPullup::get ( )
finalvirtualnoexcept

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< embvm::gpio::pull::pullup >.

References embvm::gpio::none, embvm::gpio::input< embvm::gpio::pull::pullup >::pull(), embvm::gpio::pulldown, and embvm::gpio::pullup.

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

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

Get the current pull configuration.

Returns
The currently configured GPIO pull setting.

◆ pull_()

embvm::gpio::pull UnitTestGPIOInputWithPullup::pull_ ( embvm::gpio::pull  p)
finalprotectedvirtualnoexcept

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< embvm::gpio::pull::pullup >.

References p.

Referenced by 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_()

void UnitTestGPIOInputWithPullup::start_ ( )
finalprotectedvirtualnoexcept

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

(Template Method Pattern)

Implements embvm::gpio::input< embvm::gpio::pull::pullup >.

References p_, pull_(), and embvm::gpio::pullup.

◆ 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_()

void UnitTestGPIOInputWithPullup::stop_ ( )
finalprotectedvirtualnoexcept

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

(Template Method Pattern)

Implements embvm::gpio::input< embvm::gpio::pull::pullup >.

◆ type()

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

GPIO Driver Type ID.

Returns
GPIO type ID.

Member Data Documentation

◆ name_

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

Name of the driver instance.

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

◆ p_

embvm::gpio::pull test::UnitTestGPIOInputWithPullup::p_ = embvm::gpio::pull::pullup
private

Referenced by start_().

◆ 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().

◆ test::i2cTestDriver

class test::i2cTestDriver

I2C Master Unit Test Driver.

This driver can be used as a "fake" for a unit test.

You can prepare return data for a TX operation:

uint8_t expected[2] = {0xBE, 0xAE};
d.appendToRxBuffer(expected, sizeof(expected));

You can verify the data that was transmitted:

CHECK(true == d.checkTxBuffer(input, sizeof(input)));
Inheritance diagram for test::i2cTestDriver:
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

 i2cTestDriver () noexcept
 Create a generic I2C Master. More...
 
 i2cTestDriver (const char *name) noexcept
 Create a named I2C master. More...
 
 ~i2cTestDriver () noexcept final
 Default destructor. More...
 
bool checkTxBuffer (uint8_t *data, size_t length) noexcept
 Verify that the driver transmitted the correct data. More...
 
void clearTxBuffer () noexcept
 Clear the stored TX buffer. More...
 
void appendToRxBuffer (uint8_t *data, size_t length) noexcept
 Append data to the RX buffer to be returned with the next read operation. More...
 
void clearRxBuffer () noexcept
 Clears the data stored in the RX buffer. 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...
 

Static Public Member Functions

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

Protected 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_ (embvm::i2c::pullups) 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...
 

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 Attributes

std::vector< uint8_ttxBuffer_
 Storage represnting the tx buffer. More...
 
std::queue< uint8_trxBuffer_
 Storage representing the rx bufferre. 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.

◆ 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

◆ i2cTestDriver() [1/2]

test::i2cTestDriver::i2cTestDriver ( )
inlinenoexcept

Create a generic I2C Master.

◆ i2cTestDriver() [2/2]

test::i2cTestDriver::i2cTestDriver ( const char *  name)
inlineexplicitnoexcept

Create a named I2C master.

Parameters
nameThe name of this i2c instance.

◆ ~i2cTestDriver()

i2cTestDriver::~i2cTestDriver ( )
finalnoexcept

Default destructor.

Member Function Documentation

◆ appendToRxBuffer()

void test::i2cTestDriver::appendToRxBuffer ( uint8_t data,
size_t  length 
)
inlinenoexcept

Append data to the RX buffer to be returned with the next read operation.

Parameters
dataThe data to append to the RX buffer
lengththe number of bytes to append

References length, and rxBuffer_.

◆ baudrate_()

embvm::i2c::baud i2cTestDriver::baudrate_ ( embvm::i2c::baud  baud)
finalprotectedvirtualnoexcept

Implements embvm::i2c::master.

◆ checkTxBuffer()

bool test::i2cTestDriver::checkTxBuffer ( uint8_t data,
size_t  length 
)
inlinenoexcept

Verify that the driver transmitted the correct data.

Parameters
dataThe data buffer to check.
lengthThe number of bytes in the input buffer to compare.

References length, and txBuffer_.

◆ clearRxBuffer()

void test::i2cTestDriver::clearRxBuffer ( )
inlinenoexcept

Clears the data stored in the RX buffer.

References rxBuffer_, and swap.

◆ clearTxBuffer()

void test::i2cTestDriver::clearTxBuffer ( )
inlinenoexcept

Clear the stored TX buffer.

References txBuffer_.

◆ 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 i2cTestDriver::configure_ ( embvm::i2c::pullups  pullups)
finalprotectedvirtualnoexcept

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.

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

◆ 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

◆ 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 i2cTestDriver::setPullups_ ( embvm::i2c::pullups  pullups)
finalprotectedvirtualnoexcept

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.

◆ start()

◆ start_()

void i2cTestDriver::start_ ( )
finalprotectedvirtualnoexcept

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

(Template Method Pattern)

Implements embvm::i2c::master.

◆ 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 i2cTestDriver::stop_ ( )
finalprotectedvirtualnoexcept

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

(Template Method Pattern)

Implements embvm::i2c::master.

◆ 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_()

◆ type()

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

I2C Driver Type ID.

Returns
I2C type ID.

References embvm::I2C.

Member Data Documentation

◆ 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().

◆ rxBuffer_

std::queue<uint8_t> test::i2cTestDriver::rxBuffer_
private

Storage representing the rx bufferre.

Referenced by appendToRxBuffer(), and clearRxBuffer().

◆ 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().

◆ txBuffer_

std::vector<uint8_t> test::i2cTestDriver::txBuffer_
private

Storage represnting the tx buffer.

Referenced by checkTxBuffer(), and clearTxBuffer().

◆ type_

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

Type ID of the driver instance.

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

◆ test::spiTestDriver

class test::spiTestDriver

SPI Master Unit Test Driver.

This driver can be used as a "fake" for a unit test.

You can prepare return data for a TX operation:

uint8_t expected[2] = {0xBE, 0xAE};
d.appendToRxBuffer(expected, sizeof(expected));

You can verify the data that was transmitted:

CHECK(true == d.checkTxBuffer(input, sizeof(input)));
Inheritance diagram for test::spiTestDriver:
Inheritance graph

Public Member Functions

 spiTestDriver (const embvm::spi::master::DispatcherFunc &dispatcher=nullptr) noexcept
 Create a generic spi driver with a dispatcher. More...
 
 spiTestDriver (const char *name, const embvm::spi::master::DispatcherFunc &dispatcher=nullptr) noexcept
 Create a named spi driver with a dispatcher. More...
 
 ~spiTestDriver () noexcept final
 Default destructor. More...
 
bool checkTxBuffer (uint8_t *data, size_t length) noexcept
 Verify that the driver transmitted the correct data. More...
 
void clearTxBuffer () noexcept
 Clear the stored TX buffer. More...
 
void appendToRxBuffer (uint8_t *data, size_t length) noexcept
 Append data to the RX buffer to be returned with the next read operation. More...
 
void clearRxBuffer () noexcept
 Clears the data stored in the RX buffer. 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...
 

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 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 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...
 
embvm::comm::status transfer_ (const embvm::spi::op_t &op, const embvm::spi::master::cb_t &cb) noexcept final
 
uint32_t baudrate_ (uint32_t baud) noexcept final
 
void configure_ () noexcept final
 Configure the SPI bus for operation. More...
 

Private Attributes

std::vector< uint8_ttxBuffer_
 
std::queue< uint8_trxBuffer_
 

Constructor & Destructor Documentation

◆ spiTestDriver() [1/2]

test::spiTestDriver::spiTestDriver ( const embvm::spi::master::DispatcherFunc &  dispatcher = nullptr)
inlineexplicitnoexcept

Create a generic spi driver with a dispatcher.

Parameters
dispatcherThe function to use as a dispatcher for callbacks.

◆ spiTestDriver() [2/2]

test::spiTestDriver::spiTestDriver ( const char *  name,
const embvm::spi::master::DispatcherFunc &  dispatcher = nullptr 
)
inlineexplicitnoexcept

Create a named spi driver with a dispatcher.

Parameters
nameThe name of the SPI driver instance.
dispatcherThe function to use as a dispatcher for callbacks.

◆ ~spiTestDriver()

spiTestDriver::~spiTestDriver ( )
finalnoexcept

Default destructor.

Member Function Documentation

◆ appendToRxBuffer()

void test::spiTestDriver::appendToRxBuffer ( uint8_t data,
size_t  length 
)
inlinenoexcept

Append data to the RX buffer to be returned with the next read operation.

Parameters
dataThe data to append to the RX buffer
lengththe number of bytes to append

References length, and rxBuffer_.

◆ baudrate_()

uint32_t spiTestDriver::baudrate_ ( uint32_t  baud)
finalprivatevirtualnoexcept

Implements embvm::spi::master.

◆ checkTxBuffer()

bool test::spiTestDriver::checkTxBuffer ( uint8_t data,
size_t  length 
)
inlinenoexcept

Verify that the driver transmitted the correct data.

Parameters
dataThe data buffer to check.
lengthThe number of bytes in the input buffer to compare.

References length, and txBuffer_.

◆ clearRxBuffer()

void test::spiTestDriver::clearRxBuffer ( )
inlinenoexcept

Clears the data stored in the RX buffer.

References rxBuffer_, and swap.

◆ clearTxBuffer()

void test::spiTestDriver::clearTxBuffer ( )
inlinenoexcept

Clear the stored TX buffer.

References txBuffer_.

◆ 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 spiTestDriver::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.

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

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

◆ 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 spiTestDriver::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.

◆ setOrder_()

void spiTestDriver::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.

◆ start()

◆ start_()

void spiTestDriver::start_ ( )
finalprivatevirtualnoexcept

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

(Template Method Pattern)

Implements embvm::spi::master.

◆ 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_()

void spiTestDriver::stop_ ( )
finalprivatevirtualnoexcept

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

(Template Method Pattern)

Implements embvm::spi::master.

◆ transfer_() [1/2]

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

References embvm::comm::ok.

◆ 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

◆ mode_

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

Stores the active SPI mode configuration.

Referenced by embdrv::aardvarkSPIMaster::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 embdrv::aardvarkSPIMaster::configure_(), and embvm::spi::master::order().

◆ rxBuffer_

std::queue<uint8_t> test::spiTestDriver::rxBuffer_
private

Referenced by appendToRxBuffer(), and clearRxBuffer().

◆ 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().

◆ txBuffer_

std::vector<uint8_t> test::spiTestDriver::txBuffer_
private

Referenced by checkTxBuffer(), and clearTxBuffer().

◆ type_

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

Type ID of the driver instance.

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