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 Typedefs

using ConfigurationHandler = void (*)()
 The signature of the configuration function.
 

Public Types

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  OperationAfterRead : uint8_t { OperationAfterRead::Stop = uint8_t(Operation::Stop), OperationAfterRead::Restart = uint8_t(Operation::Restart) }
 Further operations after read operation. 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...
 

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)
 

Static Public Member Functions

template<class Scl >
static void resetDevices (uint32_t baudrate=100'000)
 

Static Public Attributes

static constexpr uint8_t Read = 0x01
 Add the Read bit to the slave address.
 
static constexpr uint8_t Write = 0x00
 Add the Write bit to the slave address.
 

Protected Attributes

uint8_t address
 
volatile TransactionState state
 

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

Member Enumeration Documentation

enum modm::I2c::DetachCause : uint8_t
inheritedstrong

This tells the I2cTransaction why it was detached

See also
I2cTransaction
Enum ValuesDocumentation
NormalStop 

All operations finished normally.

ErrorCondition 

A bus error occurred and the bus was reset.

FailedToAttach 

The I2cTransaction failed to attach to the I2cMaster.

enum modm::I2c::Operation : uint8_t
inheritedstrong

All possible I2C Operations.

I2C Operations that the I2cTransaction can give the master on callback

See also
I2cTransaction
Enum ValuesDocumentation
Stop 

Generate a Stop Condition.

Restart 

Generate a Restart.

Write 

Write data to the slave.

Read 

Read data from the slave.

enum modm::I2c::OperationAfterRead : uint8_t
inheritedstrong

Further operations after read operation.

Enum ValuesDocumentation
Stop 

Generate a Stop Condition.

Restart 

Generate a Restart.

enum modm::I2c::OperationAfterStart : uint8_t
inheritedstrong

Further operations after start operation.

Enum ValuesDocumentation
Stop 

Generate a Stop Condition.

Write 

Write data to the slave.

Read 

Read data from the slave.

enum modm::I2c::OperationAfterWrite : uint8_t
inheritedstrong

Further operations after write operation.

Enum ValuesDocumentation
Stop 

Generate a Stop Condition.

Restart 

Generate a Restart.

Write 

Write data to the slave.

enum modm::I2c::TransactionState : uint8_t
inheritedstrong

State of a I2c Transaction.

Enum ValuesDocumentation
Idle 

No error occurred, detached normally.

Busy 

The transaction object is busy with data transfer.

Error 

An error occurred, check the masters getErrorCode()

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.

template<class Scl >
static void modm::I2c::resetDevices ( uint32_t  baudrate = 100'000)
inheritedinlinestatic

Reset all slave devices connected to an I2C bus.

During normal operation, I2C slave device may pull the SDA line low. However, if the master is reset during a transaction, the I2C clock may stop while the slave is outputting a low data bit and the slave will continue to hold this bit (forever, and ever and ever). The I2C master is then unable to generate a I2C start condition, since SDA is still held low by the slave device, resulting in a deadlock.

"You can always get it back to standby mode by allowing the SDA line to float high and give it 9 clocks. This assures that the device will not receive the acknowledge bit at the end the current byte and will abort the command and go to standby."

See also
Application Note AN572 by Microchip
Warning
Must be called before connecting SDA and SCL to I2cMaster!
Template Parameters
SclThe clock pin of the bus to be reset.
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: