Skip to content

Commit

Permalink
read_bytes, and read_byte.
Browse files Browse the repository at this point in the history
  • Loading branch information
nixpulvis committed Oct 11, 2015
1 parent ebad4e1 commit 5ccaf23
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 9 additions & 1 deletion lib/avrm/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions lib/avrm/i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5ccaf23

Please sign in to comment.