modm API documentation
modm::I2cTransaction Class Referenceabstract

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

Inheritance diagram for modm::I2cTransaction:
modm::I2c modm::I2cReadTransaction modm::I2cWriteReadTransaction modm::I2cWriteTransaction

Classes

struct  Reading
 
struct  Starting
 
struct  Writing
 

Public Member Functions

 I2cTransaction (uint8_t address)
 
void setAddress (uint8_t address)
 
TransactionState getState () const
 
bool isBusy () const
 
bool configurePing ()
 
bool configureWriteRead (const uint8_t *writeBuffer, std::size_t writeSize, uint8_t *readBuffer, std::size_t readSize)
 
bool configureWrite (uint8_t *buffer, std::size_t size)
 
bool configureRead (uint8_t *buffer, std::size_t size)
 
virtual bool attaching ()
 
virtual Starting starting () = 0
 
virtual Writing writing () = 0
 
virtual Reading reading () = 0
 
virtual void detaching (DetachCause cause)
 

Protected Attributes

uint8_t address
 
volatile TransactionState state
 

Additional Inherited Members

- Public Typedefs inherited from modm::I2c
using ConfigurationHandler = void (*)()
 The signature of the configuration function.
 
- Public Types inherited from modm::I2c
enum  DetachCause : uint8_t { DetachCause::NormalStop, DetachCause::ErrorCondition, DetachCause::FailedToAttach }
 
enum  TransactionState : uint8_t { TransactionState::Idle, TransactionState::Busy, TransactionState::Error }
 State of a I2c Transaction. More...
 
enum  Operation : uint8_t { Operation::Stop = 0, Operation::Restart = 1, Operation::Write = 2, Operation::Read = 3 }
 All possible I2C Operations. More...
 
enum  OperationAfterStart : uint8_t { OperationAfterStart::Stop = uint8_t(Operation::Stop), OperationAfterStart::Write = uint8_t(Operation::Write), OperationAfterStart::Read = uint8_t(Operation::Read) }
 Further operations after start operation. More...
 
enum  OperationAfterWrite : uint8_t { OperationAfterWrite::Stop = uint8_t(Operation::Stop), OperationAfterWrite::Restart = uint8_t(Operation::Restart), OperationAfterWrite::Write = uint8_t(Operation::Write) }
 Further operations after write operation. More...
 
enum  OperationAfterRead : uint8_t { OperationAfterRead::Stop = uint8_t(Operation::Stop), OperationAfterRead::Restart = uint8_t(Operation::Restart) }
 Further operations after read operation. More...
 
- Static Public Member Functions inherited from modm::I2c
template<class Scl >
static void resetDevices (uint32_t baudrate=100'000)
 
- Static Public Attributes inherited from modm::I2c
static constexpr uint8_t Write = 0x00
 Add the Write bit to the slave address.
 
static constexpr uint8_t Read = 0x01
 Add the Read bit to the slave address.
 

Detailed Description

Abstract class for transactions.

For true asynchronous operation, the communication driver should inherit from this class, allowing multi-stage driver design and performance gain by premature data evaluation. This transaction object will stay attached to the I2cMaster during whole operation.

See also
I2cMaster
Author
Georgi Grinshpun
Niklas Hauser

Constructor & Destructor Documentation

modm::I2cTransaction::I2cTransaction ( uint8_t  address)
inline
Parameters
addressthe slave address not yet shifted left (address < 128).

Member Function Documentation

virtual bool modm::I2cTransaction::attaching ( )
inlinevirtual

This method is called when the I2cMaster is not currently in use by another transaction and can be attached.

Returns
true if the I2cMaster should attach this transaction, false if it should not attach it.
bool modm::I2cTransaction::configurePing ( )

Initializes the adapter to only send the address without payload.

Return Values
<code>true</code>adapter configured successfully,
<code>false</code>adapter busy
bool modm::I2cTransaction::configureRead ( uint8_t *  buffer,
std::size_t  size 
)

Initializes the adapter with the required information for a read operation.

Parameters
[out]bufferbuffer to be read from the slave
sizenumber of bytes to be read, set to 0 to read nothing
Return Values
<code>true</code>adapter configured successfully,
<code>false</code>adapter busy
bool modm::I2cTransaction::configureWrite ( uint8_t *  buffer,
std::size_t  size 
)

Initializes the adapter with the required information for a write operation.

Parameters
[in]bufferbuffer to be written to the slave
sizenumber of bytes to be written, set to 0 to write nothing
Return Values
<code>true</code>adapter configured successfully,
<code>false</code>adapter busy
bool modm::I2cTransaction::configureWriteRead ( const uint8_t *  writeBuffer,
std::size_t  writeSize,
uint8_t *  readBuffer,
std::size_t  readSize 
)

Initializes the adapter with the required information for a write/read operation.

Parameters
[in]writeBufferbuffer to be written to the slave
writeSizenumber of bytes to be written, set to 0 to write nothing
[out]readBufferbuffer to write the read bytes from the slave
readSizenumber of bytes to be read, set to 0 to read nothing
Return Values
<code>true</code>adapter configured successfully,
<code>false</code>adapter busy
virtual void modm::I2cTransaction::detaching ( DetachCause  cause)
inlinevirtual

This is called when all transmissions finished and transaction object is about to be detached. The I2cMaster will not be free until this method returns.

Parameters
causespecifies whether the detachment was expected (NormalStop), or a error occurred (ErrorCondition), which can, but does not need to be reacted upon.
TransactionState modm::I2cTransaction::getState ( ) const
inline
Returns
Busy while an I2C operation is ongoing. Reinitialization is not permitted during this phase.
bool modm::I2cTransaction::isBusy ( ) const
inline
Returns
true while adapter is busy
virtual Reading modm::I2cTransaction::reading ( )
pure virtual

This method is called before the I2cMaster begins a read operation.

Returns
the Reading struct containing the read buffer and size and next operation

Implemented in modm::I2cReadTransaction, modm::I2cWriteTransaction, and modm::I2cWriteReadTransaction.

void modm::I2cTransaction::setAddress ( uint8_t  address)
inline
Parameters
addressthe slave address not yet shifted left (address < 128).
virtual Starting modm::I2cTransaction::starting ( )
pure virtual

This method is called when the I2cMaster is ready to (re-)start an operation.

Returns
the Starting struct containing slave address and the next operation

Implemented in modm::I2cReadTransaction, modm::I2cWriteTransaction, and modm::I2cWriteReadTransaction.

virtual Writing modm::I2cTransaction::writing ( )
pure virtual

This method is called before the I2cMaster begins a write operation.

Returns
the Writing struct containing the write buffer and size and next operation

Implemented in modm::I2cReadTransaction, modm::I2cWriteTransaction, and modm::I2cWriteReadTransaction.


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