Skip to content

Commit

Permalink
sensors: Add DTS bindings for sensor channels
Browse files Browse the repository at this point in the history
Move the sensor channel enum to a dts includable headers. This means
that the enum had to change to #define calls. In order to keep things
backwards compatible, There's a shim header that undefines them and
allows the enum to exist for now while we work on deprecating it.

Signed-off-by: Yuval Peress <[email protected]>
  • Loading branch information
yperess committed Apr 8, 2024
1 parent c38ea28 commit 4f87a6d
Show file tree
Hide file tree
Showing 4 changed files with 430 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dts/bindings/sensor/sensor-device.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ properties:
This property is defined in the Generic Sensor Property Usages of the HID
Usage Tables specification
(https://usb.org/sites/default/files/hut1_3_0.pdf, section 22.5).
supported-channels:
type: array
description: |
A list of sensor channels that are supported by this device.
7 changes: 7 additions & 0 deletions include/zephyr/drivers/sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ struct sensor_value {
int32_t val2;
};

#include <zephyr/drivers/sensor_channel_shim.h>

/**
* @brief Sensor channels.
*/
Expand Down Expand Up @@ -191,6 +193,11 @@ enum sensor_channel {
/** Desired charging current in mA */
SENSOR_CHAN_GAUGE_DESIRED_CHARGING_CURRENT,

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* DO NOT ADD NEW CHANNELS HERE!
* All new channels should be added to zephyr/dt_bindings/sensor.h
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/

/** All channels. */
SENSOR_CHAN_ALL,

Expand Down
260 changes: 260 additions & 0 deletions include/zephyr/drivers/sensor_channel_shim.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
/*
* Copyright (c) 2024 Google Inc
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef INCLUDE_ZEPHYR_DRIVERS_SENSOR_CHANNEL_SHIM_H_
#define INCLUDE_ZEPHYR_DRIVERS_SENSOR_CHANNEL_SHIM_H_

#ifdef SENSOR_CHAN_ACCEL_X
#undef SENSOR_CHAN_ACCEL_X
#endif

#ifdef SENSOR_CHAN_ACCEL_Y
#undef SENSOR_CHAN_ACCEL_Y
#endif

#ifdef SENSOR_CHAN_ACCEL_Z
#undef SENSOR_CHAN_ACCEL_Z
#endif

#ifdef SENSOR_CHAN_ACCEL_XYZ
#undef SENSOR_CHAN_ACCEL_XYZ
#endif

#ifdef SENSOR_CHAN_GYRO_X
#undef SENSOR_CHAN_GYRO_X
#endif

#ifdef SENSOR_CHAN_GYRO_Y
#undef SENSOR_CHAN_GYRO_Y
#endif

#ifdef SENSOR_CHAN_GYRO_Z
#undef SENSOR_CHAN_GYRO_Z
#endif

#ifdef SENSOR_CHAN_GYRO_XYZ
#undef SENSOR_CHAN_GYRO_XYZ
#endif

#ifdef SENSOR_CHAN_MAGN_X
#undef SENSOR_CHAN_MAGN_X
#endif

#ifdef SENSOR_CHAN_MAGN_Y
#undef SENSOR_CHAN_MAGN_Y
#endif

#ifdef SENSOR_CHAN_MAGN_Z
#undef SENSOR_CHAN_MAGN_Z
#endif

#ifdef SENSOR_CHAN_MAGN_XYZ
#undef SENSOR_CHAN_MAGN_XYZ
#endif

#ifdef SENSOR_CHAN_DIE_TEMP
#undef SENSOR_CHAN_DIE_TEMP
#endif

#ifdef SENSOR_CHAN_AMBIENT_TEMP
#undef SENSOR_CHAN_AMBIENT_TEMP
#endif

#ifdef SENSOR_CHAN_PRESS
#undef SENSOR_CHAN_PRESS
#endif

#ifdef SENSOR_CHAN_PROX
#undef SENSOR_CHAN_PROX
#endif

#ifdef SENSOR_CHAN_HUMIDITY
#undef SENSOR_CHAN_HUMIDITY
#endif

#ifdef SENSOR_CHAN_LIGHT
#undef SENSOR_CHAN_LIGHT
#endif

#ifdef SENSOR_CHAN_IR
#undef SENSOR_CHAN_IR
#endif

#ifdef SENSOR_CHAN_RED
#undef SENSOR_CHAN_RED
#endif

#ifdef SENSOR_CHAN_GREEN
#undef SENSOR_CHAN_GREEN
#endif

#ifdef SENSOR_CHAN_BLUE
#undef SENSOR_CHAN_BLUE
#endif

#ifdef SENSOR_CHAN_ALTITUDE
#undef SENSOR_CHAN_ALTITUDE
#endif

#ifdef SENSOR_CHAN_PM_1_0
#undef SENSOR_CHAN_PM_1_0
#endif

#ifdef SENSOR_CHAN_PM_2_5
#undef SENSOR_CHAN_PM_2_5
#endif

#ifdef SENSOR_CHAN_PM_10
#undef SENSOR_CHAN_PM_10
#endif

#ifdef SENSOR_CHAN_DISTANCE
#undef SENSOR_CHAN_DISTANCE
#endif

#ifdef SENSOR_CHAN_CO2
#undef SENSOR_CHAN_CO2
#endif

#ifdef SENSOR_CHAN_O2
#undef SENSOR_CHAN_O2
#endif

#ifdef SENSOR_CHAN_VOC
#undef SENSOR_CHAN_VOC
#endif

#ifdef SENSOR_CHAN_GAS_RES
#undef SENSOR_CHAN_GAS_RES
#endif

#ifdef SENSOR_CHAN_VOLTAGE
#undef SENSOR_CHAN_VOLTAGE
#endif

#ifdef SENSOR_CHAN_VSHUNT
#undef SENSOR_CHAN_VSHUNT
#endif

#ifdef SENSOR_CHAN_CURRENT
#undef SENSOR_CHAN_CURRENT
#endif

#ifdef SENSOR_CHAN_POWER
#undef SENSOR_CHAN_POWER
#endif

#ifdef SENSOR_CHAN_RESISTANCE
#undef SENSOR_CHAN_RESISTANCE
#endif

#ifdef SENSOR_CHAN_ROTATION
#undef SENSOR_CHAN_ROTATION
#endif

#ifdef SENSOR_CHAN_POS_DX
#undef SENSOR_CHAN_POS_DX
#endif

#ifdef SENSOR_CHAN_POS_DY
#undef SENSOR_CHAN_POS_DY
#endif

#ifdef SENSOR_CHAN_POS_DZ
#undef SENSOR_CHAN_POS_DZ
#endif

#ifdef SENSOR_CHAN_RPM
#undef SENSOR_CHAN_RPM
#endif

#ifdef SENSOR_CHAN_GAUGE_VOLTAGE
#undef SENSOR_CHAN_GAUGE_VOLTAGE
#endif

#ifdef SENSOR_CHAN_GAUGE_AVG_CURRENT
#undef SENSOR_CHAN_GAUGE_AVG_CURRENT
#endif

#ifdef SENSOR_CHAN_GAUGE_STDBY_CURRENT
#undef SENSOR_CHAN_GAUGE_STDBY_CURRENT
#endif

#ifdef SENSOR_CHAN_GAUGE_MAX_LOAD_CURRENT
#undef SENSOR_CHAN_GAUGE_MAX_LOAD_CURRENT
#endif

#ifdef SENSOR_CHAN_GAUGE_TEMP
#undef SENSOR_CHAN_GAUGE_TEMP
#endif

#ifdef SENSOR_CHAN_GAUGE_STATE_OF_CHARGE
#undef SENSOR_CHAN_GAUGE_STATE_OF_CHARGE
#endif

#ifdef SENSOR_CHAN_GAUGE_FULL_CHARGE_CAPACITY
#undef SENSOR_CHAN_GAUGE_FULL_CHARGE_CAPACITY
#endif

#ifdef SENSOR_CHAN_GAUGE_REMAINING_CHARGE_CAPACITY
#undef SENSOR_CHAN_GAUGE_REMAINING_CHARGE_CAPACITY
#endif

#ifdef SENSOR_CHAN_GAUGE_NOM_AVAIL_CAPACITY
#undef SENSOR_CHAN_GAUGE_NOM_AVAIL_CAPACITY
#endif

#ifdef SENSOR_CHAN_GAUGE_FULL_AVAIL_CAPACITY
#undef SENSOR_CHAN_GAUGE_FULL_AVAIL_CAPACITY
#endif

#ifdef SENSOR_CHAN_GAUGE_AVG_POWER
#undef SENSOR_CHAN_GAUGE_AVG_POWER
#endif

#ifdef SENSOR_CHAN_GAUGE_STATE_OF_HEALTH
#undef SENSOR_CHAN_GAUGE_STATE_OF_HEALTH
#endif

#ifdef SENSOR_CHAN_GAUGE_TIME_TO_EMPTY
#undef SENSOR_CHAN_GAUGE_TIME_TO_EMPTY
#endif

#ifdef SENSOR_CHAN_GAUGE_TIME_TO_FULL
#undef SENSOR_CHAN_GAUGE_TIME_TO_FULL
#endif

#ifdef SENSOR_CHAN_GAUGE_CYCLE_COUNT
#undef SENSOR_CHAN_GAUGE_CYCLE_COUNT
#endif

#ifdef SENSOR_CHAN_GAUGE_DESIGN_VOLTAGE
#undef SENSOR_CHAN_GAUGE_DESIGN_VOLTAGE
#endif

#ifdef SENSOR_CHAN_GAUGE_DESIRED_VOLTAGE
#undef SENSOR_CHAN_GAUGE_DESIRED_VOLTAGE
#endif

#ifdef SENSOR_CHAN_GAUGE_DESIRED_CHARGING_CURRENT
#undef SENSOR_CHAN_GAUGE_DESIRED_CHARGING_CURRENT
#endif

#ifdef SENSOR_CHAN_ALL
#undef SENSOR_CHAN_ALL
#endif

#ifdef SENSOR_CHAN_COMMON_COUNT
#undef SENSOR_CHAN_COMMON_COUNT
#endif

#ifdef SENSOR_CHAN_PRIV_START
#undef SENSOR_CHAN_PRIV_START
#endif

#ifdef SENSOR_CHAN_MAX
#undef SENSOR_CHAN_MAX
#endif

#endif /* INCLUDE_ZEPHYR_DRIVERS_SENSOR_CHANNEL_SHIM_H_ */
Loading

0 comments on commit 4f87a6d

Please sign in to comment.