18#include "api/HardwareI2C.h"
19#include "api/RingBuffer.h"
20#include "hardware/i2c.h"
39 : i2c_(i2c), sda_(sda), scl_(scl) {}
52 void begin(uint8_t address)
override;
99 size_t requestFrom(uint8_t address,
size_t length,
bool sendStop)
override;
119 size_t write(uint8_t data)
override;
127 size_t write(
const uint8_t* data,
size_t length)
override;
128 using arduino::Print::write;
163 void onReceive(
void (*callback)(
int))
override { on_receive_ = callback; }
169 void onRequest(
void (*callback)())
override { on_request_ = callback; }
174 void handlePeripheralEvent(
int event);
181 uint32_t clock_hz_ = 100000;
182 bool started_ =
false;
183 uint8_t tx_address_ = 0;
185 size_t tx_length_ = 0;
186 arduino::RingBufferN<kBufferSize> rx_buffer_;
189 bool peripheral_mode_ =
false;
190 void (*on_receive_)(int) =
nullptr;
191 void (*on_request_)() =
nullptr;
193 bool request_started_ =
false;
Entry header for sketches: Arduino API + board pin map + Phyduino extras.
PhyduinoWire Wire
I2C on the header SDA / SCL pins.
I2C controller or peripheral on one RP2040 I2C peripheral; sketches use Wire.
Definition Wire.h:27
void onRequest(void(*callback)()) override
Sets the function called when a controller reads from this board.
Definition Wire.h:169
size_t requestFrom(uint8_t address, size_t length) override
Reads bytes from a device and ends with a stop.
Definition Wire.h:107
void beginTransmission(uint8_t address) override
Starts a write to a device; queue the bytes with write().
static constexpr size_t kBufferSize
Largest number of bytes in one transmission or request.
Definition Wire.h:30
uint8_t endTransmission() override
Sends the queued bytes and ends with a stop.
Definition Wire.h:90
int available() override
Number of received bytes waiting to be read.
void begin() override
Starts as a controller, at 100 kHz unless setClock() was called.
size_t write(uint8_t data) override
Queues one byte: for endTransmission(), or as the reply in onRequest().
void onReceive(void(*callback)(int)) override
Sets the function called after a controller has written to this board.
Definition Wire.h:163
size_t requestFrom(uint8_t address, size_t length, bool sendStop) override
Reads bytes from a device into the receive buffer; take them with read().
void end() override
Stops I2C and frees the pins.
int peek() override
Next received byte, left in the buffer.
void begin(uint8_t address) override
Starts as a peripheral that answers at address.
PhyduinoWire(i2c_inst_t *i2c, pin_size_t sda, pin_size_t scl)
Binds Wire to an I2C peripheral and its pins; nothing is set up until begin().
Definition Wire.h:38
void setClock(uint32_t hz) override
Sets the bus clock; applies at once if already started.
uint8_t endTransmission(bool sendStop) override
Sends the queued bytes.
size_t write(const uint8_t *data, size_t length) override
Queues several bytes: for endTransmission(), or as the reply in onRequest().
void flush() override
Does nothing; kept for Arduino compatibility.
Definition Wire.h:151
int read() override
Takes the next received byte.
uint8_t pin_size_t
Type for Arduino pin numbers (uint8_t).
Definition Common.h:112