#include <Wire.h>

Inheritance diagram for TwoWire:
Collaboration diagram for TwoWire:

Public Types

enum  Status {
  I2C_OK = 0 , I2C_SCL_HELD_LOW = 1 , I2C_SCL_HELD_LOW_AFTER_READ = 2 , I2C_SDA_HELD_LOW = 3 ,
  I2C_SDA_HELD_LOW_AFTER_INIT = 4
}
 
enum  Error { I2C_ERR_SUCCESS = 0 , I2C_ERR_ADDR_NACK = 2 , I2C_ERR_DATA_NACK = 3 , I2C_ERR_LINE_BUSY = 4 }
 
using UserRequest = void(*)()
 
using UserReceive = void(*)(int len)
 

Public Member Functions

 TwoWire ()
 
void begin (uint8_t sda, uint8_t scl)
 Initialise using selected pins. More...
 
void pins (uint8_t sda, uint8_t scl)
 Switch to selected pins. More...
 
void begin ()
 Initialise using current pin values. More...
 
void end ()
 End TwoWire operation. More...
 
void setClock (uint32_t frequency)
 Set approximate clock frequency. More...
 
void setClockStretchLimit (uint32_t limit)
 Set approximate time in microseconds that clocks may be stretched by. More...
 
void beginTransmission (uint8_t address)
 Signal start of transaction. More...
 
Error endTransmission (bool sendStop=true)
 Perform actual transaction with device. More...
 
uint8_t requestFrom (uint8_t address, uint8_t size, bool sendStop=true)
 Perform a complete 'read' transaction. More...
 
Status status ()
 Query bus status. More...
 
size_t write (uint8_t) override
 Writes a single character to output stream. More...
 
size_t write (const uint8_t *, size_t) override
 Writes characters from a buffer to output stream. More...
 
int available () override
 
int read () override
 
int peek () override
 
void flush () override
 
void onReceive (UserReceive callback)
 
void onRequest (UserRequest callback)
 
virtual size_t write (uint8_t c)=0
 Writes a single character to output stream. More...
 
size_t write (const char *str)
 Writes a c-string to output stream. More...
 
virtual size_t write (const uint8_t *buffer, size_t size)
 Writes characters from a buffer to output stream. More...
 
size_t write (const char *buffer, size_t size)
 Writes characters from a buffer to output stream. More...
 
- Public Member Functions inherited from Stream
 Stream ()
 
void setTimeout (unsigned long timeout)
 Set maximum milliseconds to wait for stream data, default is 1 second. More...
 
bool find (const char *target)
 Read data from the stream until the target string is found. More...
 
bool find (const char *target, size_t length)
 Read data from the stream until the target string of given length is found. More...
 
bool findUntil (const char *target, const char *terminator)
 As find() but search ends if the terminator string is found. More...
 
bool findUntil (const char *target, size_t targetLen, const char *terminate, size_t termLen)
 As findUntil(const char*, const char*) but search ends if the terminate string is found. More...
 
long parseInt ()
 Returns the first valid (long) integer value from the current position. More...
 
float parseFloat ()
 float version of parseInt More...
 
virtual size_t readBytes (char *buffer, size_t length)
 Read chars from stream into buffer. More...
 
size_t readBytes (uint8_t *buffer, size_t length)
 
size_t readBytesUntil (char terminator, char *buffer, size_t length)
 As readBytes() with terminator character. More...
 
virtual String readString (size_t maxLen)
 Like readBytes but place content into a String More...
 
String readStringUntil (char terminator)
 
virtual int indexOf (char c)
 
- Public Member Functions inherited from Print
virtual ~Print ()
 
int getWriteError ()
 Gets last error. More...
 
void clearWriteError ()
 Clears the last write error. More...
 
size_t write (const char *str)
 Writes a c-string to output stream. More...
 
size_t write (const char *buffer, size_t size)
 Writes characters from a buffer to output stream. More...
 
size_t print (char c)
 Prints a single character to output stream. More...
 
size_t print (const char str[])
 Prints a c-string to output stream. More...
 
size_t print (double num, int digits=2)
 Print a floating-point number to output stream. More...
 
template<typename T >
std::enable_if< has_printTo< T >::value, size_t >::type print (const T &obj)
 Prints a Printable object to output stream. More...
 
size_t print (const String &s)
 Prints a String to output stream. More...
 
template<typename E >
std::enable_if< std::is_enum< E >::value &&!std::is_convertible< E, int >::value, size_t >::type print (E value)
 enums can be printed as strings provided they have a toString(E) implementation. More...
 
size_t println ()
 Prints a newline to output stream. More...
 
template<typename... Args>
size_t println (const Args &... args)
 Print value plus newline to output stream. More...
 
size_t printf (const char *fmt,...)
 Prints a formatted c-string to output stream. More...
 
size_t print (unsigned long num, uint8_t base=DEC)
 
template<typename... Args>
size_t print (unsigned long num, Args... args)
 
template<typename... Args>
size_t print (const unsigned long long &num, Args... args)
 
size_t print (long num, uint8_t base=DEC)
 
template<typename... Args>
size_t print (long num, Args... args)
 
template<typename... Args>
size_t print (const long long &num, Args... args)
 
template<typename... Args>
size_t print (unsigned int num, Args... args)
 
template<typename... Args>
size_t print (unsigned char num, Args... args)
 
template<typename... Args>
size_t print (int num, Args... args)
 

Static Public Attributes

static constexpr size_t BUFFER_LENGTH {32}
 

Additional Inherited Members

- Protected Member Functions inherited from Stream
int timedRead ()
 
int timedPeek ()
 
int peekNextDigit ()
 returns the next numeric digit in the stream or -1 if timeout More...
 
long parseInt (char skipChar)
 Like regular parseInt() but the given skipChar is ignored. More...
 
float parseFloat (char skipChar)
 Like parseInt(skipChar) for float. More...
 
- Protected Member Functions inherited from Print
void setWriteError (int err=1)
 
- Protected Attributes inherited from Stream
uint16_t receiveTimeout = 1000
 number of milliseconds to wait for the next char before aborting timed read More...
 

Member Typedef Documentation

◆ UserReceive

using TwoWire::UserReceive = void (*)(int len)

◆ UserRequest

using TwoWire::UserRequest = void (*)()

Member Enumeration Documentation

◆ Error

Enumerator
I2C_ERR_SUCCESS 
I2C_ERR_ADDR_NACK 
I2C_ERR_DATA_NACK 
I2C_ERR_LINE_BUSY 

◆ Status

Enumerator
I2C_OK 
I2C_SCL_HELD_LOW 
I2C_SCL_HELD_LOW_AFTER_READ 
I2C_SDA_HELD_LOW 
I2C_SDA_HELD_LOW_AFTER_INIT 

Constructor & Destructor Documentation

◆ TwoWire()

TwoWire::TwoWire ( )
inline

Member Function Documentation

◆ available()

int TwoWire::available ( )
overridevirtual

Implements Stream.

◆ begin() [1/2]

void TwoWire::begin ( )

Initialise using current pin values.

Default pins depend on selected architecture.

◆ begin() [2/2]

void TwoWire::begin ( uint8_t  sda,
uint8_t  scl 
)

Initialise using selected pins.

◆ beginTransmission()

void TwoWire::beginTransmission ( uint8_t  address)

Signal start of transaction.

Parameters
addressDevice address

◆ end()

void TwoWire::end ( )

End TwoWire operation.

◆ endTransmission()

Error TwoWire::endTransmission ( bool  sendStop = true)

Perform actual transaction with device.

Parameters
sendStopBy default, send a stop condition

◆ flush()

void TwoWire::flush ( )
overridevirtual

Implements Stream.

◆ onReceive()

void TwoWire::onReceive ( UserReceive  callback)
inline

◆ onRequest()

void TwoWire::onRequest ( UserRequest  callback)
inline

◆ peek()

int TwoWire::peek ( )
overridevirtual

Implements Stream.

◆ pins()

void TwoWire::pins ( uint8_t  sda,
uint8_t  scl 
)

Switch to selected pins.

If begin() has already been called then pins will change immediately, otherwise will be used by next call to begin().

◆ read()

int TwoWire::read ( )
overridevirtual

Implements Stream.

◆ requestFrom()

uint8_t TwoWire::requestFrom ( uint8_t  address,
uint8_t  size,
bool  sendStop = true 
)

Perform a complete 'read' transaction.

Parameters
addressDevice to talk to
sizeNumber of bytes to receive
sendStopBy default, send a stop condition

◆ setClock()

void TwoWire::setClock ( uint32_t  frequency)

Set approximate clock frequency.

◆ setClockStretchLimit()

void TwoWire::setClockStretchLimit ( uint32_t  limit)

Set approximate time in microseconds that clocks may be stretched by.

◆ status()

Status TwoWire::status ( )

Query bus status.

Return values
StatusIndicates whether bus is available

◆ write() [1/6]

size_t Print::write
inline

Writes characters from a buffer to output stream.

Parameters
bufferPointer to character buffer
sizeQuantity of characters to write
Return values
size_tQuantity of characters written to stream

◆ write() [2/6]

size_t Print::write
inline

Writes a c-string to output stream.

Parameters
strPointer to c-string
Return values
size_tQuantity of characters written to stream

◆ write() [3/6]

size_t TwoWire::write ( const uint8_t *  buffer,
size_t  size 
)
overridevirtual

Writes characters from a buffer to output stream.

Parameters
bufferPointer to character buffer
sizeQuantity of characters to write
Return values
size_tQuantity of characters written to stream

Reimplemented from Print.

◆ write() [4/6]

virtual size_t Print::write

Writes characters from a buffer to output stream.

Parameters
bufferPointer to character buffer
sizeQuantity of characters to write
Return values
size_tQuantity of characters written to stream

◆ write() [5/6]

virtual size_t Print::write

Writes a single character to output stream.

Parameters
cCharacter to write to output stream
Return values
size_tQuantity of characters written to output stream

◆ write() [6/6]

size_t TwoWire::write ( uint8_t  c)
overridevirtual

Writes a single character to output stream.

Parameters
cCharacter to write to output stream
Return values
size_tQuantity of characters written to output stream

Implements Print.

Member Data Documentation

◆ BUFFER_LENGTH

constexpr size_t TwoWire::BUFFER_LENGTH {32}
staticconstexpr

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