modm API documentation
modm::I2cWriteReadTransaction Class Reference

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

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

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

 I2cWriteReadTransaction (uint8_t address)
 
bool configurePing ()
 
bool configureWriteRead (const uint8_t *writeBuffer, std::size_t writeSize, uint8_t *readBuffer, std::size_t readSize)
 
bool configureWrite (const uint8_t *buffer, std::size_t size)
 
bool configureRead (uint8_t *buffer, std::size_t size)
 
virtual bool attaching ()
 
bool configureWrite (uint8_t *buffer, std::size_t size)
 
virtual void detaching (DetachCause cause)
 
TransactionState getState () const
 
bool isBusy () const
 
void setAddress (uint8_t address)
 

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 Member Functions

Starting starting () override
 
Writing writing () override
 
Reading reading () override
 

Protected Attributes

std::size_t readSize
 
std::size_t writeSize
 
uint8_t * readBuffer
 
const uint8_t * writeBuffer
 
bool isReading
 
uint8_t address
 
volatile TransactionState state
 

Detailed Description

This class is an implementation of modm::I2cTransaction which, when passed to an i2c driver, performs the sequence: start - address - write - restart - address - read - stop.

After initialization and performing operation this class keeps the references to passed buffers and may be reused again without reinitialization as long the passed buffers remain valid.

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

Member Function Documentation

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

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::I2cWriteReadTransaction::configureRead ( uint8_t *  buffer,
std::size_t  size 
)
inline

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
Returns
true if adapter was not in use, false otherwise
bool modm::I2cWriteReadTransaction::configureWrite ( const uint8_t *  buffer,
std::size_t  size 
)
inline

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
Returns
true if adapter was not in use, false otherwise
bool modm::I2cTransaction::configureWrite ( uint8_t *  buffer,
std::size_t  size 
)
inherited

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
virtual void modm::I2cTransaction::detaching ( DetachCause  cause)
inheritedinlinevirtual

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
inheritedinline
Returns
Busy while an I2C operation is ongoing. Reinitialization is not permitted during this phase.
bool modm::I2cTransaction::isBusy ( ) const
inheritedinline
Returns
true while adapter is busy
Reading modm::I2cWriteReadTransaction::reading ( )
inlineoverrideprotectedvirtual

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

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

Implements modm::I2cTransaction.

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)
inheritedinline
Parameters
addressthe slave address not yet shifted left (address < 128).
Starting modm::I2cWriteReadTransaction::starting ( )
inlineoverrideprotectedvirtual

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

Implements modm::I2cTransaction.

Writing modm::I2cWriteReadTransaction::writing ( )
inlineoverrideprotectedvirtual

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

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

Implements modm::I2cTransaction.


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