Skip to content

Conversation

haukepetersen
Copy link
Contributor

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 the ruuvitag). I2C support will be added in a follow up (as used on the thingy52), 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)

@haukepetersen haukepetersen added Type: new feature The issue requests / The PR implemements a new feature for RIOT 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 labels Jan 18, 2018
@haukepetersen
Copy link
Contributor Author

rebased

@haukepetersen
Copy link
Contributor Author

made lis2dh12_spi default in the test for now.

Copy link
Contributor

@kaspar030 kaspar030 left a comment

Choose a reason for hiding this comment

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

Only minor issues.

extern "C" {
#endif

/* So for I2C support is not implemented, so throw an error when selected */
Copy link
Contributor

Choose a reason for hiding this comment

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

drop So for

* @brief LIS2DH12 accelerometer driver implementation
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
Copy link
Contributor

Choose a reason for hiding this comment

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

remove line

/* flag to enable address auto incrementation on read or write */
#define AUTOINC (0x40)

static inline int acquire(const lis2dh12_t *dev)
Copy link
Contributor

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

spi_release(BUS);
}

static inline uint8_t read(const lis2dh12_t *dev, uint8_t reg)
Copy link
Contributor

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. ;)

assert(dev && params);

dev->p = params;
dev->comp = (1000 * (0x02 << (dev->p->scale >> 4)));
Copy link
Contributor

Choose a reason for hiding this comment

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

1000LU

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

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

#include "lis2dh12_params.h"


#define DELAY (100 * US_PER_MS)
Copy link
Contributor

Choose a reason for hiding this comment

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

100LU


int main(void)
{
xtimer_ticks32_t last_wakeup = xtimer_now();
Copy link
Contributor

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...

}

while (1) {
xtimer_periodic_wakeup(&last_wakeup, DELAY);
Copy link
Contributor

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?

@haukepetersen
Copy link
Contributor Author

addressed comments

@kaspar030
Copy link
Contributor

please squash!

@haukepetersen
Copy link
Contributor Author

squashed.

Copy link
Contributor

@kaspar030 kaspar030 left a 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!

Copy link
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.

Found some typo and possible wording improvements. Among other minor things.

*
* 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
Copy link
Contributor

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/ ?

Copy link
Contributor

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?

Copy link
Contributor

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

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/

Copy link
Contributor Author

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...

_read_burst(dev, REG_OUT_X_L, raw, 6);
_release(dev);

for (int i = 0; i < 3; i++) {
Copy link
Contributor

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 ?

{
assert(dev && data);

uint8_t raw[6];
Copy link
Contributor

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++) {
Copy link
Contributor

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.


#define DELAY (100UL * US_PER_MS)

/* allocate some memory for holding the formated sensor output */
Copy link
Contributor

Choose a reason for hiding this comment

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

s/formated/formatted/

#define DELAY (100UL * US_PER_MS)

/* allocate some memory for holding the formated sensor output */
static char str_out[3][8];
Copy link
Contributor

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" ?

@haukepetersen
Copy link
Contributor Author

@aabadie addressed comments, thanks for the feedback

This is a manual test application for the LIS2DH12 accelerometer driver.

# Usage
This test application will initialize the accelerometer with the its default
Copy link
Contributor

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'

Copy link
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 when the comment above is fixed. Please squash.

@haukepetersen
Copy link
Contributor Author

fixed readme

@haukepetersen
Copy link
Contributor Author

and squashed

@haukepetersen
Copy link
Contributor Author

ACKed and all green -> go.

Thanks for the quick reviews!

@haukepetersen haukepetersen merged commit a896d95 into RIOT-OS:master Jan 18, 2018
@haukepetersen haukepetersen deleted the add_driver_lis2dh12 branch January 18, 2018 18:45
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.

3 participants