Embedded Artistry Framework
Embedded Systems C++ Framework
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Private Member Functions | Private Attributes | List of all members
nRFi2cMaster< TTWIIndex, TSclPin, TSdaPin, TBlocking > Class Template Referencefinal

DMA-capable I2C master (TBlocking) More...

#include <nrf52_i2c_master.hpp>

Inheritance diagram for nRFi2cMaster< TTWIIndex, TSclPin, TSdaPin, TBlocking >:
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

 nRFi2cMaster (uint8_t priority=PRIORITY_DEFAULT) noexcept
 
 nRFi2cMaster (const char *name, uint8_t priority=PRIORITY_DEFAULT) noexcept
 
 ~nRFi2cMaster ()=default
 
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...
 
void setBottomHalfDispatcher (const embutil::IRQDispatcherFunc_t &dispatcher) noexcept
 
template<typename TCallback >
void invokeCallback (TCallback &cb) noexcept
 
template<typename TCallback , typename... TArgs>
void invokeCallback (TCallback &cb, TArgs &... args) noexcept
 

Static Public Member Functions

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

Static Public Attributes

static constexpr uint8_t PRIORITY_DEFAULT = NRF_IRQ_PRIOR_MID
 

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...
 
embutil::IRQDispatcherFunc_t dispatcher_
 

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_ (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
 
template<typename Dummy = embvm::i2c::status>
auto transfer_impl_ (const embvm::i2c::op_t &op, const embvm::i2c::master::cb_t &cb) noexcept -> std::enable_if_t< TBlocking, Dummy >
 Blocking Variant. More...
 
template<typename Dummy = embvm::i2c::status>
auto transfer_impl_ (const embvm::i2c::op_t &op, const embvm::i2c::master::cb_t &cb) noexcept -> std::enable_if_t<!TBlocking, Dummy >
 Non-blocking variant. More...
 
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 enableInterrupts () noexcept final
 
void disableInterrupts () noexcept final
 
void twim_callback_ (embvm::i2c::status status) noexcept
 

Private Attributes

const uint8_t priority_
 
bool busy_ = false
 
embvm::i2c::master::cb_t active_cb_ {nullptr}
 
embvm::i2c::op_t active_op_ {}
 

Detailed Description

template<NordicTWIM TTWIIndex, typename TSclPin, typename TSdaPin, bool TBlocking = false>
class nRFi2cMaster< TTWIIndex, TSclPin, TSdaPin, TBlocking >

DMA-capable I2C master (TBlocking)

Template Parameters
TTWIIndexThe instance of the TWI to use. Can be NordicTWIM0 or NordicTWIM1
TSclPinA class representing the SCL pin. This is designed for use with nRFPinID<>:
nRFi2cMaster_TBlocking<0, nRFPinID<0,27>, nRFPinID<0,26>> i2c0;
TSdaPinA class representing the SDA pin. This is designed for use with nRFPinID<>:
nRFi2cMaster_TBlocking<0, nRFPinID<0,27>, nRFPinID<0,26>> i2c0;

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

◆ nRFi2cMaster() [1/2]

template<NordicTWIM TTWIIndex, typename TSclPin, typename TSdaPin, bool TBlocking = false>
nRFi2cMaster< TTWIIndex, TSclPin, TSdaPin, TBlocking >::nRFi2cMaster ( uint8_t  priority = PRIORITY_DEFAULT)
inlinenoexcept

◆ nRFi2cMaster() [2/2]

template<NordicTWIM TTWIIndex, typename TSclPin, typename TSdaPin, bool TBlocking = false>
nRFi2cMaster< TTWIIndex, TSclPin, TSdaPin, TBlocking >::nRFi2cMaster ( const char *  name,
uint8_t  priority = PRIORITY_DEFAULT 
)
inlinenoexcept

◆ ~nRFi2cMaster()

template<NordicTWIM TTWIIndex, typename TSclPin, typename TSdaPin, bool TBlocking = false>
nRFi2cMaster< TTWIIndex, TSclPin, TSdaPin, TBlocking >::~nRFi2cMaster ( )
default

Member Function Documentation

◆ baudrate_()

template<NordicTWIM TTWIIndex, typename TSclPin, typename TSdaPin, bool TBlocking = false>
embvm::i2c::baud nRFi2cMaster< TTWIIndex, TSclPin, TSdaPin, TBlocking >::baudrate_ ( embvm::i2c::baud  baud)
inlinefinalprivatevirtualnoexcept

Implements embvm::i2c::master.

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

template<NordicTWIM TTWIIndex, typename TSclPin, typename TSdaPin, bool TBlocking = false>
void nRFi2cMaster< TTWIIndex, TSclPin, TSdaPin, TBlocking >::configure_ ( embvm::i2c::pullups  pullups)
inlinefinalprivatevirtualnoexcept

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.

◆ disableInterrupts()

template<NordicTWIM TTWIIndex, typename TSclPin, typename TSdaPin, bool TBlocking = false>
void nRFi2cMaster< TTWIIndex, TSclPin, TSdaPin, TBlocking >::disableInterrupts ( )
inlinefinalprivatevirtualnoexcept

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

◆ enableInterrupts()

template<NordicTWIM TTWIIndex, typename TSclPin, typename TSdaPin, bool TBlocking = false>
void nRFi2cMaster< TTWIIndex, TSclPin, TSdaPin, TBlocking >::enableInterrupts ( )
inlinefinalprivatevirtualnoexcept

◆ invokeCallback() [1/2]

template<typename TCallback >
void embvm::HALDriverBase::invokeCallback ( TCallback &  cb)
inlinenoexceptinherited

◆ invokeCallback() [2/2]

template<typename TCallback , typename... TArgs>
void embvm::HALDriverBase::invokeCallback ( TCallback &  cb,
TArgs &...  args 
)
inlinenoexceptinherited

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

◆ setBottomHalfDispatcher()

void embvm::HALDriverBase::setBottomHalfDispatcher ( const embutil::IRQDispatcherFunc_t dispatcher)
inlinenoexceptinherited

◆ setPullups_()

template<NordicTWIM TTWIIndex, typename TSclPin, typename TSdaPin, bool TBlocking = false>
embvm::i2c::pullups nRFi2cMaster< TTWIIndex, TSclPin, TSdaPin, TBlocking >::setPullups_ ( embvm::i2c::pullups  pullups)
inlinefinalprivatevirtualnoexcept

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

void embvm::DriverBase::start ( )
inlinenoexceptinherited

◆ start_()

template<NordicTWIM TTWIIndex, typename TSclPin, typename TSdaPin, bool TBlocking = false>
void nRFi2cMaster< TTWIIndex, TSclPin, TSdaPin, TBlocking >::start_ ( )
inlinefinalprivatevirtualnoexcept

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

void embvm::DriverBase::stop ( )
inlinenoexceptinherited

◆ stop_()

template<NordicTWIM TTWIIndex, typename TSclPin, typename TSdaPin, bool TBlocking = false>
void nRFi2cMaster< TTWIIndex, TSclPin, TSdaPin, TBlocking >::stop_ ( )
inlinefinalprivatevirtualnoexcept

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

template<NordicTWIM TTWIIndex, typename TSclPin, typename TSdaPin, bool TBlocking = false>
embvm::i2c::status nRFi2cMaster< TTWIIndex, TSclPin, TSdaPin, TBlocking >::transfer_ ( const embvm::i2c::op_t op,
const embvm::i2c::master::cb_t cb 
)
inlinefinalprivatevirtualnoexcept

Implements embvm::i2c::master.

◆ transfer_impl_() [1/2]

template<NordicTWIM TTWIIndex, typename TSclPin, typename TSdaPin, bool TBlocking = false>
template<typename Dummy = embvm::i2c::status>
auto nRFi2cMaster< TTWIIndex, TSclPin, TSdaPin, TBlocking >::transfer_impl_ ( const embvm::i2c::op_t op,
const embvm::i2c::master::cb_t cb 
) -> std::enable_if_t<TBlocking, Dummy>
inlineprivatenoexcept

◆ transfer_impl_() [2/2]

template<NordicTWIM TTWIIndex, typename TSclPin, typename TSdaPin, bool TBlocking = false>
template<typename Dummy = embvm::i2c::status>
auto nRFi2cMaster< TTWIIndex, TSclPin, TSdaPin, TBlocking >::transfer_impl_ ( const embvm::i2c::op_t op,
const embvm::i2c::master::cb_t cb 
) -> std::enable_if_t<!TBlocking, Dummy>
inlineprivatenoexcept

Non-blocking variant.

◆ twim_callback_()

template<NordicTWIM TTWIIndex, typename TSclPin, typename TSdaPin, bool TBlocking = false>
void nRFi2cMaster< TTWIIndex, TSclPin, TSdaPin, TBlocking >::twim_callback_ ( embvm::i2c::status  status)
inlineprivatenoexcept

◆ type()

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

I2C Driver Type ID.

Returns
I2C type ID.

References embvm::I2C.

Member Data Documentation

◆ active_cb_

template<NordicTWIM TTWIIndex, typename TSclPin, typename TSdaPin, bool TBlocking = false>
embvm::i2c::master::cb_t nRFi2cMaster< TTWIIndex, TSclPin, TSdaPin, TBlocking >::active_cb_ {nullptr}
private

◆ active_op_

template<NordicTWIM TTWIIndex, typename TSclPin, typename TSdaPin, bool TBlocking = false>
embvm::i2c::op_t nRFi2cMaster< TTWIIndex, TSclPin, TSdaPin, TBlocking >::active_op_ {}
private

◆ busy_

template<NordicTWIM TTWIIndex, typename TSclPin, typename TSdaPin, bool TBlocking = false>
bool nRFi2cMaster< TTWIIndex, TSclPin, TSdaPin, TBlocking >::busy_ = false
private

◆ dispatcher_

embutil::IRQDispatcherFunc_t embvm::HALDriverBase::dispatcher_
protectedinherited

◆ name_

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

Name of the driver instance.

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

◆ priority_

template<NordicTWIM TTWIIndex, typename TSclPin, typename TSdaPin, bool TBlocking = false>
const uint8_t nRFi2cMaster< TTWIIndex, TSclPin, TSdaPin, TBlocking >::priority_
private

◆ PRIORITY_DEFAULT

template<NordicTWIM TTWIIndex, typename TSclPin, typename TSdaPin, bool TBlocking = false>
constexpr uint8_t nRFi2cMaster< TTWIIndex, TSclPin, TSdaPin, TBlocking >::PRIORITY_DEFAULT = NRF_IRQ_PRIOR_MID
static

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


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