MSS
/
testI2C
Simple I2C test program. open/close/read/write supported.
Diff: dumb_i2c.cpp
- Revision:
- 2:218e22a54982
- Parent:
- 1:e105ceaee6ac
--- a/dumb_i2c.cpp Tue Apr 05 02:11:20 2016 +0000 +++ b/dumb_i2c.cpp Tue Apr 05 06:53:27 2016 +0000 @@ -25,29 +25,37 @@ return(freq) ; } -void DUMB_I2C::read(int addr, uint8_t *data, int len) +int DUMB_I2C::read(int addr, uint8_t *data, int len) { - readRegs(addr, data, len) ; + int result ; + result = readRegs(addr, data, len) ; + return( result ) ; } -void DUMB_I2C::write(int addr, uint8_t *data, int len) +int DUMB_I2C::write(int addr, uint8_t *data, int len) { uint8_t *buf ; + int ack ; buf = new uint8_t[len+1] ; buf[0] = addr ; for (int i = 0 ; i < len ; i++ ) { buf[i+1] = data[i] ; } - writeRegs(buf, len+1) ; + ack = writeRegs(buf, len+1) ; delete buf ; + return( ack ) ; } -void DUMB_I2C::readRegs(int addr, uint8_t * data, int len) { +int DUMB_I2C::readRegs(int addr, uint8_t * data, int len) { + int result ; char t[1] = {addr}; m_i2c.write(m_addr, t, 1, true); - m_i2c.read(m_addr, (char *)data, len); + result = m_i2c.read(m_addr, (char *)data, len); + return( result ) ; } -void DUMB_I2C::writeRegs(uint8_t * data, int len) { - m_i2c.write(m_addr, (char *)data, len); +int DUMB_I2C::writeRegs(uint8_t * data, int len) { + int ack ; + ack = m_i2c.write(m_addr, (char *)data, len); + return( ack ) ; } \ No newline at end of file