Power Class
begin
Syntax:
bool begin(void);
Description:
- Initialize the Power Management Integrated Circuit (PMIC).
Parameters:
Return:
- bool:
- true: Initialization successful.
- false: Initialization failed.
setExtOutput
Syntax:
void setExtOutput(bool enable, ext_port_mask_t port_mask = (ext_port_mask_t)0xFF);
Description:
- Set the power output of the external port.
Parameters:
- bool enable:
- Power output enable state:
- true: Enable output.
- false: Disable output.
- ext_port_mask_t port_mask:
- The mask for the output port to operate:
- Valid for devices that support independent power switching for multiple output ports (e.g., M5Station).
Return:
getExtOutput
Syntax:
bool getExtOutput(void);
Description:
- Read the power output state of the external port.
Parameters:
Return:
- bool:
- true: Output enabled.
- false: Output disabled.
setUsbOutput
Syntax:
void setUsbOutput(bool enable);
Description:
- Set the USB power output state (for M5Stack CoreS3 main USB port, not for M5Station external USB).
Parameters:
- bool enable:
- USB power output enable state:
- true: Enable output.
- false: Disable output.
Return:
getUsbOutput
Syntax:
bool getUsbOutput(void);
Description:
- Read the USB power output state (for M5Stack CoreS3 main USB port, not for M5Station external USB).
Parameters:
- bool enable:
- USB power output enable state.
Return:
- bool:
- true: Output enabled.
- false: Output disabled.
setLed
Syntax:
void setLed(uint8_t brightness = 255);
Description:
- Set the state of the power LED light.
Parameters:
Return:
powerOff
Syntax:
void powerOff(void);
Description:
- Turn off all power supplies.
Parameters:
Return:
timerSleep
Note on timerSleep
Some devices without integrated PMIC, such as M5Paper, cannot power off when powered by USB. This function only works when powered by a battery.
Syntax:
void timerSleep(int seconds);
Description:
- The device sleeps and wakes up after a specified period.
Parameters:
- int seconds:
- Sleep duration in seconds.
Return:
timerSleep
Syntax:
void timerSleep(const rtc_time_t& time);
Description:
- The device sleeps and wakes up at a specified time.
Parameters:
- const rtc_time_t& time:
- Wake-up time (only minutes and hours can be specified. Seconds are ignored).
Return:
timerSleep
Syntax:
void timerSleep(const rtc_date_t& date, const rtc_time_t& time);
Description:
- The device sleeps and wakes up at a specified date and time.
Parameters:
- int const rtc_date_t& date:
- Wake-up date (only date and day of the week can be specified. Year and month are ignored).
- const rtc_time_t& time:
- Wake-up time (only minutes and hours can be specified. Seconds are ignored).
Return:
deepSleep
Syntax:
void deepSleep(std::uint64_t micro_seconds = 0, bool touch_wakeup = true);
Description:
- The chip enters deep sleep and wakes up after a period.
Parameters:
- uint64_t micro_seconds:
- Sleep duration in microseconds.
- bool touch_wakeup:
- Whether to enable touch screen wake-up.
Return:
lightSleep
Syntax:
void lightSleep(std::uint64_t micro_seconds = 0, bool touch_wakeup = true);
Description:
- The chip enters light sleep and wakes up after a period.
Parameters:
- uint64_t micro_seconds:
- Sleep duration in microseconds.
- bool touch_wakeup:
- Whether to enable touch screen wake-up.
Return:
getBatteryLevel
Syntax:
std::int32_t getBatteryLevel(void);
Description:
- Get the reference value of the remaining battery power.
Parameters:
Return:
setBatteryCharge
Syntax:
void setBatteryCharge(bool enable);
Description:
- Set the battery charging enable.
Parameters:
- bool enable:
- true: Enable battery charging.
- false: Disable battery charging.
Return:
setChargeCurrent
Note on setCharge
APIs related to setting charging voltage and current are only supported on some devices with integrated PMIC.
Syntax:
void setChargeCurrent(std::uint16_t max_mA);
Description:
- Set the battery charging current.
Parameters:
- uint16_t max_mA:
- Maximum charging current in milliamperes.
Return:
setChargeVoltage
Syntax:
void setChargeVoltage(std::uint16_t max_mV);
Description:
- Set the battery charging voltage.
Parameters:
- uint16_t max_mV:
- Maximum charging voltage in millivolts.
Return:
isCharging
Syntax:
is_charging_t isCharging(void);
Description:
- Determine if currently charging.
Parameters:
Return:
- bool:
- true: Charging.
- false: Not charging.
getBatteryVoltage
Syntax:
int16_t getBatteryVoltage(void);
Description:
Parameters:
Return:
- int16_t voltage:
- Battery voltage in millivolts.
getBatteryCurrent
Syntax:
int32_t getBatteryCurrent(void);
Description:
Parameters:
Return:
- int32_t current:
- Battery current in milliamperes (+=charge / -=discharge).
getKeyState
Syntax:
uint8_t getKeyState(void);
Description:
- Get the state of the PMIC button input signal (Only for models with AXP192 or AXP2101). The state is reset after calling this function.
Parameters:
Return:
- uint8_t key:
- none: 0
- long pressed: 1
- short clicked: 2
- both: 3
setVibration
Syntax:
void setVibration(uint8_t level);
Description:
- Control the vibration motor vibration.
Parameters:
- uint8_t level:
- Vibration level: 0-255, 0=stop.
Return:
getType
Syntax:
pmic_t getType(void) const { return _pmic; }
Description:
Parameters:
Return:
enum pmic_t
{ pmic_unknown
, pmic_adc
, pmic_axp192
, pmic_ip5306
, pmic_axp2101
};