FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
Loading...
Searching...
No Matches
i2c::I2CFuturesGroup< MANAGER > Class Template Reference

Abstract class to allow aggregation of several futures in relation to I2C transactions. More...

#include <fastarduino/i2c_device_utilities.h>

Inheritance diagram for i2c::I2CFuturesGroup< MANAGER >:
Collaboration diagram for i2c::I2CFuturesGroup< MANAGER >:

Protected Member Functions

 I2CFuturesGroup (ABSTRACT_FUTURE **futures, uint8_t size, future::FutureNotification notification=future::FutureNotification::NONE)
 Called by subclass constructor, this constructs a new I2CFuturesGroup instance with the provided list of futures. More...
 
bool start (typename PARENT::DEVICE &device)
 Start the I2C transactions needed by this group of futures. More...
 

Detailed Description

template<typename MANAGER>
class i2c::I2CFuturesGroup< MANAGER >

Abstract class to allow aggregation of several futures in relation to I2C transactions.

This allows to await() for all futures, or query the overall status() of the group. This enables I2C device support developers to handle complex I2C transactions where several distinct Futures must be used. Suclasses shall define all needed individual Futures as members, pass them to I2CFuturesGroup constructor and call future::AbstractFuturesGroup::init(). In addition, subclasses may define a method get() that will handle aggregation of results of its individual futures.

The following is en excerpt of VL53L0X showing GetGPIOSettingsFuture future definition and its usage in get_GPIO_settings() method:

class GetGPIOSettingsFuture : public I2CFuturesGroup
{
public:
GetGPIOSettingsFuture() : I2CFuturesGroup{futures_, NUM_FUTURES} {
I2CFuturesGroup::init(futures_);
}
~GetGPIOSettingsFuture() {
}
bool get(vl53l0x::GPIOSettings& settings) {
if (this->await() != future::FutureStatus::READY) return false;
vl53l0x::GPIOFunction function;
read_config_.get(function);
uint8_t active_high;
read_GPIO_active_high_.get(active_high);
...
settings = vl53l0x::GPIOSettings{function, bool(active_high & 0x10), ...};
return true;
}
private:
TReadRegisterFuture<Register::SYSTEM_INTERRUPT_CONFIG_GPIO, vl53l0x::GPIOFunction> read_config_{};
TReadRegisterFuture<Register::GPIO_HV_MUX_ACTIVE_HIGH> read_GPIO_active_high_{};
...
static constexpr uint8_t NUM_FUTURES = 4;
ABSTRACT_FUTURE* futures_[NUM_FUTURES] = {&read_config_, &read_GPIO_active_high_,...};
friend VL53L0X<MANAGER>;
};
int get_GPIO_settings(GetGPIOSettingsFuture& future) {
return (future.start(*this) ? 0 : future.error());
}
Abstract class to allow aggregation of several futures in relation to I2C transactions.
Contains the API around Future implementation.
Definition: future.h:312
@ READY
The status of a Future once its output value has been fully set by a provider.
void register_handler(Handler &handler)
Register a class instance containing methods that shall be called back by an ISR.
Definition: interrupts.h:185
void unregister_handler(Handler &handler)
Unregister a class instance that was previously registered with interrupt::register_handler.
Definition: interrupts.h:207
Template Parameters
MANAGERthe type of I2C Manager used to handle I2C communication

Definition at line 552 of file i2c_device_utilities.h.

Constructor & Destructor Documentation

◆ I2CFuturesGroup()

template<typename MANAGER >
i2c::I2CFuturesGroup< MANAGER >::I2CFuturesGroup ( ABSTRACT_FUTURE **  futures,
uint8_t  size,
future::FutureNotification  notification = future::FutureNotification::NONE 
)
inlineprotected

Called by subclass constructor, this constructs a new I2CFuturesGroup instance with the provided list of futures.

Parameters
futuresthe array of futures to be handled by this group of futures
sizethe number of futures in futures
notificationdetermines if and which notifications should be dispatched by this I2CFuturesGroup; default is none.

Definition at line 568 of file i2c_device_utilities.h.

Member Function Documentation

◆ start()

template<typename MANAGER >
bool i2c::I2CFuturesGroup< MANAGER >::start ( typename PARENT::DEVICE &  device)
inlineprotected

Start the I2C transactions needed by this group of futures.

This is either called by the subclass or directly by the I2C device support class (if declared friend of the subclass).

Warning
Asynchronous API! If the currently active I2C Manager is asynchronous, then this method is too!
Blocking API! If the currently active I2C Manager is synchronous, then this method is blocking!
Parameters
devicethe i2c::I2CDevice subclass instance that shall handle I2C commands to the I2C device
Return values
trueif the first I2C command could be launched successfully

Definition at line 586 of file i2c_device_utilities.h.


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