File tree 4 files changed +31
-19
lines changed
drivers/sensor/st/lis2dux12
include/zephyr/dt-bindings/sensor
tests/drivers/build_all/sensor
4 files changed +31
-19
lines changed Original file line number Diff line number Diff line change @@ -50,21 +50,33 @@ static const float lis2dux12_odr_map[LIS2DUX12_DT_ODR_END] = {FOREACH_ODR_ENUM(G
50
50
static int lis2dux12_freq_to_odr_val (const struct device * dev , uint16_t freq )
51
51
{
52
52
const struct lis2dux12_config * cfg = dev -> config ;
53
+ int odr ;
53
54
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
+ }
59
60
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 ;
63
74
}
64
- ++ i ;
75
+
76
+ odr |= 0x10 ;
65
77
}
66
78
67
- return - EINVAL ;
79
+ return odr ;
68
80
}
69
81
70
82
static int lis2dux12_set_fs (const struct device * dev , int16_t fs )
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ description: |
5
5
When setting the odr, power-mode, and range properties in a .dts or .dtsi file you may include
6
6
st_lis2dux12.h and use the macros defined there.
7
7
Example:
8
- #include <zephyr/dt-bindings/sensor/st_lis2dux12 .h>
8
+ #include <zephyr/dt-bindings/sensor/lis2dux12 .h>
9
9
lis2dux12: lis2dux12@0 {
10
10
...
11
11
power-mode = <LIS2DUX12_OPER_MODE_LOW_POWER>;
@@ -68,8 +68,8 @@ properties:
68
68
69
69
- 0 # LIS2DUX12_OPER_MODE_POWER_DOWN
70
70
- 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
73
73
74
74
enum : [0, 1, 2, 3]
75
75
Original file line number Diff line number Diff line change 9
9
#include <zephyr/dt-bindings/dt-util.h>
10
10
11
11
/* 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
16
16
17
17
/* Data rate */
18
18
#define LIS2DUX12_DT_ODR_OFF 0
Original file line number Diff line number Diff line change @@ -1010,7 +1010,7 @@ test_i2c_lis2dux12: lis2dux12@8a {
1010
1010
int2-gpios = <&test_gpio 0 0>;
1011
1011
range = <LIS2DUX12_DT_FS_16G>;
1012
1012
odr = <LIS2DUX12_DT_ODR_100Hz>;
1013
- power-mode = <LIS2DUX12_OPER_MODE_HIGH_FREQUENCY >;
1013
+ power-mode = <LIS2DUX12_OPER_MODE_HIGH_PERFORMANCE >;
1014
1014
status = "okay";
1015
1015
};
1016
1016
@@ -1227,7 +1227,7 @@ test_i2c_lis2duxs12: lis2duxs12@a7 {
1227
1227
int2-gpios = <&test_gpio 0 0>;
1228
1228
range = <LIS2DUX12_DT_FS_16G>;
1229
1229
odr = <LIS2DUX12_DT_ODR_100Hz>;
1230
- power-mode = <LIS2DUX12_OPER_MODE_HIGH_FREQUENCY >;
1230
+ power-mode = <LIS2DUX12_OPER_MODE_HIGH_PERFORMANCE >;
1231
1231
status = "okay";
1232
1232
};
1233
1233
You can’t perform that action at this time.
0 commit comments