i2c: Use u16 for data length
The length will never be negative. Signed-off-by: Tim Crawford <tcrawford@system76.com>
This commit is contained in:
committed by
Jeremy Soller
parent
784202383e
commit
2a3830fb57
@ -46,8 +46,8 @@ void i2c_stop(struct I2C * i2c) {
|
||||
TWCR = BIT(TWINT) | BIT(TWEN) | BIT(TWSTO);
|
||||
}
|
||||
|
||||
int16_t i2c_write(struct I2C * i2c, uint8_t * data, int16_t length) {
|
||||
int16_t i;
|
||||
int16_t i2c_write(struct I2C * i2c, uint8_t * data, uint16_t length) {
|
||||
uint16_t i;
|
||||
for (i = 0; i < length; i++) {
|
||||
// load data into data register
|
||||
TWDR = data[i];
|
||||
@ -65,8 +65,8 @@ int16_t i2c_write(struct I2C * i2c, uint8_t * data, int16_t length) {
|
||||
return i;
|
||||
}
|
||||
|
||||
int16_t i2c_read(struct I2C * i2c, uint8_t * data, int16_t length) {
|
||||
int16_t i;
|
||||
int16_t i2c_read(struct I2C * i2c, uint8_t * data, uint16_t length) {
|
||||
uint16_t i;
|
||||
for (i = 0; i < length; i++) {
|
||||
if ((i + 1) < length) {
|
||||
// start TWI module and acknowledge data after reception
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include <common/i2c.h>
|
||||
|
||||
int16_t i2c_recv(struct I2C * i2c, uint8_t addr, uint8_t* data, int16_t length) __reentrant {
|
||||
int16_t i2c_recv(struct I2C * i2c, uint8_t addr, uint8_t* data, uint16_t length) __reentrant {
|
||||
int16_t res = 0;
|
||||
|
||||
res = i2c_start(i2c, addr, true);
|
||||
@ -16,7 +16,7 @@ int16_t i2c_recv(struct I2C * i2c, uint8_t addr, uint8_t* data, int16_t length)
|
||||
return res;
|
||||
}
|
||||
|
||||
int16_t i2c_send(struct I2C * i2c, uint8_t addr, uint8_t* data, int16_t length) __reentrant {
|
||||
int16_t i2c_send(struct I2C * i2c, uint8_t addr, uint8_t* data, uint16_t length) __reentrant {
|
||||
int16_t res = 0;
|
||||
|
||||
res = i2c_start(i2c, addr, false);
|
||||
@ -30,7 +30,7 @@ int16_t i2c_send(struct I2C * i2c, uint8_t addr, uint8_t* data, int16_t length)
|
||||
return res;
|
||||
}
|
||||
|
||||
int16_t i2c_get(struct I2C * i2c, uint8_t addr, uint8_t reg, uint8_t* data, int16_t length) __reentrant {
|
||||
int16_t i2c_get(struct I2C * i2c, uint8_t addr, uint8_t reg, uint8_t* data, uint16_t length) __reentrant {
|
||||
int16_t res = 0;
|
||||
|
||||
res = i2c_start(i2c, addr, false);
|
||||
@ -42,7 +42,7 @@ int16_t i2c_get(struct I2C * i2c, uint8_t addr, uint8_t reg, uint8_t* data, int1
|
||||
return i2c_recv(i2c, addr, data, length);
|
||||
}
|
||||
|
||||
int16_t i2c_set(struct I2C * i2c, uint8_t addr, uint8_t reg, uint8_t* data, int16_t length) __reentrant {
|
||||
int16_t i2c_set(struct I2C * i2c, uint8_t addr, uint8_t reg, uint8_t* data, uint16_t length) __reentrant {
|
||||
int16_t res = 0;
|
||||
|
||||
res = i2c_start(i2c, addr, false);
|
||||
|
@ -24,22 +24,22 @@ void i2c_stop(struct I2C * i2c) __reentrant;
|
||||
|
||||
// Send a byte on i2c bus
|
||||
// Must be defined by arch, board, or ec
|
||||
int16_t i2c_write(struct I2C * i2c, uint8_t * data, int16_t length) __reentrant;
|
||||
int16_t i2c_write(struct I2C * i2c, uint8_t * data, uint16_t length) __reentrant;
|
||||
|
||||
// Read bytes from bus
|
||||
// Must be defined by arch, board, or ec
|
||||
int16_t i2c_read(struct I2C * i2c, uint8_t * data, int16_t length) __reentrant;
|
||||
int16_t i2c_read(struct I2C * i2c, uint8_t * data, uint16_t length) __reentrant;
|
||||
|
||||
// Read multiple bytes from address in one transaction
|
||||
int16_t i2c_recv(struct I2C * i2c, uint8_t addr, uint8_t* data, int16_t length) __reentrant;
|
||||
int16_t i2c_recv(struct I2C * i2c, uint8_t addr, uint8_t* data, uint16_t length) __reentrant;
|
||||
|
||||
// Write multiple bytes to address in one transaction
|
||||
int16_t i2c_send(struct I2C * i2c, uint8_t addr, uint8_t* data, int16_t length) __reentrant;
|
||||
int16_t i2c_send(struct I2C * i2c, uint8_t addr, uint8_t* data, uint16_t length) __reentrant;
|
||||
|
||||
// Read multiple bytes from a register in one transaction
|
||||
int16_t i2c_get(struct I2C * i2c, uint8_t addr, uint8_t reg, uint8_t* data, int16_t length) __reentrant;
|
||||
int16_t i2c_get(struct I2C * i2c, uint8_t addr, uint8_t reg, uint8_t* data, uint16_t length) __reentrant;
|
||||
|
||||
// Write multiple bytes to a register in one transaction
|
||||
int16_t i2c_set(struct I2C * i2c, uint8_t addr, uint8_t reg, uint8_t* data, int16_t length) __reentrant;
|
||||
int16_t i2c_set(struct I2C * i2c, uint8_t addr, uint8_t reg, uint8_t* data, uint16_t length) __reentrant;
|
||||
|
||||
#endif // _COMMON_I2C_H
|
||||
|
@ -94,8 +94,8 @@ void i2c_stop(struct I2C * i2c) {
|
||||
i2c_reset(i2c, false);
|
||||
}
|
||||
|
||||
static int16_t i2c_transaction(struct I2C * i2c, uint8_t * data, int16_t length, bool read) {
|
||||
int16_t i;
|
||||
static int16_t i2c_transaction(struct I2C * i2c, uint8_t * data, uint16_t length, bool read) {
|
||||
uint16_t i;
|
||||
for (i = 0; i < length; i++) {
|
||||
if (read) {
|
||||
// If last byte
|
||||
@ -153,10 +153,10 @@ static int16_t i2c_transaction(struct I2C * i2c, uint8_t * data, int16_t length,
|
||||
return i;
|
||||
}
|
||||
|
||||
int16_t i2c_read(struct I2C * i2c, uint8_t * data, int16_t length) __reentrant {
|
||||
int16_t i2c_read(struct I2C * i2c, uint8_t * data, uint16_t length) __reentrant {
|
||||
return i2c_transaction(i2c, data, length, true);
|
||||
}
|
||||
|
||||
int16_t i2c_write(struct I2C * i2c, uint8_t * data, int16_t length) __reentrant {
|
||||
int16_t i2c_write(struct I2C * i2c, uint8_t * data, uint16_t length) __reentrant {
|
||||
return i2c_transaction(i2c, data, length, false);
|
||||
}
|
||||
|
Reference in New Issue
Block a user