modm API documentation
|
#include <modm/architecture/interface/i2c_transaction.hpp>
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 |
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.
|
inheritedstrong |
This tells the I2cTransaction
why it was detached
Enum Values | Documentation |
---|---|
NormalStop | All operations finished normally. |
ErrorCondition | A bus error occurred and the bus was reset. |
FailedToAttach | The I2cTransaction failed to attach to the I2cMaster. |
|
inheritedstrong |
All possible I2C Operations.
I2C Operations that the I2cTransaction
can give the master on callback
Enum Values | Documentation |
---|---|
Stop | Generate a Stop Condition. |
Restart | Generate a Restart. |
Write | Write data to the slave. |
Read | Read data from the slave. |
|
inheritedstrong |
|
inheritedstrong |
|
inheritedstrong |
Further operations after write operation.
Enum Values | Documentation |
---|---|
Stop | Generate a Stop Condition. |
Restart | Generate a Restart. |
Write | Write data to the slave. |
|
inheritedstrong |
State of a I2c Transaction.
Enum Values | Documentation |
---|---|
Idle | No error occurred, detached normally. |
Busy | The transaction object is busy with data transfer. |
Error | An error occurred, check the masters |
|
inline |
address | the slave address not yet shifted left (address < 128). |
|
inlinevirtual |
bool modm::I2cTransaction::configurePing | ( | ) |
Initializes the adapter to only send the address without payload.
<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.
[out] | buffer | buffer to be read from the slave |
size | number of bytes to be read, set to 0 to read nothing |
<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.
[in] | buffer | buffer to be written to the slave |
size | number of bytes to be written, set to 0 to write nothing |
<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.
[in] | writeBuffer | buffer to be written to the slave |
writeSize | number of bytes to be written, set to 0 to write nothing | |
[out] | readBuffer | buffer to write the read bytes from the slave |
readSize | number of bytes to be read, set to 0 to read nothing |
<code>true</code> | adapter configured successfully, |
<code>false</code> | adapter busy |
|
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.
cause | specifies whether the detachment was expected (NormalStop ), or a error occurred (ErrorCondition ), which can, but does not need to be reacted upon. |
|
inline |
Busy
while an I2C operation is ongoing. Reinitialization is not permitted during this phase.
|
inline |
true
while adapter is busy
|
pure virtual |
This method is called before the I2cMaster begins a read operation.
Reading
struct containing the read buffer and size and next operation Implemented in modm::I2cReadTransaction, modm::I2cWriteTransaction, and modm::I2cWriteReadTransaction.
|
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."
Scl | The clock pin of the bus to be reset. |
|
inline |
address | the slave address not yet shifted left (address < 128). |
|
pure virtual |
This method is called when the I2cMaster is ready to (re-)start an operation.
Starting
struct containing slave address and the next operation Implemented in modm::I2cReadTransaction, modm::I2cWriteTransaction, and modm::I2cWriteReadTransaction.
|
pure virtual |
This method is called before the I2cMaster begins a write operation.
Writing
struct containing the write buffer and size and next operation Implemented in modm::I2cReadTransaction, modm::I2cWriteTransaction, and modm::I2cWriteReadTransaction.