2019-03-04 23:22:39 +09:00
# Power
2019-05-06 22:54:01 +09:00
*Power related functions depend on the IP5306 chip. Please refer to the data sheet [IP5306](https://github.com/m5stack/M5-Schematic/blob/master/Core/IIC_IP5306_REG_V1.4.pdf) as required.*
2019-05-02 04:07:29 +09:00
2019-05-02 03:52:49 +09:00
* The older M5STACK hardware does not support communication with IP5306 chip. When using functions, also consider supporting out of control cases. *
Use initialization, communication check, and control in this order, as shown in the example below.
2021-02-26 17:27:20 +08:00
```clike
2019-05-02 03:52:49 +09:00
M5.Power.begin();
if(!M5.Power.canControl()) {
//can't control.
return;
}
M5.Power.lightSleep(SLEEP_SEC(5));
```
## begin()
**Syntax:**
2020-11-05 11:39:06 +08:00
`void begin()`
2019-05-02 03:52:49 +09:00
**Description:**
Performs initialization of Power class.
**Function argument**
No argument.
**Function return value**
No return value.
## setPowerBoostOnOff()
**Syntax:**
2020-11-05 11:39:06 +08:00
`bool setPowerBoostOnOff(bool en)`
2019-05-02 03:52:49 +09:00
**Description:**
Change the power on / off method.
The power does not turn off when connected via USB.
**Function argument**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true|Press and hold to turn on / off.|
|false|Turn on / off with two short presses.|
2019-05-02 03:52:49 +09:00
**Function return value**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true|Control success.|
|false|Control failure. |
2019-05-02 03:52:49 +09:00
## setPowerBoostSet()
**Syntax:**
2020-11-05 11:39:06 +08:00
`bool setPowerBoostSet(bool en)`
2019-05-02 03:52:49 +09:00
**Description:**
Change the power on / off method.
The power does not turn off when connected via USB.
**Function argument**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true| ON / OFF in one short press.|
|false| Follow the setPowerBoostOnOff () method.|
2019-05-02 03:52:49 +09:00
**Function return value**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true|Control success.|
|false|Control failure. |
2019-05-02 03:52:49 +09:00
## setPowerVin()
**Syntax:**
2020-11-05 11:39:06 +08:00
`bool setPowerVin(bool en)`
2019-05-02 03:52:49 +09:00
**Description:**
When the power supply from USB etc. is cut off,
Decide whether to turn on the power again.
**Function argument**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true|The power will be turned on again. |
|false|The power will not be turned on again. |
2019-05-02 03:52:49 +09:00
**Function return value**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true|Control success.|
|false|Control failure. |
2019-05-02 03:52:49 +09:00
## setPowerWLEDSet()
**Syntax:**
2020-11-05 11:39:06 +08:00
`bool setPowerWLEDSet(bool en)`
2019-05-02 03:52:49 +09:00
**Description:**
Set the mode to turn on the power LED.
In addition, IP5306 of M5GO is not wired and can not be controlled by this function.
**Function argument**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true| Turn on the LED with two short presses|
|false| Turn on the LED with Press and hold|
2019-05-02 03:52:49 +09:00
**Function return value**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true|Control success.|
|false|Control failure. |
2019-05-02 03:52:49 +09:00
## setPowerBtnEn()
**Syntax:**
2020-11-05 11:39:06 +08:00
`bool setPowerBtnEn(bool en)`
2019-05-02 03:52:49 +09:00
**Description:**
Set whether to accept the power button.
About the behavior when not accepting the button:
2019-05-02 14:04:24 +09:00
2019-05-02 03:52:49 +09:00
If the power is on, the power button only accepts CPU reset.
2019-05-02 14:04:24 +09:00
2019-05-02 03:52:49 +09:00
If the power is not supplied, the power can not be turned on.
**Function argument**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true| Accept power operation.|
|false| Does not accept power control.|
2019-05-02 03:52:49 +09:00
**Function return value**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true|Control success.|
|false|Control failure. |
2019-05-02 03:52:49 +09:00
## setLowPowerShutdownTime()
**Syntax:**
2020-11-05 11:39:06 +08:00
`bool setLowPowerShutdownTime(ShutdownTime time)`
2019-05-02 03:52:49 +09:00
**Description:**
Set the waiting time until IP5306 makes the energy saving judgment and the power is turned off.
**Function argument**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|ShutdownTime::SHUTDOWN_8S | wait at 8sec.|
|ShutdownTime::SHUTDOWN_16S | wait at 16sec.|
|ShutdownTime::SHUTDOWN_32S | wait at 32sec.|
|ShutdownTime::SHUTDOWN_64S | wait at 64sec.|
2019-05-02 03:52:49 +09:00
**Function return value**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true|Control success.|
|false|Control failure. |
2019-05-02 03:52:49 +09:00
2019-03-04 23:22:39 +09:00
## setPowerBoostKeepOn()
**Syntax:**
2020-11-05 11:39:06 +08:00
`bool setPowerBoostKeepOn(bool en)`
2019-03-04 23:22:39 +09:00
**Description:**
2019-03-30 11:21:24 +08:00
This function sets/unsets always boost output mode.
2019-03-04 23:22:39 +09:00
2019-03-13 23:42:54 +09:00
**Function argument**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true| Always output power.|
|false| not Always output power.|
2019-03-13 23:42:54 +09:00
**Function return value**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true|Control success.|
|false|Control failure. |
2019-03-13 23:42:54 +09:00
## setKeepLightLoad()
**Syntax:**
2020-11-05 11:39:06 +08:00
`bool setKeepLightLoad(bool en)`
2019-03-13 23:42:54 +09:00
**Description:**
2019-03-30 11:21:24 +08:00
This function sets/unsets to disable the automatic shutdown.
2019-05-02 03:52:49 +09:00
(Deprecated: This function will be disabled and will be removed in the near future)
2019-03-13 23:42:54 +09:00
**Function argument**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true| When the current is too small, IP5306 will *not* automatically shutdown, |
|false| When the current is too small, IP5306 will automatically shutdown. |
2019-03-13 23:42:54 +09:00
**Function return value**
2019-03-14 12:01:35 +08:00
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true|Control success.|
|false|Control failure. |
2019-03-13 23:42:54 +09:00
2019-05-02 03:52:49 +09:00
## setLowPowerShutdown()
2019-03-13 23:42:54 +09:00
2019-05-02 03:52:49 +09:00
**Syntax:**
2020-11-05 11:39:06 +08:00
`bool setLowPowerShutdown(bool en)`
2019-05-02 03:52:49 +09:00
**Description:**
Set the power saving automatic shutdown function.
(Deprecated: this function is disabled and will eventually disappear. Use setPowerBoostKeepOn())
**Function argument**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true|Enable energy saving shutdown function.|
|false|Disable energy saving shutdown function.|
2019-05-02 03:52:49 +09:00
**Function return value**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true|Control success.|
|false|Control failure. |
2019-05-02 03:52:49 +09:00
## setAutoBootOnLoad()
**Syntax:**
2020-11-05 11:39:06 +08:00
`bool setAutoBootOnLoad(bool en)`
2019-05-02 03:52:49 +09:00
**Description:**
Set whether to automatically start when power consumption occurs on the secondary side of IP5306.
**Function argument**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true|Enable the auto start function.|
|false|Disable auto start function.|
2019-05-02 03:52:49 +09:00
**Function return value**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true|Control success.|
|false|Control failure. |
2019-03-13 23:42:54 +09:00
2019-03-04 23:22:39 +09:00
## setCharge()
**Syntax:**
2020-11-05 11:39:06 +08:00
`bool setCharge(bool en)`
2019-03-04 23:22:39 +09:00
**Description:**
2019-03-30 11:21:24 +08:00
This function sets/unsets charge mode. When the battery is fully charged,
2019-05-02 14:04:24 +09:00
2019-03-30 11:21:24 +08:00
try set charge enable->disable->enable, It can be recharged.
2019-03-13 23:42:54 +09:00
**Function argument**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true|Start charging, |
|false| Stop charging. |
2019-03-13 23:42:54 +09:00
**Function return value**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true|Control success.|
|false|Control failure. |
2019-03-04 23:22:39 +09:00
## isChargeFull()
**Syntax:**
2020-11-05 11:39:06 +08:00
`bool isChargeFull()`
2019-03-04 23:22:39 +09:00
**Description:**
2019-03-30 11:21:24 +08:00
This function checks if the battery is fully charged.
2019-03-04 23:22:39 +09:00
2019-03-13 23:42:54 +09:00
**Function argument**
2019-03-30 11:21:24 +08:00
No argument.
2019-03-13 23:42:54 +09:00
**Function return value**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true|Full charged, |
|false|Not full charged. |
2019-03-13 23:42:54 +09:00
2019-03-04 23:22:39 +09:00
## canControl()
**Syntax:**
2020-11-05 11:39:06 +08:00
`bool canControl()`
2019-03-04 23:22:39 +09:00
**Description:**
2019-05-02 03:52:49 +09:00
This function checks the existence of the battery controller over I2C communication.
2019-03-13 23:42:54 +09:00
**Function argument**
2019-03-14 12:01:35 +08:00
No argument.
2019-03-13 23:42:54 +09:00
**Function return value**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true|Battery controller is found, |
|false|Battery controller is not found. |
2019-03-04 23:22:39 +09:00
## isCharging()
**Syntax:**
2020-11-05 11:39:06 +08:00
`bool isCharging()`
2019-03-04 23:22:39 +09:00
**Description:**
2019-03-30 11:21:24 +08:00
This function checks the state of the charging.
2019-03-04 23:22:39 +09:00
2019-03-13 23:42:54 +09:00
**Function argument**
2019-03-30 11:21:24 +08:00
No argument.
2019-03-13 23:42:54 +09:00
**Function return value**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true|In charging, |
|false| Not in charging.|
2019-03-13 23:42:54 +09:00
2019-03-30 11:21:24 +08:00
2019-03-13 23:42:54 +09:00
## getBatteryLevel()
**Syntax:**
2020-11-05 11:39:06 +08:00
`int8_t getBatteryLevel()`
2019-03-13 23:42:54 +09:00
**Description:**
2019-03-30 11:21:24 +08:00
This function gets the battery level.
2019-03-13 23:42:54 +09:00
**Function argument**
2019-03-14 12:01:35 +08:00
No argument.
2019-03-13 23:42:54 +09:00
**Function return value**
2020-11-20 18:36:39 +08:00
Battery remaining percentage. 0/25/50/75/100
2019-05-02 14:04:24 +09:00
2019-03-30 11:21:24 +08:00
Returns -1 if it can not communicate with the controller.
2019-03-13 23:42:54 +09:00
2019-03-04 23:22:39 +09:00
## setWakeupButton()
**Syntax:**
2020-11-05 11:39:06 +08:00
`void setWakeupButton(uint8_t button)`
2019-03-04 23:22:39 +09:00
**Description:**
2019-05-02 03:52:49 +09:00
Sets the signal port to monitor when waking from sleep.
2019-03-04 23:22:39 +09:00
2019-05-02 03:52:49 +09:00
**Function argument**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|button| number of port. |
2019-05-02 03:52:49 +09:00
**Function return value**
No return value.
**Example of use:**
2019-03-04 23:22:39 +09:00
2021-02-26 17:27:20 +08:00
```clike
2019-05-02 03:52:49 +09:00
setWakeupButton(BUTTON_A_PIN);
2019-03-04 23:22:39 +09:00
```
## reset()
**Syntax:**
2020-11-05 11:39:06 +08:00
`void reset();`
2019-03-04 23:22:39 +09:00
**Description:**
2019-05-02 03:52:49 +09:00
Reset CPU and reboot.
2019-03-04 23:22:39 +09:00
2019-05-02 03:52:49 +09:00
**Function argument**
2019-03-04 23:22:39 +09:00
2019-05-02 03:52:49 +09:00
No argument.
2019-03-04 23:22:39 +09:00
2019-05-02 03:52:49 +09:00
**Function return value**
No return value.
## isResetbySoftware()
2019-03-04 23:22:39 +09:00
**Syntax:**
2020-11-05 11:39:06 +08:00
`bool isResetbySoftware()`
2019-03-04 23:22:39 +09:00
**Description:**
2019-05-02 03:52:49 +09:00
It is judged whether the current activation status is after CPU reset.
(It will be true if equivalent processing from reset () or RTOS etc. is performed)
2019-03-04 23:22:39 +09:00
2019-05-02 03:52:49 +09:00
**Function argument**
2019-03-04 23:22:39 +09:00
2019-05-02 03:52:49 +09:00
No argument,
2019-03-04 23:22:39 +09:00
2019-05-02 03:52:49 +09:00
**Function return value**
2019-03-04 23:22:39 +09:00
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true| By software reset|
|false| For other reasons|
2019-05-02 03:52:49 +09:00
## isResetbyWatchdog()
**Syntax:**
2020-11-05 11:39:06 +08:00
`bool isResetbyWatchdog()`
2019-05-02 03:52:49 +09:00
**Description:**
Determines whether the current activation status is after the watchdog.
**Function argument**
No argument,
**Function return value**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true | By watchdog|
|false| For other reasons|
2019-05-02 03:52:49 +09:00
## isResetbyDeepsleep()
**Syntax:**
2020-11-05 11:39:06 +08:00
`bool isResetbyDeepsleep()`
2019-05-02 03:52:49 +09:00
**Description:**
Determines if the current wakeup state is after deepSleep ().
**Function argument**
No argument,
**Function return value**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true | after deepSleep()|
|false| For other reasons|
2019-05-02 03:52:49 +09:00
## isResetbyPowerSW()
**Syntax:**
2020-11-05 11:39:06 +08:00
`bool isResetbyPowerSW()`
2019-05-02 03:52:49 +09:00
**Description:**
Determines whether the current start state is after power on from the power switch.
**Function argument**
No argument,
**Function return value**
2019-05-02 14:24:19 +09:00
| Param | Description |
| --- | --- |
2019-05-02 14:04:24 +09:00
|true | By PowerSwitch|
|false| For other reasons|
2019-03-04 23:22:39 +09:00
## deepSleep()
**Syntax:**
2020-11-05 11:39:06 +08:00
`void deepSleep(uint64_t time_in_us)`
2019-03-04 23:22:39 +09:00
**Description:**
2019-03-30 11:21:24 +08:00
This function shifts to deep sleep mode.
2019-05-02 14:04:24 +09:00
2019-05-02 03:52:49 +09:00
It starts when the specified time or port status changes.
After waking up, the CPU will be restarted instead of running from the next line.
2019-03-04 23:22:39 +09:00
2019-05-02 03:52:49 +09:00
**Example of use:**
Save energy for 5 seconds and then restart.
2021-02-26 17:27:20 +08:00
```clike
2019-05-02 03:52:49 +09:00
deepSleep(SLEEP_SEC(5));
2019-03-14 12:01:35 +08:00
```
2019-05-02 03:52:49 +09:00
## lightSleep()
**Syntax:**
2020-11-05 11:39:06 +08:00
`void lightSleep(uint64_t time_in_us)`
2019-05-02 03:52:49 +09:00
**Description:**
This function shifts to deep sleep mode.
2019-05-02 14:04:24 +09:00
2019-05-02 03:52:49 +09:00
It starts when the specified time or port changes.
After returning, it will be executed from the next line.
2019-05-02 14:04:24 +09:00
2019-05-02 03:52:49 +09:00
Power saving capability is lacking compared to deepSleep().
**Example of use:**
Save energy for 5 seconds and then restart.
2021-02-26 17:27:20 +08:00
```clike
2019-05-02 03:52:49 +09:00
lightSleep(SLEEP_SEC(5));
```
## powerOFF()
**Syntax:**
2020-11-05 11:39:06 +08:00
`void powerOFF()`
2019-05-02 03:52:49 +09:00
**Description:**
Turn off the power.
2019-05-02 14:04:24 +09:00
2019-05-02 03:52:49 +09:00
By turning off the IP5306 after 8 seconds using the power saving function
Turn off the power supplied to the circuit side.
**Usage notes:**
M5Stack does not have a means to forcibly turn off the power.
2019-05-02 14:04:24 +09:00
2019-05-02 03:52:49 +09:00
So,this function is realized by using the power saving function of IP5306.
If the user is consuming current in the circuit IP5306 fails to determine the power off.