71#include "utility/twi.h"
81#define BUFFER_LENGTH 32
86#if !defined(WIRE_MAX_TX_BUFF_LENGTH)
87 #define WIRE_MAX_TX_BUFF_LENGTH 1024U
118 uint16_t rxBufferAllocated;
119 uint16_t rxBufferIndex;
120 uint16_t rxBufferLength;
124 uint16_t txBufferAllocated;
127 uint8_t transmitting;
132 std::function<void(
int)> user_onReceive;
133 std::function<void(
void)> user_onRequest;
135 static void onRequestService(i2c_t *);
136 static void onReceiveService(i2c_t *);
138 void allocateRxBuffer(
size_t length);
139 size_t allocateTxBuffer(
size_t length);
141 void resetRxBuffer(
void);
142 void resetTxBuffer(
void);
143 void recoverBus(
void);
164 _i2c.scl = digitalPinToPinName(scl);
172 _i2c.sda = digitalPinToPinName(sda);
198 void begin(
bool generalCall =
false);
218 void begin(uint8_t,
bool generalCall =
false,
bool NoStretchMode =
false);
226 void begin(
int,
bool generalCall =
false,
bool NoStretchMode =
false);
317 uint8_t
requestFrom(uint8_t, uint8_t, uint32_t, uint8_t, uint8_t);
354 virtual size_t write(
const uint8_t *,
size_t);
395 inline size_t write(
unsigned long n)
397 return write((uint8_t)n);
406 return write((uint8_t)n);
415 return write((uint8_t)n);
424 return write((uint8_t)n);
436 return &(_i2c.handle);
An I2C bus: the Arduino Wire API on one of the chip's I2C peripherals (the global Wire on this board)...
Definition Wire.h:105
size_t write(unsigned long n)
Writes the low byte of n (see write(uint8_t)).
Definition Wire.h:395
void end()
Leaves the bus: turns the I2C interrupts off, resets I2C1 and frees the buffers.
void begin(uint8_t, bool generalCall=false, bool NoStretchMode=false)
Joins the bus as a slave at a 7-bit address (1 means the master, as begin() does).
void onRequest(cb_function_request_t callback)
Sets what a slave does when the master asks it for data.
uint8_t endTransmission(uint8_t)
Sends the bytes collected since beginTransmission(), with or without a STOP.
virtual int available(void)
How many received bytes are left to read (after requestFrom(), or in an onReceive() callback).
void setSCL(uint32_t scl)
Sets the SCL pin; call before begin().
Definition Wire.h:162
uint8_t requestFrom(uint8_t, size_t, bool)
Reads bytes from a slave (Arduino's form with sendStop).
void setClock(uint32_t)
Sets the bus clock; call after begin().
void begin(bool generalCall=false)
Joins the bus as the master, at 100 kHz.
uint8_t requestFrom(int, int, int)
Reads bytes from a slave (the int form with sendStop).
void begin(uint32_t, uint32_t)
Joins the bus as the master on the given pins, at 100 kHz.
std::function< void(int)> cb_function_receive_t
What onReceive() takes: called with the number of bytes received.
Definition Wire.h:110
uint8_t requestFrom(uint8_t, uint8_t, uint8_t)
Reads bytes from a slave (Arduino's form with sendStop).
TwoWire()
An I2C bus on the variant's SDA and SCL (PC18 and PC19 on this board).
void beginTransmission(int)
Starts collecting bytes for a slave (the int form).
size_t write(long n)
Writes the low byte of n (see write(uint8_t)).
Definition Wire.h:404
void setSDA(PinName sda)
Sets the SDA pin; call before begin().
Definition Wire.h:186
virtual size_t write(uint8_t)
Adds a byte to the transmission, or, in a slave's onRequest() callback, sends it to the master.
void begin(int, bool generalCall=false, bool NoStretchMode=false)
Joins the bus as a slave at a 7-bit address (the int form).
virtual int read(void)
Takes the next received byte.
TwoWire(uint32_t sda, uint32_t scl)
An I2C bus on the given pins.
void beginTransmission(uint8_t)
Starts collecting bytes for a slave; nothing goes on the bus until endTransmission().
size_t write(int n)
Writes the low byte of n (see write(uint8_t)).
Definition Wire.h:422
void setSDA(uint32_t sda)
Sets the SDA pin; call before begin().
Definition Wire.h:170
virtual size_t write(const uint8_t *, size_t)
Adds bytes to the transmission, or, in a slave's onRequest() callback, sends them to the master.
I2C_HandleTypeDef * getHandle(void)
The WCH peripheral library's view of this bus: its instance and init structure, for mixing in WCH's o...
Definition Wire.h:434
std::function< void(void)> cb_function_request_t
What onRequest() takes: called when the master asks for data.
Definition Wire.h:114
void onReceive(cb_function_receive_t callback)
Sets what a slave does when the master has sent it a message.
virtual int peek(void)
The next received byte, left in the buffer.
uint8_t requestFrom(uint8_t, uint8_t, uint32_t, uint8_t, uint8_t)
Writes a register address to a slave, then reads bytes from it with a repeated start.
uint8_t requestFrom(int, int)
Reads bytes from a slave (the int form).
void setSCL(PinName scl)
Sets the SCL pin; call before begin().
Definition Wire.h:178
uint8_t requestFrom(uint8_t, uint8_t)
Reads bytes from a slave into the receive buffer, for available() and read().
virtual void flush(void)
Throws away the received bytes and the transmission's bytes.
uint8_t endTransmission(void)
Sends the bytes collected since beginTransmission(), then a STOP.
size_t write(unsigned int n)
Writes the low byte of n (see write(uint8_t)).
Definition Wire.h:413
TwoWire Wire
The I2C bus: I2C1 on PC18 (SDA, header H1.2) and PC19 (SCL, H1.1).