Zephyr API Documentation
2.7.0-rc2
A Scalable Open Source RTOS
|
Sensor Interface. More...
Data Structures | |
struct | sensor_value |
Representation of a sensor readout value. More... | |
struct | sensor_trigger |
Sensor trigger spec. More... | |
struct | sensor_driver_api |
Macros | |
#define | SENSOR_G 9806650LL |
The value of gravitational constant in micro m/s^2. More... | |
#define | SENSOR_PI 3141592LL |
The value of constant PI in micros. More... | |
Typedefs | |
typedef void(* | sensor_trigger_handler_t) (const struct device *dev, struct sensor_trigger *trigger) |
Callback API upon firing of a trigger. More... | |
typedef int(* | sensor_attr_set_t) (const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val) |
Callback API upon setting a sensor's attributes. More... | |
typedef int(* | sensor_attr_get_t) (const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, struct sensor_value *val) |
Callback API upon getting a sensor's attributes. More... | |
typedef int(* | sensor_trigger_set_t) (const struct device *dev, const struct sensor_trigger *trig, sensor_trigger_handler_t handler) |
Callback API for setting a sensor's trigger and handler. More... | |
typedef int(* | sensor_sample_fetch_t) (const struct device *dev, enum sensor_channel chan) |
Callback API for fetching data from a sensor. More... | |
typedef int(* | sensor_channel_get_t) (const struct device *dev, enum sensor_channel chan, struct sensor_value *val) |
Callback API for getting a reading from a sensor. More... | |
Functions | |
int | sensor_attr_set (const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, const struct sensor_value *val) |
Set an attribute for a sensor. More... | |
int | sensor_attr_get (const struct device *dev, enum sensor_channel chan, enum sensor_attribute attr, struct sensor_value *val) |
Get an attribute for a sensor. More... | |
static int | sensor_trigger_set (const struct device *dev, struct sensor_trigger *trig, sensor_trigger_handler_t handler) |
Activate a sensor's trigger and set the trigger handler. More... | |
int | sensor_sample_fetch (const struct device *dev) |
Fetch a sample from the sensor and store it in an internal driver buffer. More... | |
int | sensor_sample_fetch_chan (const struct device *dev, enum sensor_channel type) |
Fetch a sample from the sensor and store it in an internal driver buffer. More... | |
int | sensor_channel_get (const struct device *dev, enum sensor_channel chan, struct sensor_value *val) |
Get a reading from a sensor device. More... | |
static int32_t | sensor_ms2_to_g (const struct sensor_value *ms2) |
Helper function to convert acceleration from m/s^2 to Gs. More... | |
static void | sensor_g_to_ms2 (int32_t g, struct sensor_value *ms2) |
Helper function to convert acceleration from Gs to m/s^2. More... | |
static int32_t | sensor_rad_to_degrees (const struct sensor_value *rad) |
Helper function for converting radians to degrees. More... | |
static void | sensor_degrees_to_rad (int32_t d, struct sensor_value *rad) |
Helper function for converting degrees to radians. More... | |
static double | sensor_value_to_double (const struct sensor_value *val) |
Helper function for converting struct sensor_value to double. More... | |
static void | sensor_value_from_double (struct sensor_value *val, double inp) |
Helper function for converting double to struct sensor_value. More... | |
Sensor Interface.
#define SENSOR_G 9806650LL |
#include <include/drivers/sensor.h>
The value of gravitational constant in micro m/s^2.
#define SENSOR_PI 3141592LL |
#include <include/drivers/sensor.h>
The value of constant PI in micros.
sensor_attr_get_t |
#include <include/drivers/sensor.h>
Callback API upon getting a sensor's attributes.
See sensor_attr_get() for argument description
sensor_attr_set_t |
#include <include/drivers/sensor.h>
Callback API upon setting a sensor's attributes.
See sensor_attr_set() for argument description
sensor_channel_get_t |
#include <include/drivers/sensor.h>
Callback API for getting a reading from a sensor.
See sensor_channel_get() for argument description
sensor_sample_fetch_t |
#include <include/drivers/sensor.h>
Callback API for fetching data from a sensor.
See sensor_sample_fetch() for argument description
sensor_trigger_handler_t |
#include <include/drivers/sensor.h>
Callback API upon firing of a trigger.
dev | Pointer to the sensor device |
trigger | The trigger |
sensor_trigger_set_t |
#include <include/drivers/sensor.h>
Callback API for setting a sensor's trigger and handler.
See sensor_trigger_set() for argument description
enum sensor_attribute |
#include <include/drivers/sensor.h>
Sensor attribute types.
Enumerator | |
---|---|
SENSOR_ATTR_SAMPLING_FREQUENCY | Sensor sampling frequency, i.e. how many times a second the sensor takes a measurement. |
SENSOR_ATTR_LOWER_THRESH | Lower threshold for trigger. |
SENSOR_ATTR_UPPER_THRESH | Upper threshold for trigger. |
SENSOR_ATTR_SLOPE_TH | Threshold for any-motion (slope) trigger. |
SENSOR_ATTR_SLOPE_DUR | Duration for which the slope values needs to be outside the threshold for the trigger to fire. |
SENSOR_ATTR_HYSTERESIS | |
SENSOR_ATTR_OVERSAMPLING | Oversampling factor |
SENSOR_ATTR_FULL_SCALE | Sensor range, in SI units. |
SENSOR_ATTR_OFFSET | The sensor value returned will be altered by the amount indicated by offset: final_value = sensor_value + offset. |
SENSOR_ATTR_CALIB_TARGET | Calibration target. This will be used by the internal chip's algorithms to calibrate itself on a certain axis, or all of them. |
SENSOR_ATTR_CONFIGURATION | Configure the operating modes of a sensor. |
SENSOR_ATTR_CALIBRATION | Set a calibration value needed by a sensor. |
SENSOR_ATTR_FEATURE_MASK | Enable/disable sensor features |
SENSOR_ATTR_ALERT | Alert threshold or alert enable/disable |
SENSOR_ATTR_COMMON_COUNT | Number of all common sensor attributes. |
SENSOR_ATTR_PRIV_START | This and higher values are sensor specific. Refer to the sensor header file. |
SENSOR_ATTR_MAX | Maximum value describing a sensor attribute type. |
enum sensor_channel |
#include <include/drivers/sensor.h>
Sensor channels.
enum sensor_trigger_type |
#include <include/drivers/sensor.h>
Sensor trigger types.
Enumerator | |
---|---|
SENSOR_TRIG_TIMER | Timer-based trigger, useful when the sensor does not have an interrupt line. |
SENSOR_TRIG_DATA_READY | Trigger fires whenever new data is ready. |
SENSOR_TRIG_DELTA | Trigger fires when the selected channel varies significantly. This includes any-motion detection when the channel is acceleration or gyro. If detection is based on slope between successive channel readings, the slope threshold is configured via the SENSOR_ATTR_SLOPE_TH and SENSOR_ATTR_SLOPE_DUR attributes. |
SENSOR_TRIG_NEAR_FAR | Trigger fires when a near/far event is detected. |
SENSOR_TRIG_THRESHOLD | Trigger fires when channel reading transitions configured thresholds. The thresholds are configured via the SENSOR_ATTR_LOWER_THRESH, SENSOR_ATTR_UPPER_THRESH, and SENSOR_ATTR_HYSTERESIS attributes. |
SENSOR_TRIG_TAP | Trigger fires when a single tap is detected. |
SENSOR_TRIG_DOUBLE_TAP | Trigger fires when a double tap is detected. |
SENSOR_TRIG_FREEFALL | Trigger fires when a free fall is detected. |
SENSOR_TRIG_COMMON_COUNT | Number of all common sensor triggers. |
SENSOR_TRIG_PRIV_START | This and higher values are sensor specific. Refer to the sensor header file. |
SENSOR_TRIG_MAX | Maximum value describing a sensor trigger type. |
int sensor_attr_get | ( | const struct device * | dev, |
enum sensor_channel | chan, | ||
enum sensor_attribute | attr, | ||
struct sensor_value * | val | ||
) |
#include <include/drivers/sensor.h>
Get an attribute for a sensor.
dev | Pointer to the sensor device |
chan | The channel the attribute belongs to, if any. Some attributes may only be set for all channels of a device, depending on device capabilities. |
attr | The attribute to get |
val | Pointer to where to store the attribute |
int sensor_attr_set | ( | const struct device * | dev, |
enum sensor_channel | chan, | ||
enum sensor_attribute | attr, | ||
const struct sensor_value * | val | ||
) |
#include <include/drivers/sensor.h>
Set an attribute for a sensor.
dev | Pointer to the sensor device |
chan | The channel the attribute belongs to, if any. Some attributes may only be set for all channels of a device, depending on device capabilities. |
attr | The attribute to set |
val | The value to set the attribute to |
int sensor_channel_get | ( | const struct device * | dev, |
enum sensor_channel | chan, | ||
struct sensor_value * | val | ||
) |
#include <include/drivers/sensor.h>
Get a reading from a sensor device.
Return a useful value for a particular channel, from the driver's internal data. Before calling this function, a sample must be obtained by calling sensor_sample_fetch or sensor_sample_fetch_chan. It is guaranteed that two subsequent calls of this function for the same channels will yield the same value, if sensor_sample_fetch or sensor_sample_fetch_chan has not been called in the meantime.
For vectorial data samples you can request all axes in just one call by passing the specific channel with _XYZ suffix. The sample will be returned at val[0], val[1] and val[2] (X, Y and Z in that order).
dev | Pointer to the sensor device |
chan | The channel to read |
val | Where to store the value |
|
inlinestatic |
#include <include/drivers/sensor.h>
Helper function for converting degrees to radians.
d | The value (in degrees) to be converted. |
rad | A pointer to a sensor_value struct, where the result is stored. |
|
inlinestatic |
#include <include/drivers/sensor.h>
Helper function to convert acceleration from Gs to m/s^2.
g | The G value to be converted. |
ms2 | A pointer to a sensor_value struct, where the result is stored. |
|
inlinestatic |
#include <include/drivers/sensor.h>
Helper function to convert acceleration from m/s^2 to Gs.
ms2 | A pointer to a sensor_value struct holding the acceleration, in m/s^2. |
|
inlinestatic |
#include <include/drivers/sensor.h>
Helper function for converting radians to degrees.
rad | A pointer to a sensor_value struct, holding the value in radians. |
int sensor_sample_fetch | ( | const struct device * | dev | ) |
#include <include/drivers/sensor.h>
Fetch a sample from the sensor and store it in an internal driver buffer.
Read all of a sensor's active channels and, if necessary, perform any additional operations necessary to make the values useful. The user may then get individual channel values by calling sensor_channel_get.
Since the function communicates with the sensor device, it is unsafe to call it in an ISR if the device is connected via I2C or SPI.
dev | Pointer to the sensor device |
int sensor_sample_fetch_chan | ( | const struct device * | dev, |
enum sensor_channel | type | ||
) |
#include <include/drivers/sensor.h>
Fetch a sample from the sensor and store it in an internal driver buffer.
Read and compute compensation for one type of sensor data (magnetometer, accelerometer, etc). The user may then get individual channel values by calling sensor_channel_get.
This is mostly implemented by multi function devices enabling reading at different sampling rates.
Since the function communicates with the sensor device, it is unsafe to call it in an ISR if the device is connected via I2C or SPI.
dev | Pointer to the sensor device |
type | The channel that needs updated |
|
inlinestatic |
#include <include/drivers/sensor.h>
Activate a sensor's trigger and set the trigger handler.
The handler will be called from a thread, so I2C or SPI operations are safe. However, the thread's stack is limited and defined by the driver. It is currently up to the caller to ensure that the handler does not overflow the stack.
dev | Pointer to the sensor device |
trig | The trigger to activate |
handler | The function that should be called when the trigger fires |
|
inlinestatic |
#include <include/drivers/sensor.h>
Helper function for converting double to struct sensor_value.
val | A pointer to a sensor_value struct. |
inp | The converted value. |
|
inlinestatic |
#include <include/drivers/sensor.h>
Helper function for converting struct sensor_value to double.
val | A pointer to a sensor_value struct. |