PebbleOS v4.47.0-1362-gd278268fe
Loading...
Searching...
No Matches
sensor.h File Reference
#include <stdbool.h>
#include <stdint.h>
#include <pbl/kernel/compiler.h>

Data Structures

struct  pbl_sensor_chan_spec
 A channel of a sensor. More...
 
struct  pbl_sensor_chan
 Channel descriptor: where a channel is in a frame and how to decode it. More...
 
struct  pbl_sensor_batch
 Batch of frames, oldest first. More...
 
struct  pbl_sensor_frame
 A single frame, as returned by the driver read operation. More...
 
struct  pbl_sensor_attr_avail
 Values an attribute takes. More...
 
struct  pbl_sensor_event
 Event. More...
 
struct  pbl_sensor_listener
 Consumer of a sensor's batches and events. More...
 

Macros

#define PBL_SENSOR_SPEC(...)   ((struct pbl_sensor_chan_spec){__VA_ARGS__})
 A struct pbl_sensor_chan_spec: a type, then optionally a modifier and an index.
 
#define PBL_SENSOR_CHAN(_type, _mod, _offset, _format, _num, _den, _exp, _bias, ...)
 Initializer for a struct pbl_sensor_chan.
 
#define PBL_SENSOR_FRAME_MAX   24U
 Largest frame a driver returns from a read.
 
#define PBL_SENSOR_LATENCY_NONE   (-1)
 Report latency reporting no batches.
 

Typedefs

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.
 

Enumerations

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

Functions

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.
 

Variables

const struct pbl_sensor *const ACCEL
 The board's accelerometer, which may also measure angular rate.
 
const struct pbl_sensor *const MAG
 The board's magnetometer.
 
const struct pbl_sensor *const DIE_TEMP
 The board's die temperature sensor.
 
const struct pbl_sensor *const PRESSURE
 The board's barometric pressure sensor.