286 #include <wire_guts.h>
288 static const uint32_t I2C_RX_BUFFER_SIZE = 256;
289 uint8_t InRxBuf[I2C_RX_BUFFER_SIZE];
293 static const uint32_t I2C_TX_BUFFER_SIZE = 256;
294 uint8_t OutTxBuf[I2C_TX_BUFFER_SIZE];
300 uint32_t m_ClockBaud = 100000;
301 uint32_t m_TimeOut_usec = 1000;
302 uint32_t m_nBegins = 0;
303 uint8_t m_slave_addr = 0;
304 uint8_t m_target_addr = 0;
305 uint32_t m_flags = 0;
306 uint32_t m_NoHang_TimeOut = 2;
307 uint8_t m_numAddressBytes = 1;
312 bool m_bound =
false;
314 bool flagset(uint32_t f) {
return ((m_flags & f) != 0); }
315 void setflag(uint32_t f) { m_flags |= f; }
316 void clrflag(uint32_t f) { m_flags &= (~f); }
320 void sendRegAddress(uint32_t reg)
322 for (
int i = (
int)m_numAddressBytes - 1; i >= 0; i--)
324 write((uint8_t)(reg >> (8 * i)));
462 void setClock(uint32_t clockbaud) { m_ClockBaud = clockbaud; }
571 size_t write(
const uint8_t *pdata,
int len);
600 size_t write(
const char *pStr,
int len = -1)
602 if (len == -1) len = strlen(pStr);
603 return write((uint8_t *)pStr, len);
673 int requestFrom(uint8_t address,
size_t quantity,
bool stop =
true);
698 size_t read(uint8_t *pbuf,
size_t maxlen);
968 int writeRegN(uint8_t dAddr, uint32_t reg,
const uint8_t *buf, uint32_t blen);
1035 int readRegN(uint8_t dAddr, uint32_t reg, uint8_t *buf, uint32_t blen);
1050 inline int writeReg8(uint8_t dAddr, uint32_t reg, uint8_t data) {
return writeRegN(dAddr, reg, &data, 1); }
1065 inline int readReg8(uint8_t dAddr, uint32_t reg, uint8_t &data) {
return readRegN(dAddr, reg, &data, 1); }
1151 bool ping() {
return theWire.ping(the_addr); }
1166 int writeRegN(uint32_t reg,
const uint8_t *buf, uint32_t blen) {
return theWire.writeRegN(the_addr, reg, buf, blen); }
1177 int readRegN(uint32_t reg, uint8_t *buf, uint32_t blen) {
return theWire.readRegN(the_addr, reg, buf, blen); }
GPIO Pin Class.
Definition coldfire/cpu/MCF5441X/include/cpu_pins.h:44
Arduino Wire-compatible I2C controller/target interface.
Definition Wire.h:285
void setClock(uint32_t clockbaud)
Set the I2C clock speed.
Definition Wire.h:462
size_t write(const char *pStr, int len=-1)
Queue a string for transmission.
Definition Wire.h:600
void end()
Shut down the I2C interface.
void beginTransmission(uint8_t address)
Begin a write transaction to a target device.
int readReg8(uint8_t dAddr, uint32_t reg, uint8_t &data)
Read a single byte from a device register.
Definition Wire.h:1065
int requestFrom(uint8_t address, size_t quantity, bool stop=true)
Request bytes from a target device.
void begin(uint8_t slave_addr=0)
Initialize the I2C interface.
TwoWire(int mod)
Bind to a specific hardware I2C module, leaving the pins to the caller.
TwoWire(int sclpin_num, int sdapin_num)
Construct a TwoWire using Pins[] array index numbers.
void onRequest(slave_rq_handler *handler)
Register a callback for target (slave) request events.
bool isValid() const
Report whether this object is bound to a hardware I2C module.
Definition Wire.h:449
int writeRegN(uint8_t dAddr, uint32_t reg, const uint8_t *buf, uint32_t blen)
Write a number of bytes to a device register.
void onReceive(slave_rx_handler *handler)
Register a callback for target (slave) receive events.
int readRegN(uint8_t dAddr, uint32_t reg, uint8_t *buf, uint32_t blen)
Read a number of bytes from a device register.
int writeReg8(uint8_t dAddr, uint32_t reg, uint8_t data)
Write a single byte to a device register.
Definition Wire.h:1050
uint8_t read()
Read the next byte from the receive buffer.
Definition Wire.h:705
size_t available()
Check how many bytes are available to read.
TwoWire(PinIO scl, PinIO sda)
Construct a TwoWire using specific SCL/SDA pins.
size_t write(const uint8_t *pdata, int len)
Queue data bytes for transmission.
void setWireTimeout(int timeout_usec=0, bool reset_on_timeout=false)
Set the transaction completion timeout.
void clearTimeout()
Clear the transaction completion timeout.
int endTransmission(bool bStop=true)
End a write transaction and send data on the bus.
void setNumAddressBytes(uint8_t numAddressBytes=1)
Specify the register address size for a read or write transaction.
Definition Wire.h:1011
void reset()
Reset the I2C peripheral and return the object to an idle state.
size_t read(uint8_t *pbuf, size_t maxlen)
Read available data into a buffer (non-standard extension).
size_t write(uint8_t v)
Queue a single byte for transmission.
Definition Wire.h:587
bool getWireTimeoutFlag()
Check whether a timeout has occurred.
bool ping(uint8_t addr)
Check whether a device is present at the given address.
TwoWire(void)
Construct a TwoWire using the platform default I2C module.
int readReg8(uint32_t reg, uint8_t &data)
Read an 8-bit value from a target device register.
Definition Wire.h:1197
void reset()
Reset the I2C system and unhang the bus.
Definition Wire.h:1139
TwoWireObject(TwoWire &w, uint8_t addr)
Construct a TwoWireObject with a specific TwoWire instance.
Definition Wire.h:1127
TwoWireObject(uint8_t addr)
Construct a TwoWireObject using the global Wire instance.
Definition Wire.h:1134
bool ping()
Check to see if the bound device address exists on this bus.
Definition Wire.h:1151
int writeReg8(uint32_t reg, uint8_t data)
Write an 8-bit value to a target device register.
Definition Wire.h:1187
int readRegN(uint32_t reg, uint8_t *buf, uint32_t blen)
Read a number of 8-bit values from the specified register address.
Definition Wire.h:1177
int writeRegN(uint32_t reg, const uint8_t *buf, uint32_t blen)
Write a number of 8-bit values to the specified register address.
Definition Wire.h:1166
class TwoWire Wire
Pre-declared global TwoWire instance using platform default pins.
Definition I2C/Wire/DocExamples/src/main.cpp:24
void slave_rq_handler()
Callback type for target (slave) request events.
Definition Wire.h:249
void slave_rx_handler(int num_rx)
Callback type for target (slave) receive events.
Definition Wire.h:241
const int wire_success
Transaction completed successfully.
Definition Wire.h:255
const int wire_timeout
Transaction timed out (see setWireTimeout()).
Definition Wire.h:260
const int wire_NACK_on_address
Target device did not acknowledge its address.
Definition Wire.h:257
const int wire_data_too_big
Data exceeds the 256-byte transmit buffer.
Definition Wire.h:256
const int wire_NACK_on_data
Target device did not acknowledge a data byte.
Definition Wire.h:258
const int wire_other_error
Unspecified bus error.
Definition Wire.h:259