File tree Expand file tree Collapse file tree 4 files changed +31
-19
lines changed
drivers/sensor/st/lis2dux12
include/zephyr/dt-bindings/sensor
tests/drivers/build_all/sensor Expand file tree Collapse file tree 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
5050static 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
7082static 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: |
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
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments