30typedef void(slave_rx_handler)(
int num_rx);
32typedef void(slave_rq_handler)();
34const int wire_success = 0;
35const int wire_data_too_big = 1;
36const int wire_NACK_on_address = 2;
37const int wire_NACK_on_data = 3;
38const int wire_other_error = 4;
39const int wire_timeout = 5;
44 #include <wire_guts.h>
46 static const uint32_t I2C_RX_BUFFER_SIZE = 256;
47 uint8_t InRxBuf[I2C_RX_BUFFER_SIZE];
51 static const uint32_t I2C_TX_BUFFER_SIZE = 256;
52 uint8_t OutTxBuf[I2C_TX_BUFFER_SIZE];
57 uint32_t m_TimeOut_usec;
60 uint8_t m_target_addr;
62 uint32_t m_NoHang_TimeOut;
64 bool flagset(uint32_t f) {
return ((m_flags & f) != 0); }
65 void setflag(uint32_t f) { m_flags |= f; }
66 void clrflag(uint32_t f) { m_flags &= (~f); }
89 TwoWire(
int sclpin_num,
int sdapin_num);
97 void setClock(uint32_t clockbaud) { m_ClockBaud = clockbaud; }
135 size_t write(
const uint8_t *pdata,
int len);
157 size_t write(
const char *pStr,
int len = -1)
159 if (len == -1) len = strlen(pStr);
160 return write((uint8_t *)pStr, len);
170 int requestFrom(uint8_t address,
size_t quantity,
bool stop =
true);
185 size_t read(uint8_t *pbuf,
size_t maxlen);
266 int writeRegN(uint8_t dAddr, uint32_t reg,
const uint8_t *buf, uint32_t blen);
278 int readRegN(uint8_t dAddr, uint32_t reg, uint8_t *buf, uint32_t blen);
289 inline int writeReg8(uint8_t dAddr, uint32_t reg, uint8_t data) {
return writeRegN(dAddr, reg, &data, 1); }
300 inline int readReg8(uint8_t dAddr, uint32_t reg, uint8_t &data) {
return readRegN(dAddr, reg, &data, 1); }
313 TwoWireObject(
TwoWire &w, uint8_t addr) : theWire{w}, the_addr{addr} {};
314 TwoWireObject(uint8_t addr) : theWire{Wire}, the_addr{addr} {};
319 void reset() { theWire.reset(); }
325 bool ping() {
return theWire.ping(the_addr); }
340 int writeRegN(uint32_t reg,
const uint8_t *buf, uint32_t blen) {
return theWire.writeRegN(the_addr, reg, buf, blen); }
351 int readRegN(uint32_t reg, uint8_t *buf, uint32_t blen) {
return theWire.readRegN(the_addr, reg, buf, blen); }
361 inline int writeReg8(uint32_t reg, uint8_t data) {
return writeRegN(reg, &data, 1); }
371 inline int readReg8(uint32_t reg, uint8_t &data) {
return readRegN(reg, &data, 1); }
GPIO Pin Class.
Definition coldfire/cpu/MCF5441X/include/cpu_pins.h:15
Wire interface class.
Definition Wire.h:43
void setClock(uint32_t clockbaud)
Set baud rate.
Definition Wire.h:97
size_t write(const char *pStr, int len=-1)
Send a string to the target device.
Definition Wire.h:157
void end()
Turn system off.
void beginTransmission(uint8_t address)
Set up a start for writing.
int readReg8(uint8_t dAddr, uint32_t reg, uint8_t &data)
Read an 8-bit value from an I2C target device register.
Definition Wire.h:300
int requestFrom(uint8_t address, size_t quantity, bool stop=true)
Request bytes from the target device.
void begin(uint8_t slave_addr=0)
Initalize the system.
TwoWire(int mod)
Wire Constructor with specified module.
void onRequest(slave_rq_handler *handler)
Register a Request callback (Does not work on the BBI2C software interface)
int writeRegN(uint8_t dAddr, uint32_t reg, const uint8_t *buf, uint32_t blen)
Write a number of 8-bit values to an I2C slave to the specified register address.
void onReceive(slave_rx_handler *handler)
Register a Receive callback (Does not work on the BBI2C software interface)
int readRegN(uint8_t dAddr, uint32_t reg, uint8_t *buf, uint32_t blen)
Read a number of 8-bit values from an I2C slave at the specified register address.
int writeReg8(uint8_t dAddr, uint32_t reg, uint8_t data)
Write an 8-bit value to a I2C target device register.
Definition Wire.h:289
uint8_t read()
Read the next byte from the buffer.
Definition Wire.h:191
size_t available()
Check if any bytes are available to read.
TwoWire(PinIO scl, PinIO sda)
Constructor.
size_t write(const uint8_t *pdata, int len)
Send data to the target device.
void setWireTimeout(int timeout_usec=0, bool reset_on_timeout=false)
Set the completion timeout.
void clearTimeout()
Clear the completion timeout.
int endTransmission(bool bStop=true)
Do a stop with restart.
void reset()
Reset the I2C system and unhang the bus.
size_t read(uint8_t *pbuf, size_t maxlen)
Read available data up to maxlen bytes (Not a standard Wire function)
size_t write(uint8_t v)
Send an int to the target device.
Definition Wire.h:149
bool getWireTimeoutFlag()
Get whether there is a completion timeout set.
bool ping(uint8_t addr)
Check to see if addr exists on this bus.
TwoWire(void)
Wire Constructor with platform default I2C module.
size_t write(char v)
Send a char to the target device.
Definition Wire.h:142