Private
Public Access
2
0

i2c: use uint8_t when appropriate and remove char

Object APIs used signed chars for some operations which are not appropriate
when using i2c.

Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
Brendan Le Foll
2014-10-31 15:10:15 +00:00
parent 428c99f940
commit 274d5b2d50
4 changed files with 12 additions and 16 deletions

View File

@@ -132,7 +132,7 @@ mraa_result_t mraa_i2c_write_byte(mraa_i2c_context dev, const uint8_t data);
* general call address. * general call address.
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t mraa_i2c_address(mraa_i2c_context dev, int address); mraa_result_t mraa_i2c_address(mraa_i2c_context dev, uint8_t address);
/** /**
* De-inits an mraa_i2c_context device * De-inits an mraa_i2c_context device

View File

@@ -85,7 +85,7 @@ class I2c {
* @param address Communicate to the i2c slave on this address * @param address Communicate to the i2c slave on this address
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t address(int address) { mraa_result_t address(uint8_t address) {
return mraa_i2c_address(m_i2c, address); return mraa_i2c_address(m_i2c, address);
} }
/** /**
@@ -93,8 +93,8 @@ class I2c {
* *
* @return char read from the bus * @return char read from the bus
*/ */
unsigned char read() { uint8_t read() {
return (unsigned char) mraa_i2c_read_byte(m_i2c); return (uint8_t) mraa_i2c_read_byte(m_i2c);
} }
/** /**
* Read mutliple bytes from the bus * Read mutliple bytes from the bus
@@ -103,7 +103,7 @@ class I2c {
* @param length Size of read * @param length Size of read
* @return length of the read or 0 if failed * @return length of the read or 0 if failed
*/ */
int read(char *data, size_t length) { uint8_t read(char *data, size_t length) {
return mraa_i2c_read(m_i2c, (uint8_t*) data, (int) length); return mraa_i2c_read(m_i2c, (uint8_t*) data, (int) length);
} }
/** /**
@@ -138,8 +138,8 @@ class I2c {
* @param data Value to write to register * @param data Value to write to register
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t writeReg(char reg, char data) { mraa_result_t writeReg(uint8_t reg, uint8_t data) {
const unsigned char buf[2] = {(unsigned char) reg, (unsigned char) data}; const uint8_t buf[2] = {reg, data};
return mraa_i2c_write(m_i2c, buf, 2); return mraa_i2c_write(m_i2c, buf, 2);
} }
@@ -147,21 +147,19 @@ class I2c {
* Read an i2c register * Read an i2c register
* *
* @param reg Register to read from * @param reg Register to read from
* @return char read from the bus
* @return char read from register * @return char read from register
*/ */
int readReg(char reg) { uint8_t readReg(uint8_t reg) {
return mraa_i2c_read_byte_data(m_i2c, reg); return mraa_i2c_read_byte_data(m_i2c, reg);
} }
/** /**
* Write multiple bytes to the bus * Write a byte on the bus
* *
* @param data The byte to send on the bus * @param data The byte to send on the bus
* @return Result of operation * @return Result of operation
*/ */
mraa_result_t write(char data) { mraa_result_t write(uint8_t data) {
return mraa_i2c_write_byte(m_i2c, data); return mraa_i2c_write_byte(m_i2c, data);
} }
private: private:

View File

@@ -129,9 +129,9 @@ mraa_i2c_write_byte(mraa_i2c_context dev, const uint8_t data)
} }
mraa_result_t mraa_result_t
mraa_i2c_address(mraa_i2c_context dev, int addr) mraa_i2c_address(mraa_i2c_context dev, uint8_t addr)
{ {
dev->addr = addr; dev->addr = (int) addr;
if (ioctl(dev->fh, I2C_SLAVE_FORCE, addr) < 0) { if (ioctl(dev->fh, I2C_SLAVE_FORCE, addr) < 0) {
syslog(LOG_ERR, "i2c: Failed to set slave address %d", addr); syslog(LOG_ERR, "i2c: Failed to set slave address %d", addr);
return MRAA_ERROR_INVALID_HANDLE; return MRAA_ERROR_INVALID_HANDLE;

View File

@@ -37,8 +37,6 @@
} }
} }
%typemap(in) uint8_t = char;
%typemap(in) unsigned char* = char*;
%apply (char *STRING, size_t LENGTH) { (char *data, size_t length) }; %apply (char *STRING, size_t LENGTH) { (char *data, size_t length) };
%include "common.hpp" %include "common.hpp"