sensor: bme680: support power domains
Support the BME680 being on a power domain, which may not be powered at boot. For example, Nordic Thingy53. Signed-off-by: Jordan Yates <jordan@embeint.com>
This commit is contained in:
parent
ecbcb5b80f
commit
5953a26dc6
1 changed files with 37 additions and 13 deletions
|
@ -18,6 +18,7 @@
|
||||||
#include <zephyr/sys/__assert.h>
|
#include <zephyr/sys/__assert.h>
|
||||||
#include <zephyr/drivers/sensor.h>
|
#include <zephyr/drivers/sensor.h>
|
||||||
#include <zephyr/logging/log.h>
|
#include <zephyr/logging/log.h>
|
||||||
|
#include <zephyr/pm/device.h>
|
||||||
|
|
||||||
#include "bme680.h"
|
#include "bme680.h"
|
||||||
|
|
||||||
|
@ -375,17 +376,11 @@ static int bme680_read_compensation(const struct device *dev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bme680_init(const struct device *dev)
|
static int bme680_power_up(const struct device *dev)
|
||||||
{
|
{
|
||||||
struct bme680_data *data = dev->data;
|
struct bme680_data *data = dev->data;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = bme680_bus_check(dev);
|
|
||||||
if (err < 0) {
|
|
||||||
LOG_ERR("Bus not ready for '%s'", dev->name);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if BME680_BUS_SPI
|
#if BME680_BUS_SPI
|
||||||
if (bme680_is_on_spi(dev)) {
|
if (bme680_is_on_spi(dev)) {
|
||||||
uint8_t mem_page;
|
uint8_t mem_page;
|
||||||
|
@ -426,8 +421,7 @@ static int bme680_init(const struct device *dev)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = bme680_reg_write(dev, BME680_REG_CTRL_GAS_1,
|
err = bme680_reg_write(dev, BME680_REG_CTRL_GAS_1, BME680_CTRL_GAS_1_VAL);
|
||||||
BME680_CTRL_GAS_1_VAL);
|
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -444,12 +438,41 @@ static int bme680_init(const struct device *dev)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = bme680_reg_write(dev, BME680_REG_CTRL_MEAS,
|
return bme680_reg_write(dev, BME680_REG_CTRL_MEAS, BME680_CTRL_MEAS_VAL);
|
||||||
BME680_CTRL_MEAS_VAL);
|
}
|
||||||
|
|
||||||
|
static int bme680_pm_control(const struct device *dev, enum pm_device_action action)
|
||||||
|
{
|
||||||
|
int rc = 0;
|
||||||
|
|
||||||
|
switch (action) {
|
||||||
|
case PM_DEVICE_ACTION_SUSPEND:
|
||||||
|
case PM_DEVICE_ACTION_RESUME:
|
||||||
|
case PM_DEVICE_ACTION_TURN_OFF:
|
||||||
|
break;
|
||||||
|
case PM_DEVICE_ACTION_TURN_ON:
|
||||||
|
rc = bme680_power_up(dev);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return -ENOTSUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int bme680_init(const struct device *dev)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
|
||||||
|
err = bme680_bus_check(dev);
|
||||||
|
if (err < 0) {
|
||||||
|
LOG_ERR("Bus not ready for '%s'", dev->name);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return pm_device_driver_init(dev, bme680_pm_control);
|
||||||
|
}
|
||||||
|
|
||||||
static const struct sensor_driver_api bme680_api_funcs = {
|
static const struct sensor_driver_api bme680_api_funcs = {
|
||||||
.sample_fetch = bme680_sample_fetch,
|
.sample_fetch = bme680_sample_fetch,
|
||||||
.channel_get = bme680_channel_get,
|
.channel_get = bme680_channel_get,
|
||||||
|
@ -480,9 +503,10 @@ static const struct sensor_driver_api bme680_api_funcs = {
|
||||||
COND_CODE_1(DT_INST_ON_BUS(inst, spi), \
|
COND_CODE_1(DT_INST_ON_BUS(inst, spi), \
|
||||||
(BME680_CONFIG_SPI(inst)), \
|
(BME680_CONFIG_SPI(inst)), \
|
||||||
(BME680_CONFIG_I2C(inst))); \
|
(BME680_CONFIG_I2C(inst))); \
|
||||||
|
PM_DEVICE_DT_INST_DEFINE(inst, bme680_pm_control); \
|
||||||
SENSOR_DEVICE_DT_INST_DEFINE(inst, \
|
SENSOR_DEVICE_DT_INST_DEFINE(inst, \
|
||||||
bme680_init, \
|
bme680_init, \
|
||||||
NULL, \
|
PM_DEVICE_DT_INST_GET(inst), \
|
||||||
&bme680_data_##inst, \
|
&bme680_data_##inst, \
|
||||||
&bme680_config_##inst, \
|
&bme680_config_##inst, \
|
||||||
POST_KERNEL, \
|
POST_KERNEL, \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue