Skip to content

drivers: add lsm6dsl accelerometer/gyroscope device driver#6835

Merged
aabadie merged 2 commits intoRIOT-OS:masterfrom
OTAkeys:pr/lsm6dsl
Apr 6, 2017
Merged

drivers: add lsm6dsl accelerometer/gyroscope device driver#6835
aabadie merged 2 commits intoRIOT-OS:masterfrom
OTAkeys:pr/lsm6dsl

Conversation

@vincent-d
Copy link
Copy Markdown
Member

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.

@vincent-d vincent-d added the Area: drivers Area: Device drivers label Mar 31, 2017
@aabadie aabadie self-assigned this Mar 31, 2017
@aabadie aabadie added this to the Release 2017.04 milestone Mar 31, 2017
@aabadie aabadie added the Type: new feature The issue requests / The PR implemements a new feature for RIOT label Mar 31, 2017
Copy link
Copy Markdown
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, will test next week (I have the hardware). a few style comments though.

@@ -0,0 +1,2 @@

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty line, can be removed

*/

/**
* @addtogroup drivers_lsm6dsl
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be @InGroup ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like @InGroup is used everywhere, indeed.

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

misaligned ;)

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

align, and in other places

@vincent-d
Copy link
Copy Markdown
Member Author

@aabadie comments addressed

@aabadie
Copy link
Copy Markdown
Contributor

aabadie commented Mar 31, 2017

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
There's also a similar PR #3263 opened for LSM6DS3.

They seem to be very similar, do you think it would make sense to make this driver compatible with both ?

*/

/**
* @defgroup drivers_lsm6dsl LSM36DSL 3D accelerometer/gyroscope
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LSM36DSL => LSM6DSL

and in other places below

*
* @{
* @file
* @brief Internal configuration for LSM36DSL devices
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here as well

*
* @{
* @file
* @brief Default configuration for LSM36DSL devices
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here

@vincent-d
Copy link
Copy Markdown
Member Author

Copy/paste error fixed ;)

@vincent-d
Copy link
Copy Markdown
Member Author

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.

Copy link
Copy Markdown
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few nitpicks + some remaining typo. I'll test this driver on LSM6DS0

#endif

#endif /* LSM6DSL_H */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra line could be removed

* @name LSM6DSL registers
* @{
*/
#define LSM6DSL_REG_FUNC_CFG_ACCESS (0x01)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alignment

/** @} */

/** WHO_AM_I value */
#define LSM6DSL_WHO_AM_I (0b01101010)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you align with the other values above, here and below

#endif

#endif /* LSM6DS_LINTERNAL_H */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra line

#endif

#endif /* LSM6DSL_PARAMS_H */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra line

* @{
*
* @file
* @brief Auto initialization of LSM6DSL pressure sensors
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/pressure/accelerometer../

void auto_init_lsm6dsl(void)
{
for (unsigned int i = 0; i < LSM6DSL_NUM; i++) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer using a continue after and no else

@@ -0,0 +1,158 @@
/*
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rename this file to lsm6dsl_internals.h ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, but a lot of other drivers have a dash in the xxx-internals.h file name.

@vincent-d
Copy link
Copy Markdown
Member Author

@aabadie comments addressed

@aabadie
Copy link
Copy Markdown
Contributor

aabadie commented Apr 5, 2017

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.

((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,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

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,
Copy link
Copy Markdown
Contributor

@aabadie aabadie Apr 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 :)

xtimer_usleep(5000);

i2c_read_reg(dev->params.i2c, dev->params.addr, LSM6DSL_REG_WHO_AM_I, &res);
if (res != LSM6DSL_WHO_AM_I) {
Copy link
Copy Markdown
Contributor

@aabadie aabadie Apr 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only place where you actually use the res value. I would drop res = in the other res = i2c_write_reg... lines

@vincent-d
Copy link
Copy Markdown
Member Author

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,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even better

Copy link
Copy Markdown
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK. Thanks @vincent-d !

@aabadie
Copy link
Copy Markdown
Contributor

aabadie commented Apr 6, 2017

Please squash

@aabadie
Copy link
Copy Markdown
Contributor

aabadie commented Apr 6, 2017

Just curious, do you plan to write drivers for other sensors on this shield ? (HTS221, LPS22HB, LSM303AGR)

@vincent-d vincent-d added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Apr 6, 2017
@vincent-d
Copy link
Copy Markdown
Member Author

Squashed

@vincent-d
Copy link
Copy Markdown
Member Author

Just curious, do you plan to write drivers for other sensors on this shield ? (HTS221, LPS22HB, LSM303AGR)

No, but I can help testing and reviewing if you plan it ;)

@aabadie
Copy link
Copy Markdown
Contributor

aabadie commented Apr 6, 2017

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.

@aabadie aabadie merged commit c65e57b into RIOT-OS:master Apr 6, 2017
@vincent-d vincent-d deleted the pr/lsm6dsl branch April 7, 2017 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: new feature The issue requests / The PR implemements a new feature for RIOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants