Private
Public Access
2
0

i2c: remove smbus helper library & clean up command use in API

This commit changes the mraa_i2c_read() API call behaviour, a register should
now always be set when using this call. The smbus helper library is no longer
required since the code is now all contained from i2c.c which avoids multiple
function calls

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Brendan Le Foll
2014-11-18 16:09:08 +00:00
parent e9de25d797
commit 19d7dad364
8 changed files with 146 additions and 546 deletions

View File

@@ -116,7 +116,8 @@ uint8_t mraa_i2c_read_byte_data(mraa_i2c_context dev, const uint8_t command);
uint16_t mraa_i2c_read_word_data(mraa_i2c_context dev, const uint8_t command);
/**
* Perform a simple write to an i2c context, always at offset 0x0
* Write length bytes to the bus, the first byte in the array is the
* command/register to write
*
* @param dev The i2c context
* @param data pointer to the byte array to be written

View File

@@ -106,6 +106,7 @@ class I2c {
*
* @param data Buffer to write into
* @param length Size of read
* @param command The i2c command
* @return length of the read or 0 if failed
*/
uint8_t read(char *data, size_t length) {
@@ -116,13 +117,13 @@ class I2c {
* Read length bytes from the bus, and return as a std::string note
* that this is not a null terminated string
*
* @param length Size of read to make
* @param length Size of read in bytes to make
* @return pointer to std::string
*/
std::string read(size_t length) {
char* data = (char*) malloc(sizeof(char) * length);
mraa_i2c_read(m_i2c, (uint8_t*) data, (int) length);
std::string str(data, (int) length);
std::string read(int length, uint8_t command) {
uint8_t* data = (uint8_t*) malloc(sizeof(uint8_t) * length);
mraa_i2c_read(m_i2c, data, command, length);
std::string str((char*)data, length);
free(data);
return str;
}
@@ -144,7 +145,7 @@ class I2c {
* @return char read from register
*/
uint16_t readWordReg(uint8_t reg) {
return mraa_i2c_read_byte_data(m_i2c, reg);
return mraa_i2c_read_word_data(m_i2c, reg);
}
/**
@@ -158,9 +159,10 @@ class I2c {
}
/**
* Write length bytes to the bus
* Write length bytes to the bus, the first byte in the array is the
* command/register to write
*
* @param data Buffer to send on the bus
* @param data Buffer to send on the bus, first byte is i2c command
* @param length Size of buffer to send
* @return Result of operation
*/