Power Management

Class Name: Power

Functions related to power management might involve registers of the IP5306 chip. For any uncertainties, you can refer to the IP5306 register manual .

The IP5306 chip does not support communication with older M5STACK hardware. When using features, also consider support for uncontrollable situations.

Use in order: initialization, communication check, and control, as shown in the example below:

  M5.Power.begin();
  if(!M5.Power.canControl()) {
    //can't control.
    return;
  }
  M5.Power.lightSleep(SLEEP_SEC(5));

begin()

Functionality:

Initializes the Power class.

Function Prototype:

void begin()

Usage Example:

#include <M5Stack.h>

void setup() {
    M5.begin();
    M5.Power.begin();
}

void loop() {}

setPowerBoostOnOff()

Functionality:

Changes the method of turning the device on/off with the power button.

Note:
The device will not power off when connected via USB.

Function Prototype:

bool setPowerBoostOnOff(bool en)

en Functionality
true Long press to turn on/off
false Double press to turn on/off

Return Value:

Value Functionality
true Control succeeded
false Control failed

Usage Example:

#include <M5Stack.h>

void setup() {
    M5.begin();
    M5.Power.begin();
    if (M5.Power.setPowerBoostOnOff(false)) {
        M5.Lcd.println("Changed power on/off method");
    } else {
        M5.Lcd.println("Failed to change power on/off method");
    }
}

void loop() {}

setPowerBoostKeepOn()

Functionality:

Changes the power on/off method. The power will not turn off when connected via USB.

Function Prototype:

bool setPowerBoostKeepOn(bool en)

en Functionality
true Short press for on/off
false Follow the setPowerBoostOnOff() method

Return Value:

Value Functionality
true Control succeeded
false Control failed

setPowerVin()

Functionality:

Decides whether to power on again when external sources like USB are disconnected.

Function Prototype:

bool setPowerVin(bool en)

Value Functionality
true Power will turn on again
false Power will not turn on again

Return Value:

Value Functionality
true Control succeeded
false Control failed

setPowerWLEDSet()

Functionality:

Sets the mode to turn on the power LED. Not controllable via this function for M5GO due to lack of wiring to IP5306.

Function Prototype:

bool setPowerWLEDSet(bool en)

Value Functionality
true Double press to turn on LED
false Hold to turn on LED

Return Value:

Value Functionality
true Control succeeded
false Control failed

setPowerBtnEn()

Functionality:

Sets whether to accept power button actions.

Regarding behavior when not accepting button actions: If the power is on, the power button only accepts CPU reset. If no power is provided, it's not possible to turn the power on.

Function Prototype:

bool setPowerBtnEn(bool en)

Value Functionality
true Accept power actions
false Do not accept power control

Return Value:

Value Functionality
true Control succeeded
false Control failed

setLowPowerShutdownTime()

Functionality:

Sets the wait time until IP5306 decides to save energy and turns off the power.

Function Prototype:

bool setLowPowerShutdownTime(ShutdownTime time)

Value Functionality
SHUTDOWN_8S Wait 8 seconds
SHUTDOWN_16S Wait 16 seconds
SHUTDOWN_32S Wait 32 seconds
SHUTDOWN_64S Wait 64 seconds

Return Value:

| Value | Function

| ality | | ----- | ----------------- | | true | Control succeeded | | false | Control failed |

setPowerBoostKeepOn()

Functionality:

This function enables/disables the always-on boost output mode.

Function Prototype:

bool setPowerBoostKeepOn(bool en)

Value Functionality
true Always provide power output
false Do not always provide power output

Return Value:

Value Functionality
true Control succeeded
false Control failed

setAutoBootOnLoad()

Functionality:

Sets whether to auto-boot when there is a power consumption on the secondary side of IP5306.

Function Prototype:

bool setAutoBootOnLoad(bool en)

Value Functionality
true Enable auto-boot feature
false Disable auto-boot feature

Return Value:

Value Functionality
true Control succeeded
false Control failed

setCharge()

Functionality:

This function enables/disables charging mode. After the battery is full, toggling charge enable -> disable -> enable may allow charging to resume.

Function Prototype:

bool setCharge(bool en)

Value Functionality
true Begin charging command
false Stop charging command

Return Value:

Value Functionality
true Control succeeded
false Control failed

isChargeFull()

Functionality:

Checks if the battery is fully charged.

Function Prototype:

bool isChargeFull()

Return Value:

Value Functionality
true Fully charged
false Not fully charged

canControl()

Functionality:

This function checks if the battery controller is present via I2C communication.

Function Prototype:

bool canControl()

Return Value:

Value Functionality
true Power controller found
false Power controller not found

isCharging()

Functionality:

Checks if charging is in progress.

Function Prototype:

bool isCharging()

Return Value:

Value Functionality
true Charging
false Not charging

getBatteryLevel()

Functionality:

Returns the battery level.

Function Prototype:

int8_t getBatteryLevel()

Return Value:

Returns battery level as 0/25/50/75/100. Returns -1 if unable to check the remaining capacity.

setWakeupButton()

Functionality:

Sets the wake-up port upon sleep return.

Function Prototype:

void setWakeupButton(uint8_t button)

Value Functionality
button Port number

Usage Example:

setWakeupButton(BUTTON_A_PIN);

reset()

Functionality:

Performs a CPU reset.

Function Prototype:

void reset()

isResetbySoftware()

Functionality:

Determines if the current activation state is after a CPU reset. (Applies if executing reset() or an equivalent process such as RTOS.)

Function Prototype:

bool isResetbySoftware()

Return Value:

Value Functionality
true Reset by software
false Due to other reasons

isResetbyWatchdog()

Functionality:

Determines if the current activation state is after a watchdog timer.

Function Prototype:

bool isResetbyWatchdog()

Return Value:

Value Functionality
true Reset by watchdog
false Due to other reasons

isResetbyDeepsleep()

Functionality:

Determines if the current wake state is after deepSleep().

Function Prototype:

bool isResetbyDeepsleep()

Return Value:

Value Functionality
true After deepSleep()
false Due to other reasons

isResetbyPowerSW()

Functionality:

Determines if the current start-up state is after turning on the power switch.

Function Prototype:

bool isResetbyPowerSW()

Return Value:

Value Functionality
true Reset by power switch
false Due to other reasons

deepSleep()

Functionality:

This function transitions to deep sleep mode. It wakes up after a specified time or

when a port state changes. Upon wake-up, the CPU restarts, not running from the next line.

Function Prototype:

void deepSleep()

Usage Example:

To save power for 5 seconds then restart:

deepSleep(SLEEP_SEC(5));

lightSleep()

Functionality:

This function transitions to light sleep mode. It wakes up after a specified time or when a port changes. Upon returning, it runs from the next line. Compared to deepSleep(), it lacks power-saving functionality.

Function Prototype:

void lightSleep(uint64_t time_in_us)

Usage Example:

To save power for 5 seconds then restart:

lightSleep(SLEEP_SEC(5));

powerOFF()

Functionality:

Turns off the power. Uses the power-saving feature to turn off IP5306 after 8 seconds. Shuts off power provided to the circuit side.

Function Prototype:

void powerOFF()

Note:
M5Stack cannot be forcibly powered off. Hence, this function achieves it through the power-saving feature of IP5306. If the user consumes current in the circuit, IP5306 cannot determine to turn off the power.

On This Page