Sensor class: accelerometers, gyroscopes, magnetometers, temperature and pressure sensors.
More...
|
| | LIS2DW12 |
| | ST LIS2DW12 accelerometer.
|
| |
| | Sensor drivers |
| | Interface for sensor drivers.
|
| |
| | LSM6DSO |
| | ST LSM6DSO accelerometer and gyroscope; only the accelerometer is used.
|
| |
| | MMC5603NJ |
| | MEMSIC MMC5603NJ magnetometer.
|
| |
| | BMP390 |
| | Bosch BMP380/BMP390 pressure sensor (compatible bosch,bmp380).
|
| |
| | Simulators |
| | Simulated sensors, measuring what their simulator API sets.
|
| |
| | nRF5 TEMP |
| | Nordic nRF5 die temperature sensor (TEMP).
|
| |
| | SF32LB TSEN |
| | SiFli SF32LB die temperature sensor (TSEN).
|
| |
|
| typedef const uint8_t *(* | pbl_sensor_next_frame_t) (const struct pbl_sensor_batch *batch, uint8_t type, uint16_t *pos, uint64_t *timestamp_us) |
| | Find the next frame of a batch holding the channels of a type.
|
| |
|
| enum | pbl_sensor_type {
PBL_SENSOR_ACCEL
, PBL_SENSOR_ANGL_VEL
, PBL_SENSOR_MAGN
, PBL_SENSOR_TEMP
,
PBL_SENSOR_PRESSURE
, PBL_SENSOR_TYPE_COUNT
} |
| | Channel type. More...
|
| |
| enum | pbl_sensor_mod {
PBL_SENSOR_MOD_NONE
, PBL_SENSOR_MOD_X
, PBL_SENSOR_MOD_Y
, PBL_SENSOR_MOD_Z
,
PBL_SENSOR_MOD_TEMP_AMBIENT
, PBL_SENSOR_MOD_TEMP_OBJECT
} |
| | Channel modifier, refining what a channel of a type measures. More...
|
| |
| enum | pbl_sensor_format {
PBL_SENSOR_FMT_S8
, PBL_SENSOR_FMT_S16_LE
, PBL_SENSOR_FMT_S16_BE
, PBL_SENSOR_FMT_U16_LE
,
PBL_SENSOR_FMT_U16_BE
, PBL_SENSOR_FMT_S24_LE
, PBL_SENSOR_FMT_U24_LE
, PBL_SENSOR_FMT_S32_LE
} |
| | Encoding of a channel in a frame. More...
|
| |
| enum | pbl_sensor_attr {
PBL_SENSOR_ATTR_SAMPLING_FREQUENCY
, PBL_SENSOR_ATTR_REPORT_LATENCY
, PBL_SENSOR_ATTR_BATCH_MAX
, PBL_SENSOR_ATTR_RANGE
,
PBL_SENSOR_ATTR_COUNT
} |
| | Attribute. More...
|
| |
| enum | pbl_sensor_avail_kind { PBL_SENSOR_AVAIL_LIST
, PBL_SENSOR_AVAIL_RANGE
} |
| | How the values an attribute takes are given. More...
|
| |
| enum | pbl_sensor_event_type { PBL_SENSOR_EVENT_SHAKE
, PBL_SENSOR_EVENT_DOUBLE_TAP
, PBL_SENSOR_EVENT_COUNT
} |
| | Event type. More...
|
| |
| enum | pbl_sensor_event_attr { PBL_SENSOR_EVENT_ATTR_THRESHOLD
} |
| | Event attribute. More...
|
| |
|
| const struct pbl_sensor * | pbl_sensor_next (const struct pbl_sensor *prev) |
| | Iterate over the sensors.
|
| |
| bool | pbl_sensor_is_ready (const struct pbl_sensor *sensor) |
| | Check whether a sensor is ready to be used.
|
| |
| const char * | pbl_sensor_get_name (const struct pbl_sensor *sensor) |
| | Get the name of a sensor.
|
| |
| static uint8_t | pbl_sensor_num_values (struct pbl_sensor_chan_spec spec) |
| | Get the number of values of a channel: 3 for a whole vector, 1 otherwise.
|
| |
| bool | pbl_sensor_has_type (const struct pbl_sensor *sensor, enum pbl_sensor_type type) |
| | Check whether a sensor measures a type.
|
| |
| const struct pbl_sensor_chan * | pbl_sensor_get_chans (const struct pbl_sensor *sensor, uint8_t *num) |
| | Get the channels of a sensor.
|
| |
| bool | pbl_sensor_has_event (const struct pbl_sensor *sensor, enum pbl_sensor_event_type type) |
| | Check whether a sensor detects an event.
|
| |
| uint16_t | pbl_sensor_num_frames (const struct pbl_sensor_batch *batch, enum pbl_sensor_type type) |
| | Get the number of frames of a batch holding the channels of a type.
|
| |
| uint64_t | pbl_sensor_frame_time (const struct pbl_sensor_batch *batch, enum pbl_sensor_type type, uint16_t i) |
| | Get the time of a frame of a batch.
|
| |
| int | pbl_sensor_read (const struct pbl_sensor *sensor, struct pbl_sensor_chan_spec spec, uint32_t scale, int32_t *val, uint64_t *timestamp_us) |
| | Read the latest values of a channel.
|
| |
| int | pbl_sensor_attr_set (const struct pbl_sensor *sensor, enum pbl_sensor_type type, enum pbl_sensor_attr attr, int32_t *val) |
| | Set an attribute.
|
| |
| int | pbl_sensor_attr_get (const struct pbl_sensor *sensor, enum pbl_sensor_type type, enum pbl_sensor_attr attr, int32_t *val) |
| | Get an attribute.
|
| |
| int | pbl_sensor_attr_get_avail (const struct pbl_sensor *sensor, enum pbl_sensor_type type, enum pbl_sensor_attr attr, struct pbl_sensor_attr_avail *avail) |
| | Get the values an attribute takes.
|
| |
| int | pbl_sensor_set_listener (const struct pbl_sensor *sensor, const struct pbl_sensor_listener *listener) |
| | Set the listener of batches and events.
|
| |
| int | pbl_sensor_flush (const struct pbl_sensor *sensor) |
| | Report the frames the sensor has queued, without waiting for the report latency.
|
| |
| int | pbl_sensor_set_event (const struct pbl_sensor *sensor, enum pbl_sensor_event_type type, bool on) |
| | Enable or disable the detection of an event.
|
| |
| int | pbl_sensor_event_attr_set (const struct pbl_sensor *sensor, enum pbl_sensor_event_type type, enum pbl_sensor_event_attr attr, int32_t *val) |
| | Set an event attribute.
|
| |
| int | pbl_sensor_event_attr_get (const struct pbl_sensor *sensor, enum pbl_sensor_event_type type, enum pbl_sensor_event_attr attr, int32_t *val) |
| | Get an event attribute.
|
| |
| bool | pbl_sensor_get_event (const struct pbl_sensor *sensor, enum pbl_sensor_event_type type) |
| | Check whether the detection of an event is enabled.
|
| |
| int | pbl_sensor_decode (const struct pbl_sensor *sensor, const struct pbl_sensor_batch *batch, struct pbl_sensor_chan_spec spec, uint32_t scale, uint16_t first, uint16_t count, int32_t *out) |
| | Decode a channel from frames of a batch, in SI units and the device frame.
|
| |
| int | pbl_sensor_decode_raw (const struct pbl_sensor_batch *batch, struct pbl_sensor_chan_spec spec, uint16_t first, uint16_t count, int32_t *out) |
| | Decode the raw values of a channel from frames of a batch, in the sensor frame.
|
| |
| int | pbl_sensor_convert (const struct pbl_sensor_batch *batch, struct pbl_sensor_chan_spec spec, uint32_t scale, uint16_t count, const int32_t *raw, int32_t *out) |
| | Convert raw values from pbl_sensor_decode_raw() to SI units, in the sensor frame.
|
| |
| void | pbl_sensor_get_mount_matrix (const struct pbl_sensor *sensor, int8_t matrix[3][3]) |
| | Get the mount matrix of a sensor.
|
| |
| void | pbl_sensor_mount_apply (const struct pbl_sensor *sensor, uint16_t count, int32_t *xyz) |
| | Move vectors from the sensor frame to the device frame, with the mount matrix.
|
| |
| void | pbl_sensor_hold (const struct pbl_sensor *sensor, const struct pbl_sensor_batch *batch) |
| | Keep the buffer of a batch past the listener call.
|
| |
| void | pbl_sensor_release (const struct pbl_sensor *sensor, const struct pbl_sensor_batch *batch) |
| | Give back the buffer of a batch kept with pbl_sensor_hold().
|
| |
| static uint32_t | pbl_sensor_mhz_to_us (int32_t mhz) |
| | Convert a sampling frequency to the longest interval sampling at least that fast.
|
| |
| static int32_t | pbl_sensor_us_to_mhz (uint32_t us) |
| | Convert a sampling interval to a frequency, rounded to the nearest.
|
| |
Sensor class: accelerometers, gyroscopes, magnetometers, temperature and pressure sensors.
A sensor is a struct pbl_sensor device measuring one or more channel types, e.g. an IMU measuring acceleration, angular velocity and temperature. Drivers do not convert their data: they hand over frames as the hardware produced them, together with channel descriptors saying where each channel is in a frame, how it is encoded and how it scales to the SI unit of its type.
A channel is a type, a modifier and an index, a struct pbl_sensor_chan_spec. Vector types have a channel per axis; scalar types have one without modifier, or one per modifier when a sensor measures the type several ways, as an infrared thermometer measuring the ambient and the object temperature. The index tells apart channels of the same type and modifier, and is usually 0. PBL_SENSOR_MOD_NONE selects the whole vector of a vector type, or the plain channel of a scalar type; any other modifier selects that channel alone.
Values come in the SI unit of their type times a multiplier the caller picks, a power of ten: 1000 gives mm/s², m°C or mPa. They are rounded to the nearest, and saturate at the limits of an int32_t, which reads and decodes tell with -ERANGE. pbl_sensor_read() and pbl_sensor_decode() give them with the board's mount matrix applied to vectors, in the device frame. pbl_sensor_decode_raw() gives the raw values of frames instead, in the sensor frame, for processing before pbl_sensor_convert() takes them to SI units; pbl_sensor_mount_apply() then moves vectors to the device frame, with the matrix pbl_sensor_get_mount_matrix() publishes.
A sensor has one mount matrix. A part whose types do not share axes, as a magnetometer die turned with respect to the accelerometer one, describes them all in the axes of one of them: the channel modifiers name the axis in that frame, and a negative scale flips it.
pbl_sensor_get_chans() lists the channels of a sensor. pbl_sensor_read() returns the latest values of one: a fresh conversion, or the latest frame when the sensor is streaming. A sensor streams while it has a sampling frequency and a report latency, both attributes: it reports batches of frames to the listener its consumer registered with pbl_sensor_set_listener(), no later than the latency after sampling them, and pbl_sensor_flush() asks for what it has queued right away. It also reports events such as shakes, once enabled with pbl_sensor_set_event(). pbl_sensor_attr_get_avail() tells the values an attribute takes.
A sensor has one consumer: its listener, and the one setting its attributes. Several users of one sensor share it through a service that owns it.
Batches live in buffers owned by the class, sized by the driver and DMA-safe, so a driver can read a hardware FIFO straight into one, from its interrupt if its bus allows, and report it with pbl_sensor_report() from any context. Frames the offsets and stride of a batch cannot describe, as the tagged words of a FIFO shared by types sampled at different rates, are found by a function the driver gives with the batch; their conversion stays the same. The listener runs on the high priority system work queue, without the device lock, so it may take locks of its own and call back into the device. Once it returns the buffer goes back to the driver, unless the listener kept it with pbl_sensor_hold() to work on it later.
int32_t millicelsius;
nullptr) == 0) {
...
}
int pbl_sensor_read(const struct pbl_sensor *sensor, struct pbl_sensor_chan_spec spec, uint32_t scale, int32_t *val, uint64_t *timestamp_us)
Read the latest values of a channel.
#define PBL_SENSOR_SPEC(...)
A struct pbl_sensor_chan_spec: a type, then optionally a modifier and an index.
Definition sensor.h:154
const struct pbl_sensor *const DIE_TEMP
The board's die temperature sensor.
@ PBL_SENSOR_TEMP
Temperature, in °C.
Definition sensor.h:115
Streaming:
void *user_data) {
int32_t mm_s2[3];
mm_s2) > 0) {
...
}
}
}
int32_t mhz = 25000;
int32_t latency_us = 1000000;
A sensor.
Definition driver.h:142
Batch of frames, oldest first.
Definition sensor.h:256
const struct pbl_sensor *const ACCEL
The board's accelerometer, which may also measure angular rate.
uint16_t pbl_sensor_num_frames(const struct pbl_sensor_batch *batch, enum pbl_sensor_type type)
Get the number of frames of a batch holding the channels of a type.
int pbl_sensor_attr_set(const struct pbl_sensor *sensor, enum pbl_sensor_type type, enum pbl_sensor_attr attr, int32_t *val)
Set an attribute.
int pbl_sensor_decode(const struct pbl_sensor *sensor, const struct pbl_sensor_batch *batch, struct pbl_sensor_chan_spec spec, uint32_t scale, uint16_t first, uint16_t count, int32_t *out)
Decode a channel from frames of a batch, in SI units and the device frame.
int pbl_sensor_set_listener(const struct pbl_sensor *sensor, const struct pbl_sensor_listener *listener)
Set the listener of batches and events.
@ PBL_SENSOR_ACCEL
Acceleration, in m/s².
Definition sensor.h:109
@ PBL_SENSOR_ATTR_REPORT_LATENCY
Report latency, the longest the driver holds frames before reporting them, in microseconds: PBL_SENSO...
Definition sensor.h:316
@ PBL_SENSOR_ATTR_SAMPLING_FREQUENCY
Sampling frequency in millihertz.
Definition sensor.h:307
Consumer of a sensor's batches and events.
Definition sensor.h:391
void(* batch)(const struct pbl_sensor *sensor, const struct pbl_sensor_batch *batch, void *user_data)
Optional.
Definition sensor.h:393
◆ pbl_sensor_chan_spec
| struct pbl_sensor_chan_spec |
| Data Fields |
|
uint8_t |
idx |
Index among the channels of the same type and modifier, usually 0. |
|
uint8_t |
mod |
Modifier, an enum pbl_sensor_mod: PBL_SENSOR_MOD_NONE for a whole vector. |
|
uint8_t |
type |
Type, an enum pbl_sensor_type. |
◆ pbl_sensor_chan
Channel descriptor: where a channel is in a frame and how to decode it.
The value in the SI unit of the type is (raw * scale_num / scale_den + bias) * 10^scale_exp, computed in 64 bits: the exponent sets the resolution the scale and bias are expressed at, e.g. -6 for µm/s². A driver whose conversion is not linear applies the compensation itself and stores the compensated value in the frame with a fixed scale.
| Data Fields |
|
int32_t |
bias |
Offset added after scaling, in units of 10^scale_exp. |
|
uint8_t |
format |
Encoding, an enum pbl_sensor_format. |
|
uint8_t |
idx |
Index among the channels of the same type and modifier. |
|
uint8_t |
mod |
Modifier, an enum pbl_sensor_mod; axes are in the sensor frame. |
|
uint8_t |
offset |
Byte offset in the frame. |
|
int32_t |
scale_den |
Scale denominator, above 0. |
|
int8_t |
scale_exp |
Decimal exponent of the scale and bias, from -9 to 9. |
|
int32_t |
scale_num |
Scale numerator. |
|
uint8_t |
type |
Type, an enum pbl_sensor_type. |
◆ pbl_sensor_batch
Batch of frames, oldest first.
Every frame holds the same channels at the same offsets, a stride apart, unless the driver gives a function finding them: then frames may hold different channels, come at different rates and carry their own time.
| Data Fields |
|
const struct pbl_sensor_chan * |
chans |
Channels of each frame. |
|
const uint8_t * |
data |
First frame, in a buffer from pbl_sensor_buf_alloc(). |
|
uint32_t |
interval_us |
Interval between frames, in microseconds: the one measured, when the driver measures it. |
|
pbl_sensor_next_frame_t |
next_frame |
Optional. Finds the frames, instead of the stride.
|
|
uint8_t |
num_chans |
Number of channels. |
|
uint16_t |
num_frames |
Number of frames; unused with next_frame. |
|
uint16_t |
size |
Size of the data in bytes, for next_frame. |
|
uint8_t |
stride |
Bytes from one frame to the next. |
|
uint64_t |
timestamp_us |
Time of the last frame, in microseconds of uptime. |
◆ pbl_sensor_frame
A single frame, as returned by the driver read operation.
| Data Fields |
|
const struct pbl_sensor_chan * |
chans |
Channels of the frame. |
|
uint8_t |
data[PBL_SENSOR_FRAME_MAX] |
Frame data. |
|
uint8_t |
num_chans |
Number of channels. |
|
uint64_t |
timestamp_us |
Time of the frame, in microseconds of uptime. |
◆ pbl_sensor_attr_avail
| struct pbl_sensor_attr_avail |
Values an attribute takes.
| Data Fields |
|
uint8_t |
kind |
An enum pbl_sensor_avail_kind. |
|
uint8_t |
num |
Number of values. |
|
const int32_t * |
vals |
Values, in the unit of the attribute, ascending. |
◆ pbl_sensor_event
| Data Fields |
|
int8_t |
direction |
Direction along the axis, 1 or -1. |
|
enum pbl_sensor_mod |
mod |
Axis it was detected on, an axis modifier: in the sensor frame from the driver, the device frame to listeners. |
|
uint64_t |
timestamp_us |
Time it was detected, in microseconds of uptime. |
|
enum pbl_sensor_event_type |
type |
Type. |
◆ PBL_SENSOR_CHAN
| #define PBL_SENSOR_CHAN |
( |
|
_type, |
|
|
|
_mod, |
|
|
|
_offset, |
|
|
|
_format, |
|
|
|
_num, |
|
|
|
_den, |
|
|
|
_exp, |
|
|
|
_bias, |
|
|
|
... |
|
) |
| |
Value: {.type = (_type), \
.mod = (_mod), \
.offset = (_offset), \
.format = (_format), \
.scale_exp = (int8_t)((_exp) + 0 * sizeof(char[((_exp) >= -9 && (_exp) <= 9) ? 1 : -1])), \
.scale_num = (_num), \
.scale_den = (_den) + 0 * sizeof(char[((_den) > 0) ? 1 : -1]), \
.bias = (_bias), \
__VA_ARGS__}
Initializer for a struct pbl_sensor_chan.
- Parameters
-
| _type | Type. |
| _mod | Modifier, axes in the sensor frame. |
| _offset | Byte offset in the frame. |
| _format | Encoding. |
| _num | Scale numerator. |
| _den | Scale denominator, above 0, checked at build time. |
| _exp | Decimal exponent of the scale and bias, from -9 to 9, checked at build time. |
| _bias | Offset added after scaling, in units of 10^_exp. |
| ... | Optional, more designated initializers, such as .idx = 1. |
◆ PBL_SENSOR_FRAME_MAX
| #define PBL_SENSOR_FRAME_MAX 24U |
Largest frame a driver returns from a read.
◆ PBL_SENSOR_LATENCY_NONE
| #define PBL_SENSOR_LATENCY_NONE (-1) |
Report latency reporting no batches.
◆ PBL_SENSOR_SPEC
◆ pbl_sensor_next_frame_t
| typedef const uint8_t *(* pbl_sensor_next_frame_t) (const struct pbl_sensor_batch *batch, uint8_t type, uint16_t *pos, uint64_t *timestamp_us) |
Find the next frame of a batch holding the channels of a type.
Given by a driver with batches whose frames the offsets and stride cannot describe. Channel offsets count from the frame it returns.
- Parameters
-
| batch | Batch. |
| type | Type, an enum pbl_sensor_type. |
| [in,out] | pos | Where to look from, in bytes from the start of the batch data: 0 at first, updated past the frame returned. |
| [out] | timestamp_us | Time of the frame, in microseconds of uptime. |
- Returns
- The frame, or NULL if the batch has no more of them.
◆ pbl_sensor_attr
Attribute.
Set and read per channel type: a driver applying an attribute to the whole device, as the report latency of a FIFO shared by all its channels, ignores the type.
| Enumerator |
|---|
| PBL_SENSOR_ATTR_SAMPLING_FREQUENCY | Sampling frequency in millihertz.
The driver selects the lowest supported frequency equal to or higher than the requested one, saturating at the highest it supports, and reports the frames sampled at the previous one first. 0 stops sampling, except what enabled events need.
|
| PBL_SENSOR_ATTR_REPORT_LATENCY | Report latency, the longest the driver holds frames before reporting them, in microseconds: PBL_SENSOR_LATENCY_NONE reports no batches, the default, 0 reports every frame as soon as it is acquired, and more lets the driver queue frames that long, an upper bound it can use to save power.
The driver keeps to it when the sampling frequency changes, and selects the closest it supports, a whole number of frames, once a sampling frequency is set. Drivers without a FIFO report every frame.
|
| PBL_SENSOR_ATTR_BATCH_MAX | Read-only.
Most frames the driver reports in a batch, the depth of its FIFO.
|
| PBL_SENSOR_ATTR_RANGE | Range, the largest magnitude measured, in the SI unit of the type times 1000, e.g.
mm/s². The driver selects the smallest range it supports holding the requested one, saturating at the largest, and reports the frames measured at the previous one first.
|
| PBL_SENSOR_ATTR_COUNT | Number of attributes.
|
◆ pbl_sensor_avail_kind
How the values an attribute takes are given.
| Enumerator |
|---|
| PBL_SENSOR_AVAIL_LIST | Each of the values.
|
| PBL_SENSOR_AVAIL_RANGE | Three values: the smallest, the step and the largest.
|
◆ pbl_sensor_event_attr
Event attribute.
Set and read per event type, whether its detection is enabled or not.
| Enumerator |
|---|
| PBL_SENSOR_EVENT_ATTR_THRESHOLD | Threshold the event triggers above, in the SI unit of the measured type times 1000, e.g.
mm/s² for a shake. The driver selects the nearest it supports and writes it back.
|
◆ pbl_sensor_event_type
Event type.
| Enumerator |
|---|
| PBL_SENSOR_EVENT_SHAKE | Shake, a motion above PBL_SENSOR_EVENT_ATTR_THRESHOLD.
|
| PBL_SENSOR_EVENT_DOUBLE_TAP | Double tap on the device body.
|
| PBL_SENSOR_EVENT_COUNT | Number of event types.
|
◆ pbl_sensor_format
Encoding of a channel in a frame.
| Enumerator |
|---|
| PBL_SENSOR_FMT_S8 | Signed 8 bits.
|
| PBL_SENSOR_FMT_S16_LE | Signed 16 bits, little-endian.
|
| PBL_SENSOR_FMT_S16_BE | Signed 16 bits, big-endian.
|
| PBL_SENSOR_FMT_U16_LE | Unsigned 16 bits, little-endian.
|
| PBL_SENSOR_FMT_U16_BE | Unsigned 16 bits, big-endian.
|
| PBL_SENSOR_FMT_S24_LE | Signed 24 bits, little-endian.
|
| PBL_SENSOR_FMT_U24_LE | Unsigned 24 bits, little-endian.
|
| PBL_SENSOR_FMT_S32_LE | Signed 32 bits, little-endian.
|
◆ pbl_sensor_mod
Channel modifier, refining what a channel of a type measures.
| Enumerator |
|---|
| PBL_SENSOR_MOD_NONE | None, for scalar types.
|
| PBL_SENSOR_MOD_X | X axis; in the device frame, toward the right of the device.
|
| PBL_SENSOR_MOD_Y | Y axis; in the device frame, toward the top of the device.
|
| PBL_SENSOR_MOD_Z | Z axis; in the device frame, out of the display.
|
| PBL_SENSOR_MOD_TEMP_AMBIENT | Ambient temperature, next to an object temperature.
|
| PBL_SENSOR_MOD_TEMP_OBJECT | Temperature of an object, as measured by infrared thermometers.
|
◆ pbl_sensor_type
Channel type.
| Enumerator |
|---|
| PBL_SENSOR_ACCEL | Acceleration, in m/s².
|
| PBL_SENSOR_ANGL_VEL | Angular velocity, in rad/s.
|
| PBL_SENSOR_MAGN | Magnetic field, in T.
|
| PBL_SENSOR_TEMP | Temperature, in °C.
|
| PBL_SENSOR_PRESSURE | Pressure, in Pa.
|
| PBL_SENSOR_TYPE_COUNT | Number of channel types.
|
◆ pbl_sensor_attr_get()
Get an attribute.
- Parameters
-
| sensor | Sensor. |
| type | Type the attribute applies to. |
| attr | Attribute. |
| [out] | val | Value. |
- Returns
- 0, -ENODEV if the sensor is not ready, -ENOTSUP if the attribute is not supported for
type, or a negative errno.
◆ pbl_sensor_attr_get_avail()
Get the values an attribute takes.
- Parameters
-
| sensor | Sensor. |
| type | Type the attribute applies to. |
| attr | Attribute. |
| [out] | avail | Values, valid for as long as the sensor. |
- Returns
- 0, -ENODEV if the sensor is not ready, -ENOTSUP if the driver does not tell them for
attr and type, or a negative errno.
◆ pbl_sensor_attr_set()
Set an attribute.
- Parameters
-
| sensor | Sensor. |
| type | Type the attribute applies to. |
| attr | Attribute. |
| [in,out] | val | Requested value, updated to the value applied. |
- Returns
- 0, -ENODEV if the sensor is not ready, -ENOTSUP if the attribute is not supported for
type, -EACCES for a read-only attribute, or a negative errno.
◆ pbl_sensor_convert()
Convert raw values from pbl_sensor_decode_raw() to SI units, in the sensor frame.
Applies the scale and bias of each channel. Converting a value derived from raw values, such as an average, gives the same as averaging converted values; a value whose channel has a bias, as a difference of raw values, does not.
- Parameters
-
- Returns
- Number of values per frame, -ENOENT if the batch does not have the channel, -EINVAL for an invalid
scale, or -ERANGE if a value saturated: out is filled all the same.
◆ pbl_sensor_decode()
Decode a channel from frames of a batch, in SI units and the device frame.
The same as pbl_sensor_decode_raw(), then pbl_sensor_convert() and pbl_sensor_mount_apply().
- Parameters
-
| sensor | Sensor that reported the batch. |
| batch | Batch. |
| spec | Channel. |
| scale | Multiplier of the SI unit, a power of ten up to 10^9. |
| first | Index of the first frame. |
| count | Number of frames. |
| [out] | out | Values, pbl_sensor_num_values() per frame, axes in the device frame. |
- Returns
- Number of values per frame, -ENOENT if the batch does not have the channel, -EINVAL for an invalid
scale or frames the batch does not have, or -ERANGE if a value saturated: out is filled all the same.
◆ pbl_sensor_decode_raw()
Decode the raw values of a channel from frames of a batch, in the sensor frame.
Raw values are those the hardware produced, sign-extended, before any scaling, offset or mount matrix: vectors come in the sensor's own X, Y, Z order. Keep the batch, or a copy of it, to convert them later with pbl_sensor_convert(): its channel descriptors say how.
- Parameters
-
| batch | Batch. |
| spec | Channel. |
| first | Index of the first frame. |
| count | Number of frames. |
| [out] | out | Raw values, pbl_sensor_num_values() per frame. |
- Returns
- Number of values per frame, -ENOENT if the batch does not have the channel, or -EINVAL for frames the batch does not have.
◆ pbl_sensor_event_attr_get()
Get an event attribute.
- Parameters
-
| sensor | Sensor. |
| type | Event type. |
| attr | Attribute. |
| [out] | val | Value. |
- Returns
- 0, -ENODEV if the sensor is not ready, -ENOTSUP if it does not detect
type or does not support attr for it, or a negative errno.
◆ pbl_sensor_event_attr_set()
Set an event attribute.
- Parameters
-
| sensor | Sensor. |
| type | Event type. |
| attr | Attribute. |
| [in,out] | val | Value to set, then the value applied. |
- Returns
- 0, -ENODEV if the sensor is not ready, -ENOTSUP if it does not detect
type or does not support attr for it, or a negative errno.
◆ pbl_sensor_flush()
| int pbl_sensor_flush |
( |
const struct pbl_sensor * |
sensor | ) |
|
Report the frames the sensor has queued, without waiting for the report latency.
The listener gets them like any batch, after this call.
- Parameters
-
- Returns
- 0, also when nothing was queued, -ENODEV if the sensor is not ready, -ENOTSUP if the driver queues no frames, or a negative errno.
◆ pbl_sensor_frame_time()
Get the time of a frame of a batch.
- Parameters
-
- Returns
- Time of the frame, in microseconds of uptime.
◆ pbl_sensor_get_chans()
Get the channels of a sensor.
Their scale is the one at the default range: batches carry the one in effect.
- Parameters
-
| sensor | Sensor. |
| [out] | num | Number of channels. |
- Returns
- Channels.
◆ pbl_sensor_get_event()
Check whether the detection of an event is enabled.
- Parameters
-
| sensor | Sensor. |
| type | Event type. |
- Returns
- True if enabled.
◆ pbl_sensor_get_mount_matrix()
| void pbl_sensor_get_mount_matrix |
( |
const struct pbl_sensor * |
sensor, |
|
|
int8_t |
matrix[3][3] |
|
) |
| |
Get the mount matrix of a sensor.
Device axis i is the sum over j of matrix[i][j] times sensor axis j.
- Parameters
-
| sensor | Sensor. |
| [out] | matrix | Matrix, rows by device axis. |
◆ pbl_sensor_get_name()
| const char * pbl_sensor_get_name |
( |
const struct pbl_sensor * |
sensor | ) |
|
Get the name of a sensor.
- Parameters
-
- Returns
- Name.
◆ pbl_sensor_has_event()
Check whether a sensor detects an event.
- Parameters
-
| sensor | Sensor. |
| type | Event type. |
- Returns
- True if it does.
◆ pbl_sensor_has_type()
Check whether a sensor measures a type.
- Parameters
-
- Returns
- True if it does.
◆ pbl_sensor_hold()
Keep the buffer of a batch past the listener call.
Called by the listener. Copy the batch itself, and give the buffer back with pbl_sensor_release() once done with it. The driver reports nothing while it has no free buffer, and loses what its hardware cannot queue meanwhile.
- Parameters
-
| sensor | Sensor. |
| batch | Batch. |
◆ pbl_sensor_is_ready()
| bool pbl_sensor_is_ready |
( |
const struct pbl_sensor * |
sensor | ) |
|
Check whether a sensor is ready to be used.
- Parameters
-
- Returns
- True if it is.
◆ pbl_sensor_mhz_to_us()
| static uint32_t pbl_sensor_mhz_to_us |
( |
int32_t |
mhz | ) |
|
|
inlinestatic |
Convert a sampling frequency to the longest interval sampling at least that fast.
0 stays 0.
- Parameters
-
| mhz | Frequency in millihertz. |
- Returns
- Interval in microseconds.
◆ pbl_sensor_mount_apply()
| void pbl_sensor_mount_apply |
( |
const struct pbl_sensor * |
sensor, |
|
|
uint16_t |
count, |
|
|
int32_t * |
xyz |
|
) |
| |
Move vectors from the sensor frame to the device frame, with the mount matrix.
- Parameters
-
| sensor | Sensor. |
| count | Number of vectors. |
| [in,out] | xyz | Vectors, 3 values each. |
◆ pbl_sensor_next()
Iterate over the sensors.
- Parameters
-
| prev | Sensor returned by the previous call, or NULL for the first one. |
- Returns
- Next sensor, or NULL after the last one.
◆ pbl_sensor_num_frames()
Get the number of frames of a batch holding the channels of a type.
- Parameters
-
- Returns
- Number of frames.
◆ pbl_sensor_num_values()
◆ pbl_sensor_read()
Read the latest values of a channel.
Runs a conversion if the sensor is not sampling, which may sleep the caller.
- Parameters
-
| sensor | Sensor. |
| spec | Channel. |
| scale | Multiplier of the SI unit, a power of ten up to 10^9. |
| [out] | val | Values, pbl_sensor_num_values() of them, axes in the device frame. |
| [out] | timestamp_us | Time of the values in microseconds of uptime, or NULL. |
- Returns
- 0, -ENODEV if the sensor is not ready, -ENOTSUP if it does not measure
spec, -EINVAL for an invalid scale, -ERANGE if a value saturated, -ENODATA if it has no values yet, or a negative errno.
◆ pbl_sensor_release()
Give back the buffer of a batch kept with pbl_sensor_hold().
Callable from any context.
- Parameters
-
| sensor | Sensor. |
| batch | Batch. |
◆ pbl_sensor_set_event()
Enable or disable the detection of an event.
- Parameters
-
| sensor | Sensor. |
| type | Event type. |
| on | True to enable, false to disable. |
- Returns
- 0, -ENODEV if the sensor is not ready, -ENOTSUP if it does not detect
type, or a negative errno.
◆ pbl_sensor_set_listener()
Set the listener of batches and events.
A sensor has one listener: remove it before setting another. A call the work queue is in the middle of still completes after the listener is removed.
- Parameters
-
| sensor | Sensor. |
| listener | Listener, or NULL to remove it. |
- Returns
- 0, or -EBUSY if the sensor has another listener.
◆ pbl_sensor_us_to_mhz()
| static int32_t pbl_sensor_us_to_mhz |
( |
uint32_t |
us | ) |
|
|
inlinestatic |
Convert a sampling interval to a frequency, rounded to the nearest.
0 stays 0.
- Parameters
-
| us | Interval in microseconds. |
- Returns
- Frequency in millihertz.
◆ ACCEL
The board's accelerometer, which may also measure angular rate.
◆ DIE_TEMP
The board's die temperature sensor.
◆ MAG
The board's magnetometer.
◆ PRESSURE
The board's barometric pressure sensor.