Skip to content

Commit

Permalink
add lsm6dsl and lps22hb driver
Browse files Browse the repository at this point in the history
  • Loading branch information
andy2012zwj committed Feb 8, 2018
1 parent 433fa1f commit e2a6deb
Show file tree
Hide file tree
Showing 14 changed files with 1,365 additions and 53 deletions.
20 changes: 13 additions & 7 deletions device/sensor/drv/drv_acc_bosch_bma253.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ static uint32_t current_factor = 0;

i2c_dev_t bma253_ctx = {
.port = 1,
.config.address_width = 7,
.config.address_width = 8,
.config.freq = 400000,
.config.dev_addr = BMA253_I2C_ADDR1,
};
Expand All @@ -204,7 +204,7 @@ static int drv_acc_bosch_bma253_soft_reset(i2c_dev_t* drv)
return 0;
}

static int drv_acc_bosch_bma253_validate_id(i2c_dev_t* drv, uint8_t id_addr, uint8_t id_value)
static int drv_acc_bosch_bma253_validate_id(i2c_dev_t* drv, uint8_t id_value)
{
uint8_t value = 0x00;
int ret = 0;
Expand All @@ -213,7 +213,7 @@ static int drv_acc_bosch_bma253_validate_id(i2c_dev_t* drv, uint8_t id_addr, ui
return -1;
}

ret = sensor_i2c_read(drv, id_addr, &value, I2C_DATA_LEN, I2C_OP_RETRIES);
ret = sensor_i2c_read(drv, BMA253_CHIP_ID_ADDR, &value, I2C_DATA_LEN, I2C_OP_RETRIES);
if(unlikely(ret)){
return ret;
}
Expand Down Expand Up @@ -411,12 +411,18 @@ static int drv_acc_bosch_bma253_close(void)
static int drv_acc_bosch_bma253_read(void *buf, size_t len)
{
int ret = 0;
size_t size;
uint8_t reg[6];
accel_data_t *accel = buf;
accel_data_t *accel = (accel_data_t *)buf;
if(buf == NULL){
return -1;
}

size = sizeof(accel_data_t);
if(len < size){
return -1;
}

ret = sensor_i2c_read(&bma253_ctx, BMA253_X_AXIS_LSB_ADDR, &reg[0], I2C_REG_LEN, I2C_OP_RETRIES);
ret |= sensor_i2c_read(&bma253_ctx, BMA253_X_AXIS_MSB_ADDR, &reg[1], I2C_REG_LEN, I2C_OP_RETRIES);
ret |= sensor_i2c_read(&bma253_ctx, BMA253_Y_AXIS_LSB_ADDR, &reg[2], I2C_REG_LEN, I2C_OP_RETRIES);
Expand All @@ -443,8 +449,8 @@ static int drv_acc_bosch_bma253_read(void *buf, size_t len)
accel->data[DATA_AXIS_Z] = accel->data[DATA_AXIS_Z] * ACCELEROMETER_UNIT_FACTOR / current_factor;
}
accel->timestamp = aos_now_ms();
len = sizeof(accel_data_t);
return 0;

return (int)size;
}

static int drv_acc_bosch_bma253_ioctl(int cmd, unsigned long arg)
Expand Down Expand Up @@ -506,7 +512,7 @@ int drv_acc_bosch_bma253_init(void){
return -1;
}

ret = drv_acc_bosch_bma253_validate_id(&bma253_ctx, BMA253_CHIP_ID_ADDR, BMA253_CHIP_ID_VALUE);
ret = drv_acc_bosch_bma253_validate_id(&bma253_ctx, BMA253_CHIP_ID_VALUE);
if(unlikely(ret)){
return -1;
}
Expand Down
Loading

0 comments on commit e2a6deb

Please sign in to comment.