Skip to content

Commit 4c34b5d

Browse files
aviscontikartben
authored andcommitted
drivers/sensor: lis2dux12: add high performance mode
Add driver capability to properly set high performance mode while setting data rate (thru lis2duxxx_mode_set() API) based on how power-mode is set into DTS: if it is set to LIS2DUX12_OPER_MODE_HIGH_PERFORMANCE then configure HP mode, LP/ULP mode otherwise. Signed-off-by: Armando Visconti <[email protected]>
1 parent dc52ec7 commit 4c34b5d

File tree

4 files changed

+31
-19
lines changed

4 files changed

+31
-19
lines changed

drivers/sensor/st/lis2dux12/lis2dux12.c

+22-10
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,33 @@ static const float lis2dux12_odr_map[LIS2DUX12_DT_ODR_END] = {FOREACH_ODR_ENUM(G
5050
static int lis2dux12_freq_to_odr_val(const struct device *dev, uint16_t freq)
5151
{
5252
const struct lis2dux12_config *cfg = dev->config;
53+
int odr;
5354

54-
/* constrain loop to prevent erroneous power mode/odr combinations */
55-
size_t i = (cfg->pm != LIS2DUX12_OPER_MODE_LOW_POWER) ? LIS2DUX12_DT_ODR_6Hz
56-
: LIS2DUX12_DT_ODR_1Hz_ULP;
57-
size_t len = (cfg->pm != LIS2DUX12_OPER_MODE_LOW_POWER) ? LIS2DUX12_DT_ODR_END
58-
: LIS2DUX12_DT_ODR_6Hz;
55+
for (odr = LIS2DUX12_DT_ODR_OFF; odr < LIS2DUX12_DT_ODR_END; odr++) {
56+
if (freq <= lis2dux12_odr_map[odr]) {
57+
break;
58+
}
59+
}
5960

60-
while (i < len) {
61-
if (freq <= lis2dux12_odr_map[i]) {
62-
return i;
61+
if (unlikely(odr == LIS2DUX12_DT_ODR_END)) {
62+
/* no valid odr found */
63+
return -EINVAL;
64+
}
65+
66+
if (unlikely(odr == LIS2DUX12_DT_ODR_OFF)) {
67+
return LIS2DUX12_DT_ODR_OFF;
68+
}
69+
70+
/* handle high performance mode */
71+
if (cfg->pm == LIS2DUX12_OPER_MODE_HIGH_PERFORMANCE) {
72+
if (odr < LIS2DUX12_DT_ODR_6Hz) {
73+
odr = LIS2DUX12_DT_ODR_6Hz;
6374
}
64-
++i;
75+
76+
odr |= 0x10;
6577
}
6678

67-
return -EINVAL;
79+
return odr;
6880
}
6981

7082
static int lis2dux12_set_fs(const struct device *dev, int16_t fs)

dts/bindings/sensor/st,lis2dux12-common.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: |
55
When setting the odr, power-mode, and range properties in a .dts or .dtsi file you may include
66
st_lis2dux12.h and use the macros defined there.
77
Example:
8-
#include <zephyr/dt-bindings/sensor/st_lis2dux12.h>
8+
#include <zephyr/dt-bindings/sensor/lis2dux12.h>
99
lis2dux12: lis2dux12@0 {
1010
...
1111
power-mode = <LIS2DUX12_OPER_MODE_LOW_POWER>;
@@ -68,8 +68,8 @@ properties:
6868
6969
- 0 # LIS2DUX12_OPER_MODE_POWER_DOWN
7070
- 1 # LIS2DUX12_OPER_MODE_LOW_POWER
71-
- 2 # LIS2DUX12_OPER_MODE_HIGH_RESOLUTION
72-
- 3 # LIS2DUX12_OPER_MODE_HIGH_FREQUENCY
71+
- 2 # LIS2DUX12_OPER_MODE_HIGH_PERFORMANCE
72+
- 3 # LIS2DUX12_OPER_MODE_SINGLE_SHOT
7373
7474
enum: [0, 1, 2, 3]
7575

include/zephyr/dt-bindings/sensor/lis2dux12.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
#include <zephyr/dt-bindings/dt-util.h>
1010

1111
/* Operating Mode */
12-
#define LIS2DUX12_OPER_MODE_POWER_DOWN 0
13-
#define LIS2DUX12_OPER_MODE_LOW_POWER 1
14-
#define LIS2DUX12_OPER_MODE_HIGH_RESOLUTION 2
15-
#define LIS2DUX12_OPER_MODE_HIGH_FREQUENCY 3
12+
#define LIS2DUX12_OPER_MODE_POWER_DOWN 0
13+
#define LIS2DUX12_OPER_MODE_LOW_POWER 1
14+
#define LIS2DUX12_OPER_MODE_HIGH_PERFORMANCE 2
15+
#define LIS2DUX12_OPER_MODE_SINGLE_SHOT 3
1616

1717
/* Data rate */
1818
#define LIS2DUX12_DT_ODR_OFF 0

tests/drivers/build_all/sensor/i2c.dtsi

+2-2
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ test_i2c_lis2dux12: lis2dux12@8a {
10101010
int2-gpios = <&test_gpio 0 0>;
10111011
range = <LIS2DUX12_DT_FS_16G>;
10121012
odr = <LIS2DUX12_DT_ODR_100Hz>;
1013-
power-mode = <LIS2DUX12_OPER_MODE_HIGH_FREQUENCY>;
1013+
power-mode = <LIS2DUX12_OPER_MODE_HIGH_PERFORMANCE>;
10141014
status = "okay";
10151015
};
10161016

@@ -1227,7 +1227,7 @@ test_i2c_lis2duxs12: lis2duxs12@a7 {
12271227
int2-gpios = <&test_gpio 0 0>;
12281228
range = <LIS2DUX12_DT_FS_16G>;
12291229
odr = <LIS2DUX12_DT_ODR_100Hz>;
1230-
power-mode = <LIS2DUX12_OPER_MODE_HIGH_FREQUENCY>;
1230+
power-mode = <LIS2DUX12_OPER_MODE_HIGH_PERFORMANCE>;
12311231
status = "okay";
12321232
};
12331233

0 commit comments

Comments
 (0)