LCOV - code coverage report
Current view: top level - zephyr/drivers - sensor_data_types.h Hit Total Coverage
Test: new.info Lines: 21 69 30.4 %
Date: 2024-12-22 00:14:23

          Line data    Source code
       1           0 : /*
       2             :  * Copyright (c) 2023 Google LLC
       3             :  *
       4             :  * SPDX-License-Identifier: Apache-2.0
       5             :  */
       6             : 
       7             : #ifndef ZEPHYR_INCLUDE_DRIVERS_SENSOR_DATA_TYPES_H
       8             : #define ZEPHYR_INCLUDE_DRIVERS_SENSOR_DATA_TYPES_H
       9             : 
      10             : #include <zephyr/dsp/types.h>
      11             : #include <zephyr/dsp/print_format.h>
      12             : 
      13             : #include <inttypes.h>
      14             : 
      15             : #ifdef __cplusplus
      16             : extern "C" {
      17             : #endif
      18             : 
      19           0 : struct sensor_data_header {
      20             :         /**
      21             :          * The closest timestamp for when the first frame was generated as attained by
      22             :          * :c:func:`k_uptime_ticks`.
      23             :          */
      24           1 :         uint64_t base_timestamp_ns;
      25             :         /**
      26             :          * The number of elements in the 'readings' array.
      27             :          *
      28             :          * This must be at least 1
      29             :          */
      30           1 :         uint16_t reading_count;
      31             : };
      32             : 
      33             : /**
      34             :  * Data for a sensor channel which reports on three axes. This is used by:
      35             :  * - :c:enum:`SENSOR_CHAN_ACCEL_X`
      36             :  * - :c:enum:`SENSOR_CHAN_ACCEL_Y`
      37             :  * - :c:enum:`SENSOR_CHAN_ACCEL_Z`
      38             :  * - :c:enum:`SENSOR_CHAN_ACCEL_XYZ`
      39             :  * - :c:enum:`SENSOR_CHAN_GYRO_X`
      40             :  * - :c:enum:`SENSOR_CHAN_GYRO_Y`
      41             :  * - :c:enum:`SENSOR_CHAN_GYRO_Z`
      42             :  * - :c:enum:`SENSOR_CHAN_GYRO_XYZ`
      43             :  * - :c:enum:`SENSOR_CHAN_MAGN_X`
      44             :  * - :c:enum:`SENSOR_CHAN_MAGN_Y`
      45             :  * - :c:enum:`SENSOR_CHAN_MAGN_Z`
      46             :  * - :c:enum:`SENSOR_CHAN_MAGN_XYZ`
      47             :  * - :c:enum:`SENSOR_CHAN_POS_DX`
      48             :  * - :c:enum:`SENSOR_CHAN_POS_DY`
      49             :  * - :c:enum:`SENSOR_CHAN_POS_DZ`
      50             :  * - :c:enum:`SENSOR_CHAN_POS_DXYZ`
      51             :  */
      52           1 : struct sensor_three_axis_data {
      53           0 :         struct sensor_data_header header;
      54           0 :         int8_t shift;
      55           0 :         struct sensor_three_axis_sample_data {
      56           0 :                 uint32_t timestamp_delta;
      57             :                 union {
      58           0 :                         q31_t values[3];
      59           0 :                         q31_t v[3];
      60             :                         struct {
      61           0 :                                 q31_t x;
      62           0 :                                 q31_t y;
      63           0 :                                 q31_t z;
      64             :                         };
      65           0 :                 };
      66           0 :         } readings[1];
      67             : };
      68             : 
      69           0 : #define PRIsensor_three_axis_data PRIu64 "ns, (%" PRIq(6) ", %" PRIq(6) ", %" PRIq(6) ")"
      70             : 
      71           0 : #define PRIsensor_three_axis_data_arg(data_, readings_offset_)                                     \
      72             :         (data_).header.base_timestamp_ns + (data_).readings[(readings_offset_)].timestamp_delta,   \
      73             :                 PRIq_arg((data_).readings[(readings_offset_)].x, 6, (data_).shift),                \
      74             :                 PRIq_arg((data_).readings[(readings_offset_)].y, 6, (data_).shift),                \
      75             :                 PRIq_arg((data_).readings[(readings_offset_)].z, 6, (data_).shift)
      76             : 
      77             : /**
      78             :  * Data from a sensor where we only care about an event occurring. This is used to report triggers.
      79             :  */
      80           1 : struct sensor_occurrence_data {
      81           0 :         struct sensor_data_header header;
      82           0 :         struct sensor_occurrence_sample_data {
      83           0 :                 uint32_t timestamp_delta;
      84           0 :         } readings[1];
      85             : };
      86             : 
      87           0 : #define PRIsensor_occurrence_data PRIu64 "ns"
      88             : 
      89           0 : #define PRIsensor_occurrence_data_arg(data_, readings_offset_)                                     \
      90             :         (data_).header.base_timestamp_ns + (data_).readings[(readings_offset_)].timestamp_delta
      91             : 
      92           0 : struct sensor_q31_data {
      93           0 :         struct sensor_data_header header;
      94           0 :         int8_t shift;
      95           0 :         struct sensor_q31_sample_data {
      96           0 :                 uint32_t timestamp_delta;
      97             :                 union {
      98           0 :                         q31_t value;
      99           1 :                         q31_t light;           /**< Unit: lux */
     100           1 :                         q31_t pressure;        /**< Unit: kilopascal */
     101           1 :                         q31_t temperature;     /**< Unit: degrees Celsius */
     102           1 :                         q31_t percent;         /**< Unit: percent */
     103           1 :                         q31_t distance;        /**< Unit: meters */
     104           1 :                         q31_t density;         /**< Unit: ug/m^3 */
     105           1 :                         q31_t density_ppm;     /**< Unit: parts per million */
     106           1 :                         q31_t density_ppb;     /**< Unit: parts per billion */
     107           1 :                         q31_t resistance;      /**< Unit: ohms */
     108           1 :                         q31_t voltage;         /**< Unit: volts */
     109           1 :                         q31_t current;         /**< Unit: amps */
     110           1 :                         q31_t power;           /**< Unit: watts */
     111           1 :                         q31_t angle;           /**< Unit: degrees */
     112           1 :                         q31_t electric_charge; /**< Unit: mAh */
     113           1 :                         q31_t humidity;        /**< Unit: RH */
     114           0 :                 };
     115           0 :         } readings[1];
     116             : };
     117             : 
     118           0 : #define PRIsensor_q31_data PRIu64 "ns (%" PRIq(6) ")"
     119             : 
     120           0 : #define PRIsensor_q31_data_arg(data_, readings_offset_)                                            \
     121             :         (data_).header.base_timestamp_ns + (data_).readings[(readings_offset_)].timestamp_delta,   \
     122             :                 PRIq_arg((data_).readings[(readings_offset_)].value, 6, (data_).shift)
     123             : 
     124             : /**
     125             :  * Data from a sensor that produces a byte of data. This is used by:
     126             :  * - :c:enum:`SENSOR_CHAN_PROX`
     127             :  */
     128           1 : struct sensor_byte_data {
     129           0 :         struct sensor_data_header header;
     130           0 :         struct sensor_byte_sample_data {
     131           0 :                 uint32_t timestamp_delta;
     132             :                 union {
     133           0 :                         uint8_t value;
     134             :                         struct {
     135           0 :                                 uint8_t is_near: 1;
     136           0 :                                 uint8_t padding: 7;
     137             :                         };
     138           0 :                 };
     139           0 :         } readings[1];
     140             : };
     141             : 
     142           0 : #define PRIsensor_byte_data(field_name_) PRIu64 "ns (" STRINGIFY(field_name_) " = %" PRIu8 ")"
     143             : 
     144           0 : #define PRIsensor_byte_data_arg(data_, readings_offset_, field_name_)                              \
     145             :         (data_).header.base_timestamp_ns + (data_).readings[(readings_offset_)].timestamp_delta,   \
     146             :                 (data_).readings[(readings_offset_)].field_name_
     147             : 
     148             : /**
     149             :  * Data from a sensor that produces a count like value. This is used by:
     150             :  * - :c:enum:`SENSOR_CHAN_GAUGE_CYCLE_COUNT`
     151             :  */
     152           1 : struct sensor_uint64_data {
     153           0 :         struct sensor_data_header header;
     154           0 :         struct sensor_uint64_sample_data {
     155           0 :                 uint32_t timestamp_delta;
     156           0 :                 uint64_t value;
     157           0 :         } readings[1];
     158             : };
     159             : 
     160           0 : #define PRIsensor_uint64_data PRIu64 "ns (%" PRIu64 ")"
     161             : 
     162           0 : #define PRIsensor_uint64_data_arg(data_, readings_offset_)                                         \
     163             :         (data_).header.base_timestamp_ns + (data_).readings[(readings_offset_)].timestamp_delta,   \
     164             :                 (data_).readings[(readings_offset_)].value
     165             : 
     166             : #ifdef __cplusplus
     167             : }
     168             : #endif
     169             : 
     170             : #endif /* ZEPHYR_INCLUDE_DRIVERS_SENSOR_DATA_TYPES_H */

Generated by: LCOV version 1.14