Skip to content

Commit a887fe1

Browse files
thugheskartben
authored andcommitted
drivers: sensor: Fix unused function warning
Building with clang warns: drivers/sensor/st/lis2dw12/lis2dw12.c:194:23: error: unused function 'sensor_ms2_to_mg' [-Werror,-Wunused-function] static inline int32_t sensor_ms2_to_mg(const struct sensor_value *ms2) ^ Move the function to include/zephyr/drivers/sensor.h with the other sensor_ms2_to* functions. Signed-off-by: Tom Hughes <[email protected]>
1 parent 5bb0298 commit a887fe1

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

drivers/sensor/st/lis2dw12/lis2dw12.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -190,18 +190,6 @@ static int lis2dw12_config(const struct device *dev, enum sensor_channel chan,
190190
return -ENOTSUP;
191191
}
192192

193-
194-
static inline int32_t sensor_ms2_to_mg(const struct sensor_value *ms2)
195-
{
196-
int64_t nano_ms2 = (ms2->val1 * 1000000LL + ms2->val2) * 1000LL;
197-
198-
if (nano_ms2 > 0) {
199-
return (nano_ms2 + SENSOR_G / 2) / SENSOR_G;
200-
} else {
201-
return (nano_ms2 - SENSOR_G / 2) / SENSOR_G;
202-
}
203-
}
204-
205193
#if (CONFIG_LIS2DW12_SLEEP || CONFIG_LIS2DW12_WAKEUP)
206194

207195
/* Converts a lis2dw12_fs_t range to its value in milli-g

include/zephyr/drivers/sensor.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,25 @@ static inline void sensor_g_to_ms2(int32_t g, struct sensor_value *ms2)
12081208
ms2->val2 = ((int64_t)g * SENSOR_G) % 1000000LL;
12091209
}
12101210

1211+
/**
1212+
* @brief Helper function to convert acceleration from m/s^2 to milli Gs
1213+
*
1214+
* @param ms2 A pointer to a sensor_value struct holding the acceleration,
1215+
* in m/s^2.
1216+
*
1217+
* @return The converted value, in milli Gs.
1218+
*/
1219+
static inline int32_t sensor_ms2_to_mg(const struct sensor_value *ms2)
1220+
{
1221+
int64_t nano_ms2 = (ms2->val1 * 1000000LL + ms2->val2) * 1000LL;
1222+
1223+
if (nano_ms2 > 0) {
1224+
return (nano_ms2 + SENSOR_G / 2) / SENSOR_G;
1225+
} else {
1226+
return (nano_ms2 - SENSOR_G / 2) / SENSOR_G;
1227+
}
1228+
}
1229+
12111230
/**
12121231
* @brief Helper function to convert acceleration from m/s^2 to micro Gs
12131232
*

0 commit comments

Comments
 (0)