AceWire
0.4.1
Unified interface for selecting different I2C implementations on Arduino platforms
|
A thin wrapper for the SoftI2CMaster class from the https://github.com/todbot/SoftI2CMaster project so that it is compatible with the AceWire API. More...
#include <TodbotWireInterface.h>
Public Member Functions | |
TodbotWireInterface (T_WIRE &wire) | |
Constructor. More... | |
void | begin () const |
Initial the interface. More... | |
void | end () const |
End the interface. More... | |
uint8_t | beginTransmission (uint8_t addr) const |
Send the I2C address on the bus immediately, since the underlying implementation does not use a TX buffer. More... | |
uint8_t | write (uint8_t data) const |
Write data immediately into the I2C bus with the Write bit set, since SoftI2CMaster library does not use a TX buffer. More... | |
uint8_t | endTransmission (bool sendStop=true) const |
Send the data in the buffer. More... | |
uint8_t | requestFrom (uint8_t addr, uint8_t quantity, bool sendStop=true) const |
Prepare to send quantity bytes to the device at addr. More... | |
uint8_t | read () const |
Read byte from the I2C bus. More... | |
TodbotWireInterface (const TodbotWireInterface &)=default | |
TodbotWireInterface & | operator= (const TodbotWireInterface &)=default |
A thin wrapper for the SoftI2CMaster class from the https://github.com/todbot/SoftI2CMaster project so that it is compatible with the AceWire API.
The SoftI2CMaster library uses no RX or TX buffer.
The SoftI2CMaster
class name conflicts with the same class name in the https://github.com/felias-fogg/SoftI2CMaster project, so the two cannot be activated at the same time.
T_WIRE | underlying class which will be SoftI2CMaster |
Definition at line 44 of file TodbotWireInterface.h.
|
inlineexplicit |
Constructor.
wire | instance of SoftI2CMaster |
Definition at line 50 of file TodbotWireInterface.h.
|
inline |
|
inline |
Send the I2C address on the bus immediately, since the underlying implementation does not use a TX buffer.
The underlying SoftI2CMaster::beginTransmission() method returns a 0 if the device responded with a NACK, and a 1 if ACK. This is opposite of the convention used by the endTransmission() function. The AceWire library defines the return value of beginTransmission() to use the same return value convention as endTransmission(). So we have to flip the return status from the SoftI2CMaster library.
Definition at line 71 of file TodbotWireInterface.h.
|
inline |
|
inline |
Send the data in the buffer.
The sendStop parameter is ignored by the SoftI2CMaster class and the underlying implementation always sends the STOP condition.
Returns the status value of the original beginTransmission().
Definition at line 94 of file TodbotWireInterface.h.
|
inline |
Read byte from the I2C bus.
The SoftI2CMaster library provides 2 different read()
methods:
read()
for all bytes except the last one (which sends an ACK from the master to device), exposed by this methodreadLast()
to read the last byte (which sends a NACK from master to device), not exposed by this wrapper classIt is probably possible for this adapter class to merge the two read() methods, and generate the required STOP condition, so that it becomes consistent with other I2C libraries. But I don't want to spend the effort to do that because I don't use the SoftI2CMaster library.
Definition at line 133 of file TodbotWireInterface.h.
|
inline |
Prepare to send quantity bytes to the device at addr.
SoftI2CMaster does not implement at TX buffer, so the addr is sent immediately on the bus.
addr | I2C address |
quantity | number of bytes to read |
sendStop | whether to send a STOP condition after reading. This parameter is ignored by the SoftI2CMaster implementation which never sends a STOP condition |
Definition at line 113 of file TodbotWireInterface.h.
|
inline |
Write data immediately into the I2C bus with the Write bit set, since SoftI2CMaster library does not use a TX buffer.
Definition at line 83 of file TodbotWireInterface.h.