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));
Description:
Initializes the Power class.
Syntax:
void begin();
Example:
#include <M5Stack.h>
void setup() {
M5.begin();
M5.Power.begin();
}
void loop() {}
Description:
Changes the method of turning the device on/off with the power button.
Syntax:
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 |
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() {}
Description:
Changes the power on/off method. The power will not turn off when connected via USB.
Syntax:
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 |
Description:
Decides whether to power on again when external sources like USB are disconnected.
Syntax:
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 |
Description:
Sets the mode to turn on the power LED. Not controllable via this function for M5GO due to lack of wiring to IP5306.
Syntax:
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 |
Description:
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.
Syntax:
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 |
Description:
Sets the wait time until IP5306 decides to save energy and turns off the power.
Syntax:
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 |
Description:
This function enables/disables the always-on boost output mode.
Syntax:
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 |
Description:
Sets whether to auto-boot when there is a power consumption on the secondary side of IP5306.
Syntax:
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 |
Description:
This function enables/disables charging mode. After the battery is full, toggling charge enable -> disable -> enable may allow charging to resume.
Syntax:
bool setCharge(bool en);
Value | Functionality |
---|---|
true | Begin charging command |
false | Stop charging command |
Return Value:
Value | Functionality |
---|---|
true | Control succeeded |
false | Control failed |
Description:
Checks if the battery is fully charged.
Syntax:
bool isChargeFull();
Return Value:
Value | Functionality |
---|---|
true | Fully charged |
false | Not fully charged |
Description:
This function checks if the battery controller is present via I2C communication.
Syntax:
bool canControl();
Return Value:
Value | Functionality |
---|---|
true | Power controller found |
false | Power controller not found |
Description:
Checks if charging is in progress.
Syntax:
bool isCharging();
Return Value:
Value | Functionality |
---|---|
true | Charging |
false | Not charging |
Description:
Returns the battery level.
Syntax:
int8_t getBatteryLevel();
Return Value:
Returns battery level as 0/25/50/75/100. Returns -1 if unable to check the remaining capacity.
Description:
Sets the wake-up port upon sleep return.
Syntax:
void setWakeupButton(uint8_t button);
Value | Functionality |
---|---|
button | Port number |
Example:
setWakeupButton(BUTTON_A_PIN);
Description:
Performs a CPU reset.
Syntax:
void reset();
Description:
Determines if the current activation state is after a CPU reset.
(Applies if executing reset()
or an equivalent process such as RTOS.)
Syntax:
bool isResetbySoftware();
Return Value:
Value | Functionality |
---|---|
true | Reset by software |
false | Due to other reasons |
Description:
Determines if the current activation state is after a watchdog timer.
Syntax:
bool isResetbyWatchdog();
Return Value:
Value | Functionality |
---|---|
true | Reset by watchdog |
false | Due to other reasons |
Description:
Determines if the current wake state is after deepSleep()
.
Syntax:
bool isResetbyDeepsleep();
Return Value:
Value | Functionality |
---|---|
true | After deepSleep() |
false | Due to other reasons |
Description:
Determines if the current start-up state is after turning on the power switch.
Syntax:
bool isResetbyPowerSW();
Return Value:
Value | Functionality |
---|---|
true | Reset by power switch |
false | Due to other reasons |
Description:
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.
Syntax:
void deepSleep();
Example:
To save power for 5 seconds then restart:
deepSleep(SLEEP_SEC(5));
Description:
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.
Syntax:
void lightSleep(uint64_t time_in_us);
Example:
To save power for 5 seconds then restart:
lightSleep(SLEEP_SEC(5));
Description:
Turns off the power. Uses the power-saving feature to turn off IP5306 after 8 seconds. Shuts off power provided to the circuit side.
Syntax:
void powerOFF();