Skip to content
Snippets Groups Projects
Commit d724a7d6 authored by schneider's avatar schneider
Browse files

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

parent d8b1056a
No related branches found
No related tags found
No related merge requests found
...@@ -74,16 +74,23 @@ static char *version = BHY_MCU_REFERENCE_VERSION; ...@@ -74,16 +74,23 @@ 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) static int8_t sensor_i2c_write(uint8_t addr, uint8_t reg, uint8_t *p_buf, uint16_t size)
{ {
uint8_t buf[size + 1]; uint8_t buf[size + 1];
//printf("sensor_i2c_write 0x%02x %d\n", reg, size);
buf[0] = reg; buf[0] = reg;
memcpy(buf + 1, p_buf, size); memcpy(buf + 1, p_buf, size);
return I2C_MasterWrite(I2C_DEVICE, addr << 1, buf, size + 1, 0); 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) 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); //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); return I2C_MasterRead(I2C_DEVICE, addr << 1, p_buf, size, 0);
} }
// TODO: return error code
return 0;
}
/********************************************************************************/ /********************************************************************************/
/* FUNCTION DECLARATIONS */ /* FUNCTION DECLARATIONS */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment