#include <Wire.h>
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
enum TwoWire::Error |
◆ Status
enum TwoWire::Status |
Constructor & Destructor Documentation
◆ TwoWire()
|
inline |
Member Function Documentation
◆ 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
-
address Device address
◆ end()
void TwoWire::end | ( | ) |
End TwoWire operation.
◆ endTransmission()
Error TwoWire::endTransmission | ( | bool | sendStop = true | ) |
Perform actual transaction with device.
- Parameters
-
sendStop By default, send a stop condition
◆ flush()
|
overridevirtual |
Implements Stream.
◆ onReceive()
|
inline |
◆ onRequest()
|
inline |
◆ peek()
|
overridevirtual |
Implements Stream.
◆ pins()
void TwoWire::pins | ( | uint8_t | sda, |
uint8_t | scl | ||
) |
◆ read()
|
overridevirtual |
Implements Stream.
◆ requestFrom()
uint8_t TwoWire::requestFrom | ( | uint8_t | address, |
uint8_t | size, | ||
bool | sendStop = true |
||
) |
Perform a complete 'read' transaction.
- Parameters
-
address Device to talk to size Number of bytes to receive sendStop By 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
-
Status Indicates whether bus is available
◆ write() [1/6]
|
inline |
Writes characters from a buffer to output stream.
- Parameters
-
buffer Pointer to character buffer size Quantity of characters to write
- Return values
-
size_t Quantity of characters written to stream
◆ write() [2/6]
|
inline |
Writes a c-string to output stream.
- Parameters
-
str Pointer to c-string
- Return values
-
size_t Quantity of characters written to stream
◆ write() [3/6]
|
overridevirtual |
Writes characters from a buffer to output stream.
- Parameters
-
buffer Pointer to character buffer size Quantity of characters to write
- Return values
-
size_t Quantity 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
-
buffer Pointer to character buffer size Quantity of characters to write
- Return values
-
size_t Quantity of characters written to stream
◆ write() [5/6]
virtual size_t Print::write |
Writes a single character to output stream.
- Parameters
-
c Character to write to output stream
- Return values
-
size_t Quantity of characters written to output stream
◆ write() [6/6]
|
overridevirtual |
Writes a single character to output stream.
- Parameters
-
c Character to write to output stream
- Return values
-
size_t Quantity of characters written to output stream
Implements Print.
Member Data Documentation
◆ BUFFER_LENGTH
|
staticconstexpr |
The documentation for this class was generated from the following file: