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 25ddf14cf5e6f8265778ceda17b2514f53de4aa8
Author: raiden00pl <[email protected]>
AuthorDate: Mon Dec 1 10:06:25 2025 +0100

    sensors/hyt271_uorb: support for fixed-point data
    
    support for fixed-point data for hyt271_uorb
    
    Signed-off-by: raiden00pl <[email protected]>
---
 drivers/sensors/hyt271_uorb.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

diff --git a/drivers/sensors/hyt271_uorb.c b/drivers/sensors/hyt271_uorb.c
index 5b760a89815..3124e85a714 100644
--- a/drivers/sensors/hyt271_uorb.c
+++ b/drivers/sensors/hyt271_uorb.c
@@ -47,12 +47,6 @@
  * 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
 
@@ -67,9 +61,6 @@
 #define HYT271_HUMIRAWEQUAL(x, y) \
   (HYT271_HUMIRAWDATA(x) == HYT271_HUMIRAWDATA(y))
 
-#define HYT271_TEMPDATA(x) (HYT271_TEMPRAWDATA(x) * 165.0 / 16383.0 - 40.0)
-#define HYT271_HUMIDATA(x) (HYT271_HUMIRAWDATA(x) * 100.0 / 16383.0)
-
 #define HYT271_SENSOR_HUMI    0
 #define HYT271_SENSOR_TEMP    1
 #define HYT271_SENSOR_MAX     2
@@ -165,8 +156,12 @@ static const struct sensor_ops_s g_hyt271_ops =
 static void hyt271_humi_from_rawdata(FAR struct hyt271_sensor_data_s *data,
                                      FAR struct sensor_humi *humi)
 {
-  humi->timestamp   = data->timestamp;
-  humi->humidity    = HYT271_HUMIDATA(data->data);
+  /* hum = HUM_RAW * (100 / 16383) */
+
+  humi->timestamp = data->timestamp;
+  humi->humidity  = sensor_data_mul(
+    sensor_data_itof(HYT271_HUMIRAWDATA(data->data)),
+    sensor_data_ftof(100.0f / 16383.0f));
 }
 
 /****************************************************************************
@@ -183,8 +178,14 @@ static void hyt271_humi_from_rawdata(FAR struct 
hyt271_sensor_data_s *data,
 static void hyt271_temp_from_rawdata(FAR struct hyt271_sensor_data_s *data,
                                      FAR struct sensor_temp *temp)
 {
+  /* temp = TEMP_RAW * (165 / 16383) - 40 */
+
   temp->timestamp   = data->timestamp;
-  temp->temperature = HYT271_TEMPDATA(data->data);
+  temp->temperature = sensor_data_subi(
+    sensor_data_mul(
+      sensor_data_itof(HYT271_TEMPRAWDATA(data->data)),
+      sensor_data_ftof(165.0f / 16383.0f)),
+    40);
 }
 
 /****************************************************************************

Reply via email to