diff --git a/lib/avrm/i2c.c b/lib/avrm/i2c.c index 400cde9..b4ac770 100644 --- a/lib/avrm/i2c.c +++ b/lib/avrm/i2c.c @@ -52,13 +52,21 @@ void i2c_write(byte data){ return; } -int i2c_read_register(byte addr, byte rgstr, byte *buf, size_t len) +byte i2c_read_register_byte(byte addr, byte rgstr) +{ + byte ret; + i2c_read_register_bytes(addr, rgstr, &ret, 1); + return ret; +} + +int i2c_read_register_bytes(byte addr, byte rgstr, byte *buf, size_t len) { i2c_start(addr, I2C_WRITE); i2c_write(rgstr); i2c_start(addr, I2C_READ); for (int i = 0; i < len; i++) buf[i] = i2c_read_ack(); + i2c_stop(); // TODO: Errors? return 0; diff --git a/lib/avrm/i2c.h b/lib/avrm/i2c.h index fbabb8b..6e310d5 100644 --- a/lib/avrm/i2c.h +++ b/lib/avrm/i2c.h @@ -24,8 +24,11 @@ byte i2c_start(byte address, byte config); // i2c_write void i2c_write(byte data); -// i2c_read_address -int i2c_read_register(byte address, byte register, byte *buffer, size_t length); +// i2c_read_register_byte +byte i2c_read_register_byte(byte addr, byte rgstr); + +// i2c_read_register_bytes +int i2c_read_register_bytes(byte address, byte register, byte *buffer, size_t length); // i2c_read_ack byte i2c_read_ack(void);