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

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 seperate transaction object.
 
bool isTransactionRunning ()
 
bool wasTransactionSuccessful ()
 
modm::ResumableResult< bool > runTransaction ()
 Starts our own transaction and waits until finished.
 
modm::ResumableResult< ReturnType > resumable function (...)
 
int8_t getResumableDepth () const
 
bool isResumableRunning () const
 
void stopResumable ()
 Force all resumable functions to stop running at the current nesting level.
 

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.

modm::ResumableResult< ReturnType > resumable modm::NestedResumable< 1 >::function (   ...)
inherited

Run the resumable function.

You need to implement this method in you subclass yourself.

Returns
>NestingError if still running, <=NestingError if it has finished.
int8_t modm::NestedResumable< 1 >::getResumableDepth ( ) const
inheritedinline
Returns
the nesting depth in the current resumable function, or -1 if called outside any resumable function
bool modm::NestedResumable< 1 >::isResumableRunning ( ) const
inheritedinline
Returns
true if a resumable function is running at the current nesting level, else false
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: