256 #include <wire_guts.h>
258 static const uint32_t I2C_RX_BUFFER_SIZE = 256;
259 uint8_t InRxBuf[I2C_RX_BUFFER_SIZE];
263 static const uint32_t I2C_TX_BUFFER_SIZE = 256;
264 uint8_t OutTxBuf[I2C_TX_BUFFER_SIZE];
268 uint32_t m_ClockBaud;
269 uint32_t m_TimeOut_usec;
271 uint8_t m_slave_addr;
272 uint8_t m_target_addr;
274 uint32_t m_NoHang_TimeOut;
276 bool flagset(uint32_t f) {
return ((m_flags & f) != 0); }
277 void setflag(uint32_t f) { m_flags |= f; }
278 void clrflag(uint32_t f) { m_flags &= (~f); }
345 void setClock(uint32_t clockbaud) { m_ClockBaud = clockbaud; }
454 size_t write(
const uint8_t *pdata,
int len);
489 size_t write(
const char *pStr,
int len = -1)
491 if (len == -1) len = strlen(pStr);
492 return write((uint8_t *)pStr, len);
532 int requestFrom(uint8_t address,
size_t quantity,
bool stop =
true);
557 size_t read(uint8_t *pbuf,
size_t maxlen);
741 int writeRegN(uint8_t dAddr, uint32_t reg,
const uint8_t *buf, uint32_t blen);
758 int readRegN(uint8_t dAddr, uint32_t reg, uint8_t *buf, uint32_t blen);
773 inline int writeReg8(uint8_t dAddr, uint32_t reg, uint8_t data) {
return writeRegN(dAddr, reg, &data, 1); }
788 inline int readReg8(uint8_t dAddr, uint32_t reg, uint8_t &data) {
return readRegN(dAddr, reg, &data, 1); }
883 int writeRegN(uint32_t reg,
const uint8_t *buf, uint32_t blen) {
return theWire.
writeRegN(the_addr, reg, buf, blen); }
894 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:15
Arduino Wire-compatible I2C controller/target interface.
Definition Wire.h:255
void setClock(uint32_t clockbaud)
Set the I2C clock speed.
Definition Wire.h:345
size_t write(const char *pStr, int len=-1)
Queue a string for transmission.
Definition Wire.h:489
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:788
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)
Construct a TwoWire using a specific hardware I2C module.
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.
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:773
uint8_t read()
Read the next byte from the receive buffer.
Definition Wire.h:564
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 reset()
Reset the I2C bus and recover from a hung 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:476
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.
size_t write(char v)
Queue a single char for transmission.
Definition Wire.h:465
Convenience wrapper binding a TwoWire instance and device address.
Definition Wire.h:839
int readReg8(uint32_t reg, uint8_t &data)
Read an 8-bit value from a target device register.
Definition Wire.h:914
void reset()
Reset the I2C system and unhang the bus.
Definition Wire.h:862
TwoWireObject(TwoWire &w, uint8_t addr)
Construct a TwoWireObject with a specific TwoWire instance.
Definition Wire.h:850
TwoWireObject(uint8_t addr)
Construct a TwoWireObject using the global Wire instance.
Definition Wire.h:857
bool ping()
Check to see if the bound device address exists on this bus.
Definition Wire.h:868
int writeReg8(uint32_t reg, uint8_t data)
Write an 8-bit value to a target device register.
Definition Wire.h:904
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:894
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:883
class TwoWire Wire
Pre-declared global TwoWire instance using platform default pins.
Definition I2C/Wire/PAC193X/src/main.cpp:15
void slave_rq_handler()
Callback type for target (slave) request events.
Definition Wire.h:80
void slave_rx_handler(int num_rx)
Callback type for target (slave) receive events.
Definition Wire.h:72
const int wire_success
Transaction completed successfully.
Definition Wire.h:86
const int wire_timeout
Transaction timed out (see setWireTimeout())
Definition Wire.h:91
const int wire_NACK_on_address
Target device did not acknowledge its address.
Definition Wire.h:88
const int wire_data_too_big
Data exceeds the 256-byte transmit buffer.
Definition Wire.h:87
const int wire_NACK_on_data
Target device did not acknowledge a data byte.
Definition Wire.h:89
const int wire_other_error
Unspecified bus error.
Definition Wire.h:90