|
PebbleOS v4.47.0-1362-gd278268fe
|
Interface for sensor drivers. More...
Data Structures | |
| struct | pbl_sensor_mount |
| Mounting of a sensor in the device. More... | |
| struct | pbl_sensor_ops |
| Driver operations. More... | |
| struct | pbl_sensor_state |
| Class runtime state. More... | |
| struct | pbl_sensor |
| A sensor. More... | |
| struct | pbl_sensor_rate |
| Sampling interval of a sensor, as measured from the time of its frames. More... | |
Macros | |
| #define | PBL_SENSOR_MOUNT_MATRIX(xx, xy, xz, yx, yy, yz, zx, zy, zz) |
| Initializer for a struct pbl_sensor_mount, from the rows of a mount matrix. | |
| #define | PBL_SENSOR_MOUNT_IDENTITY PBL_SENSOR_MOUNT_MATRIX(1, 0, 0, 0, 1, 0, 0, 0, 1) |
| Identity mounting, for sensors aligned with the device or without vector types. | |
| #define | PBL_SENSOR_STATE_DEFINE(sym) |
Define the class state of sensor sym, without batch buffers, for sensors that are only read. | |
| #define | PBL_SENSOR_STREAM_STATE_DEFINE(sym, _num_bufs, _buf_size) |
Define the class state of streaming sensor sym, with its batch buffers. | |
| #define | PBL_SENSOR_INIT(sym, _name, _parent, _ops, _chans, _events, ...) |
Initializer for the struct pbl_sensor of sensor sym. | |
Functions | |
| void | pbl_sensor_lock (const struct pbl_sensor *sensor) |
| Take the device lock. | |
| void | pbl_sensor_unlock (const struct pbl_sensor *sensor) |
| Release the device lock. | |
| uint8_t * | pbl_sensor_buf_alloc (const struct pbl_sensor *sensor, uint16_t *size) |
| Get a free batch buffer. | |
| void | pbl_sensor_buf_free (const struct pbl_sensor *sensor, const uint8_t *data) |
| Give back a buffer from pbl_sensor_buf_alloc() without reporting it. | |
| void | pbl_sensor_report (const struct pbl_sensor *sensor, const struct pbl_sensor_batch *batch) |
| Report a batch to the listener. | |
| void | pbl_sensor_report_event (const struct pbl_sensor *sensor, const struct pbl_sensor_event *event) |
| Report an event to the listener. | |
| static uint16_t | pbl_sensor_latency_to_frames (int32_t latency_us, uint32_t interval_us, uint16_t max) |
| Convert a report latency to the frames a driver queues before reporting them. | |
| void | pbl_sensor_rate_reset (struct pbl_sensor_rate *rate, uint32_t nominal_us) |
| Start measuring a sampling interval over, from the nominal one. | |
| uint32_t | pbl_sensor_rate_update (struct pbl_sensor_rate *rate, uint64_t timestamp_us, uint32_t frames) |
| Take the time of a frame into the measurement of a sampling interval. | |
Interface for sensor drivers.
A driver embeds a struct pbl_sensor in its instance, sets it up with PBL_SENSOR_STATE_DEFINE() or PBL_SENSOR_STREAM_STATE_DEFINE() and PBL_SENSOR_INIT(), and implements the struct pbl_sensor_ops the class calls.
| struct pbl_sensor_mount |
| struct pbl_sensor_state |
Class runtime state.
| Data Fields | ||
|---|---|---|
| struct pbl_mutex | lock | Device lock. |
| struct pbl_sensor |
A sensor.
| Data Fields | ||
|---|---|---|
| const struct pbl_sensor_chan * | chans | Channels measured; their scale is the one at the default range. |
| struct pbl_device | dev | Device. |
| uint8_t | events | Events detected, a bit per enum pbl_sensor_event_type. |
| struct pbl_sensor_mount | mount | Mounting in the device. |
| uint8_t | num_chans | Number of channels. |
| const struct pbl_sensor_ops * | ops | Driver operations. |
| struct pbl_sensor_state * | state | Runtime state. |
| struct pbl_sensor_rate |
| #define PBL_SENSOR_INIT | ( | sym, | |
| _name, | |||
| _parent, | |||
| _ops, | |||
| _chans, | |||
| _events, | |||
| ... | |||
| ) |
Initializer for the struct pbl_sensor of sensor sym.
| sym | Symbol of the sensor instance, with its state defined by PBL_SENSOR_STATE_DEFINE() or PBL_SENSOR_STREAM_STATE_DEFINE(). |
| _name | Name. |
| _parent | Parent device, such as the I2C bus, or NULL. |
| _ops | Driver operations. |
| _chans | Channels measured, an array of struct pbl_sensor_chan. |
| _events | Events detected, PBL_BIT() of each enum pbl_sensor_event_type. |
| ... | Mounting, a struct pbl_sensor_mount initializer such as PBL_SENSOR_MOUNT_MATRIX(). |
| #define PBL_SENSOR_MOUNT_IDENTITY PBL_SENSOR_MOUNT_MATRIX(1, 0, 0, 0, 1, 0, 0, 0, 1) |
Identity mounting, for sensors aligned with the device or without vector types.
| #define PBL_SENSOR_MOUNT_MATRIX | ( | xx, | |
| xy, | |||
| xz, | |||
| yx, | |||
| yy, | |||
| yz, | |||
| zx, | |||
| zy, | |||
| zz | |||
| ) |
Initializer for a struct pbl_sensor_mount, from the rows of a mount matrix.
With devicetree, the rows come from the node's mount-matrix property. Only matrices swapping and flipping axes are supported, with a single 1 or -1 in every row and column: anything else fails the build.
| #define PBL_SENSOR_STATE_DEFINE | ( | sym | ) |
Define the class state of sensor sym, without batch buffers, for sensors that are only read.
| sym | Symbol of the sensor instance. |
| #define PBL_SENSOR_STREAM_STATE_DEFINE | ( | sym, | |
| _num_bufs, | |||
| _buf_size | |||
| ) |
Define the class state of streaming sensor sym, with its batch buffers.
| sym | Symbol of the sensor instance. |
| _num_bufs | Number of buffers, at least 1, up to 32. |
| _buf_size | Size of each buffer in bytes. |
| uint8_t * pbl_sensor_buf_alloc | ( | const struct pbl_sensor * | sensor, |
| uint16_t * | size | ||
| ) |
Get a free batch buffer.
Callable from any context.
| sensor | Sensor. | |
| [out] | size | Size of the buffer in bytes, or NULL. |
| void pbl_sensor_buf_free | ( | const struct pbl_sensor * | sensor, |
| const uint8_t * | data | ||
| ) |
Give back a buffer from pbl_sensor_buf_alloc() without reporting it.
Callable from any context.
| sensor | Sensor. |
| data | Buffer data, or a pointer into it. |
|
inlinestatic |
Convert a report latency to the frames a driver queues before reporting them.
| latency_us | Report latency in microseconds, or PBL_SENSOR_LATENCY_NONE. |
| interval_us | Sampling interval in microseconds. |
| max | Most frames the driver queues. |
max. References PBL_CLAMP.
| void pbl_sensor_lock | ( | const struct pbl_sensor * | sensor | ) |
Take the device lock.
Recursive. Taken around what a driver does outside of its operations.
| sensor | Sensor. |
| void pbl_sensor_rate_reset | ( | struct pbl_sensor_rate * | rate, |
| uint32_t | nominal_us | ||
| ) |
Start measuring a sampling interval over, from the nominal one.
Called when the sampling frequency changes or frames are lost.
| [out] | rate | Measurement. |
| nominal_us | Interval the part is set to, in microseconds. |
| uint32_t pbl_sensor_rate_update | ( | struct pbl_sensor_rate * | rate, |
| uint64_t | timestamp_us, | ||
| uint32_t | frames | ||
| ) |
Take the time of a frame into the measurement of a sampling interval.
Called with times taken in the interrupt of the part. Intervals far from the nominal one are left out.
| rate | Measurement. |
| timestamp_us | Time of the frame, in microseconds of uptime. |
| frames | Frames sampled since the previous call, this one included. |
| void pbl_sensor_report | ( | const struct pbl_sensor * | sensor, |
| const struct pbl_sensor_batch * | batch | ||
| ) |
Report a batch to the listener.
Callable from any context, ISRs included. The batch data is in a buffer from pbl_sensor_buf_alloc(), which the class takes back. Batches reach the listener in the order they are reported, from the high priority system work queue.
| sensor | Sensor. |
| batch | Batch, copied. |
| void pbl_sensor_report_event | ( | const struct pbl_sensor * | sensor, |
| const struct pbl_sensor_event * | event | ||
| ) |
Report an event to the listener.
Callable from any context, ISRs included. Dropped unless detection of that event type is enabled. The axis modifier is in the sensor frame. Events reach the listener from the high priority system work queue; those it has not caught up with are dropped past a few.
| sensor | Sensor. |
| event | Event, copied. |
| void pbl_sensor_unlock | ( | const struct pbl_sensor * | sensor | ) |
Release the device lock.
| sensor | Sensor. |