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

A thin wrapper around an I2C TwoWire class and its Wire object. More...

#include <TwoWireInterface.h>

Public Member Functions

 TwoWireInterface (T_WIRE &wire)
 Constructor. More...
 
void begin ()
 Initial the interface. More...
 
void end ()
 End the interface. More...
 
void beginTransmission (uint8_t addr)
 Start transmission at specified I2C addr.
 
void write (uint8_t data)
 Write data into the write buffer.
 
void endTransmission ()
 End building of the buffer, and actually transmit the data.
 
uint8_t requestFrom (uint8_t addr, uint8_t quantity, bool stop=true)
 Read bytes from the slave and store in buffer owned by T_WIRE.
 
uint8_t read ()
 Read byte from buffer.
 
void endRequest ()
 End requestFrom(). More...
 
 TwoWireInterface (const TwoWireInterface &)=default
 
TwoWireInterfaceoperator= (const TwoWireInterface &)=default
 

Detailed Description

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

A thin wrapper around an I2C TwoWire class and its Wire object.

This is a template class to avoid including the <Wire.h> header file, which increases flash memory on AVR by about 1000 byte even if the Wire object is never used.

This wrapper can also be used with alternative implementations of I2C (software or hardware) so long as they implement some basic API of the TwoWire class: specifically the beginTransmission(), write() and endTransmission() methods. SinceTwoWireInterface` is a template, the alternative implementation classes do not need to inherit from the TwoWire class.

Definition at line 45 of file TwoWireInterface.h.

Constructor & Destructor Documentation

◆ TwoWireInterface()

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

Constructor.

Parameters
wireinstance of T_WIRE. If the pre-installed Wire.h is used, then T_WIRE is TwoWire and wire is the precreated Wire object

Definition at line 53 of file TwoWireInterface.h.

Member Function Documentation

◆ begin()

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

Initial the interface.

Currently does nothing.

Definition at line 56 of file TwoWireInterface.h.

◆ end()

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

End the interface.

Currently does nothing.

Definition at line 59 of file TwoWireInterface.h.

◆ endRequest()

template<typename T_WIRE >
void ace_wire::TwoWireInterface< T_WIRE >::endRequest ( )
inline

End requestFrom().

Clients should always call this. This implementation does nothing, but other implementations will perform additional actions.

Definition at line 90 of file TwoWireInterface.h.


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