33#define TWIHS_SR_IOS (TWIHS_SR_SCL | TWIHS_SR_SDA)
41 uint8_t regAddrLen : 3;
44 void dump(uint32_t line);
99 uint32_t
requestFrom(uint8_t addr, uint32_t len,
bool stop =
true);
156 uint32_t
write(uint8_t * buf, uint32_t len);
186 void flush(
bool bIssueStop =
false);
240 uint8_t iadrAddressSize;
242 volatile I2CTxn_t *pTxn;
246 void isr_rx(uint32_t sr);
247 void isr_tx(uint32_t sr);
249 inline uint32_t getStatus()
250 { uint32_t sr = twi.TWIHS_SR; sticky_sr |= sr;
return sr; }
251 inline uint32_t getStickyStatus()
252 { uint32_t sr = twi.TWIHS_SR; sticky_sr |= sr;
return sticky_sr; }
253 inline void clrStickyStatus() { sticky_sr = 0; }
255 inline bool busBusy()
256 {
return ((getStatus() & TWIHS_SR_IOS) != TWIHS_SR_IOS); }
258 void start(uint8_t deviceAddr,
bool rnw, uint8_t regAddrlen = 0,
bool bIssueStop =
false);
259 void restart(uint8_t deviceAddr,
bool rnw, uint8_t regAddrlen = 0,
bool bIssueStop =
false);
264 Result_t read8Restart(uint8_t &dat, uint8_t addr,
bool Rnw);
277 : twi(rhs.twi), modNum(rhs.modNum), txnStatus(rhs.txnStatus)
374 static Result_t writeReg8(
int module, uint8_t devAddr, uint32_t reg, uint8_t dat);
375 static Result_t readReg8(
int module, uint8_t devAddr, uint32_t reg, uint8_t &dat);
376 static Result_t writeRegN(
int module, uint8_t devAddr, uint32_t reg,
const uint8_t *buf, uint32_t blen);
377 static Result_t readRegN(
int module, uint8_t devAddr, uint32_t reg, uint8_t *buf, uint32_t blen);
379 void ShowStat(TxnStat s,
const char * lab=
"");
382 void dump(uint32_t line);
383 friend void TWIHS0_Handler();
384 friend void TWIHS1_Handler();
385 friend void TWIHS2_Handler();
400 return i2c[module].
writeReg8(devAddr, reg, dat);
407 return i2c[module].
readReg8(devAddr, reg, dat);
414 return i2c[module].
writeRegN(devAddr, reg, buf, blen);
420 return i2c[module].
readRegN(devAddr, reg, buf, blen);
448 uint8_t numRegAddrBytes;
466 inline I2CDevice(
I2C & pInterface, uint8_t deviceAddress, uint8_t numAddressBytes = 1)
468 pI2CInterface = &pInterface;
469 devAddress = deviceAddress;
470 numRegAddrBytes = numAddressBytes;
494 inline void setup(uint32_t busSpeed);
514 return pI2CInterface->
writeReg8(devAddress, reg, data);
528 return pI2CInterface->
readReg8(devAddress, reg, data);
547 return pI2CInterface->
writeRegN(devAddress, reg, buf, blen);
562 return pI2CInterface->
readRegN(devAddress, reg, buf, blen);
I2C Device Class (recommended)
Definition i2c.h:443
I2CDevice(I2C &pInterface, uint8_t deviceAddress, uint8_t numAddressBytes=1)
Initialize the I2C module.
Definition i2c.h:466
void resetBus()
Reset the I2C bus.
uint8_t getI2CAddress()
Get device's I2C address.
Definition i2c.h:485
void setup(uint32_t busSpeed)
Setup the I2C peripheral module.
I2C::Result_t writeRegN(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.
Definition i2c.h:544
I2C::Result_t readReg8(uint32_t reg, uint8_t &data)
Read an 8-bit value form an I2C slave device register.
Definition i2c.h:525
I2C::Result_t writeReg8(uint32_t reg, uint8_t data)
Write an 8-bit value to an I2C slave device register.
Definition i2c.h:511
I2C::Result_t readRegN(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.
Definition i2c.h:559
I2C Peripheral Class.
Definition i2c.h:213
void setup(uint32_t busSpeed)
Setup the I2C peripheral interface.
Result_t
Return result types.
Definition i2c.h:219
@ I2C_RES_NACK
Not acknowledged.
Definition i2c.h:221
@ I2C_RES_BUSY
Bus is busy.
Definition i2c.h:223
@ I2C_RES_ARB_LST
Arbitration listening.
Definition i2c.h:222
@ I2C_RES_ARG
Bad argument.
Definition i2c.h:224
@ I2C_RES_ACK
Acknowledged.
Definition i2c.h:220
Result_t readRegN(uint8_t devAddr, 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.
void setNumAddressBytes(uint8_t numAddressBytes=1)
Specify the register address size for a read or write transaction. A number of bytes,...
Definition i2c.h:321
Result_t readReg8(uint8_t devAddr, uint32_t reg, uint8_t &data)
Read an 8-bit value form an I2C slave device register.
void resetBus()
Reset the I2C bus.
Result_t writeRegN(uint8_t devAddr, 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.
Result_t writeReg8(uint8_t devAddr, uint32_t reg, uint8_t data)
Write an 8-bit value to a I2C slave device register.
I2C(int module)
Constructor for the I2C peripheral module.
Result_t DoTransaction(I2CTxn_t *pTransaction, bool bRepeatedStart=false)
Start an I2C transaction.
Wire interface class.
Definition Wire.h:43
Wire Interface Class for I2C.
Definition i2c.h:66
uint8_t read()
Reads a byte of data that was transmitted from a slave I2C device after a call to requestFrom().
uint32_t write(char *str)
Queues bytes of data to be transmitted to the slave device. This function can be called after a call ...
void begin()
Initialize the WireIntf driver object as a master with a bus speed of 100 kHz. This normally only nee...
uint32_t write(uint8_t *buf, uint32_t len)
Queues bytes of data to be transmitted to the slave device. This function can be called after a call ...
void flush(bool bIssueStop=false)
Force the data that were queued to be transmitted using the write() functions to be transmitted on th...
void beginTransmission(uint8_t addr)
Begin a transmission to a I2C slave device at the provided address. Bytes can be queued for transmiss...
void endTransmission(bool stop=true)
Transmits the bytes of data queued by using the write() functions, and ends a transmission to a slave...
uint32_t requestFrom(uint8_t addr, uint32_t len, bool stop=true)
Request a number of bytes from a slave device. The bytes can then be retrieved from the slave device ...
uint32_t write(uint8_t dat)
Queues bytes of data to be transmitted to the slave device. This function can be called after a call ...
uint32_t available()
Get the number of bytes available to be read from the slave device with read(). This function can be ...