Arduino入門

2. デバイス&サンプル

5. 拡張モジュール&サンプル

アクセサリー

6. アプリケーション

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

以下の充電制御・状態取得 API は M5Unified 0.3.0 に準拠しています。旧バージョンでは異なる場合があります。

構文:

bool setBatteryCharge(bool enable);

説明:

  • バッテリー充電を有効または無効にします。

引数:

  • bool enable:
    • true: 充電を有効にします。
    • false: 充電を無効にします。

戻り値:

  • bool:
    • true: 設定処理の成功を確認できました。
    • false: 設定の成功を確認できませんでした。制御機能が非対応、または通信失敗などの可能性があります。設定が反映されているかどうかは保証されません。

setChargeCurrent

構文:

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

説明:

  • バッテリーの充電電流の段階を設定します。

引数:

  • std::uint16_t max_mA:
    • 要求する充電電流。単位は mA です。
  • std::uint16_t* applied_mA:
    • 実際に設定した電流の段階を mA 単位で受け取る省略可能な出力引数です。実測値ではありません。既定値は nullptr で、false が返された場合は出力先の値を変更しません。

戻り値:

  • bool:
    • true: 設定処理の成功を確認できました。
    • false: 設定の成功を確認できませんでした。制御機能が非対応、または通信失敗などの可能性があります。設定が反映されているかどうかは保証されません。
充電制御機能と設定可能な段階はハードウェアによって異なります。通常は要求値以下の最大の段階を選択し、最低値未満の場合は最低値に切り上げます。一部の機種は固定の選択規則を使用するため、実際の設定は出力引数で確認してください。setChargeCurrent(0) では充電は停止しません。停止には setBatteryCharge(false) を使用してください。

setChargeVoltage

構文:

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

説明:

  • バッテリーの充電電圧の段階を設定します。

引数:

  • std::uint16_t max_mV:
    • 要求する充電電圧。単位は mV です。
  • std::uint16_t* applied_mV:
    • 実際に設定した公称電圧の段階を mV 単位で受け取る省略可能な出力引数です。実測値ではありません。既定値は nullptr で、false が返された場合は出力先の値を変更しません。

戻り値:

  • bool:
    • true: 設定処理の成功を確認できました。
    • false: 設定の成功を確認できませんでした。制御機能が非対応、または通信失敗などの可能性があります。設定が反映されているかどうかは保証されません。

getChargeState

構文:

charge_state_t getChargeState(void);

説明:

  • バッテリーの充電状態を取得します。報告できる状態はハードウェアによって異なります。

引数:

  • null

戻り値:

  • m5::charge_state_t:
    • not_initialized (-3): M5.begin() が完了していません。
    • io_error (-2): 状態の読み取りに失敗しました。
    • undetermined (-1): 信号は読み取れましたが状態を確定できません。
    • unsupported (0): 充電状態の検出に対応していません。
    • charging (1): 充電中です。
    • not_charging (2): 充電していません。詳細は不明です。
    • full (3): 充電が完了しています。
    • disabled (4): 充電が無効になっています。
    • discharging (5): バッテリーが放電中です。
    • idle (6): バッテリーへの充放電電流がありません。

isCharging

構文:

bool isCharging(void);

説明:

  • デバイスが充電中と報告しているか確認します。

引数:

  • null

戻り値:

  • bool:
    • true: デバイスが充電中と報告しています。
    • false: 充電中とは報告されていません。未初期化、検出非対応、状態不確定、読み取り失敗の場合も含みます。区別するには getChargeState() を使用してください。

使用例:

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