i2c: add doxygen documentation and make return types use maa_result_t
Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
@@ -40,26 +40,28 @@ maa_i2c_init()
|
||||
return dev;
|
||||
}
|
||||
|
||||
void
|
||||
maa_result_t
|
||||
maa_i2c_frequency(maa_i2c_context* dev, int hz)
|
||||
{
|
||||
dev->hz = hz;
|
||||
|
||||
return MAA_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
maa_result_t
|
||||
maa_i2c_receive(maa_i2c_context* dev)
|
||||
{
|
||||
return -1;
|
||||
return MAA_ERROR_FEATURE_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
int
|
||||
maa_result_t
|
||||
maa_i2c_read(maa_i2c_context* dev, char *data, int length)
|
||||
{
|
||||
// this is the read(3) syscall not maa_i2c_read()
|
||||
if (read(dev->fh, data, length) == length) {
|
||||
return length;
|
||||
}
|
||||
return -1;
|
||||
return MAA_ERROR_NO_DATA_AVAILABLE;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -73,37 +75,40 @@ maa_i2c_read_byte(maa_i2c_context* dev)
|
||||
return byte;
|
||||
}
|
||||
|
||||
int
|
||||
maa_result_t
|
||||
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) {
|
||||
fprintf(stderr, "Failed to write to I2CSlave slave\n");
|
||||
return -1;
|
||||
fprintf(stderr, "Failed to write to i2c\n");
|
||||
return MAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
return 0;
|
||||
return MAA_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
maa_result_t
|
||||
maa_i2c_write_byte(maa_i2c_context* dev, int data)
|
||||
{
|
||||
if (i2c_smbus_write_byte(dev->fh, data) < 0) {
|
||||
fprintf(stderr, "Failed to write to I2CSlave slave\n");
|
||||
return -1;
|
||||
fprintf(stderr, "Failed to write to i2c\n");
|
||||
return MAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
return 0;
|
||||
return MAA_SUCCESS;
|
||||
}
|
||||
|
||||
void
|
||||
maa_result_t
|
||||
maa_i2c_address(maa_i2c_context* dev, int addr)
|
||||
{
|
||||
dev->addr = addr;
|
||||
if (ioctl(dev->fh, I2C_SLAVE_FORCE, addr) < 0) {
|
||||
fprintf(stderr, "Failed to set slave address %d\n", addr);
|
||||
return MAA_ERROR_INVALID_HANDLE;
|
||||
}
|
||||
return MAA_SUCCESS;
|
||||
}
|
||||
|
||||
void
|
||||
maa_result_t
|
||||
maa_i2c_stop(maa_i2c_context* dev)
|
||||
{
|
||||
free(dev);
|
||||
return MAA_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user