AceWire  0.4.0
Unified interface for selecting different I2C implementations on Arduino platforms
Public Member Functions | List of all members
ace_wire::TodbotWireInterface< T_WIRE > Class Template Reference

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
 
TodbotWireInterfaceoperator= (const TodbotWireInterface &)=default
 

Detailed Description

template<typename T_WIRE>
class ace_wire::TodbotWireInterface< T_WIRE >

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.

Template Parameters
T_WIREunderlying class which will be SoftI2CMaster

Definition at line 44 of file TodbotWireInterface.h.

Constructor & Destructor Documentation

◆ TodbotWireInterface()

template<typename T_WIRE >
ace_wire::TodbotWireInterface< T_WIRE >::TodbotWireInterface ( T_WIRE &  wire)
inlineexplicit

Constructor.

Parameters
wireinstance of SoftI2CMaster

Definition at line 50 of file TodbotWireInterface.h.

Member Function Documentation

◆ begin()

template<typename T_WIRE >
void ace_wire::TodbotWireInterface< T_WIRE >::begin ( ) const
inline

Initial the interface.

Currently does nothing.

Definition at line 53 of file TodbotWireInterface.h.

◆ beginTransmission()

template<typename T_WIRE >
uint8_t ace_wire::TodbotWireInterface< T_WIRE >::beginTransmission ( uint8_t  addr) const
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.

Returns
returns 0 upon ACK from the device, 1 upon NACK from the device

Definition at line 71 of file TodbotWireInterface.h.

◆ end()

template<typename T_WIRE >
void ace_wire::TodbotWireInterface< T_WIRE >::end ( ) const
inline

End the interface.

Currently does nothing.

Definition at line 56 of file TodbotWireInterface.h.

◆ endTransmission()

template<typename T_WIRE >
uint8_t ace_wire::TodbotWireInterface< T_WIRE >::endTransmission ( bool  sendStop = true) const
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.

◆ read()

template<typename T_WIRE >
uint8_t ace_wire::TodbotWireInterface< T_WIRE >::read ( ) const
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 method
  • readLast() to read the last byte (which sends a NACK from master to device), not exposed by this wrapper class

It 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 132 of file TodbotWireInterface.h.

◆ requestFrom()

template<typename T_WIRE >
uint8_t ace_wire::TodbotWireInterface< T_WIRE >::requestFrom ( uint8_t  addr,
uint8_t  quantity,
bool  sendStop = true 
) const
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.

Parameters
addrI2C address
quantitynumber of bytes to read
sendStopwhether to send a STOP condition after reading. This parameter is ignored by the SoftI2CMaster implementation which never sends a STOP condition
Returns
the value returned by the underlying SoftI2CMaster::requestFrom() method, which is 0 for success if the device responded with an ACK, and 1 if the device sent a NACK

Definition at line 113 of file TodbotWireInterface.h.

◆ write()

template<typename T_WIRE >
uint8_t ace_wire::TodbotWireInterface< T_WIRE >::write ( uint8_t  data) const
inline

Write data immediately into the I2C bus with the Write bit set, since SoftI2CMaster library does not use a TX buffer.

Returns
the number of bytes written into buffer. It will be 1 if the device responded with an ACK, it will be 0 if the device responds with a NACK.

Definition at line 83 of file TodbotWireInterface.h.


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