23 #define TWIHS_SR_IOS (TWIHS_SR_SCL | TWIHS_SR_SDA) 31 uint8_t regAddrLen : 3;
34 void dump(uint32_t line);
84 uint32_t
requestFrom(uint8_t addr, uint32_t len,
bool stop =
true);
117 uint32_t
write(uint8_t dat);
129 uint32_t
write(
char * str);
141 uint32_t
write(uint8_t * buf, uint32_t len);
171 void flush(
bool bIssueStop =
false);
231 volatile I2CTxn_t *pTxn;
235 void isr_rx(uint32_t sr);
236 void isr_tx(uint32_t sr);
237 inline uint32_t getStatus()
238 { uint32_t sr = twi.TWIHS_SR; sticky_sr |= sr;
return sr; }
239 inline uint32_t getStickyStatus()
240 { uint32_t sr = twi.TWIHS_SR; sticky_sr |= sr;
return sticky_sr; }
241 inline void clrStickyStatus() { sticky_sr = 0; }
242 inline bool busBusy()
243 {
return ((getStatus() & TWIHS_SR_IOS) != TWIHS_SR_IOS); }
245 void start(uint8_t deviceAddr,
bool rnw, uint8_t regAddrlen = 0,
bool bIssueStop =
false);
246 void restart(uint8_t deviceAddr,
bool rnw, uint8_t regAddrlen = 0,
bool bIssueStop =
false);
262 : twi(rhs.twi), modNum(rhs.modNum), txnStatus(rhs.txnStatus)
271 void setup(uint32_t busSpeed);
340 Result_t readRegN(uint8_t devAddr, uint8_t reg, uint8_t *buf, uint32_t blen);
343 static Result_t writeReg8(
int module, uint8_t devAddr, uint8_t reg, uint8_t dat);
344 static Result_t readReg8(
int module, uint8_t devAddr, uint8_t reg, uint8_t &dat);
345 static Result_t writeRegN(
int module, uint8_t devAddr, uint8_t reg, uint8_t *buf, uint32_t blen);
346 static Result_t readRegN(
int module, uint8_t devAddr, uint8_t reg, uint8_t *buf, uint32_t blen);
349 void dump(uint32_t line);
350 friend void TWIHS0_Handler();
351 friend void TWIHS1_Handler();
352 friend void TWIHS2_Handler();
366 return i2c[module].
writeReg8(devAddr, reg, dat);
372 return i2c[module].
readReg8(devAddr, reg, dat);
379 return i2c[module].
writeRegN(devAddr, reg, buf, blen);
385 return i2c[module].
readRegN(devAddr, reg, buf, blen);
NetBurner Real-Time Operating System API.
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 ...
void begin()
Initialize the WireIntf driver object as a master with a bus speed of 100 kHz. This normally only nee...
Wire Interface Class for I2C.
Definition: i2c.h:51
Bad argument.
Definition: i2c.h:214
Semaphores are used to control access to shared resource critical section, or to communicate between ...
Definition: nbrtos.h:318
void setup(uint32_t busSpeed)
Initialize the I2C module.
void beginTransmission(uint8_t addr)
Begin a transmission to a I2C slave device at the provided address. Bytes can be queued for transmiss...
I2C Peripheral Class.
Definition: i2c.h:203
uint32_t available()
Get the number of bytes available to be read from the slave device with read(). This function can be ...
I2C(int module)
Constructor for the I2C peripheral module.
Result_t readReg8(uint8_t devAddr, uint8_t reg, uint8_t &dat)
Read an 8-bit value form an I2C slave device register.
Acknowledged.
Definition: i2c.h:210
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 ...
Not acknowledged.
Definition: i2c.h:211
void resetBus()
Reset the I2C bus.
Result_t writeReg8(uint8_t devAddr, uint8_t reg, uint8_t dat)
Write an 8-bit value to a I2C slave device register.
Result_t writeRegN(uint8_t devAddr, uint8_t reg, uint8_t *buf, uint32_t blen)
Write a number of 8-bit values to an I2C slave to the specified register address. ...
Result_t DoTransaction(I2CTxn_t *pTransaction, bool bRepeatedStart=false)
Start an I2C transaction.
Arbitration listening.
Definition: i2c.h:212
void flush(bool bIssueStop=false)
Force the data that were queued to be transmitted using the write() functions to be transmitted on th...
Result_t
Return result types.
Definition: i2c.h:209
Bus is busy.
Definition: i2c.h:213
Result_t readRegN(uint8_t devAddr, uint8_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 endTransmission(bool stop=true)
Transmits the bytes of data queued by using the write() functions, and ends a transmission to a slave...
uint8_t read()
Reads a byte of data that was transmitted from a slave I2C device after a call to requestFrom()...