drivers: add lsm6dsl accelerometer/gyroscope device driver#6835
drivers: add lsm6dsl accelerometer/gyroscope device driver#6835aabadie merged 2 commits intoRIOT-OS:masterfrom
Conversation
aabadie
left a comment
There was a problem hiding this comment.
looks good, will test next week (I have the hardware). a few style comments though.
drivers/lsm6dsl/Makefile
Outdated
| @@ -0,0 +1,2 @@ | |||
|
|
|||
There was a problem hiding this comment.
empty line, can be removed
| */ | ||
|
|
||
| /** | ||
| * @addtogroup drivers_lsm6dsl |
There was a problem hiding this comment.
Looks like @InGroup is used everywhere, indeed.
drivers/lsm6dsl/lsm6dsl.c
Outdated
| LSM6DSL_REG_OUTX_H_XL, &tmp); | ||
| data->x |= tmp << 8; | ||
| res += i2c_read_reg(dev->params.i2c, dev->params.addr, | ||
| LSM6DSL_REG_OUTY_L_XL, &tmp); |
drivers/lsm6dsl/lsm6dsl.c
Outdated
| LSM6DSL_REG_OUTX_H_G, &tmp); | ||
| data->x |= tmp << 8; | ||
| res += i2c_read_reg(dev->params.i2c, dev->params.addr, | ||
| LSM6DSL_REG_OUTY_L_G, &tmp); |
There was a problem hiding this comment.
align, and in other places
|
@aabadie comments addressed |
|
Just had a look at the producs on ST website. There are several versions of this sensor: LSM6DS0 in X-NUCLEO-IKS01A1 and LSM6DSL in X-NUCLEO-IKS01A2 They seem to be very similar, do you think it would make sense to make this driver compatible with both ? |
drivers/include/lsm6dsl.h
Outdated
| */ | ||
|
|
||
| /** | ||
| * @defgroup drivers_lsm6dsl LSM36DSL 3D accelerometer/gyroscope |
There was a problem hiding this comment.
LSM36DSL => LSM6DSL
and in other places below
| * | ||
| * @{ | ||
| * @file | ||
| * @brief Internal configuration for LSM36DSL devices |
| * | ||
| * @{ | ||
| * @file | ||
| * @brief Default configuration for LSM36DSL devices |
|
Copy/paste error fixed ;) |
|
As usual, there is no unique datasheet, so we need to compare to be sure the interface is similar. But if it's the case, I would say it make sense to factorize the code and have a unique driver. |
aabadie
left a comment
There was a problem hiding this comment.
a few nitpicks + some remaining typo. I'll test this driver on LSM6DS0
drivers/include/lsm6dsl.h
Outdated
| #endif | ||
|
|
||
| #endif /* LSM6DSL_H */ | ||
|
|
There was a problem hiding this comment.
extra line could be removed
| * @name LSM6DSL registers | ||
| * @{ | ||
| */ | ||
| #define LSM6DSL_REG_FUNC_CFG_ACCESS (0x01) |
| /** @} */ | ||
|
|
||
| /** WHO_AM_I value */ | ||
| #define LSM6DSL_WHO_AM_I (0b01101010) |
There was a problem hiding this comment.
Can you align with the other values above, here and below
| #endif | ||
|
|
||
| #endif /* LSM6DS_LINTERNAL_H */ | ||
|
|
| #endif | ||
|
|
||
| #endif /* LSM6DSL_PARAMS_H */ | ||
|
|
| * @{ | ||
| * | ||
| * @file | ||
| * @brief Auto initialization of LSM6DSL pressure sensors |
There was a problem hiding this comment.
s/pressure/accelerometer../
| void auto_init_lsm6dsl(void) | ||
| { | ||
| for (unsigned int i = 0; i < LSM6DSL_NUM; i++) { | ||
|
|
There was a problem hiding this comment.
extra space that can be removed
|
|
||
| int res = lsm6dsl_init(&lsm6dsl_devs[i], &lsm6dsl_params[i]); | ||
| if (res < 0) { | ||
| LOG_ERROR("[auto_init_saul] error initializing lsm6dsl #%u\n", i); |
There was a problem hiding this comment.
I would prefer using a continue after and no else
| @@ -0,0 +1,158 @@ | |||
| /* | |||
There was a problem hiding this comment.
Can you rename this file to lsm6dsl_internals.h ?
There was a problem hiding this comment.
Done, but a lot of other drivers have a dash in the xxx-internals.h file name.
|
@aabadie comments addressed |
|
Tested on a LSM6DS0 with small adaptations. The gyroscope and accelerometer seems to work but I don't have the temperature. Looking at the datasheet the registers addresses are quite different even if some have similar names... So it might not be that simple to unify the drivers. |
drivers/lsm6dsl/lsm6dsl.c
Outdated
| ((dev->params.acc_odr << LSM6DSL_CTRL_ODR_SHIFT) | | ||
| (dev->params.acc_fs << LSM6DSL_CTRL_FS_SHIFT))); | ||
| /* Set gyro odr / full scale */ | ||
| res = i2c_write_reg(dev->params.i2c, dev->params.addr, LSM6DSL_REG_CTRL2_G, |
There was a problem hiding this comment.
this line makes static-test fails on my laptop:
drivers/lsm6dsl/lsm6dsl.c:55: style (redundantAssignment): Variable 'res' is reassigned a value before the old one has been used
drivers/lsm6dsl/lsm6dsl.c
Outdated
| res = i2c_write_reg(dev->params.i2c, dev->params.addr, LSM6DSL_REG_FIFO_CTRL5, | ||
| (fifo_odr << LSM6DSL_FIFO_CTRL5_FIFO_ODR_SHIFT) | | ||
| LSM6DSL_FIFO_CTRL5_CONTINUOUS_MODE); | ||
| res = i2c_write_reg(dev->params.i2c, dev->params.addr, LSM6DSL_REG_FIFO_CTRL3, |
There was a problem hiding this comment.
same with this one because of another reason:
drivers/lsm6dsl/lsm6dsl.c:64: style (unreadVariable): Variable 'res' is assigned a value that is never used
The make static-test command returns interesting results :)
drivers/lsm6dsl/lsm6dsl.c
Outdated
| xtimer_usleep(5000); | ||
|
|
||
| i2c_read_reg(dev->params.i2c, dev->params.addr, LSM6DSL_REG_WHO_AM_I, &res); | ||
| if (res != LSM6DSL_WHO_AM_I) { |
There was a problem hiding this comment.
This is only place where you actually use the res value. I would drop res = in the other res = i2c_write_reg... lines
|
Improved init function |
| ((dev->params.acc_odr << LSM6DSL_CTRL_ODR_SHIFT) | | ||
| (dev->params.acc_fs << LSM6DSL_CTRL_FS_SHIFT))); | ||
| /* Set gyro odr / full scale */ | ||
| res += i2c_write_reg(dev->params.i2c, dev->params.addr, LSM6DSL_REG_CTRL2_G, |
aabadie
left a comment
There was a problem hiding this comment.
ACK. Thanks @vincent-d !
|
Please squash |
|
Just curious, do you plan to write drivers for other sensors on this shield ? (HTS221, LPS22HB, LSM303AGR) |
|
Squashed |
No, but I can help testing and reviewing if you plan it ;) |
|
HTS221 is interesting, I'll let you know if one day I start having a look at this one. Otherwise there's already #4257 opened that should be quite similar to LPS22HB. Let's go when Murdock is green. |
This PR add a driver for ST LSM6DSL accelerometer/gyroscope + saul support.
It's available on the x-nucleo-iks01a2 shield.
It's a basic driver which just read accelerometer and gyroscope data.