Skip to content

Commit 2eaec8b

Browse files
aviscontinashif
authored andcommitted
sensor: lis2dux12: fix SENSOR_ATTR_FULL_SCALE case
When setting the full scale through SENSOR_ATTR_FULL_SCALE the driver must convert the g value (i.e. one of 2g/4g/8g/16g) to the corrispondent sensor fs raw value. Signed-off-by: Armando Visconti <armando.visconti@st.com>
1 parent 878b5a9 commit 2eaec8b

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

drivers/sensor/st/lis2dux12/lis2dux12.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,47 @@ static int lis2dux12_freq_to_odr_val(const struct device *dev, uint16_t freq)
107107
return -EINVAL;
108108
}
109109

110+
static int lis2dux12_set_fs(const struct device *dev, int16_t fs)
111+
{
112+
int ret;
113+
uint8_t range;
114+
115+
switch (fs) {
116+
case 2:
117+
range = LIS2DUX12_DT_FS_2G;
118+
break;
119+
case 4:
120+
range = LIS2DUX12_DT_FS_4G;
121+
break;
122+
case 8:
123+
range = LIS2DUX12_DT_FS_8G;
124+
break;
125+
case 16:
126+
range = LIS2DUX12_DT_FS_16G;
127+
break;
128+
default:
129+
LOG_ERR("fs [%d] not supported.", fs);
130+
return -EINVAL;
131+
}
132+
133+
ret = lis2dux12_set_range(dev, range);
134+
if (ret < 0) {
135+
LOG_ERR("%s: range init error %d", dev->name, range);
136+
return ret;
137+
}
138+
139+
LOG_DBG("%s: set fs to %d g", dev->name, fs);
140+
return ret;
141+
}
142+
110143
static int lis2dux12_accel_config(const struct device *dev, enum sensor_channel chan,
111144
enum sensor_attribute attr, const struct sensor_value *val)
112145
{
113146
int odr_val;
114147

115148
switch (attr) {
116149
case SENSOR_ATTR_FULL_SCALE:
117-
return lis2dux12_set_range(dev, sensor_ms2_to_g(val));
150+
return lis2dux12_set_fs(dev, sensor_ms2_to_g(val));
118151
case SENSOR_ATTR_SAMPLING_FREQUENCY:
119152
odr_val = lis2dux12_freq_to_odr_val(dev, val->val1);
120153
if (odr_val < 0) {

0 commit comments

Comments
 (0)