Skip to content

sens0: Simple sensor device interface #9075

Closed
jnohlgard wants to merge 7 commits intoRIOT-OS:masterfrom
jnohlgard:pr/sens0
Closed

sens0: Simple sensor device interface #9075
jnohlgard wants to merge 7 commits intoRIOT-OS:masterfrom
jnohlgard:pr/sens0

Conversation

@jnohlgard
Copy link
Member

Contribution description

Provide an easy way to interface new sensors without writing a lot of boilerplate code.
This driver provides a basic polled interface for digital sensors, currently only I2C is supported, but it will be a small effort to add SPI support later.

The output format from the sens0 read API was chosen as phydat_t, which makes this a good match for using with SAUL.

An example application is provided in tests/driver_sens0. The example application is configured for the onboard accelerometer on FRDM-K64F, and an optional external FRDM-STBC-AGM01 IMU 9DOF shield.

This driver is meant to only provide a basic polled read functionality of digital sensors and will not support interrupts, FIFOs, caching, or other more advanced features, which are usually more difficult to generalize into a generic interface like this.

Background

Three important observations:

  • Many sensing applications only need the basic functionality of the sensor, i.e. polling for a measurement reading every X ms and then doing something with that value in software.
  • Many digital sensors follow this operating procedure: Set up sensor parameters (sample rate, resolution, full scale range etc.), read measurements from output registers.
  • Many digital sensors support both I2C or SPI communication on the same chip, but the hardware register map and operating procedures are the same, or at least closely similar, regardless whether the register read/write operations happen over SPI or I2C.

Interfacing with a basic digital sensor in RIOT today requires writing or copying a whole bunch of boilerplate code, just to get some readings from the sensor. The Sens0 driver is meant to eliminate as much as possible of the boilerplate and leaving the developer to only create a simple hardware specification, which contains information about what registers to write during init, where to find the output, and how to parse the raw output into something usable. This will obviously limit the functionality compared to writing a specific driver from the ground up, but it also takes a lot less time to configure.

As an example, I wrote the fully working FXAS21002C hardware interface specification in some 15 minutes, without any prior experience with that particular sensor.

@jnohlgard jnohlgard 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 Area: SAUL Area: Sensor/Actuator Uber Layer labels May 4, 2018
@jnohlgard jnohlgard added this to the Release 2018.07 milestone May 4, 2018
@jnohlgard jnohlgard requested review from aabadie and kaspar030 May 4, 2018 11:58
@jnohlgard jnohlgard force-pushed the pr/sens0 branch 2 times, most recently from b9a4036 to 9d8ab38 Compare May 4, 2018 12:07
@jnohlgard
Copy link
Member Author

I have prepared an auto init implementation which uses xfa (#7523) for the device configuration instances, but let's merge this without auto init first to ease review.

@jnohlgard jnohlgard force-pushed the pr/sens0 branch 3 times, most recently from c29f7ef to c5ba2b1 Compare May 7, 2018 06:30
@stale
Copy link

stale bot commented Jan 17, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Jan 17, 2020
@stale stale bot closed this Feb 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: drivers Area: Device drivers Area: SAUL Area: Sensor/Actuator Uber Layer CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR State: stale State: The issue / PR has no activity for >185 days 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.

6 participants