You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2026/05/01 16:56:51 UTC

(nuttx) 01/10: drivers/sensors: add initial support for fixed-point data for sensors

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 39378e1d4678934338aff02d6161473536f7f544
Author: raiden00pl <ra...@railab.me>
AuthorDate: Sat Nov 29 21:37:11 2025 +0100

    drivers/sensors: add initial support for fixed-point data for sensors
    
    new sensor framework can now select between float data type and
    fixed-point data type
    
    Signed-off-by: raiden00pl <ra...@railab.me>
---
 .../drivers/special/sensors/sensors_uorb.rst       |  71 +++-
 drivers/sensors/Kconfig                            |  18 +
 drivers/sensors/adxl362_uorb.c                     |   6 +
 drivers/sensors/bme680_uorb.c                      |   6 +
 drivers/sensors/bme688_uorb.c                      |   6 +
 drivers/sensors/bmi088_uorb.c                      |   6 +
 drivers/sensors/bmi160_uorb.c                      |   6 +
 drivers/sensors/bmi270_uorb.c                      |   6 +
 drivers/sensors/bmm150_uorb.c                      |   6 +
 drivers/sensors/bmp180_uorb.c                      |   6 +
 drivers/sensors/bmp280_uorb.c                      |   6 +
 drivers/sensors/ds18b20_uorb.c                     |   6 +
 drivers/sensors/fakesensor_uorb.c                  |  10 +
 drivers/sensors/fs3000_uorb.c                      |   6 +
 drivers/sensors/gnss_uorb.c                        |   6 +
 drivers/sensors/goldfish_gnss_uorb.c               |  10 +
 drivers/sensors/goldfish_sensor_uorb.c             |   6 +
 drivers/sensors/hyt271_uorb.c                      |   6 +
 drivers/sensors/l3gd20_uorb.c                      |  10 +
 drivers/sensors/l86xxx_uorb.c                      |   6 +
 drivers/sensors/lis2mdl_uorb.c                     |   6 +
 drivers/sensors/lsm6dso32_uorb.c                   |   6 +
 drivers/sensors/lsm9ds1_uorb.c                     |   6 +
 drivers/sensors/ltr308_uorb.c                      |   6 +
 drivers/sensors/mcp9600_uorb.c                     |   6 +
 drivers/sensors/mpu9250_uorb.c                     |   6 +
 drivers/sensors/ms56xx_uorb.c                      |   6 +
 drivers/sensors/sht4x_uorb.c                       |   6 +
 drivers/sensors/wtgahrs2_uorb.c                    |   6 +
 include/nuttx/uorb.h                               | 468 ++++++++++++---------
 30 files changed, 529 insertions(+), 202 deletions(-)

diff --git a/Documentation/components/drivers/special/sensors/sensors_uorb.rst b/Documentation/components/drivers/special/sensors/sensors_uorb.rst
index ebdb66e55c8..f253f4eeca2 100644
--- a/Documentation/components/drivers/special/sensors/sensors_uorb.rst
+++ b/Documentation/components/drivers/special/sensors/sensors_uorb.rst
@@ -48,11 +48,68 @@ sensor events are sent to the ring buffer in the upper layer.
    :width: 800px
    :align: center
 
-Problems to solve
-=================
+Sensor data type
+================
+
+The framework supports two types of sensor data:
+
+#. ``float`` if ``CONFIG_SENSORS_USE_FLOAT=y``, not recommended for
+   targets without FPU.
+
+#. ``b16_t`` if ``CONFIG_SENSORS_USE_B16=y``, recommended for targets without
+   FPU.
+
+Currently all sensors support ``float``, support for ``b16_t`` is work-in-progress.
+
+.. warning::
+
+   Using fixed-point math instead of floating point may cause sensors measurements
+   to saturate where they wouldn't before. Verify that fixed-point data types are
+   sufficient for your application. Just because a driver has fixed-point support
+   **does not mean** it can support the sensor's full range.
+
+To create generic drivers that support both data types, you should use the dedicated
+sensor data type:
+
+.. code:: C
+
+   /* Data type for sensors */
+
+   #ifdef CONFIG_SENSORS_USE_B16
+   typedef b16_t sensor_data_t;
+   #else
+   typedef float sensor_data_t;
+   #endif
+
+Mathematical operations on this type should only be performed using dedicated
+macros:
+
+- ``sensor_data_ftof(f1)`` - convert float to sensor data number.
+  Should be used only for compile-time constants.
+
+- ``sensor_data_itof(i)`` - convert int to sensor data number.
+
+- ``sensor_data_inv(i)`` - invert int and convert to sensor data number
+
+- ``sensor_data_add(f1, f2)`` - add two sensor data numbers
+
+- ``sensor_data_sub(f1, f2)`` - subtract two sensor data numbers
+
+- ``sensor_data_subi(f1, i)`` - subtract int from sensor data number
+
+- ``sensor_data_mul(f1, f2)`` - multiply two sensor data numbers
+
+- ``sensor_data_muli(f1, i)`` - multiply sensor data with int
+
+- ``sensor_data_div(f1, f2)`` - divide two sensor data numbers
+
+- ``sensor_data_divi(f1, i)`` - divide sensor data with int
+
+- ``sensor_data_abs(f1)`` - get absolute value for sensor data number
+
+- ``sensor_data_sqrt(f1)`` - get sqrt for sensro data number
 
-The current implementation uses the ``float`` type which may make it difficult
-to use on platforms without FPU support.
+- ``sensor_data_usat(f1)`` - unsigned saturation for sensor data.
 
 **Code**
 ========
@@ -313,9 +370,9 @@ being ``sensor_device_info_s``.
   struct sensor_device_info_s
   {
     uint32_t      version;
-    float         power;
-    float         max_range;
-    float         resolution;
+    sensor_data_t power;
+    sensor_data_t max_range;
+    sensor_data_t resolution;
     int32_t       min_delay;
     int32_t       max_delay;
     uint32_t      fifo_reserved_event_count;
diff --git a/drivers/sensors/Kconfig b/drivers/sensors/Kconfig
index 587c75ee635..c8e13eb0075 100644
--- a/drivers/sensors/Kconfig
+++ b/drivers/sensors/Kconfig
@@ -17,6 +17,24 @@ config USENSOR
 	---help---
 		Allow application to register user sensor by /dev/usensor.
 
+choice
+	prompt "Sensor framework data type"
+	default SENSORS_USE_FLOAT
+
+config SENSORS_USE_FLOAT
+	bool "Use float as data type for sensors"
+	---help---
+		Use float as data type for sensors.
+		This option is recommended for targets with FPU support.
+
+config SENSORS_USE_B16
+	bool "Use b16_t as data type for sensors"
+	---help---
+		Use b16_t (fixed-point type) as data type for sensors.
+		This option is recommended for targets without FPU support.
+
+endchoice # Sensor framework data type
+
 config SENSORS_RPMSG
 	bool "Sensor RPMSG Support"
 	default n
diff --git a/drivers/sensors/adxl362_uorb.c b/drivers/sensors/adxl362_uorb.c
index bd0b526f6cc..dee8a2842cd 100644
--- a/drivers/sensors/adxl362_uorb.c
+++ b/drivers/sensors/adxl362_uorb.c
@@ -43,6 +43,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 #define ADXL362_SPI_FREQUENCY         1000000
 #define ADXL362_SPI_MODE              SPIDEV_MODE0
 
diff --git a/drivers/sensors/bme680_uorb.c b/drivers/sensors/bme680_uorb.c
index f4cc67d29d9..b4dece225ab 100644
--- a/drivers/sensors/bme680_uorb.c
+++ b/drivers/sensors/bme680_uorb.c
@@ -49,6 +49,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 #define BME680_ADDR 0x76 /* I2C Slave Address */
 #define BME680_FREQ CONFIG_BME680_I2C_FREQUENCY
 #define BME680_DEVID 0x61
diff --git a/drivers/sensors/bme688_uorb.c b/drivers/sensors/bme688_uorb.c
index 675af210aea..bbff3556751 100644
--- a/drivers/sensors/bme688_uorb.c
+++ b/drivers/sensors/bme688_uorb.c
@@ -49,6 +49,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 #define BME688_ADDR                0x76 /* I2C Slave Address */
 #define BME688_FREQ                CONFIG_BME688_I2C_FREQUENCY
 #define BME688_DEVID               0x61
diff --git a/drivers/sensors/bmi088_uorb.c b/drivers/sensors/bmi088_uorb.c
index 267670a2aa2..d0ccfebd3b9 100644
--- a/drivers/sensors/bmi088_uorb.c
+++ b/drivers/sensors/bmi088_uorb.c
@@ -36,6 +36,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 #define BMI088_DEFAULT_INTERVAL 10000  /* Default conversion interval. */
 
 /****************************************************************************
diff --git a/drivers/sensors/bmi160_uorb.c b/drivers/sensors/bmi160_uorb.c
index f5ffe2da801..0ee2ed220c0 100644
--- a/drivers/sensors/bmi160_uorb.c
+++ b/drivers/sensors/bmi160_uorb.c
@@ -36,6 +36,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 #define BMI160_DEFAULT_INTERVAL 10000  /* Default conversion interval. */
 
 /****************************************************************************
diff --git a/drivers/sensors/bmi270_uorb.c b/drivers/sensors/bmi270_uorb.c
index fbc76c8d93c..4030f8aaf2e 100644
--- a/drivers/sensors/bmi270_uorb.c
+++ b/drivers/sensors/bmi270_uorb.c
@@ -49,6 +49,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 #define CONSTANTS_ONE_G 9.8f
 
 /****************************************************************************
diff --git a/drivers/sensors/bmm150_uorb.c b/drivers/sensors/bmm150_uorb.c
index 9b3c54ad40c..cc54c9d10af 100644
--- a/drivers/sensors/bmm150_uorb.c
+++ b/drivers/sensors/bmm150_uorb.c
@@ -43,6 +43,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 #define BMM150_CHIPID_VAL        0x32
 
 #define BMM150_CHIPID            0x40
diff --git a/drivers/sensors/bmp180_uorb.c b/drivers/sensors/bmp180_uorb.c
index b3c553219d9..305a7bf91dc 100644
--- a/drivers/sensors/bmp180_uorb.c
+++ b/drivers/sensors/bmp180_uorb.c
@@ -37,6 +37,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 #define BMP180_MIN_INTERVAL 30000
 
 /****************************************************************************
diff --git a/drivers/sensors/bmp280_uorb.c b/drivers/sensors/bmp280_uorb.c
index 99e6fb647ae..958ae5a9967 100644
--- a/drivers/sensors/bmp280_uorb.c
+++ b/drivers/sensors/bmp280_uorb.c
@@ -45,6 +45,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 #ifdef  CONFIG_BMP280_I2C_ADDR_76
 #define BMP280_ADDR         0x76
 #else
diff --git a/drivers/sensors/ds18b20_uorb.c b/drivers/sensors/ds18b20_uorb.c
index 27510e1b1e2..c50e75f194a 100644
--- a/drivers/sensors/ds18b20_uorb.c
+++ b/drivers/sensors/ds18b20_uorb.c
@@ -50,6 +50,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 #ifndef CONFIG_ENDIAN_BIG
 #  define ds18b20_leuint64(x) (x)
 #endif
diff --git a/drivers/sensors/fakesensor_uorb.c b/drivers/sensors/fakesensor_uorb.c
index fe47c459794..adf5b7d7716 100644
--- a/drivers/sensors/fakesensor_uorb.c
+++ b/drivers/sensors/fakesensor_uorb.c
@@ -46,6 +46,16 @@
 #include <nuttx/sensors/gnss.h>
 #endif
 
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 /****************************************************************************
  * Private Types
  ****************************************************************************/
diff --git a/drivers/sensors/fs3000_uorb.c b/drivers/sensors/fs3000_uorb.c
index 77b5eaa1601..7c7bca4deee 100644
--- a/drivers/sensors/fs3000_uorb.c
+++ b/drivers/sensors/fs3000_uorb.c
@@ -45,6 +45,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 #define FS3000_ADDR           0x28
 
 /****************************************************************************
diff --git a/drivers/sensors/gnss_uorb.c b/drivers/sensors/gnss_uorb.c
index 56344ed0d04..ff9b5cd2395 100644
--- a/drivers/sensors/gnss_uorb.c
+++ b/drivers/sensors/gnss_uorb.c
@@ -43,6 +43,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 #define GNSS_PATH_FMT          "/dev/ttyGNSS%d"
 
 #define GNSS_PARSE_BUFFERSIZE  256
diff --git a/drivers/sensors/goldfish_gnss_uorb.c b/drivers/sensors/goldfish_gnss_uorb.c
index b099d292973..09ea56649cd 100644
--- a/drivers/sensors/goldfish_gnss_uorb.c
+++ b/drivers/sensors/goldfish_gnss_uorb.c
@@ -40,6 +40,16 @@
 #include <nuttx/sensors/goldfish_gnss.h>
 #include <nuttx/sensors/gnss.h>
 
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 /****************************************************************************
  * Private Types
  ****************************************************************************/
diff --git a/drivers/sensors/goldfish_sensor_uorb.c b/drivers/sensors/goldfish_sensor_uorb.c
index 9b3a1d65137..e0ff6285a78 100644
--- a/drivers/sensors/goldfish_sensor_uorb.c
+++ b/drivers/sensors/goldfish_sensor_uorb.c
@@ -45,6 +45,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 #define GOLDFISH_LIST_SENSOR_CMD "list-sensors"
 
 /****************************************************************************
diff --git a/drivers/sensors/hyt271_uorb.c b/drivers/sensors/hyt271_uorb.c
index 0a48d472317..5b760a89815 100644
--- a/drivers/sensors/hyt271_uorb.c
+++ b/drivers/sensors/hyt271_uorb.c
@@ -47,6 +47,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 #define HYT271_TEMPDATA_MASK 0x3fff
 #define HYT271_HUMIDATA_MASK 0x3fff
 
diff --git a/drivers/sensors/l3gd20_uorb.c b/drivers/sensors/l3gd20_uorb.c
index 653d6e9e1bd..26d3f5b5070 100644
--- a/drivers/sensors/l3gd20_uorb.c
+++ b/drivers/sensors/l3gd20_uorb.c
@@ -46,6 +46,16 @@
 
 #if defined(CONFIG_SPI) && defined(CONFIG_SENSORS_L3GD20)
 
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 /****************************************************************************
  * Private Types
  ****************************************************************************/
diff --git a/drivers/sensors/l86xxx_uorb.c b/drivers/sensors/l86xxx_uorb.c
index 72481bdd1d6..c596fec18d6 100644
--- a/drivers/sensors/l86xxx_uorb.c
+++ b/drivers/sensors/l86xxx_uorb.c
@@ -58,6 +58,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 #ifndef CONFIG_SENSORS_L86_XXX_THREAD_STACKSIZE
 #define CONFIG_SENSORS_L86_XXX_THREAD_STACKSIZE 10000
 #endif
diff --git a/drivers/sensors/lis2mdl_uorb.c b/drivers/sensors/lis2mdl_uorb.c
index 59d9596f2dd..49f7a9b0a52 100644
--- a/drivers/sensors/lis2mdl_uorb.c
+++ b/drivers/sensors/lis2mdl_uorb.c
@@ -49,6 +49,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 /* The value that should be in the "who am I" register */
 
 #define WHO_AM_I_VAL 0x40
diff --git a/drivers/sensors/lsm6dso32_uorb.c b/drivers/sensors/lsm6dso32_uorb.c
index 568437be6a8..8d4edc5e514 100644
--- a/drivers/sensors/lsm6dso32_uorb.c
+++ b/drivers/sensors/lsm6dso32_uorb.c
@@ -46,6 +46,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 /* The value that should be in the WHO_AM_I register. */
 
 #define WHO_AM_I_VAL 0x6c
diff --git a/drivers/sensors/lsm9ds1_uorb.c b/drivers/sensors/lsm9ds1_uorb.c
index a3e7d8281f3..ab335615d27 100644
--- a/drivers/sensors/lsm9ds1_uorb.c
+++ b/drivers/sensors/lsm9ds1_uorb.c
@@ -49,6 +49,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 #define CONSTANTS_ONE_G 9.8f
 
 /****************************************************************************
diff --git a/drivers/sensors/ltr308_uorb.c b/drivers/sensors/ltr308_uorb.c
index 994eb42f405..75ed30a40fd 100644
--- a/drivers/sensors/ltr308_uorb.c
+++ b/drivers/sensors/ltr308_uorb.c
@@ -45,6 +45,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 #define LTR308_ADDR           0x53
 #define DEVID                 0xB1
 
diff --git a/drivers/sensors/mcp9600_uorb.c b/drivers/sensors/mcp9600_uorb.c
index 79c7ab534e1..263649135bf 100644
--- a/drivers/sensors/mcp9600_uorb.c
+++ b/drivers/sensors/mcp9600_uorb.c
@@ -47,6 +47,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 #define REG_THERMO_HOT_JUNC 0x0 /* Thermocouple Hot-Junction, T H */
 #define REG_JUNC_TEMP_DELTA 0x1 /* Junctions Temperature Delta, TΔ */
 #define REG_COLD_JUNC_TEMP 0x2  /* Cold-Junction Temperature, T C */
diff --git a/drivers/sensors/mpu9250_uorb.c b/drivers/sensors/mpu9250_uorb.c
index 4a843b4fad6..bb4b26dfe61 100644
--- a/drivers/sensors/mpu9250_uorb.c
+++ b/drivers/sensors/mpu9250_uorb.c
@@ -51,6 +51,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 #define  MPU9250_AKM_DEV_ID                 0x48  /* Magnetometer device ID */
 #define  MIN(x, y)         (x) > (y) ? (y) : (x)
 
diff --git a/drivers/sensors/ms56xx_uorb.c b/drivers/sensors/ms56xx_uorb.c
index 1ed52ff1811..fa2753e2540 100644
--- a/drivers/sensors/ms56xx_uorb.c
+++ b/drivers/sensors/ms56xx_uorb.c
@@ -52,6 +52,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 #define MS56XX_CMD_RESET              0x1e
 #define MS56XX_CMD_START_ADC_READ     0x00
 #define MS56XX_CMD_CONV_D1_OSR_256    0x40 /* D1 = uncompensated pressure */
diff --git a/drivers/sensors/sht4x_uorb.c b/drivers/sensors/sht4x_uorb.c
index eca4187fb50..57265d452c8 100644
--- a/drivers/sensors/sht4x_uorb.c
+++ b/drivers/sensors/sht4x_uorb.c
@@ -47,6 +47,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 #define SHT4X_CRC_INIT 0xFF /* Initial value of the calculated CRC. */
 #define SHT4X_CRC_POLY 0x31 /* CRC calculation polynomial. */
 
diff --git a/drivers/sensors/wtgahrs2_uorb.c b/drivers/sensors/wtgahrs2_uorb.c
index 6f40c26ea9a..512c6401d95 100644
--- a/drivers/sensors/wtgahrs2_uorb.c
+++ b/drivers/sensors/wtgahrs2_uorb.c
@@ -43,6 +43,12 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Only float data type supported now */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  error fixed-point data type not supported yet
+#endif
+
 #define WTGAHRS2_ACCEL_IDX         0
 #define WTGAHRS2_GYRO_IDX          1
 #define WTGAHRS2_MAG_IDX           2
diff --git a/include/nuttx/uorb.h b/include/nuttx/uorb.h
index 4db10dce601..ea64f06579b 100644
--- a/include/nuttx/uorb.h
+++ b/include/nuttx/uorb.h
@@ -36,10 +36,80 @@
 
 #include <nuttx/sensors/ioctl.h>
 
+#ifdef CONFIG_SENSORS_USE_B16
+#  include <fixedmath.h>
+#endif
+
 /****************************************************************************
  * Pre-processor Definitions
  ****************************************************************************/
 
+/* Sensor data math operations. Sensors driver must use these macros to
+ * create portable code!
+ *
+ * Available macros:
+ *
+ *   - sensor_data_ftof(f1) - convert float to sensor data number.
+ *     Should be used only for compile-time constants.
+ *
+ *   - sensor_data_itof(i) - convert int to sensor data number.
+ *
+ *   - sensor_data_inv(i) - invert int and convert to sensor data
+ *     number
+ *
+ *   - sensor_data_add(f1, f2) - add two sensor data numbers
+ *
+ *   - sensor_data_sub(f1, f2) - subtract two sensor data numbers
+ *
+ *   - sensor_data_subi(f1, i) - subtract int from sensor data number
+ *
+ *   - sensor_data_mul(f1, f2) - multiply two sensor data numbers
+ *
+ *   - sensor_data_muli(f1, i) - multiply sensor data with int
+ *
+ *   - sensor_data_div(f1, f2) - divide two sensor data numbers
+ *
+ *   - sensor_data_divi(f1, i) - divide sensor data with int
+ *
+ *   - sensor_data_abs(f1) - get absolute value for sensor data
+ *     number
+ *
+ *   - sensor_data_sqrt(f1) - get sqrt for sensro data number
+ *
+ *   - sensor_data_usat(f1) - unsigned saturation for sensor data.
+ *
+ */
+
+#ifdef CONFIG_SENSORS_USE_B16
+#  define sensor_data_ftof(f1)    ftob16(((float)f1))
+#  define sensor_data_itof(i)     itob16((i))
+#  define sensor_data_inv(i)      b16inv((i))
+#  define sensor_data_add(f1, f2) b16addb16((f1), (f2))
+#  define sensor_data_sub(f1, f2) b16subb16((f1), (f2))
+#  define sensor_data_subi(f1, i) b16subi((f1), (i))
+#  define sensor_data_mul(f1, f2) b16mulb16((f1), (f2))
+#  define sensor_data_muli(f1, i) b16muli((f1), (i))
+#  define sensor_data_div(f1, f2) b16divb16((f1), (f2))
+#  define sensor_data_divi(f1, i) b16divi((f1), (i))
+#  define sensor_data_abs(f1)     b16abs((f1))
+#  define sensor_data_sqrt(f1)    b16sqrt((f1))
+#  define sensor_data_usat(f1)    ((f1) < 0 ? b16MAX : (f1))
+#else
+#  define sensor_data_ftof(f1)    ((float)f1)
+#  define sensor_data_itof(i)     ((float)i)
+#  define sensor_data_inv(i)      ((1.0f) / (i))
+#  define sensor_data_add(f1, f2) ((f1) + (f2))
+#  define sensor_data_sub(f1, f2) ((f1) - (f2))
+#  define sensor_data_subi(f1, i) ((f1) - ((float)i))
+#  define sensor_data_mul(f1, f2) ((f1) * (f2))
+#  define sensor_data_muli(f1, i) ((f1) * ((float)i))
+#  define sensor_data_div(f1, f2) ((f1) / (f2))
+#  define sensor_data_divi(f1, i) ((f1) / ((float)i))
+#  define sensor_data_abs(f1)     absf(f1)
+#  define sensor_data_sqrt(f1)    sqrtf(f1)
+#  define sensor_data_usat(f1)    (f1)
+#endif
+
 /* sensor type definition */
 
 /* Note: Some of the types of these sensors are aligned with Android, and
@@ -634,275 +704,283 @@
  * Public Types
  ****************************************************************************/
 
+/* Data type for sensors */
+
+#ifdef CONFIG_SENSORS_USE_B16
+typedef b16_t sensor_data_t;
+#else
+typedef float sensor_data_t;
+#endif
+
 /* These structures prefixed with sensor_event are sensor data, and member
  * that are not used must be written as NAN or INT_MIN/INT_MAX, than
  * reported.
  */
 
-struct sensor_event  /* Type: Sensor Common Event */
+struct sensor_event          /* Type: Sensor Common Event */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  uint32_t event;           /* Common events */
+  uint64_t timestamp;        /* Units is microseconds */
+  uint32_t event;            /* Common events */
 };
 
-struct sensor_accel         /* Type: Accerometer */
+struct sensor_accel          /* Type: Accerometer */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float x;                  /* Axis X in m/s^2 */
-  float y;                  /* Axis Y in m/s^2 */
-  float z;                  /* Axis Z in m/s^2 */
-  float temperature;        /* Temperature in degrees celsius */
+  uint64_t      timestamp;   /* Units is microseconds */
+  sensor_data_t x;           /* Axis X in m/s^2 */
+  sensor_data_t y;           /* Axis Y in m/s^2 */
+  sensor_data_t z;           /* Axis Z in m/s^2 */
+  sensor_data_t temperature; /* Temperature in degrees celsius */
 };
 
 struct sensor_accel_uncal   /* Type: Accerometer Uncalibrated */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float x;                  /* Axis X in m/s^2 */
-  float y;                  /* Axis Y in m/s^2 */
-  float z;                  /* Axis Z in m/s^2 */
-  float x_bias;             /* Axis X bias in m/s^2 */
-  float y_bias;             /* Axis Y bias in m/s^2 */
-  float z_bias;             /* Axis Z bias in m/s^2 */
-  float temperature;        /* Temperature in degrees celsius */
+  uint64_t      timestamp;   /* Units is microseconds */
+  sensor_data_t x;           /* Axis X in m/s^2 */
+  sensor_data_t y;           /* Axis Y in m/s^2 */
+  sensor_data_t z;           /* Axis Z in m/s^2 */
+  sensor_data_t x_bias;      /* Axis X bias in m/s^2 */
+  sensor_data_t y_bias;      /* Axis Y bias in m/s^2 */
+  sensor_data_t z_bias;      /* Axis Z bias in m/s^2 */
+  sensor_data_t temperature; /* Temperature in degrees celsius */
 };
 
-struct sensor_mag           /* Type: Magnetic Field */
+struct sensor_mag            /* Type: Magnetic Field */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float x;                  /* Axis X in Gauss or micro Tesla (uT) */
-  float y;                  /* Axis Y in Gauss or micro Tesla (uT) */
-  float z;                  /* Axis Z in Gauss or micro Tesla (uT) */
-  float temperature;        /* Temperature in degrees celsius */
-  int32_t status;           /* Status of calibration */
+  uint64_t      timestamp;   /* Units is microseconds */
+  sensor_data_t x;           /* Axis X in Gauss or micro Tesla (uT) */
+  sensor_data_t y;           /* Axis Y in Gauss or micro Tesla (uT) */
+  sensor_data_t z;           /* Axis Z in Gauss or micro Tesla (uT) */
+  sensor_data_t temperature; /* Temperature in degrees celsius */
+  int32_t       status;      /* Status of calibration */
 };
 
-struct sensor_mag_uncal     /* Type: Magnetic Field Uncalibrated */
+struct sensor_mag_uncal      /* Type: Magnetic Field Uncalibrated */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float x;                  /* Axis X in Gauss or micro Tesla (uT) */
-  float y;                  /* Axis Y in Gauss or micro Tesla (uT) */
-  float z;                  /* Axis Z in Gauss or micro Tesla (uT) */
-  float x_bias;             /* Axis X bias in Gauss or micro Tesla (uT) */
-  float y_bias;             /* Axis Y bias in Gauss or micro Tesla (uT) */
-  float z_bias;             /* Axis Z bias in Gauss or micro Tesla (uT) */
-  float temperature;        /* Temperature in degrees celsius */
-  int32_t status;           /* Status of calibration */
+  uint64_t      timestamp;   /* Units is microseconds */
+  sensor_data_t x;           /* Axis X in Gauss or micro Tesla (uT) */
+  sensor_data_t y;           /* Axis Y in Gauss or micro Tesla (uT) */
+  sensor_data_t z;           /* Axis Z in Gauss or micro Tesla (uT) */
+  sensor_data_t x_bias;      /* Axis X bias in Gauss or micro Tesla (uT) */
+  sensor_data_t y_bias;      /* Axis Y bias in Gauss or micro Tesla (uT) */
+  sensor_data_t z_bias;      /* Axis Z bias in Gauss or micro Tesla (uT) */
+  sensor_data_t temperature; /* Temperature in degrees celsius */
+  int32_t       status;      /* Status of calibration */
 };
 
-struct sensor_orientation   /* Type: Orientation */
+struct sensor_orientation    /* Type: Orientation */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float    x;               /* azimuth */
-  float    y;               /* pitch */
-  float    z;               /* roll */
+  uint64_t      timestamp;   /* Units is microseconds */
+  sensor_data_t x;           /* azimuth */
+  sensor_data_t y;           /* pitch */
+  sensor_data_t z;           /* roll */
 };
 
-struct sensor_gyro          /* Type: Gyroscope */
+struct sensor_gyro           /* Type: Gyroscope */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float x;                  /* Axis X in rad/s */
-  float y;                  /* Axis Y in rad/s */
-  float z;                  /* Axis Z in rad/s */
-  float temperature;        /* Temperature in degrees celsius */
+  uint64_t      timestamp;   /* Units is microseconds */
+  sensor_data_t x;           /* Axis X in rad/s */
+  sensor_data_t y;           /* Axis Y in rad/s */
+  sensor_data_t z;           /* Axis Z in rad/s */
+  sensor_data_t temperature; /* Temperature in degrees celsius */
 };
 
-struct sensor_gyro_uncal    /* Type: Gyroscope Uncalibrated */
+struct sensor_gyro_uncal     /* Type: Gyroscope Uncalibrated */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float x;                  /* Axis X in rad/s */
-  float y;                  /* Axis Y in rad/s */
-  float z;                  /* Axis Z in rad/s */
-  float x_bias;             /* Axis X bias in rad/s */
-  float y_bias;             /* Axis Y bias in rad/s */
-  float z_bias;             /* Axis Z bias in rad/s */
-  float temperature;        /* Temperature in degrees celsius */
+  uint64_t      timestamp;   /* Units is microseconds */
+  sensor_data_t x;           /* Axis X in rad/s */
+  sensor_data_t y;           /* Axis Y in rad/s */
+  sensor_data_t z;           /* Axis Z in rad/s */
+  sensor_data_t x_bias;      /* Axis X bias in rad/s */
+  sensor_data_t y_bias;      /* Axis Y bias in rad/s */
+  sensor_data_t z_bias;      /* Axis Z bias in rad/s */
+  sensor_data_t temperature; /* Temperature in degrees celsius */
 };
 
-struct sensor_light         /* Type: Light */
+struct sensor_light          /* Type: Light */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float light;              /* in SI lux units */
-  float ir;                 /* in SI lux units */
+  uint64_t      timestamp;   /* Units is microseconds */
+  sensor_data_t light;       /* in SI lux units */
+  sensor_data_t ir;          /* in SI lux units */
 };
 
-struct sensor_baro          /* Type: Barometer */
+struct sensor_baro           /* Type: Barometer */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float pressure;           /* pressure measurement in millibar or hpa */
-  float temperature;        /* Temperature in degrees celsius */
+  uint64_t      timestamp;   /* Units is microseconds */
+  sensor_data_t pressure;    /* pressure measurement in millibar or hpa */
+  sensor_data_t temperature; /* Temperature in degrees celsius */
 };
 
-struct sensor_noise         /* Type: Noise Loudness */
+struct sensor_noise          /* Type: Noise Loudness */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float db;                 /* in SI units db */
+  uint64_t      timestamp;   /* Units is microseconds */
+  sensor_data_t db;          /* in SI units db */
 };
 
-struct sensor_prox          /* Type: proximity */
+struct sensor_prox           /* Type: proximity */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float proximity;          /* distance to the nearest object in centimeters */
+  uint64_t      timestamp;   /* Units is microseconds */
+  sensor_data_t proximity;   /* distance to the nearest object in centimeters */
 };
 
-struct sensor_rgb           /* Type: RGB */
+struct sensor_rgb            /* Type: RGB */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float r;                  /* Units is percent */
-  float g;                  /* Units is percent */
-  float b;                  /* Units is percent */
+  uint64_t      timestamp;   /* Units is microseconds */
+  sensor_data_t r;           /* Units is percent */
+  sensor_data_t g;           /* Units is percent */
+  sensor_data_t b;           /* Units is percent */
 };
 
-struct sensor_rotation      /* Type: Rotation */
+struct sensor_rotation       /* Type: Rotation */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float    x;               /* x*sin(θ/2) */
-  float    y;               /* y*sin(θ/2) */
-  float    z;               /* z*sin(θ/2) */
-  float    w;               /* cos(θ/2) */
-  float    status;          /* estimated heading Accuracy (in radians) (-1 if unavailable) */
+  uint64_t      timestamp;   /* Units is microseconds */
+  sensor_data_t x;           /* x*sin(θ/2) */
+  sensor_data_t y;           /* y*sin(θ/2) */
+  sensor_data_t z;           /* z*sin(θ/2) */
+  sensor_data_t w;           /* cos(θ/2) */
+  sensor_data_t status;      /* estimated heading Accuracy (in radians) (-1 if unavailable) */
 };
 
-struct sensor_humi          /* Type: Relative Humidity */
+struct sensor_humi           /* Type: Relative Humidity */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float humidity;           /* in percent  */
+  uint64_t      timestamp;   /* Units is microseconds */
+  sensor_data_t humidity;    /* in percent  */
 };
 
-struct sensor_temp          /* Type: Ambient Temperature */
+struct sensor_temp           /* Type: Ambient Temperature */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float temperature;        /* Temperature in degrees celsius */
+  uint64_t      timestamp;   /* Units is microseconds */
+  sensor_data_t temperature; /* Temperature in degrees celsius */
 };
 
-struct sensor_pm25          /* Type: PM25 */
+struct sensor_pm25           /* Type: PM25 */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float pm25;               /* in SI units ug/m^3 */
+  uint64_t      timestamp;   /* Units is microseconds */
+  sensor_data_t pm25;        /* in SI units ug/m^3 */
 };
 
-struct sensor_pm1p0         /* Type: PM1P0 */
+struct sensor_pm1p0          /* Type: PM1P0 */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float pm1p0;              /* in SI units ug/m^3 */
+  uint64_t      timestamp;   /* Units is microseconds */
+  sensor_data_t pm1p0;       /* in SI units ug/m^3 */
 };
 
-struct sensor_pm10          /* Type: PM10 */
+struct sensor_pm10           /* Type: PM10 */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float pm10;               /* in SI units ug/m^3 */
+  uint64_t      timestamp;   /* Units is microseconds */
+  sensor_data_t pm10;        /* in SI units ug/m^3 */
 };
 
-struct sensor_step_counter  /* Type: Step Coun */
+struct sensor_step_counter   /* Type: Step Coun */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  uint32_t steps;           /* Step counting */
-  uint32_t cadence;         /* Stride frequency */
+  uint64_t timestamp;        /* Units is microseconds */
+  uint32_t steps;            /* Step counting */
+  uint32_t cadence;          /* Stride frequency */
 };
 
-struct sensor_ph            /* Type: PH */
+struct sensor_ph             /* Type: PH */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float ph;                 /* PH = 7.0 neutral, PH < 7.0 acidic, PH > 7.0 alkaline */
+  uint64_t      timestamp;   /* Units is microseconds */
+  sensor_data_t ph;          /* PH = 7.0 neutral, PH < 7.0 acidic, PH > 7.0 alkaline */
 };
 
-struct sensor_hrate         /* Type: Heart Rate */
+struct sensor_hrate          /* Type: Heart Rate */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float bpm;                /* is SI units BPM */
+  uint64_t      timestamp;   /* Units is microseconds */
+  sensor_data_t bpm;         /* is SI units BPM */
 };
 
-struct sensor_pose_6dof     /* Type: Pose 6dof */
+struct sensor_pose_6dof      /* Type: Pose 6dof */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float    x;               /* x*sin(theta/2) */
-  float    y;               /* y*sin(theta/2) */
-  float    z;               /* z*sin(theta/2) */
-  float    w;               /* cos(theta/2) */
-  float    tx;              /* Translation along x axis from an arbitrary origin. */
-  float    ty;              /* Translation along y axis from an arbitrary origin. */
-  float    tz;              /* Translation along z axis from an arbitrary origin. */
-  float    dx;              /* Delta quaternion rotation x*sin(theta/2) */
-  float    dy;              /* Delta quaternion rotation y*sin(theta/2) */
-  float    dz;              /* Delta quaternion rotation z*sin(theta/2) */
-  float    dw;              /* Delta quaternion rotation cos(theta/2) */
-  float    dtx;             /* Delta translation along x axis. */
-  float    dty;             /* Delta translation along y axis. */
-  float    dtz;             /* Delta translation along z axis. */
-  uint64_t number;          /* Sequence number; ascending sequentially from 0 */
+  uint64_t      timestamp;   /* Units is microseconds */
+  sensor_data_t x;           /* x*sin(theta/2) */
+  sensor_data_t y;           /* y*sin(theta/2) */
+  sensor_data_t z;           /* z*sin(theta/2) */
+  sensor_data_t w;           /* cos(theta/2) */
+  sensor_data_t tx;          /* Translation along x axis from an arbitrary origin. */
+  sensor_data_t ty;          /* Translation along y axis from an arbitrary origin. */
+  sensor_data_t tz;          /* Translation along z axis from an arbitrary origin. */
+  sensor_data_t dx;          /* Delta quaternion rotation x*sin(theta/2) */
+  sensor_data_t dy;          /* Delta quaternion rotation y*sin(theta/2) */
+  sensor_data_t dz;          /* Delta quaternion rotation z*sin(theta/2) */
+  sensor_data_t dw;          /* Delta quaternion rotation cos(theta/2) */
+  sensor_data_t dtx;         /* Delta translation along x axis. */
+  sensor_data_t dty;         /* Delta translation along y axis. */
+  sensor_data_t dtz;         /* Delta translation along z axis. */
+  uint64_t      number;      /* Sequence number; ascending sequentially from 0 */
 };
 
-struct sensor_gas           /* Type: Gas */
+struct sensor_gas            /* Type: Gas */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float gas_resistance;     /* Gas resistance in kOhm */
+  uint64_t      timestamp;      /* Units is microseconds */
+  sensor_data_t gas_resistance; /* Gas resistance in kOhm */
 };
 
 struct sensor_hbeat         /* Type: Heart Beat */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float beat;               /* Units is times/minutes */
+  uint64_t      timestamp;  /* Units is microseconds */
+  sensor_data_t beat;       /* Units is times/minutes */
 };
 
 struct sensor_force         /* Type: Force */
 {
-  uint64_t timestamp;       /* Unit is microseconds */
-  float force;              /* Force value, units is N */
-  int32_t event;            /* Force event */
+  uint64_t      timestamp;  /* Unit is microseconds */
+  sensor_data_t force;      /* Force value, units is N */
+  int32_t       event;      /* Force event */
 };
 
 struct sensor_velocity      /* Type: Velocity */
 {
-  uint64_t timestamp;       /* Unit is microseconds */
-  float velocity;           /* Velocity value, units is m/s (SI) */
+  uint64_t      timestamp;  /* Unit is microseconds */
+  sensor_data_t velocity;   /* Velocity value, units is m/s (SI) */
 };
 
 struct sensor_hall          /* Type: HALL */
 {
   uint64_t timestamp;       /* Units is microseconds */
-  int32_t hall;             /* Hall state */
+  int32_t  hall;            /* Hall state */
 };
 
 struct sensor_uv            /* Type: Ultraviolet Light */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float uvi;                /* the value range is 0 - 15 */
+  uint64_t      timestamp;  /* Units is microseconds */
+  sensor_data_t uvi;        /* the value range is 0 - 15 */
 };
 
 struct sensor_angle         /* Type: Angle */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float    angle;           /* Angle. Unit is degree */
+  uint64_t      timestamp;  /* Units is microseconds */
+  sensor_data_t angle;      /* Angle. Unit is degree */
 };
 
 struct sensor_ir            /* Type: Infrared Ray */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float ir;                 /* in SI units lux */
+  uint64_t      timestamp;  /* Units is microseconds */
+  sensor_data_t ir;         /* in SI units lux */
 };
 
 struct sensor_hcho          /* Type: HCHO */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float hcho;               /* in SI units ppm */
+  uint64_t      timestamp;  /* Units is microseconds */
+  sensor_data_t hcho;       /* in SI units ppm */
 };
 
 struct sensor_tvoc          /* Type: TVOC */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float tvoc;               /* in SI units ppm */
+  uint64_t      timestamp;  /* Units is microseconds */
+  sensor_data_t tvoc;       /* in SI units ppm */
 };
 
 struct sensor_dust          /* Type: DUST */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float dust;               /* is SI units ug/m^3 */
+  uint64_t      timestamp;  /* Units is microseconds */
+  sensor_data_t dust;       /* is SI units ug/m^3 */
 };
 
 struct sensor_ecg           /* Type: ECG */
 {
-  uint64_t timestamp;       /* Unit is microseconds */
-  float ecg;                /* Unit is μV */
-  uint32_t status;          /* Status info */
+  uint64_t      timestamp;  /* Unit is microseconds */
+  sensor_data_t ecg;        /* Unit is μV */
+  uint32_t      status;     /* Status info */
 };
 
 struct sensor_ppgd          /* Type: PPGD */
@@ -923,29 +1001,29 @@ struct sensor_ppgq          /* Type: PPDQ */
 
 struct sensor_impd          /* Type: Impedance */
 {
-  uint64_t timestamp;       /* Unit is microseconds */
-  float real;               /* Real part, unit is Ohm(Ω) */
-  float imag;               /* Imaginary part, unit is Ohm(Ω) */
+  uint64_t      timestamp;  /* Unit is microseconds */
+  sensor_data_t real;       /* Real part, unit is Ohm(Ω) */
+  sensor_data_t imag;       /* Imaginary part, unit is Ohm(Ω) */
 };
 
 struct sensor_ots           /* Type: OTS */
 {
   uint64_t timestamp;       /* Unit is microseconds */
-  int32_t x;                /* Axis X in counts */
-  int32_t y;                /* Axis Y in counts */
+  int32_t  x;               /* Axis X in counts */
+  int32_t  y;               /* Axis Y in counts */
 };
 
 struct sensor_co2           /* Type: CO2 */
 {
-  uint64_t timestamp;       /* Units is microseconds */
-  float co2;                /* in SI units ppm */
+  uint64_t      timestamp;  /* Units is microseconds */
+  sensor_data_t co2;        /* in SI units ppm */
 };
 
 struct sensor_cap           /* Type: Capacitance */
 {
   uint64_t timestamp;       /* Unit is microseconds */
-  int32_t status;           /* Detection status */
-  int32_t rawdata[4];       /* in SI units pF */
+  int32_t  status;          /* Detection status */
+  int32_t  rawdata[4];      /* in SI units pF */
 };
 
 struct sensor_eng           /* Type: ENG */
@@ -966,25 +1044,25 @@ struct sensor_gnss          /* Type: GNSS */
 
   uint64_t time_utc;
 
-  float latitude;           /* Unit is degrees */
-  float longitude;          /* Unit is degrees */
-  float altitude;           /* Altitude above MSL(mean seal level), Unit is SI m */
-  float altitude_ellipsoid; /* Altitude bove Ellipsoid, Unit is SI m */
+  sensor_data_t latitude;           /* Unit is degrees */
+  sensor_data_t longitude;          /* Unit is degrees */
+  sensor_data_t altitude;           /* Altitude above MSL(mean seal level), Unit is SI m */
+  sensor_data_t altitude_ellipsoid; /* Altitude bove Ellipsoid, Unit is SI m */
 
-  float eph;                /* GNSS horizontal position accuracy (metres) */
-  float epv;                /* GNSS vertical position accuracy (metres) */
+  sensor_data_t eph;                /* GNSS horizontal position accuracy (metres) */
+  sensor_data_t epv;                /* GNSS vertical position accuracy (metres) */
 
-  float hdop;               /* Horizontal dilution of precision */
-  float pdop;               /* Position dilution of precision */
-  float vdop;               /* Vertical dilution of precision */
+  sensor_data_t hdop;               /* Horizontal dilution of precision */
+  sensor_data_t pdop;               /* Position dilution of precision */
+  sensor_data_t vdop;               /* Vertical dilution of precision */
 
-  float ground_speed;       /* GNSS ground speed, Unit is m/s */
+  sensor_data_t ground_speed;       /* GNSS ground speed, Unit is m/s */
 
   /* Course over ground (NOT heading, but direction of movement),
    * Unit is Si degrees
    */
 
-  float course;
+  sensor_data_t course;
 
   uint32_t satellites_used; /* Number of satellites used */
   uint32_t firmware_ver;    /* Version of GNSS firmware */
@@ -1019,7 +1097,7 @@ struct sensor_gnss_satellite
    * Flag: SENSOR_GNSS_SV_FLAGS_HAS_CARRIER_FREQUENCY
    */
 
-  float cf;
+  sensor_data_t cf;
 
   struct satellite
   {
@@ -1070,14 +1148,14 @@ struct sensor_gnss_measurement
    * nanoseconds.
    */
 
-  float    time_offset_ns;
+  sensor_data_t time_offset_ns;
 
   /* The received GNSS Time-of-Week at the measurement time, in
    * nanoseconds.
    */
 
-  int64_t  received_sv_time_in_ns;
-  int64_t  received_sv_time_uncertainty_in_ns;
+  int64_t received_sv_time_in_ns;
+  int64_t received_sv_time_uncertainty_in_ns;
 
   /* GNSS measurement state, see SENSOR_GNSS_MEASUREMENT_STATE_*. */
 
@@ -1085,18 +1163,18 @@ struct sensor_gnss_measurement
 
   /* dBHz, Carrier-to-noise density. */
 
-  float    c_n0_dbhz;
+  sensor_data_t c_n0_dbhz;
 
   /* Pseudorange rate(m/s) at the timestamp. */
 
-  float    pseudorange_rate_mps;
-  float    pseudorange_rate_uncertainty_mps;
+  sensor_data_t pseudorange_rate_mps;
+  sensor_data_t pseudorange_rate_uncertainty_mps;
 
   /* Accumulated delta range. */
 
-  uint32_t accumulated_delta_range_state;
-  float    accumulated_delta_range_m;
-  float    accumulated_delta_range_uncertainty_m;
+  uint32_t      accumulated_delta_range_state;
+  sensor_data_t accumulated_delta_range_m;
+  sensor_data_t accumulated_delta_range_uncertainty_m;
 
   /* Carrier related between the satellite and the receiver.
    * flags:
@@ -1106,10 +1184,10 @@ struct sensor_gnss_measurement
    *   SENSOR_GNSS_MEASUREMENT_HAS_CARRIER_PHASE_UNCERTAINTY
    */
 
-  float    carrier_frequency_hz;
-  int64_t  carrier_cycles;
-  float    carrier_phase;
-  float    carrier_phase_uncertainty;
+  sensor_data_t carrier_frequency_hz;
+  int64_t       carrier_cycles;
+  sensor_data_t carrier_phase;
+  sensor_data_t carrier_phase_uncertainty;
 
   uint32_t multipath_indicator;
 
@@ -1141,8 +1219,8 @@ struct sensor_gnss_clock
    *   SENSOR_GNSS_CLOCK_HAS_TIME_UNCERTAINTY
    */
 
-  int64_t  time_ns;
-  float    time_uncertainty_ns;
+  int64_t       time_ns;
+  sensor_data_t time_uncertainty_ns;
 
   /* Discontinuities in the HW clock. */
 
@@ -1157,9 +1235,9 @@ struct sensor_gnss_clock
    *   SENSOR_GNSS_CLOCK_HAS_BIAS_UNCERTAINTY
    */
 
-  int64_t  full_bias_ns;
-  float    bias_ns;             /* Sub-nanosecond bias */
-  float    bias_uncertainty_ns;
+  int64_t       full_bias_ns;
+  sensor_data_t bias_ns;             /* Sub-nanosecond bias */
+  sensor_data_t bias_uncertainty_ns;
 
   /* The clock's drift in nanoseconds (per second).
    * A positive value means that the frequency is higher than
@@ -1169,8 +1247,8 @@ struct sensor_gnss_clock
    *   SENSOR_GNSS_CLOCK_HAS_DRIFT_UNCERTAINTY
    */
 
-  float    drift_nsps;
-  float    drift_uncertainty_nsps;
+  sensor_data_t drift_nsps;
+  sensor_data_t drift_uncertainty_nsps;
 };
 
 /* GNSS Geofence events */
@@ -1223,9 +1301,9 @@ struct sensor_gnss_geofence_param
   int32_t            type;
 
   int32_t            geofence_id;
-  float              latitude;
-  float              longitude;
-  float              radius_meters;
+  sensor_data_t      latitude;
+  sensor_data_t      longitude;
+  sensor_data_t      radius_meters;
 
   /* Which transitions to monitor.
    * Available: see SENSOR_GNSS_GEOFENCE_TRANS_*.
@@ -1280,15 +1358,15 @@ struct sensor_device_info_s
 
   /* Rough estimate of this sensor's power consumption in mA. */
 
-  float         power;
+  sensor_data_t power;
 
   /* Maximum range of this sensor's value in SI units. */
 
-  float         max_range;
+  sensor_data_t max_range;
 
   /* Smallest difference between two values reported by this sensor. */
 
-  float         resolution;
+  sensor_data_t resolution;
 
   /* This value depends on the reporting mode:
    *