what is the best practice for sensor power down/up management and driver (de)initialise

Hi, 

I have a board that has a couple of sensors and their power switches to turn on and off to save power. Whenever i dont need the sensor, i need to shut it down. But after turning it on, i need to initialise their driver again, 

for example, BME680 sensor, if I use the default bme680 driver, it is initialised during boot in post kernel:  to initialise it whenever I need basically.

SENSOR_DEVICE_DT_INST_DEFINE(inst,				\
			 bme680_init,					\
			 NULL,						\
			 &bme680_data_##inst,				\
			 &bme680_config_##inst,				\
			 POST_KERNEL,					\
			 CONFIG_SENSOR_INIT_PRIORITY,			\
			 &bme680_api_funcs);

 it seems it is obvious that I need to edit the default driver file, but 

Q1: I am unsure How I can init the driver in runtime. As far as I see in other questions, the power management system for Zephyr is recommended https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/services/pm/index.html . is it enough to read that page to achieve my intention? I also saw in some of the questions regulators APIs and had a quick search about this, https://developer.nordicsemi.com/nRF_Connect_SDK/doc/1.9.2-dev1/zephyr/reference/peripherals/regulators.html

So It seems I need this one too and to use a combination of power management and regulator apis.

Is there any sample to see this mechanism? or can you please shed some light on what should be the steps for this?

and this is the other question looks like it is a similar one.  Power off LSM6DSO Sensor between measurements 

Thank you, Kind regars

  • Hello,

    My impressions is that many of the sensor drivers have got the PM_DEVICE_DT_INST_DEFINE() macro that allow the application to transition between the power states by calling pm_device_action_run(device, PM_DEVICE_ACTION_SUSPEND) and pm_device_action_run(device, PM_DEVICE_ACTION_RESUME). Unfortunatly I can see that is not supported for the bme680, so I guess you will have to add support for this yourself, similar to for intance bme280, where you can see the third parameter in SENSOR_DEVICE_DT_INST_DEFINE() is PM_DEVICE_DT_INST_GET(inst).

    Relevant files:
    \v2.5.0\zephyr\drivers\sensor\bme280\bme280.c
    \v2.5.0\zephyr\drivers\sensor\bme680\bme680.c

    Edit: Drivers will always be init during boot in any case, but you can allways put it to sleep after startup by using PM_DEVICE_ACTION_SUSPEND. 

    Kenneth

Related