-
Notifications
You must be signed in to change notification settings - Fork 2.1k
drivers: add support for LIS2DH12 acceleromter (SPI mode) #8381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
drivers: add support for LIS2DH12 acceleromter (SPI mode) #8381
Conversation
96c3f50
to
3d91529
Compare
rebased |
3d91529
to
38b9365
Compare
made |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only minor issues.
drivers/include/lis2dh12.h
Outdated
extern "C" { | ||
#endif | ||
|
||
/* So for I2C support is not implemented, so throw an error when selected */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drop So for
drivers/lis2dh12/lis2dh12.c
Outdated
* @brief LIS2DH12 accelerometer driver implementation | ||
* | ||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de> | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove line
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1000LU
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also name clashing with posix function
tests/driver_lis2dh12/main.c
Outdated
#include "lis2dh12_params.h" | ||
|
||
|
||
#define DELAY (100 * US_PER_MS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
100LU
tests/driver_lis2dh12/main.c
Outdated
|
||
int main(void) | ||
{ | ||
xtimer_ticks32_t last_wakeup = xtimer_now(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe move to the end of the loop?
addressed comments |
please squash! |
fdec3b2
to
8575701
Compare
squashed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested on ruuvitag, works like a charm. ACK.
Nice PR!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/continuously reading/continuous reading of/ ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
continuously is an adverb of reading?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/does also support/also supports/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in this case, I like the existing wording better...
drivers/lis2dh12/lis2dh12.c
Outdated
_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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use a defined constant instead of 3
?
drivers/lis2dh12/lis2dh12.c
Outdated
{ | ||
assert(dev && data); | ||
|
||
uint8_t raw[6]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 6?
|
||
void auto_init_lis2dh12(void) | ||
{ | ||
for (unsigned int i = 0; i < LIS2DH12_NUM; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/formated/formatted/
tests/driver_lis2dh12/main.c
Outdated
#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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's an extra 'the' before 'its'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
lis2dh12
accelerometers. 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)