Skip to content

drivers/sensor/: lis2dux12: fix ODR setting #92641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions drivers/sensor/st/lis2dux12/lis2dux12.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ static int lis2dux12_freq_to_odr_val(const struct device *dev, uint16_t freq)
int odr;

for (odr = LIS2DUX12_DT_ODR_OFF; odr < LIS2DUX12_DT_ODR_END; odr++) {
/*
* In case power-mode is HP, skip the ULP odrs in order to
* avoid to erroneously break the loop sooner than expected.
* In HP mode the correct ODRs must be found from
* LIS2DUX12_DT_ODR_6Hz on.
*/
if ((cfg->pm == LIS2DUX12_OPER_MODE_HIGH_PERFORMANCE) &&
((odr == LIS2DUX12_DT_ODR_1Hz_ULP) ||
(odr == LIS2DUX12_DT_ODR_3Hz_ULP) ||
(odr == LIS2DUX12_DT_ODR_25Hz_ULP))) {
continue;
}

if (freq <= lis2dux12_odr_map[odr]) {
break;
}
Expand All @@ -69,15 +82,6 @@ static int lis2dux12_freq_to_odr_val(const struct device *dev, uint16_t freq)
return LIS2DUX12_DT_ODR_OFF;
}

/* handle high performance mode */
if (cfg->pm == LIS2DUX12_OPER_MODE_HIGH_PERFORMANCE) {
if (odr < LIS2DUX12_DT_ODR_6Hz) {
odr = LIS2DUX12_DT_ODR_6Hz;
}

odr |= 0x10;
}

return odr;
}

Expand Down
14 changes: 13 additions & 1 deletion drivers/sensor/st/lis2dux12/lis2dux12_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@ static int32_t st_lis2dux12_set_odr_raw(const struct device *dev, uint8_t odr)
struct lis2dux12_data *data = dev->data;
const struct lis2dux12_config *cfg = dev->config;
stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx;
lis2dux12_md_t mode = {.odr = odr, .fs = data->range};
lis2dux12_md_t mode;

/* handle high performance mode */
if (cfg->pm == LIS2DUX12_OPER_MODE_HIGH_PERFORMANCE) {
if (odr < LIS2DUX12_DT_ODR_6Hz) {
odr = LIS2DUX12_DT_ODR_6Hz;
}

odr |= 0x10;
}

mode.odr = odr;
mode.fs = data->range;

data->odr = odr;
return lis2dux12_mode_set(ctx, &mode);
Expand Down
14 changes: 13 additions & 1 deletion drivers/sensor/st/lis2dux12/lis2duxs12_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,19 @@ static int32_t st_lis2duxs12_set_odr_raw(const struct device *dev, uint8_t odr)
struct lis2dux12_data *data = dev->data;
const struct lis2dux12_config *cfg = dev->config;
stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx;
lis2duxs12_md_t mode = {.odr = odr, .fs = data->range};
lis2duxs12_md_t mode;

/* handle high performance mode */
if (cfg->pm == LIS2DUX12_OPER_MODE_HIGH_PERFORMANCE) {
if (odr < LIS2DUX12_DT_ODR_6Hz) {
odr = LIS2DUX12_DT_ODR_6Hz;
}

odr |= 0x10;
}

mode.odr = odr;
mode.fs = data->range;

data->odr = odr;
return lis2duxs12_mode_set(ctx, &mode);
Expand Down