drivers/isl29020: fix return value integer error
Problem: Since `i2c_read_reg` returns (signed) `int` values, the result can be negative. However, the variable used to save the result is unsigned. Fix: Add and use a signed variable for return value storing.
This commit is contained in:
parent
8ba166df6d
commit
a729afa9ec
@ -57,13 +57,14 @@ int isl29020_read(isl29020_t *dev)
|
|||||||
{
|
{
|
||||||
char low, high;
|
char low, high;
|
||||||
uint16_t res;
|
uint16_t res;
|
||||||
|
int ret;
|
||||||
|
|
||||||
i2c_acquire(dev->i2c);
|
i2c_acquire(dev->i2c);
|
||||||
/* read lighting value */
|
/* read lighting value */
|
||||||
res = i2c_read_reg(dev->i2c, dev->address, ISL29020_REG_LDATA, &low);
|
ret = i2c_read_reg(dev->i2c, dev->address, ISL29020_REG_LDATA, &low);
|
||||||
res += i2c_read_reg(dev->i2c, dev->address, ISL29020_REG_HDATA, &high);
|
ret += i2c_read_reg(dev->i2c, dev->address, ISL29020_REG_HDATA, &high);
|
||||||
i2c_release(dev->i2c);
|
i2c_release(dev->i2c);
|
||||||
if (res < 2) {
|
if (ret < 2) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
res = (high << 8) | low;
|
res = (high << 8) | low;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user