Skip to content

Commit

Permalink
drivers/sensor: lps22hh: Enable fetching individual sensor channels
Browse files Browse the repository at this point in the history
Add the possibility to fetch specific sensor channels independently,
either pressure data with SENSOR_CHAN_PRESS or temperature data
with SENSOR_CHAN_AMBIENT_TEMP.
Additionally, the option to fetch both channels simultaneously remains
available using SENSOR_CHAN_ALL, thus not breaking any samples.

(cherry picked from commit 61536c1)

Original-Signed-off-by: Chris Braissant <chrisbraissant@gmail.com>
GitOrigin-RevId: 61536c1
Change-Id: Ic245b5bc3264358162f979b925645b223d721378
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/zephyr/+/5597077
Tested-by: Fabio Baltieri <fabiobaltieri@google.com>
Commit-Queue: Fabio Baltieri <fabiobaltieri@google.com>
Tested-by: ChromeOS Prod (Robot) <chromeos-ci-prod@chromeos-bot.iam.gserviceaccount.com>
Reviewed-by: Fabio Baltieri <fabiobaltieri@google.com>
  • Loading branch information
cbraissant authored and Chromeos LUCI committed Jun 4, 2024
1 parent a5bbc4a commit 139887b
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions drivers/sensor/st/lps22hh/lps22hh.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,36 @@ static int lps22hh_sample_fetch(const struct device *dev,
uint32_t raw_press;
int16_t raw_temp;

__ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL);

if (lps22hh_pressure_raw_get(ctx, &raw_press) < 0) {
LOG_DBG("Failed to read sample");
return -EIO;
}
if (lps22hh_temperature_raw_get(ctx, &raw_temp) < 0) {
LOG_DBG("Failed to read sample");
return -EIO;
__ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL
|| chan == SENSOR_CHAN_PRESS
|| chan == SENSOR_CHAN_AMBIENT_TEMP);

switch (chan) {
case SENSOR_CHAN_PRESS:
if (lps22hh_pressure_raw_get(ctx, &raw_press) < 0) {
LOG_DBG("Failed to read sample");
return -EIO;
}
break;
case SENSOR_CHAN_AMBIENT_TEMP:
if (lps22hh_temperature_raw_get(ctx, &raw_temp) < 0) {
LOG_DBG("Failed to read sample");
return -EIO;
}
break;
case SENSOR_CHAN_ALL:
if (lps22hh_pressure_raw_get(ctx, &raw_press) < 0) {
LOG_DBG("Failed to read sample");
return -EIO;
}
if (lps22hh_temperature_raw_get(ctx, &raw_temp) < 0) {
LOG_DBG("Failed to read sample");
return -EIO;
}
break;
default:
LOG_ERR("Unsupported sensor channel");
return -ENOTSUP;
}

data->sample_press = raw_press;
Expand Down

0 comments on commit 139887b

Please sign in to comment.