i2c: fix write API to use const char*
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
@@ -77,7 +77,7 @@ maa_result_t maa_i2c_frequency(maa_i2c_context dev, int hz);
|
|||||||
*
|
*
|
||||||
* @return maa_result_t the maa result.
|
* @return maa_result_t the maa result.
|
||||||
*/
|
*/
|
||||||
maa_result_t maa_i2c_read(maa_i2c_context dev, const char *data, int length);
|
maa_result_t maa_i2c_read(maa_i2c_context dev, char *data, int length);
|
||||||
|
|
||||||
/** Read a single byte from the i2c context
|
/** Read a single byte from the i2c context
|
||||||
*
|
*
|
||||||
@@ -95,7 +95,7 @@ int maa_i2c_read_byte(maa_i2c_context dev);
|
|||||||
*
|
*
|
||||||
* @return maa_result_t the maa result.
|
* @return maa_result_t the maa result.
|
||||||
*/
|
*/
|
||||||
maa_result_t maa_i2c_write(maa_i2c_context dev, char *data, int length);
|
maa_result_t maa_i2c_write(maa_i2c_context dev, const char *data, int length);
|
||||||
|
|
||||||
/** Write a single byte to an i2c context
|
/** Write a single byte to an i2c context
|
||||||
*
|
*
|
||||||
@@ -104,7 +104,7 @@ maa_result_t maa_i2c_write(maa_i2c_context dev, char *data, int length);
|
|||||||
*
|
*
|
||||||
* @return maa_result_t the maa result.
|
* @return maa_result_t the maa result.
|
||||||
*/
|
*/
|
||||||
maa_result_t maa_i2c_write_byte(maa_i2c_context dev, int data);
|
maa_result_t maa_i2c_write_byte(maa_i2c_context dev, const int data);
|
||||||
|
|
||||||
/** Sets the i2c context address.
|
/** Sets the i2c context address.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -54,13 +54,13 @@ class I2c {
|
|||||||
int read_byte() {
|
int read_byte() {
|
||||||
return maa_i2c_read_byte(m_i2c);
|
return maa_i2c_read_byte(m_i2c);
|
||||||
}
|
}
|
||||||
maa_result_t read(const char *data, int length) {
|
maa_result_t read(char *data, int length) {
|
||||||
return maa_i2c_read(m_i2c, data, length);
|
return maa_i2c_read(m_i2c, data, length);
|
||||||
}
|
}
|
||||||
maa_result_t write(char *data, int length) {
|
maa_result_t write(const char *data, int length) {
|
||||||
return maa_i2c_write(m_i2c, data, length);
|
return maa_i2c_write(m_i2c, data, length);
|
||||||
}
|
}
|
||||||
maa_result_t write_byte(int data) {
|
maa_result_t write_byte(const int data) {
|
||||||
return maa_i2c_write_byte(m_i2c, data);
|
return maa_i2c_write_byte(m_i2c, data);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ maa_i2c_frequency(maa_i2c_context dev, int hz)
|
|||||||
}
|
}
|
||||||
|
|
||||||
maa_result_t
|
maa_result_t
|
||||||
maa_i2c_read(maa_i2c_context dev, const char *data, int length)
|
maa_i2c_read(maa_i2c_context dev, char *data, int length)
|
||||||
{
|
{
|
||||||
// this is the read(3) syscall not maa_i2c_read()
|
// this is the read(3) syscall not maa_i2c_read()
|
||||||
if (read(dev->fh, data, length) == length) {
|
if (read(dev->fh, data, length) == length) {
|
||||||
@@ -99,7 +99,7 @@ maa_i2c_read_byte(maa_i2c_context dev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
maa_result_t
|
maa_result_t
|
||||||
maa_i2c_write(maa_i2c_context dev, char* data, int length)
|
maa_i2c_write(maa_i2c_context dev, const char* data, int length)
|
||||||
{
|
{
|
||||||
if (i2c_smbus_write_i2c_block_data(dev->fh, data[0], length-1, (uint8_t*) data+1) < 0) {
|
if (i2c_smbus_write_i2c_block_data(dev->fh, data[0], length-1, (uint8_t*) data+1) < 0) {
|
||||||
fprintf(stderr, "Failed to write to i2c\n");
|
fprintf(stderr, "Failed to write to i2c\n");
|
||||||
@@ -109,7 +109,7 @@ maa_i2c_write(maa_i2c_context dev, char* data, int length)
|
|||||||
}
|
}
|
||||||
|
|
||||||
maa_result_t
|
maa_result_t
|
||||||
maa_i2c_write_byte(maa_i2c_context dev, int data)
|
maa_i2c_write_byte(maa_i2c_context dev, const int data)
|
||||||
{
|
{
|
||||||
if (i2c_smbus_write_byte(dev->fh, data) < 0) {
|
if (i2c_smbus_write_byte(dev->fh, data) < 0) {
|
||||||
fprintf(stderr, "Failed to write to i2c\n");
|
fprintf(stderr, "Failed to write to i2c\n");
|
||||||
|
|||||||
Reference in New Issue
Block a user