From f19036ee4e5ac53a44f9ab3321c8811065cc73ec Mon Sep 17 00:00:00 2001
From: Emilio Corigliano <emilio.corigliano@skywarder.eu>
Date: Mon, 26 Jun 2023 18:51:06 +0200
Subject: [PATCH] [LPS28DFW] Refactored names of addresses

---
 src/shared/sensors/LPS28DFW/LPS28DFW.cpp   | 25 +++++-----
 src/shared/sensors/LPS28DFW/LPS28DFWDefs.h | 54 +++++++++++-----------
 src/tests/sensors/test-lps28dfw.cpp        |  4 +-
 3 files changed, 41 insertions(+), 42 deletions(-)

diff --git a/src/shared/sensors/LPS28DFW/LPS28DFW.cpp b/src/shared/sensors/LPS28DFW/LPS28DFW.cpp
index 51df6d858..a73590c84 100644
--- a/src/shared/sensors/LPS28DFW/LPS28DFW.cpp
+++ b/src/shared/sensors/LPS28DFW/LPS28DFW.cpp
@@ -84,7 +84,7 @@ bool LPS28DFW::selfTest()
 
     // Reading the whoami value to assure communication
     uint8_t whoamiValue{0};
-    if (!i2c.readRegister(i2cConfig, WHO_AM_I_addr, whoamiValue))
+    if (!i2c.readRegister(i2cConfig, WHO_AM_I, whoamiValue))
     {
         LOG_ERR(logger, "Can't communicate with the sensor");
         lastError = BUS_FAULT;
@@ -111,7 +111,7 @@ bool LPS28DFW::setConfig(const SensorConfig& newSensorConfig)
     // ODR set: BYPASS for the one shot mode and CONTINUOUS for the
     // continuous mode).
     if (!i2c.writeRegister(
-            i2cConfig, FIFO_CTRL_addr,
+            i2cConfig, FIFO_CTRL,
             (newSensorConfig.odr == ODR::ONE_SHOT ? FIFO_CTRL::BYPASS
                                                   : FIFO_CTRL::CONTINUOUS)))
     {
@@ -136,7 +136,7 @@ bool LPS28DFW::setAverage(AVG avg)
     // internal driver state to set the register with the wanted ODR and AVG
     // without previously reading it. This allows to avoid a useless
     // transaction.
-    if (!i2c.writeRegister(i2cConfig, CTRL_REG1_addr, sensorConfig.odr | avg))
+    if (!i2c.writeRegister(i2cConfig, CTRL_REG1, sensorConfig.odr | avg))
     {
         lastError = BUS_FAULT;
         return false;
@@ -152,7 +152,7 @@ bool LPS28DFW::setOutputDataRate(ODR odr)
     // internal driver state to set the register with the wanted ODR and AVG
     // without previously reading it. This allows to avoid a useless
     // transaction.
-    if (!i2c.writeRegister(i2cConfig, CTRL_REG1_addr, odr | sensorConfig.avg))
+    if (!i2c.writeRegister(i2cConfig, CTRL_REG1, odr | sensorConfig.avg))
     {
         lastError = BUS_FAULT;
         return false;
@@ -165,7 +165,7 @@ bool LPS28DFW::setOutputDataRate(ODR odr)
 bool LPS28DFW::setFullScaleRange(FullScaleRange fs)
 {
     uint8_t ctrl_reg2;
-    if (!i2c.readRegister(i2cConfig, CTRL_REG2_addr, ctrl_reg2))
+    if (!i2c.readRegister(i2cConfig, CTRL_REG2, ctrl_reg2))
     {
         lastError = BUS_FAULT;
         return false;
@@ -182,7 +182,7 @@ bool LPS28DFW::setFullScaleRange(FullScaleRange fs)
         ctrl_reg2           = (ctrl_reg2 | CTRL_REG2::FS_MODE);
     }
 
-    if (!i2c.writeRegister(i2cConfig, CTRL_REG2_addr, ctrl_reg2))
+    if (!i2c.writeRegister(i2cConfig, CTRL_REG2, ctrl_reg2))
     {
         lastError = BUS_FAULT;
         return false;
@@ -194,8 +194,7 @@ bool LPS28DFW::setFullScaleRange(FullScaleRange fs)
 
 bool LPS28DFW::setDRDYInterrupt(bool drdy)
 {
-    if (!i2c.writeRegister(i2cConfig, CTRL_REG4_addr,
-                           (drdy ? (INT_EN | DRDY) : 0)))
+    if (!i2c.writeRegister(i2cConfig, CTRL_REG4, (drdy ? (INT_EN | DRDY) : 0)))
     {
         lastError = BUS_FAULT;
         return false;
@@ -237,8 +236,8 @@ LPS28DFWData LPS28DFW::sampleImpl()
         uint8_t ctrl_reg2_val{0};
 
         // Triggering sampling
-        if (!(i2c.readRegister(i2cConfig, CTRL_REG2_addr, ctrl_reg2_val) &&
-              i2c.writeRegister(i2cConfig, CTRL_REG2_addr,
+        if (!(i2c.readRegister(i2cConfig, CTRL_REG2, ctrl_reg2_val) &&
+              i2c.writeRegister(i2cConfig, CTRL_REG2,
                                 ctrl_reg2_val | CTRL_REG2::ONE_SHOT_START)))
         {
             lastError = BUS_FAULT;
@@ -248,7 +247,7 @@ LPS28DFWData LPS28DFW::sampleImpl()
         // Poll status register until the sample is ready
         do
         {
-            if (!i2c.readRegister(i2cConfig, STATUS_addr, statusValue))
+            if (!i2c.readRegister(i2cConfig, STATUS, statusValue))
             {
                 lastError = BUS_FAULT;
                 return lastSample;
@@ -259,7 +258,7 @@ LPS28DFWData LPS28DFW::sampleImpl()
     else
     {
         // read status register value
-        if (!i2c.readRegister(i2cConfig, STATUS_addr, statusValue))
+        if (!i2c.readRegister(i2cConfig, STATUS, statusValue))
         {
             lastError = BUS_FAULT;
             return lastSample;
@@ -270,7 +269,7 @@ LPS28DFWData LPS28DFW::sampleImpl()
 
     // reading 5 bytes if also Temperature new sample, otherwise only the 3
     // pressure bytes
-    if (!i2c.readFromRegister(i2cConfig, PRESS_OUT_XL_addr, val,
+    if (!i2c.readFromRegister(i2cConfig, PRESS_OUT_XL, val,
                               ((statusValue & STATUS::T_DA) ? 5 : 3)))
     {
         lastError = BUS_FAULT;
diff --git a/src/shared/sensors/LPS28DFW/LPS28DFWDefs.h b/src/shared/sensors/LPS28DFW/LPS28DFWDefs.h
index 36287c7a8..d189ca321 100644
--- a/src/shared/sensors/LPS28DFW/LPS28DFWDefs.h
+++ b/src/shared/sensors/LPS28DFW/LPS28DFWDefs.h
@@ -42,46 +42,46 @@ static const float temperatureSensitivity{
 
 enum Registers : uint8_t
 {
-    INTERRUPT_CFG_addr = 0x0B,  ///< Interrupt mode for pressure acquisition
+    INTERRUPT_CFG = 0x0B,  ///< Interrupt mode for pressure acquisition
 
-    THS_P_L_addr = 0x0C,  ///< User-defined threshold LSB register
-    THS_P_H_addr = 0x0D,  ///< User-defined threshold MSB register
+    THS_P_L = 0x0C,  ///< User-defined threshold LSB register
+    THS_P_H = 0x0D,  ///< User-defined threshold MSB register
 
-    IF_CTRL_addr = 0x0E,  ///< Interface control register
+    IF_CTRL = 0x0E,  ///< Interface control register
 
-    WHO_AM_I_addr = 0x0F,  ///< Device Who am I register
+    WHO_AM_I = 0x0F,  ///< Device Who am I register
 
-    CTRL_REG1_addr = 0x10,  ///< Control Register 1 [ODR, AVG]
-    CTRL_REG2_addr = 0x11,  ///< Control Register 2
-    CTRL_REG3_addr = 0x12,  ///< Control Register 3
-    CTRL_REG4_addr = 0x13,  ///< Control Register 4
+    CTRL_REG1 = 0x10,  ///< Control Register 1 [ODR, AVG]
+    CTRL_REG2 = 0x11,  ///< Control Register 2
+    CTRL_REG3 = 0x12,  ///< Control Register 3
+    CTRL_REG4 = 0x13,  ///< Control Register 4
 
-    FIFO_CTRL_addr = 0x14,  ///< FIFO control register
-    FIFO_WTM_addr  = 0x15,  ///< FIFO threshold setting register
+    FIFO_CTRL = 0x14,  ///< FIFO control register
+    FIFO_WTM  = 0x15,  ///< FIFO threshold setting register
 
-    REF_P_L_addr = 0x16,  ///< Reference pressure LSB data
-    REF_P_H_addr = 0x17,  ///< Reference pressure MSB data
+    REF_P_L = 0x16,  ///< Reference pressure LSB data
+    REF_P_H = 0x17,  ///< Reference pressure MSB data
 
-    RPDS_L_addr = 0x1a,  ///< Pressure offset LSB data
-    RPDS_H_addr = 0x1b,  ///< Pressure offset HSB data
+    RPDS_L = 0x1a,  ///< Pressure offset LSB data
+    RPDS_H = 0x1b,  ///< Pressure offset HSB data
 
-    INT_SOURCE_addr = 0x24,  ///< Interrupt source register
+    INT_SOURCE = 0x24,  ///< Interrupt source register
 
-    FIFO_STATUS1_addr = 0x25,  ///< FIFO status register 1
-    FIFO_STATUS2_addr = 0x26,  ///< FIFO status register 2
+    FIFO_STATUS1 = 0x25,  ///< FIFO status register 1
+    FIFO_STATUS2 = 0x26,  ///< FIFO status register 2
 
-    STATUS_addr = 0x27,  ///< Status register
+    STATUS = 0x27,  ///< Status register
 
-    PRESS_OUT_XL_addr = 0x28,  ///< Pressure output value LSB data
-    PRESS_OUT_L_addr  = 0x29,  ///< Pressure output value middle data
-    PRESS_OUT_H_addr  = 0x2a,  ///< Pressure output value MSB data
+    PRESS_OUT_XL = 0x28,  ///< Pressure output value LSB data
+    PRESS_OUT_L  = 0x29,  ///< Pressure output value middle data
+    PRESS_OUT_H  = 0x2a,  ///< Pressure output value MSB data
 
-    TEMP_OUT_L_addr = 0x2b,  ///< Temperature output value LSB data
-    TEMP_OUT_H_addr = 0x2c,  ///< Temperature output value MSB data
+    TEMP_OUT_L = 0x2b,  ///< Temperature output value LSB data
+    TEMP_OUT_H = 0x2c,  ///< Temperature output value MSB data
 
-    FIFO_DATA_OUT_PRESS_XL_addr = 0x78,  ///< FIFO pressure output LSB data
-    FIFO_DATA_OUT_PRESS_L_addr  = 0x79,  ///< FIFO pressure output middle data
-    FIFO_DATA_OUT_PRESS_H_addr  = 0x7a,  ///< FIFO pressure output MSB data
+    FIFO_DATA_OUT_PRESS_XL = 0x78,  ///< FIFO pressure output LSB data
+    FIFO_DATA_OUT_PRESS_L  = 0x79,  ///< FIFO pressure output middle data
+    FIFO_DATA_OUT_PRESS_H  = 0x7a,  ///< FIFO pressure output MSB data
 };
 
 enum CTRL_REG2 : uint8_t
diff --git a/src/tests/sensors/test-lps28dfw.cpp b/src/tests/sensors/test-lps28dfw.cpp
index c39bfd443..e5a287d1f 100644
--- a/src/tests/sensors/test-lps28dfw.cpp
+++ b/src/tests/sensors/test-lps28dfw.cpp
@@ -107,6 +107,8 @@ void sampleContinuousMode(I2C &i2c)
 
     for (uint8_t i = 0; i < nSamples; i++)
     {
+        Thread::sleep(100);
+
         lps28dfw.sample();
 
         if (lps28dfw.getLastError() == SensorErrors::NO_ERRORS)
@@ -117,8 +119,6 @@ void sampleContinuousMode(I2C &i2c)
         {
             printf("Error: %d\n", lps28dfw.getLastError());
         }
-
-        Thread::sleep(100);
     }
 
     printf("End Continuous\n");
-- 
GitLab