Commit d724a7d6 authored by schneider's avatar schneider
Browse files

fix(BHI): Add a bit of I2C error handling

parent d8b1056a
......@@ -74,15 +74,22 @@ static char *version = BHY_MCU_REFERENCE_VERSION;
static int8_t sensor_i2c_write(uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size)
{
uint8_t buf[size + 1];
//printf("sensor_i2c_write 0x%02x %d\n", reg, size);
buf[0] = reg;
memcpy(buf + 1, p_buf, size);
return I2C_MasterWrite(I2C_DEVICE, addr << 1, buf, size + 1, 0);
}
static int8_t sensor_i2c_read(uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size)
{
I2C_MasterWrite(I2C_DEVICE, addr << 1, &reg, 1, 1);
return I2C_MasterRead(I2C_DEVICE, addr << 1, p_buf, size, 0);
//printf("sensor_i2c_read 0x%02x %d\n", reg, size);
if(I2C_MasterWrite(I2C_DEVICE, addr << 1, &reg, 1, 1) == 1) {
return I2C_MasterRead(I2C_DEVICE, addr << 1, p_buf, size, 0);
}
// TODO: return error code
return 0;
}
/********************************************************************************/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment