2016-06-23 16:36:04 +02:00
|
|
|
/**
|
|
|
|
* @file sensor.h
|
|
|
|
*
|
|
|
|
* @brief Public APIs for the sensor driver.
|
|
|
|
*/
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation
|
|
|
|
*
|
2017-01-19 02:01:01 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
*/
|
2018-09-14 19:43:44 +02:00
|
|
|
#ifndef ZEPHYR_INCLUDE_SENSOR_H_
|
|
|
|
#define ZEPHYR_INCLUDE_SENSOR_H_
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sensor Interface
|
|
|
|
* @defgroup sensor_interface Sensor Interface
|
|
|
|
* @ingroup io_interfaces
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 17:32:08 +02:00
|
|
|
#include <zephyr/types.h>
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
#include <device.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2019-01-25 12:23:37 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
/**
|
|
|
|
* @brief Representation of a sensor readout value.
|
|
|
|
*
|
2017-01-12 14:28:25 +01:00
|
|
|
* The value is represented as having an integer and a fractional part,
|
2018-02-12 10:57:44 +01:00
|
|
|
* and can be obtained using the formula val1 + val2 * 10^(-6). Negative
|
|
|
|
* values also adhere to the above formula, but may need special attention.
|
|
|
|
* Here are some examples of the value representation:
|
|
|
|
*
|
|
|
|
* 0.5: val1 = 0, val2 = 500000
|
|
|
|
* -0.5: val1 = 0, val2 = -500000
|
|
|
|
* -1.0: val1 = -1, val2 = 0
|
|
|
|
* -1.5: val1 = -1, val2 = -500000
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
*/
|
|
|
|
struct sensor_value {
|
2017-01-12 14:28:25 +01:00
|
|
|
/** Integer part of the value. */
|
2017-04-21 17:55:34 +02:00
|
|
|
s32_t val1;
|
2018-02-12 10:57:44 +01:00
|
|
|
/** Fractional part of the value (in one-millionth parts). */
|
2017-04-21 17:55:34 +02:00
|
|
|
s32_t val2;
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sensor channels.
|
|
|
|
*/
|
|
|
|
enum sensor_channel {
|
|
|
|
/** Acceleration on the X axis, in m/s^2. */
|
|
|
|
SENSOR_CHAN_ACCEL_X,
|
|
|
|
/** Acceleration on the Y axis, in m/s^2. */
|
|
|
|
SENSOR_CHAN_ACCEL_Y,
|
|
|
|
/** Acceleration on the Z axis, in m/s^2. */
|
|
|
|
SENSOR_CHAN_ACCEL_Z,
|
2017-01-26 15:36:57 +01:00
|
|
|
/** Acceleration on the X, Y and Z axes. */
|
|
|
|
SENSOR_CHAN_ACCEL_XYZ,
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
/** Angular velocity around the X axis, in radians/s. */
|
|
|
|
SENSOR_CHAN_GYRO_X,
|
|
|
|
/** Angular velocity around the Y axis, in radians/s. */
|
|
|
|
SENSOR_CHAN_GYRO_Y,
|
|
|
|
/** Angular velocity around the Z axis, in radians/s. */
|
|
|
|
SENSOR_CHAN_GYRO_Z,
|
2017-01-26 15:36:57 +01:00
|
|
|
/** Angular velocity around the X, Y and Z axes. */
|
|
|
|
SENSOR_CHAN_GYRO_XYZ,
|
2016-02-17 12:27:05 +01:00
|
|
|
/** Magnetic field on the X axis, in Gauss. */
|
|
|
|
SENSOR_CHAN_MAGN_X,
|
|
|
|
/** Magnetic field on the Y axis, in Gauss. */
|
|
|
|
SENSOR_CHAN_MAGN_Y,
|
|
|
|
/** Magnetic field on the Z axis, in Gauss. */
|
|
|
|
SENSOR_CHAN_MAGN_Z,
|
2017-01-26 15:36:57 +01:00
|
|
|
/** Magnetic field on the X, Y and Z axes. */
|
|
|
|
SENSOR_CHAN_MAGN_XYZ,
|
2018-03-23 09:41:09 +01:00
|
|
|
/** Device die temperature in degrees Celsius. */
|
|
|
|
SENSOR_CHAN_DIE_TEMP,
|
|
|
|
/** Ambient temperature in degrees Celsius. */
|
|
|
|
SENSOR_CHAN_AMBIENT_TEMP,
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
/** Pressure in kilopascal. */
|
|
|
|
SENSOR_CHAN_PRESS,
|
|
|
|
/**
|
|
|
|
* Proximity. Adimensional. A value of 1 indicates that an
|
|
|
|
* object is close.
|
|
|
|
*/
|
|
|
|
SENSOR_CHAN_PROX,
|
sensors: Redefine SENSOR_CHAN_HUMIDITY in percents, not milli-percents.
Based on the discussion in #5693, the reason why humidity was defined
in milli-percent was likely following Linux which defines it as such
in its sensor subsystem:
http://elixir.free-electrons.com/linux/latest/source/Documentation/ABI/testing/sysfs-bus-iio#L263
However, Linux defines temperature in milli-degrees either, but
Zephyr uses degrees (similarly for most other quantities). Typical
sensor resolution/precision for humidity is also on the order of 1%.
One of the existing drivers, th02.c, already returned values in
percents, and few apps showed it without conversion and/or units,
leading to confusing output to user like "54500".
So, switching units to percents, and update all the drivers and
sample apps.
For few drivers, there was also optimized conversion arithmetics
to avoid u64_t operations. (There're probably more places to
optimize it, and temperature conversion could use such optimization
too, but that's left for another patch.)
Fixes: #5693
Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-01-25 14:06:17 +01:00
|
|
|
/** Humidity, in percent. */
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
SENSOR_CHAN_HUMIDITY,
|
|
|
|
/** Illuminance in visible spectrum, in lux. */
|
|
|
|
SENSOR_CHAN_LIGHT,
|
|
|
|
/** Illuminance in infra-red spectrum, in lux. */
|
|
|
|
SENSOR_CHAN_IR,
|
2017-03-18 01:49:23 +01:00
|
|
|
/** Illuminance in red spectrum, in lux. */
|
|
|
|
SENSOR_CHAN_RED,
|
|
|
|
/** Illuminance in green spectrum, in lux. */
|
|
|
|
SENSOR_CHAN_GREEN,
|
2017-06-12 07:53:28 +02:00
|
|
|
/** Illuminance in blue spectrum, in lux. */
|
|
|
|
SENSOR_CHAN_BLUE,
|
2016-05-17 16:13:14 +02:00
|
|
|
/** Altitude, in meters */
|
|
|
|
SENSOR_CHAN_ALTITUDE,
|
2017-11-23 11:01:18 +01:00
|
|
|
|
2017-11-24 14:50:13 +01:00
|
|
|
/** 1.0 micro-meters Particulate Matter, in ug/m^3 */
|
2017-11-23 11:01:18 +01:00
|
|
|
SENSOR_CHAN_PM_1_0,
|
2017-11-24 14:50:13 +01:00
|
|
|
/** 2.5 micro-meters Particulate Matter, in ug/m^3 */
|
2017-11-23 11:01:18 +01:00
|
|
|
SENSOR_CHAN_PM_2_5,
|
2017-11-24 14:50:13 +01:00
|
|
|
/** 10 micro-meters Particulate Matter, in ug/m^3 */
|
2017-11-23 11:01:18 +01:00
|
|
|
SENSOR_CHAN_PM_10,
|
2018-02-05 12:04:55 +01:00
|
|
|
/** Distance. From sensor to target, in meters */
|
2017-07-17 11:40:26 +02:00
|
|
|
SENSOR_CHAN_DISTANCE,
|
2018-01-05 13:47:58 +01:00
|
|
|
|
|
|
|
/** CO2 level, in parts per million (ppm) **/
|
|
|
|
SENSOR_CHAN_CO2,
|
|
|
|
/** VOC level, in parts per billion (ppb) **/
|
|
|
|
SENSOR_CHAN_VOC,
|
|
|
|
|
|
|
|
/** Voltage, in volts **/
|
|
|
|
SENSOR_CHAN_VOLTAGE,
|
|
|
|
/** Current, in amps **/
|
|
|
|
SENSOR_CHAN_CURRENT,
|
|
|
|
|
2018-09-24 14:59:41 +02:00
|
|
|
/** Angular rotation, in degrees */
|
|
|
|
SENSOR_CHAN_ROTATION,
|
|
|
|
|
2016-04-11 13:49:26 +02:00
|
|
|
/** All channels. */
|
|
|
|
SENSOR_CHAN_ALL,
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sensor trigger types.
|
|
|
|
*/
|
|
|
|
enum sensor_trigger_type {
|
|
|
|
/**
|
|
|
|
* Timer-based trigger, useful when the sensor does not have an
|
|
|
|
* interrupt line.
|
|
|
|
*/
|
|
|
|
SENSOR_TRIG_TIMER,
|
|
|
|
/** Trigger fires whenever new data is ready. */
|
|
|
|
SENSOR_TRIG_DATA_READY,
|
|
|
|
/**
|
|
|
|
* Trigger fires when the selected channel varies significantly.
|
|
|
|
* This includes any-motion detection when the channel is
|
2016-04-11 16:11:00 +02:00
|
|
|
* acceleration or gyro. If detection is based on slope between
|
2016-02-29 15:20:30 +01:00
|
|
|
* successive channel readings, the slope threshold is configured
|
|
|
|
* via the @ref SENSOR_ATTR_SLOPE_TH and @ref SENSOR_ATTR_SLOPE_DUR
|
|
|
|
* attributes.
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
*/
|
|
|
|
SENSOR_TRIG_DELTA,
|
|
|
|
/** Trigger fires when a near/far event is detected. */
|
|
|
|
SENSOR_TRIG_NEAR_FAR,
|
|
|
|
/**
|
|
|
|
* Trigger fires when channel reading transitions configured
|
|
|
|
* thresholds. The thresholds are configured via the @ref
|
|
|
|
* SENSOR_ATTR_LOWER_THRESH and @ref SENSOR_ATTR_UPPER_THRESH
|
|
|
|
* attributes.
|
|
|
|
*/
|
|
|
|
SENSOR_TRIG_THRESHOLD,
|
2016-12-19 22:27:27 +01:00
|
|
|
|
|
|
|
/** Trigger fires when a single tap is detected. */
|
|
|
|
SENSOR_TRIG_TAP,
|
|
|
|
|
|
|
|
/** Trigger fires when a double tap is detected. */
|
|
|
|
SENSOR_TRIG_DOUBLE_TAP,
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sensor trigger spec.
|
|
|
|
*/
|
|
|
|
struct sensor_trigger {
|
|
|
|
/** Trigger type. */
|
|
|
|
enum sensor_trigger_type type;
|
|
|
|
/** Channel the trigger is set on. */
|
|
|
|
enum sensor_channel chan;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Sensor attribute types.
|
|
|
|
*/
|
|
|
|
enum sensor_attribute {
|
|
|
|
/**
|
|
|
|
* Sensor sampling frequency, i.e. how many times a second the
|
|
|
|
* sensor takes a measurement.
|
|
|
|
*/
|
|
|
|
SENSOR_ATTR_SAMPLING_FREQUENCY,
|
|
|
|
/** Lower threshold for trigger. */
|
|
|
|
SENSOR_ATTR_LOWER_THRESH,
|
|
|
|
/** Upper threshold for trigger. */
|
|
|
|
SENSOR_ATTR_UPPER_THRESH,
|
2016-02-29 15:20:30 +01:00
|
|
|
/** Threshold for any-motion (slope) trigger. */
|
|
|
|
SENSOR_ATTR_SLOPE_TH,
|
|
|
|
/**
|
|
|
|
* Duration for which the slope values needs to be
|
|
|
|
* outside the threshold for the trigger to fire.
|
|
|
|
*/
|
|
|
|
SENSOR_ATTR_SLOPE_DUR,
|
2016-02-17 12:27:05 +01:00
|
|
|
/** Oversampling factor */
|
|
|
|
SENSOR_ATTR_OVERSAMPLING,
|
2016-03-31 13:59:53 +02:00
|
|
|
/** Sensor range, in SI units. */
|
2016-03-10 12:55:47 +01:00
|
|
|
SENSOR_ATTR_FULL_SCALE,
|
2016-03-31 13:59:53 +02:00
|
|
|
/**
|
|
|
|
* The sensor value returned will be altered by the amount indicated by
|
|
|
|
* offset: final_value = sensor_value + offset.
|
|
|
|
*/
|
|
|
|
SENSOR_ATTR_OFFSET,
|
|
|
|
/**
|
|
|
|
* 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_CALIB_TARGET,
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
};
|
|
|
|
|
2016-06-15 23:18:38 +02:00
|
|
|
/**
|
|
|
|
* @typedef sensor_trigger_handler_t
|
|
|
|
* @brief Callback API upon firing of a trigger
|
|
|
|
*
|
|
|
|
* @param "struct device *dev" Pointer to the sensor device
|
|
|
|
* @param "struct sensor_trigger *trigger" The trigger
|
|
|
|
*/
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
typedef void (*sensor_trigger_handler_t)(struct device *dev,
|
|
|
|
struct sensor_trigger *trigger);
|
|
|
|
|
2016-06-15 23:18:38 +02:00
|
|
|
/**
|
|
|
|
* @typedef sensor_attr_set_t
|
|
|
|
* @brief Callback API upon setting a sensor's attributes
|
|
|
|
*
|
|
|
|
* See sensor_attr_set() for argument description
|
|
|
|
*/
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
typedef int (*sensor_attr_set_t)(struct device *dev,
|
|
|
|
enum sensor_channel chan,
|
|
|
|
enum sensor_attribute attr,
|
|
|
|
const struct sensor_value *val);
|
2016-06-15 23:18:38 +02:00
|
|
|
/**
|
|
|
|
* @typedef sensor_trigger_set_t
|
|
|
|
* @brief Callback API for setting a sensor's trigger and handler
|
|
|
|
*
|
|
|
|
* See sensor_trigger_set() for argument description
|
|
|
|
*/
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
typedef int (*sensor_trigger_set_t)(struct device *dev,
|
|
|
|
const struct sensor_trigger *trig,
|
|
|
|
sensor_trigger_handler_t handler);
|
2016-06-15 23:18:38 +02:00
|
|
|
/**
|
|
|
|
* @typedef sensor_sample_fetch_t
|
|
|
|
* @brief Callback API for fetching data from a sensor
|
|
|
|
*
|
2017-02-13 15:30:08 +01:00
|
|
|
* See sensor_sample_fetch() for argument description
|
2016-06-15 23:18:38 +02:00
|
|
|
*/
|
2016-04-11 13:49:26 +02:00
|
|
|
typedef int (*sensor_sample_fetch_t)(struct device *dev,
|
|
|
|
enum sensor_channel chan);
|
2016-06-15 23:18:38 +02:00
|
|
|
/**
|
|
|
|
* @typedef sensor_channel_get_t
|
|
|
|
* @brief Callback API for getting a reading from a sensor
|
|
|
|
*
|
2017-02-13 15:30:08 +01:00
|
|
|
* See sensor_channel_get() for argument description
|
2016-06-15 23:18:38 +02:00
|
|
|
*/
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
typedef int (*sensor_channel_get_t)(struct device *dev,
|
|
|
|
enum sensor_channel chan,
|
|
|
|
struct sensor_value *val);
|
|
|
|
|
|
|
|
struct sensor_driver_api {
|
|
|
|
sensor_attr_set_t attr_set;
|
|
|
|
sensor_trigger_set_t trigger_set;
|
|
|
|
sensor_sample_fetch_t sample_fetch;
|
|
|
|
sensor_channel_get_t channel_get;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Set an attribute for a sensor
|
|
|
|
*
|
|
|
|
* @param dev Pointer to the sensor device
|
|
|
|
* @param 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.
|
|
|
|
* @param attr The attribute to set
|
|
|
|
* @param val The value to set the attribute to
|
|
|
|
*
|
2016-03-10 15:47:06 +01:00
|
|
|
* @return 0 if successful, negative errno code if failure.
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
*/
|
2017-09-29 11:56:55 +02:00
|
|
|
__syscall int sensor_attr_set(struct device *dev,
|
|
|
|
enum sensor_channel chan,
|
|
|
|
enum sensor_attribute attr,
|
|
|
|
const struct sensor_value *val);
|
|
|
|
|
|
|
|
static inline int _impl_sensor_attr_set(struct device *dev,
|
|
|
|
enum sensor_channel chan,
|
|
|
|
enum sensor_attribute attr,
|
|
|
|
const struct sensor_value *val)
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
{
|
2016-10-22 11:00:28 +02:00
|
|
|
const struct sensor_driver_api *api = dev->driver_api;
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
|
|
|
|
if (!api->attr_set) {
|
2016-03-09 18:54:42 +01:00
|
|
|
return -ENOTSUP;
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return api->attr_set(dev, chan, attr, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Activate a sensor's trigger and set the trigger handler
|
|
|
|
*
|
2017-10-29 12:10:22 +01:00
|
|
|
* 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
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
* driver. It is currently up to the caller to ensure that the handler
|
|
|
|
* does not overflow the stack.
|
|
|
|
*
|
2017-09-29 11:56:55 +02:00
|
|
|
* This API is not permitted for user threads.
|
|
|
|
*
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
* @param dev Pointer to the sensor device
|
|
|
|
* @param trig The trigger to activate
|
|
|
|
* @param handler The function that should be called when the trigger
|
|
|
|
* fires
|
|
|
|
*
|
2016-03-10 15:47:06 +01:00
|
|
|
* @return 0 if successful, negative errno code if failure.
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
*/
|
|
|
|
static inline int sensor_trigger_set(struct device *dev,
|
|
|
|
struct sensor_trigger *trig,
|
|
|
|
sensor_trigger_handler_t handler)
|
|
|
|
{
|
2016-10-22 11:00:28 +02:00
|
|
|
const struct sensor_driver_api *api = dev->driver_api;
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
|
|
|
|
if (!api->trigger_set) {
|
2016-03-09 18:54:42 +01:00
|
|
|
return -ENOTSUP;
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return api->trigger_set(dev, trig, handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 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 @ref
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* @param dev Pointer to the sensor device
|
|
|
|
*
|
2016-03-10 15:47:06 +01:00
|
|
|
* @return 0 if successful, negative errno code if failure.
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
*/
|
2017-09-29 11:56:55 +02:00
|
|
|
__syscall int sensor_sample_fetch(struct device *dev);
|
|
|
|
|
|
|
|
static inline int _impl_sensor_sample_fetch(struct device *dev)
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
{
|
2016-10-22 11:00:28 +02:00
|
|
|
const struct sensor_driver_api *api = dev->driver_api;
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
|
2016-04-11 13:49:26 +02:00
|
|
|
return api->sample_fetch(dev, SENSOR_CHAN_ALL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 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 @ref 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.
|
|
|
|
*
|
|
|
|
* @param dev Pointer to the sensor device
|
2016-06-15 03:45:43 +02:00
|
|
|
* @param type The channel that needs updated
|
2016-04-11 13:49:26 +02:00
|
|
|
*
|
|
|
|
* @return 0 if successful, negative errno code if failure.
|
|
|
|
*/
|
2017-09-29 11:56:55 +02:00
|
|
|
__syscall int sensor_sample_fetch_chan(struct device *dev,
|
|
|
|
enum sensor_channel type);
|
|
|
|
|
|
|
|
static inline int _impl_sensor_sample_fetch_chan(struct device *dev,
|
|
|
|
enum sensor_channel type)
|
2016-04-11 13:49:26 +02:00
|
|
|
{
|
2016-10-22 11:00:28 +02:00
|
|
|
const struct sensor_driver_api *api = dev->driver_api;
|
2016-04-11 13:49:26 +02:00
|
|
|
|
|
|
|
return api->sample_fetch(dev, type);
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 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
|
2016-04-11 13:49:26 +02:00
|
|
|
* obtained by calling @ref sensor_sample_fetch or
|
|
|
|
* @ref sensor_sample_fetch_chan. It is guaranteed that two subsequent
|
|
|
|
* calls of this function for the same channels will yield the same
|
|
|
|
* value, if @ref sensor_sample_fetch or @ref sensor_sample_fetch_chan
|
|
|
|
* has not been called in the meantime.
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
*
|
2016-05-05 15:12:28 +02:00
|
|
|
* For vectorial data samples you can request all axes in just one call
|
2017-01-26 15:36:57 +01:00
|
|
|
* by passing the specific channel with _XYZ suffix. The sample will be
|
2016-05-05 15:12:28 +02:00
|
|
|
* returned at val[0], val[1] and val[2] (X, Y and Z in that order).
|
|
|
|
*
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
* @param dev Pointer to the sensor device
|
|
|
|
* @param chan The channel to read
|
|
|
|
* @param val Where to store the value
|
|
|
|
*
|
2016-03-10 15:47:06 +01:00
|
|
|
* @return 0 if successful, negative errno code if failure.
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
*/
|
2017-09-29 11:56:55 +02:00
|
|
|
__syscall int sensor_channel_get(struct device *dev,
|
|
|
|
enum sensor_channel chan,
|
|
|
|
struct sensor_value *val);
|
|
|
|
|
|
|
|
static inline int _impl_sensor_channel_get(struct device *dev,
|
|
|
|
enum sensor_channel chan,
|
|
|
|
struct sensor_value *val)
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
{
|
2016-10-22 11:00:28 +02:00
|
|
|
const struct sensor_driver_api *api = dev->driver_api;
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
|
|
|
|
return api->channel_get(dev, chan, val);
|
|
|
|
}
|
|
|
|
|
2016-03-31 14:01:47 +02:00
|
|
|
/**
|
|
|
|
* @brief The value of gravitational constant in micro m/s^2.
|
|
|
|
*/
|
|
|
|
#define SENSOR_G 9806650LL
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief The value of constant PI in micros.
|
|
|
|
*/
|
|
|
|
#define SENSOR_PI 3141592LL
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Helper function to convert acceleration from m/s^2 to Gs
|
|
|
|
*
|
|
|
|
* @param ms2 A pointer to a sensor_value struct holding the acceleration,
|
|
|
|
* in m/s^2.
|
|
|
|
*
|
|
|
|
* @return The converted value, in Gs.
|
|
|
|
*/
|
2017-04-21 17:55:34 +02:00
|
|
|
static inline s32_t sensor_ms2_to_g(const struct sensor_value *ms2)
|
2016-03-31 14:01:47 +02:00
|
|
|
{
|
2017-04-21 17:55:34 +02:00
|
|
|
s64_t micro_ms2 = ms2->val1 * 1000000LL + ms2->val2;
|
2016-03-31 14:01:47 +02:00
|
|
|
|
|
|
|
if (micro_ms2 > 0) {
|
|
|
|
return (micro_ms2 + SENSOR_G / 2) / SENSOR_G;
|
|
|
|
} else {
|
|
|
|
return (micro_ms2 - SENSOR_G / 2) / SENSOR_G;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Helper function to convert acceleration from Gs to m/s^2
|
|
|
|
*
|
|
|
|
* @param g The G value to be converted.
|
|
|
|
* @param ms2 A pointer to a sensor_value struct, where the result is stored.
|
|
|
|
*/
|
2017-04-21 17:55:34 +02:00
|
|
|
static inline void sensor_g_to_ms2(s32_t g, struct sensor_value *ms2)
|
2016-03-31 14:01:47 +02:00
|
|
|
{
|
2017-04-21 17:55:34 +02:00
|
|
|
ms2->val1 = ((s64_t)g * SENSOR_G) / 1000000LL;
|
|
|
|
ms2->val2 = ((s64_t)g * SENSOR_G) % 1000000LL;
|
2016-03-31 14:01:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Helper function for converting radians to degrees.
|
|
|
|
*
|
|
|
|
* @param rad A pointer to a sensor_value struct, holding the value in radians.
|
|
|
|
*
|
|
|
|
* @return The converted value, in degrees.
|
|
|
|
*/
|
2017-04-21 17:55:34 +02:00
|
|
|
static inline s32_t sensor_rad_to_degrees(const struct sensor_value *rad)
|
2016-03-31 14:01:47 +02:00
|
|
|
{
|
2017-04-21 17:55:34 +02:00
|
|
|
s64_t micro_rad_s = rad->val1 * 1000000LL + rad->val2;
|
2016-03-31 14:01:47 +02:00
|
|
|
|
|
|
|
if (micro_rad_s > 0) {
|
|
|
|
return (micro_rad_s * 180LL + SENSOR_PI / 2) / SENSOR_PI;
|
|
|
|
} else {
|
|
|
|
return (micro_rad_s * 180LL - SENSOR_PI / 2) / SENSOR_PI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Helper function for converting degrees to radians.
|
|
|
|
*
|
|
|
|
* @param d The value (in degrees) to be converted.
|
|
|
|
* @param rad A pointer to a sensor_value struct, where the result is stored.
|
|
|
|
*/
|
2017-04-21 17:55:34 +02:00
|
|
|
static inline void sensor_degrees_to_rad(s32_t d, struct sensor_value *rad)
|
2016-03-31 14:01:47 +02:00
|
|
|
{
|
2017-04-21 17:55:34 +02:00
|
|
|
rad->val1 = ((s64_t)d * SENSOR_PI / 180LL) / 1000000LL;
|
|
|
|
rad->val2 = ((s64_t)d * SENSOR_PI / 180LL) % 1000000LL;
|
2016-03-31 14:01:47 +02:00
|
|
|
}
|
|
|
|
|
2017-01-04 21:22:54 +01:00
|
|
|
/**
|
|
|
|
* @brief Helper function for converting struct sensor_value to double.
|
|
|
|
*
|
|
|
|
* @param val A pointer to a sensor_value struct.
|
|
|
|
* @return The converted value.
|
|
|
|
*/
|
|
|
|
static inline double sensor_value_to_double(struct sensor_value *val)
|
|
|
|
{
|
2017-01-12 14:28:25 +01:00
|
|
|
return (double)val->val1 + (double)val->val2 / 1000000;
|
2017-01-04 21:22:54 +01:00
|
|
|
}
|
|
|
|
|
2017-09-29 11:56:55 +02:00
|
|
|
#include <syscalls/sensor.h>
|
2016-04-21 16:13:46 +02:00
|
|
|
|
Introduce new sensor API
Sensor drivers expose one or more channels, corresponding to each
individual quantity they can measure. Such quantities may be different
altogether (e.g. temperature and pressure) or different axes for the
same unit (e.g. three axes of acceleration). Before reading channels, a
driver must be explicitly instructed to obtain a sample from the device.
This helps accommodate sensors which can only read all channels at once,
and also helps ensure coherence of measurements and optimize I2C/SPI
traffic.
Channels can be read as floating point values or struct sensor_value.
The latter consists of a pair of integers and a type field which
dictates how to interpret said integers. The most common type is INT
(where the second value is ignored) or INT_PLUS_MICRO, which means the
second value should be multiplied by 1.0e-6 and added to the first.
A sensor driver may support one or more triggers, corresponding to
interrupts or timers. Registering for a trigger involves supplying the
driver with a callback which is called when a condition is reached.
Examples of trigger types are: data ready, timer expiration, any-motion,
near/far.
Finally, sensors support attributes such as sample frequency,
measurement accuracy or threshold values for triggers. However, runtime
configuration is discouraged, in the interest of keeping code simple.
Origin: Original
Change-Id: Id290fe544b6f7eccc4b109f3912fca1692e55623
Signed-off-by: Vlad Dogaru <vlad.dogaru@intel.com>
2016-01-22 13:59:10 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2018-09-14 19:43:44 +02:00
|
|
|
#endif /* ZEPHYR_INCLUDE_SENSOR_H_ */
|