modm API documentation
modm::I2cDevice< I2cMaster, NestingLevels, Transaction > Class Template Reference

#include <modm/architecture/interface/i2c_device.hpp>

Inheritance diagram for modm::I2cDevice< I2cMaster, NestingLevels, Transaction >:
modm::NestedResumable< NestingLevels+1 >

Public Member Functions

 I2cDevice (uint8_t address)
 
void setAddress (uint8_t address)
 
void attachConfigurationHandler (I2c::ConfigurationHandler handler)
 
modm::ResumableResult< bool > ping ()
 
modm::ResumableResult< bool > writeRead (const uint8_t *writeBuffer, std::size_t writeSize, uint8_t *readBuffer, std::size_t readSize)
 Starts a write-read transaction and waits until finished.
 
modm::ResumableResult< bool > write (const uint8_t *buffer, std::size_t size)
 Starts a write transaction and waits until finished.
 
modm::ResumableResult< bool > read (uint8_t *buffer, std::size_t size)
 Starts a write transaction and waits until finished.
 

Protected Member Functions

bool startWriteRead (const uint8_t *writeBuffer, std::size_t writeSize, uint8_t *readBuffer, std::size_t readSize)
 Configures the transaction with a write/read operation and starts it.
 
bool startWrite (const uint8_t *buffer, std::size_t size)
 Configures the transaction with a write operation and starts it.
 
bool startRead (uint8_t *buffer, std::size_t size)
 Configures the transaction with a read operation and starts it.
 
bool startTransaction ()
 Starts the transaction with our own transaction object.
 
bool startTransaction (modm::I2cTransaction *transaction)
 Starts the transaction with a separate transaction object.
 
bool isTransactionRunning ()
 
bool wasTransactionSuccessful ()
 
modm::ResumableResult< bool > runTransaction ()
 Starts our own transaction and waits until finished.
 
int8_t getResumableDepth () const
 
bool isResumableRunning () const
 
void stopResumable ()
 

Protected Attributes

Transaction transaction
 

Detailed Description

template<class I2cMaster, uint8_t NestingLevels = 10, class Transaction = I2cWriteReadTransaction>
class modm::I2cDevice< I2cMaster, NestingLevels, Transaction >

Base class of an I2C Device.

This class provides functions for configuring the adapter and peripheral and starting transactions. It also provides a basic ping() resumable function, which checks if the device responds to its address.

You need to provide the number of required nesting levels for your driver here. By default, 10 levels are chosen, which should be more than enough in any case.

You can choose to use your own custom I2c Transaction Adapter, by providing a class subclassed from an existing I2cAdapter or which implements the I2cTransaction interface manually.

Template Parameters
I2cMasteran I2cMaster conforming to the I2cMaster interface.
NestingLevelsnumber of nesting levels required for your driver
Transactiona class conforming to the I2cTransaction interface.
Author
Georgi Grinshpun
Niklas Hauser

Constructor & Destructor Documentation

template<class I2cMaster , uint8_t NestingLevels = 10, class Transaction = I2cWriteReadTransaction>
modm::I2cDevice< I2cMaster, NestingLevels, Transaction >::I2cDevice ( uint8_t  address)
inline
Parameters
addressthe slave address not yet shifted left (address < 128).

Member Function Documentation

template<class I2cMaster , uint8_t NestingLevels = 10, class Transaction = I2cWriteReadTransaction>
void modm::I2cDevice< I2cMaster, NestingLevels, Transaction >::attachConfigurationHandler ( I2c::ConfigurationHandler  handler)
inline

Attaches a configuration handler, which is called before a transaction, whenever the configuration has to be changed.

template<class I2cMaster , uint8_t NestingLevels = 10, class Transaction = I2cWriteReadTransaction>
bool modm::I2cDevice< I2cMaster, NestingLevels, Transaction >::isTransactionRunning ( )
inlineprotected
Returns
true when transaction is busy.
template<class I2cMaster , uint8_t NestingLevels = 10, class Transaction = I2cWriteReadTransaction>
modm::ResumableResult<bool> modm::I2cDevice< I2cMaster, NestingLevels, Transaction >::ping ( )
inline
Return Values
truedevice responds to address
falseno device with address found
template<class I2cMaster , uint8_t NestingLevels = 10, class Transaction = I2cWriteReadTransaction>
void modm::I2cDevice< I2cMaster, NestingLevels, Transaction >::setAddress ( uint8_t  address)
inline

Sets a new address of the slave device.

Parameters
addressthe slave address not yet shifted left (address < 128).
template<class I2cMaster , uint8_t NestingLevels = 10, class Transaction = I2cWriteReadTransaction>
bool modm::I2cDevice< I2cMaster, NestingLevels, Transaction >::wasTransactionSuccessful ( )
inlineprotected
Returns
true when transaction did not return an error.

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