Line data Source code
1 0 : /*
2 : * Copyright (c) 2022-2023 Intel Corporation.
3 : *
4 : * SPDX-License-Identifier: Apache-2.0
5 : */
6 :
7 : #ifndef ZEPHYR_INCLUDE_SENSING_DATATYPES_H_
8 : #define ZEPHYR_INCLUDE_SENSING_DATATYPES_H_
9 :
10 : #include <stdint.h>
11 : #include <zephyr/dsp/types.h>
12 :
13 : /**
14 : * @defgroup sensing_datatypes Data Types
15 : * @ingroup sensing_api
16 : * @brief Sensor data structures used by the sensing subsystem
17 : *
18 : * @{
19 : */
20 :
21 : /**
22 : * @brief Common header for all sensor value payloads.
23 : *
24 : * Each sensor value data structure should have this header
25 : *
26 : * Here use 'base_timestamp' (uint64_t) and 'timestamp_delta' (uint32_t) to
27 : * save memory usage in batching mode.
28 : *
29 : * The 'base_timestamp' is for readings[0], the 'timestamp_delta' is relation
30 : * to the previous 'readings'. So,
31 : * timestamp of readings[0] is
32 : * header.base_timestamp + readings[0].timestamp_delta.
33 : * timestamp of readings[1] is
34 : * timestamp of readings[0] + readings[1].timestamp_delta.
35 : *
36 : * Since timestamp unit is micro seconds, the max 'timestamp_delta' (uint32_t)
37 : * is 4295 seconds.
38 : *
39 : * If a sensor has batched data where two consecutive readings differ by
40 : * more than 4295 seconds, the sensor subsystem core will split them
41 : * across multiple instances of the readings structure, and send multiple
42 : * events.
43 : *
44 : * This concept is borrowed from CHRE:
45 : * https://cs.android.com/android/platform/superproject/+/master:\
46 : * system/chre/chre_api/include/chre_api/chre/sensor_types.h
47 : */
48 1 : struct sensing_sensor_value_header {
49 : /** Base timestamp of this data readings, unit is micro seconds */
50 1 : uint64_t base_timestamp;
51 : /** Count of this data readings */
52 1 : uint16_t reading_count;
53 : };
54 :
55 : /**
56 : * @brief Sensor value data structure types based on common data types.
57 : * Suitable for common sensors, such as IMU, Light sensors and orientation sensors.
58 : */
59 :
60 : /**
61 : * @brief Sensor value data structure for 3-axis sensors.
62 : * struct sensing_sensor_value_3d_q31 can be used by 3D IMU sensors like:
63 : * SENSING_SENSOR_TYPE_MOTION_ACCELEROMETER_3D,
64 : * SENSING_SENSOR_TYPE_MOTION_UNCALIB_ACCELEROMETER_3D,
65 : * SENSING_SENSOR_TYPE_MOTION_GYROMETER_3D,
66 : * q31 version
67 : */
68 1 : struct sensing_sensor_value_3d_q31 {
69 : /** Header of the sensor value data structure. */
70 1 : struct sensing_sensor_value_header header;
71 1 : int8_t shift; /**< The shift value for the q31_t v[3] reading. */
72 : struct {
73 : /** Timestamp delta of the reading. Unit is micro seconds. */
74 1 : uint32_t timestamp_delta;
75 : union {
76 : /**
77 : * 3D vector of the reading represented as an array.
78 : * For SENSING_SENSOR_TYPE_MOTION_ACCELEROMETER_3D and
79 : * SENSING_SENSOR_TYPE_MOTION_UNCALIB_ACCELEROMETER_3D,
80 : * the unit is Gs (gravitational force).
81 : * For SENSING_SENSOR_TYPE_MOTION_GYROMETER_3D, the unit is degrees.
82 : */
83 1 : q31_t v[3];
84 : struct {
85 1 : q31_t x; /**< X value of the 3D vector. */
86 1 : q31_t y; /**< Y value of the 3D vector. */
87 1 : q31_t z; /**< Z value of the 3D vector. */
88 : };
89 : };
90 1 : } readings[1]; /**< Array of readings. */
91 : };
92 :
93 : /**
94 : * @brief Sensor value data structure for single 1-axis value.
95 : * struct sensing_sensor_value_uint32 can be used by SENSING_SENSOR_TYPE_LIGHT_AMBIENTLIGHT sensor
96 : * uint32_t version
97 : */
98 1 : struct sensing_sensor_value_uint32 {
99 : /** Header of the sensor value data structure. */
100 1 : struct sensing_sensor_value_header header;
101 : struct {
102 : /** Timestamp delta of the reading. Unit is micro seconds. */
103 1 : uint32_t timestamp_delta;
104 : /**
105 : * Value of the reading.
106 : * For SENSING_SENSOR_TYPE_LIGHT_AMBIENTLIGHT, the unit is luxs.
107 : */
108 1 : uint32_t v;
109 1 : } readings[1]; /**< Array of readings. */
110 : };
111 :
112 : /**
113 : * @brief Sensor value data structure for single 1-axis value.
114 : * struct sensing_sensor_value_q31 can be used by SENSING_SENSOR_TYPE_MOTION_HINGE_ANGLE sensor
115 : * q31 version
116 : */
117 1 : struct sensing_sensor_value_q31 {
118 : /** Header of the sensor value data structure. */
119 1 : struct sensing_sensor_value_header header;
120 1 : int8_t shift; /**< The shift value for the q31_t v reading. */
121 : struct {
122 : /** Timestamp delta of the reading. Unit is micro seconds. */
123 1 : uint32_t timestamp_delta;
124 : /**
125 : * Value of the reading.
126 : * For SENSING_SENSOR_TYPE_MOTION_HINGE_ANGLE, the unit is degrees.
127 : */
128 1 : q31_t v;
129 1 : } readings[1]; /**< Array of readings. */
130 : };
131 :
132 : /**
133 : * @}
134 : */
135 :
136 : #endif /*ZEPHYR_INCLUDE_SENSING_DATATYPES_H_*/
|