diff --git a/doc/releases/release-notes-4.2.rst b/doc/releases/release-notes-4.2.rst index c2188a4aa02..fa9666e7263 100644 --- a/doc/releases/release-notes-4.2.rst +++ b/doc/releases/release-notes-4.2.rst @@ -163,6 +163,11 @@ New APIs and options * :kconfig:option:`CONFIG_NET_SOCKETS_INET_RAW` +* Sensor + + * :c:func:`sensor_value_to_deci` + * :c:func:`sensor_value_to_centi` + * Stepper * :c:func:`stepper_stop()` diff --git a/include/zephyr/drivers/sensor.h b/include/zephyr/drivers/sensor.h index 62b765b81b4..af8651886d0 100644 --- a/include/zephyr/drivers/sensor.h +++ b/include/zephyr/drivers/sensor.h @@ -1468,6 +1468,28 @@ struct sensor_info { #define SENSOR_DEVICE_DT_INST_DEFINE(inst, ...) \ SENSOR_DEVICE_DT_DEFINE(DT_DRV_INST(inst), __VA_ARGS__) +/** + * @brief Helper function for converting struct sensor_value to integer deci units. + * + * @param val A pointer to a sensor_value struct. + * @return The converted value. + */ +static inline int64_t sensor_value_to_deci(const struct sensor_value *val) +{ + return ((int64_t)val->val1 * 10) + val->val2 / 100000; +} + +/** + * @brief Helper function for converting struct sensor_value to integer centi units. + * + * @param val A pointer to a sensor_value struct. + * @return The converted value. + */ +static inline int64_t sensor_value_to_centi(const struct sensor_value *val) +{ + return ((int64_t)val->val1 * 100) + val->val2 / 10000; +} + /** * @brief Helper function for converting struct sensor_value to integer milli units. *