libhal / libhal.github.io

Organization wide repo for docs, assets, and tools any other static information
Apache License 2.0
0 stars 1 forks source link

Power down guide #34

Open kammce opened 3 weeks ago

kammce commented 3 weeks ago

Explain how powering down devices and peripherals works in libhal. Specifically, power down APIs should be:

void class::power_down();

But this may be too limiting as there maybe other options for powering down the devices such as deep sleep, complete shutdown, low power mode, etc.

An important specification is that all APIs that are not powering down the device, MUST perform the work of bringing the device into a power state where the API can work successfully. This prevents the viral pattern of:

if (driver.is_powered_down()) {
  driver.power_on();
}
driver.use_api();

The issue with this pattern is that it spreads EVERYWHERE and will have to be placed before every driver api usage, when possible.