AXP192

AXP192 是一款高度集成的电源系统管理芯片, 在M5Core2库中封装了一系列电源芯片对周边外设电源控制的API

SetLcdVoltage()

功能:

设置屏幕电压,调整亮度,参数有效范围 2500-3300

函数原型:

void SetLcdVoltage(uint16_t voltage)

使用示例:

#include <M5Core2.h>

void setup() {
  M5.begin(); //By default, "M5.begin()" will initialize AXP192 chip
  M5.Lcd.fillScreen(RED);
}
void loop() {
  M5.update();
  for(int i=2500; i<3300;i++){
    M5.Axp.SetLcdVoltage(i);
    delay(10);
  }
  for(int i=3300; i>2500;i--){
    M5.Axp.SetLcdVoltage(i);
    delay(10);
  }
}

PowerOff()

功能:

切断所有供电(除RTC外)

函数原型:

void PowerOff()

使用示例:

#include <M5Core2.h>

void setup() {
  M5.begin();
  M5.Lcd.fillScreen(RED);
  delay(1000);
}
void loop() {
  M5.Axp.PowerOff();
}

deepSleep()

功能:

深度睡眠(恢复后程序将从头开始执行)

函数原型:

void deepSleep(uint64_t time_in_us)

参数 类型 描述
time_in_us uint64_t 睡眠时间

使用示例:

#include <M5Core2.h>

void setup() {
  M5.begin();
  M5.Lcd.println("Going to deep sleep for 5 seconds.");
  delay(2000);
  M5.Axp.DeepSleep(SLEEP_SEC(5));
}
void loop() {
}

lightSleep()

功能:

浅度睡眠(恢复后程序将从下一行继续执行)

函数原型:

void lightSleep(uint64_t time_in_us)

参数 类型 描述
time_in_us uint64_t 睡眠时间

使用示例:

#include <M5Core2.h>

void setup() {
  M5.begin();
  M5.Lcd.println("Going to light sleep for 5 seconds.");
  delay(2000);
  M5.Axp.lightSleep(SLEEP_SEC(5));
}
void loop() {
}

SetLed()

功能:

设置内置LED灯: state = 1 为点亮; state = 0 为熄灭

函数原型:

void SetLed(uint8_t state)

使用示例:

#include <M5Core2.h>

void setup() {
  M5.begin();
}
void loop() {
  M5.Axp.SetLed(1);
  delay(1000);
  M5.Axp.SetLed(0);
  delay(1000);
}

SetBusPowerMode()

功能:

设置BUS电源模式,设置0为USB/BAT供电,设置1为外部输入供电

函数原型:

void SetBusPowerMode( uint8_t state )

使用示例:

#include <M5Core2.h>

void setup() {
  M5.begin();
  M5.Axp.SetBusPowerMode(0);  //Set the Bus power mode for USB/BAT power supply.  设置Bus电源模式为USB/BAT供电
}
void loop() {
}

SetSpkEnable()

功能:

设置扬声器电源启用

函数原型:

void SetSpkEnable(uint8_t state)

使用示例:

#include <M5Core2.h>

void setup() {
  M5.begin();
  M5.Axp.SetSpkEnable(1);  //Power on the speaker.  开启扬声器电源
}
void loop() {
}

SetCHGCurrent()

功能:

设置电池充电电流

函数原型:

void SetCHGCurrent(uint8_t state)

GetBatVoltage()

功能:

读取电池电压

函数原型:

float GetBatVoltage()

使用示例:

#include <M5Core2.h>

void setup() {
  M5.begin();
}
void loop() {
  Serial.printf("Bat Voltage:%f\n", M5.Axp.GetBatVoltage());
  delay(500);
}

GetBatCurrent()

函数原型:

功能:

读取电池电流

float GetBatCurrent()

使用示例:

#include <M5Core2.h>

void setup() {
  M5.begin();
}
void loop() {
  Serial.printf("Bat Current:%f\n", M5.Axp.GetBatCurrent());
  delay(500);
}

GetVBusVoltage()

功能:

读取VBUS电压

函数原型:

float GetVBusVoltage()

使用示例:

#include <M5Core2.h>

void setup() {
  M5.begin();
}
void loop() {
  Serial.printf("VBus Voltage:%f\n", M5.Axp.GetVBusVoltage());
  delay(500);
}

GetVBusCurrent()

功能:

读取VBUS电流

函数原型:

float GetVBusCurrent()

使用示例:

#include <M5Core2.h>

void setup() {
  M5.begin();
}
void loop() {
  Serial.printf("VBus Current:%f\n", M5.Axp.GetVBusCurrent());
  delay(500);
}

GetTempInAXP192()

功能:

读取AXP192芯片温度

函数原型:

float GetTempInAXP192()

使用示例:

#include <M5Core2.h>

void setup() {
  M5.begin();
}
void loop() {
  Serial.printf("AXP192 Temp:%f\n", M5.Axp.GetTempInAXP192());
  delay(500);
}

GetBatPower()

功能:

读取电池当前消耗功率

函数原型:

float GetBatPower()

使用示例:

#include <M5Core2.h>

void setup() {
  M5.begin();
}
void loop() {
  Serial.printf("AXP192 Temp:%f\n", M5.Axp.GetTempInAXP192());
  delay(500);
}

GetBatChargeCurrent()

功能:

读取电池充电电流

函数原型:

float GetBatChargeCurrent()

使用示例:

#include <M5Core2.h>

void setup() {
  M5.begin();
}
void loop() {
  Serial.printf("Bat Charge Current:%f\n", M5.Axp.GetBatChargeCurrent());
  delay(500);
}

isCharging()

功能:

检查是否处于充电状态

函数原型:

bool isCharging()

使用示例:

#include <M5Core2.h>

void setup() {
  M5.begin();
}
void loop() {
  Serial.printf("Charging state:%d\n", M5.Axp.isCharging());
  delay(500);
}
On This Page