Skip to content

Commit

Permalink
i2cget: add support for reading without passing command
Browse files Browse the repository at this point in the history
i2cget can be used without passing command byte
i2cget 3 0x50 0x5F <-- should shift out register 0x5F
i2cget 3 0x50 <-- should shift out register 0x60
  • Loading branch information
jmakip authored and landley committed Mar 18, 2023
1 parent e8f2f55 commit ba5b7c2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion toys/other/i2ctools.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,10 @@ void i2cget_main(void)
confirm("Read register 0x%02x from chip 0x%02x on bus %d?", addr, chip, bus);

fd = i2c_open(bus, FLAG(f) ? I2C_SLAVE_FORCE : I2C_SLAVE, chip);
if (i2c_read_byte(fd, addr, &byte)==-1) perror_exit("i2c_read_byte");
if (toys.optc == 3) {
if (i2c_read_byte(fd, addr, &byte)==-1) perror_exit("i2c_read_byte");
} else if (read(fd, &byte, 1) != 1) perror_exit("i2c_read");

printf("0x%02x\n", byte);
close(fd);
}
Expand Down

0 comments on commit ba5b7c2

Please sign in to comment.