English
English
简体中文
日本語

Arduino Quick Start

2. Devices & Examples

5. Extensions

6. Applications

M5Unified Power Class

begin

Syntax:

bool begin(void);

Description:

  • Initialize the Power Management Integrated Circuit (PMIC).

Parameters:

  • null

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:

  • null

getExtOutput

Syntax:

bool getExtOutput(void);

Description:

  • Read the power output state of the external port.

Parameters:

  • null

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:

  • null

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:

  • uint8_t brightness:
    • 0=OFF
    • 1-255=ON

Return:

  • null

powerOff

Syntax:

void powerOff(void);

Description:

  • Turn off all power supplies.

Parameters:

  • null

Return:

  • null

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:

  • null

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:

  • null

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:

  • null

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:

  • null

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:

  • null

getBatteryLevel

Syntax:

cpp
1 2 3
/// Get the remaining battery power.
/// @return 0-100 level
std::int32_t getBatteryLevel(void);

Description:

  • Get the reference value of the remaining battery power.

Parameters:

  • null

Return:

  • int32_t level:
    • 0-100

setBatteryCharge

The following charging control and status APIs follow M5Unified 0.3.0; older versions may differ.

Syntax:

bool setBatteryCharge(bool enable);

Description:

  • Enable or disable battery charging.

Parameters:

  • bool enable:
    • true: Enable battery charging.
    • false: Disable battery charging.

Return:

  • bool:
    • true: The configuration operation was confirmed successful.
    • false: The configuration could not be confirmed, for example because the control is unsupported or communication failed. The setting may or may not have been applied.

setChargeCurrent

Syntax:

bool setChargeCurrent(std::uint16_t max_mA, std::uint16_t* applied_mA = nullptr);

Description:

  • Set the battery charging current step.

Parameters:

  • std::uint16_t max_mA:
    • Requested charging current in mA.
  • std::uint16_t* applied_mA:
    • Optional output receiving the configured current step in mA, not a live measurement. Defaults to nullptr; the pointed-to value is unchanged on false.

Return:

  • bool:
    • true: The configuration operation was confirmed successful.
    • false: The configuration could not be confirmed, for example because the control is unsupported or communication failed. The setting may or may not have been applied.
Charging controls and available steps depend on the hardware. Normally, the highest step not exceeding the request is selected, with requests below the minimum clamped upward. Some devices use fixed selection rules; use the output parameter to check the configured step. setChargeCurrent(0) does not stop charging; use setBatteryCharge(false).

setChargeVoltage

Syntax:

bool setChargeVoltage(std::uint16_t max_mV, std::uint16_t* applied_mV = nullptr);

Description:

  • Set the battery charging voltage step.

Parameters:

  • std::uint16_t max_mV:
    • Requested charging voltage in mV.
  • std::uint16_t* applied_mV:
    • Optional output receiving the configured nominal voltage step in mV, not a live measurement. Defaults to nullptr; the pointed-to value is unchanged on false.

Return:

  • bool:
    • true: The configuration operation was confirmed successful.
    • false: The configuration could not be confirmed, for example because the control is unsupported or communication failed. The setting may or may not have been applied.

getChargeState

Syntax:

charge_state_t getChargeState(void);

Description:

  • Get the battery charge state. The states a device can report depend on its hardware.

Parameters:

  • null

Return:

  • m5::charge_state_t:
    • not_initialized (-3): M5.begin() has not completed.
    • io_error (-2): Reading the state failed.
    • undetermined (-1): Signals were read but do not determine a state.
    • unsupported (0): Charge state detection is unsupported.
    • charging (1): Charging.
    • not_charging (2): Not charging; no further detail is available.
    • full (3): Charging is complete.
    • disabled (4): Charging is disabled.
    • discharging (5): The battery is discharging.
    • idle (6): No current is flowing into or out of the battery.

isCharging

Syntax:

bool isCharging(void);

Description:

  • Check whether the device reports that it is charging.

Parameters:

  • null

Return:

  • bool:
    • true: The device reports that it is charging.
    • false: The device does not report charging. This also includes an uninitialized, unsupported, undetermined, or unreadable state. Use getChargeState() to distinguish these cases.

Example:

auto state = M5.Power.getChargeState();
if (m5::charge_states_any_charging.contains(state)) {
    Serial.println("Charging");
} else if (m5::charge_states_any_not_charging.contains(state)) {
    Serial.println("Not charging");
} else {
    Serial.println("Charge state unavailable");
}

getBatteryVoltage

Syntax:

int16_t getBatteryVoltage(void);

Description:

  • Get the battery voltage.

Parameters:

  • null

Return:

  • int16_t voltage:
    • Battery voltage in millivolts.

getBatteryCurrent

Syntax:

int32_t getBatteryCurrent(void);

Description:

  • Get the battery current.

Parameters:

  • null

Return:

  • int32_t current:
    • Battery current in milliamperes (+=charge / -=discharge).

getKeyState

Syntax:

cpp
1 2 3 4 5
/// Get Power Key Press condition.
/// @return 0=none / 1=long pressed / 2=short clicked / 3=both
/// @attention Only for models with AXP192 or AXP2101
/// @attention Once this function is called, the value is reset to 0, and the value changes when pressed next time.
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:

  • null

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:

  • null

getType

Syntax:

pmic_t getType(void) const { return _pmic; }

Description:

  • Get the PMIC type.

Parameters:

  • null

Return:

  • pmic_t:
    • The type of PMIC chip.
cpp
1 2 3 4 5 6 7
enum pmic_t
{ pmic_unknown
, pmic_adc
, pmic_axp192
, pmic_ip5306
, pmic_axp2101
};
Page Tools
PDF
On This Page