drivers: add support for LIS2DH12 acceleromter (SPI mode)#8381
drivers: add support for LIS2DH12 acceleromter (SPI mode)#8381haukepetersen merged 6 commits intoRIOT-OS:masterfrom
Conversation
96c3f50 to
3d91529
Compare
|
rebased |
3d91529 to
38b9365
Compare
|
made |
drivers/include/lis2dh12.h
Outdated
| extern "C" { | ||
| #endif | ||
|
|
||
| /* So for I2C support is not implemented, so throw an error when selected */ |
drivers/lis2dh12/lis2dh12.c
Outdated
| * @brief LIS2DH12 accelerometer driver implementation | ||
| * | ||
| * @author Hauke Petersen <hauke.petersen@fu-berlin.de> | ||
| * |
drivers/lis2dh12/lis2dh12.c
Outdated
| /* flag to enable address auto incrementation on read or write */ | ||
| #define AUTOINC (0x40) | ||
|
|
||
| static inline int acquire(const lis2dh12_t *dev) |
There was a problem hiding this comment.
here and below: no need to inline when not in *.c file
drivers/lis2dh12/lis2dh12.c
Outdated
| spi_release(BUS); | ||
| } | ||
|
|
||
| static inline uint8_t read(const lis2dh12_t *dev, uint8_t reg) |
There was a problem hiding this comment.
while this might work, IMO name clashes with standard functions should be avoided. _[a-z] is guaranteed to be free. ;)
drivers/lis2dh12/lis2dh12.c
Outdated
| assert(dev && params); | ||
|
|
||
| dev->p = params; | ||
| dev->comp = (1000 * (0x02 << (dev->p->scale >> 4))); |
drivers/lis2dh12/lis2dh12.c
Outdated
| spi_transfer_regs(BUS, CS, (READ | AUTOINC | reg), NULL, data, len); | ||
| } | ||
|
|
||
| static inline void write(const lis2dh12_t *dev, uint8_t reg, uint8_t data) |
There was a problem hiding this comment.
also name clashing with posix function
tests/driver_lis2dh12/main.c
Outdated
| #include "lis2dh12_params.h" | ||
|
|
||
|
|
||
| #define DELAY (100 * US_PER_MS) |
tests/driver_lis2dh12/main.c
Outdated
|
|
||
| int main(void) | ||
| { | ||
| xtimer_ticks32_t last_wakeup = xtimer_now(); |
There was a problem hiding this comment.
I propose moving this in front of the while queue so the following puts() are not part of the first interval...
tests/driver_lis2dh12/main.c
Outdated
| } | ||
|
|
||
| while (1) { | ||
| xtimer_periodic_wakeup(&last_wakeup, DELAY); |
There was a problem hiding this comment.
maybe move to the end of the loop?
|
addressed comments |
|
please squash! |
fdec3b2 to
8575701
Compare
|
squashed. |
kaspar030
left a comment
There was a problem hiding this comment.
Tested on ruuvitag, works like a charm. ACK.
Nice PR!
aabadie
left a comment
There was a problem hiding this comment.
Found some typo and possible wording improvements. Among other minor things.
drivers/include/lis2dh12.h
Outdated
| * | ||
| * This device driver provides a minimal interface to LIS2DH12 devices. As of | ||
| * now, it only provides very basic access to the device. The driver configures | ||
| * the device into continuously reading the acceleration data with statically |
There was a problem hiding this comment.
s/continuously reading/continuous reading of/ ?
There was a problem hiding this comment.
continuously is an adverb of reading?
There was a problem hiding this comment.
Yeah, that looked weird at first sight but ok, let's keep this one as it is
| /** | ||
| * @brief Available sampling rates | ||
| * | ||
| * @note The device does also support some additional rates for specific low- |
There was a problem hiding this comment.
s/does also support/also supports/
There was a problem hiding this comment.
in this case, I like the existing wording better...
| _read_burst(dev, REG_OUT_X_L, raw, 6); | ||
| _release(dev); | ||
|
|
||
| for (int i = 0; i < 3; i++) { |
There was a problem hiding this comment.
Why not use a defined constant instead of 3 ?
| { | ||
| assert(dev && data); | ||
|
|
||
| uint8_t raw[6]; |
|
|
||
| void auto_init_lis2dh12(void) | ||
| { | ||
| for (unsigned int i = 0; i < LIS2DH12_NUM; i++) { |
There was a problem hiding this comment.
Maybe add an assert between LIS2DH12_NUM and a LIS2DH12_INFO_NUM, see #7937 for examples.
tests/driver_lis2dh12/main.c
Outdated
|
|
||
| #define DELAY (100UL * US_PER_MS) | ||
|
|
||
| /* allocate some memory for holding the formated sensor output */ |
| #define DELAY (100UL * US_PER_MS) | ||
|
|
||
| /* allocate some memory for holding the formated sensor output */ | ||
| static char str_out[3][8]; |
There was a problem hiding this comment.
What are those magic numbers? Maybe describe the "formatted sensor output" ?
|
@aabadie addressed comments, thanks for the feedback |
tests/driver_lis2dh12/README.md
Outdated
| This is a manual test application for the LIS2DH12 accelerometer driver. | ||
|
|
||
| # Usage | ||
| This test application will initialize the accelerometer with the its default |
There was a problem hiding this comment.
there's an extra 'the' before 'its'
aabadie
left a comment
There was a problem hiding this comment.
ACK when the comment above is fixed. Please squash.
|
fixed readme |
96128f2 to
0c8b131
Compare
|
and squashed |
|
ACKed and all green -> go. Thanks for the quick reviews! |
Contribution description
This PR adds a device driver for STM
lis2dh12accelerometers. In the current state, the driver supports only to interface the device via SPI (as used on theruuvitag). I2C support will be added in a follow up (as used on thethingy52), but the structure of the driver is already prepared for this...In the current state, the driver is very rudimentary, as it supports only a very basic operating mode with continuous sampling. Events, interrupts, and low power modes are not yet supported.
Issues/PRs references
one step towards full support of the
ruuvitag(#8366)