Add i2c tool for reading multiple bytes from an SMBus device register

This commit is contained in:
Adam Honse 2020-08-27 19:12:37 -05:00
parent 4e95bc55d8
commit c386a6c571
5 changed files with 163 additions and 39 deletions

View file

@ -121,3 +121,35 @@ std::string i2c_dump(i2c_smbus_interface * bus, unsigned char address)
return text;
} /* i2c_dump() */
/******************************************************************************************\
* *
* i2c_read *
* *
* Prints <size> values read from register address regaddr of a given SMBus device *
* *
* bus - pointer to i2c_smbus_interface to scan *
* address - SMBus device address to scan *
* regaddr - register address to read from *
* size - number of bytes to read *
* *
\******************************************************************************************/
std::string i2c_read(i2c_smbus_interface * bus, unsigned char address, unsigned char regaddr, unsigned char size)
{
int i;
bus->i2c_smbus_write_byte(address, regaddr);
char line[128];
std::string text;
for(i = 0; i < size; i++)
{
sprintf(line, "%02x ", (unsigned char)bus->i2c_smbus_read_byte(address));
text.append(line);
}
return text;
} /* i2c_read() */

View file

@ -9,3 +9,5 @@
std::string i2c_detect(i2c_smbus_interface * bus, int mode);
std::string i2c_dump(i2c_smbus_interface * bus, unsigned char address);
std::string i2c_read(i2c_smbus_interface * bus, unsigned char address, unsigned char regaddr, unsigned char size);