AXP192 是一款高度集成的电源系统管理芯片, 在M5Core2库中封装了一系列电源芯片对周边外设电源控制的API
功能说明:
设置屏幕电压,调整亮度,参数有效范围 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); }}
功能说明:
切断所有供电(除RTC外)
函数原型:
void PowerOff();
案例程序:
#include <M5Core2.h> void setup() { M5.begin(); M5.Lcd.fillScreen(RED); delay(1000);}void loop() { M5.Axp.PowerOff();}
功能说明:
深度睡眠(恢复后程序将从头开始执行)
函数原型:
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() {}
功能说明:
浅度睡眠(恢复后程序将从下一行继续执行)
函数原型:
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() {}
功能说明:
设置内置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);}
功能说明:
设置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() {}
功能说明:
设置扬声器电源启用
函数原型:
void SetSpkEnable(uint8_t state);
案例程序:
#include <M5Core2.h> void setup() { M5.begin(); M5.Axp.SetSpkEnable(1); //Power on the speaker. 开启扬声器电源}void loop() {}
功能说明:
设置电池充电电流
函数原型:
void SetCHGCurrent(uint8_t state);
功能说明:
读取电池电压
函数原型:
float GetBatVoltage();
案例程序:
#include <M5Core2.h> void setup() { M5.begin();}void loop() { Serial.printf("Bat Voltage:%f\n", M5.Axp.GetBatVoltage()); delay(500);}
函数原型:
功能说明:
读取电池电流
float GetBatCurrent();
案例程序:
#include <M5Core2.h> void setup() { M5.begin();}void loop() { Serial.printf("Bat Current:%f\n", M5.Axp.GetBatCurrent()); delay(500);}
功能说明:
读取VBUS电压
函数原型:
float GetVBusVoltage();
案例程序:
#include <M5Core2.h> void setup() { M5.begin();}void loop() { Serial.printf("VBus Voltage:%f\n", M5.Axp.GetVBusVoltage()); delay(500);}
功能说明:
读取VBUS电流
函数原型:
float GetVBusCurrent();
案例程序:
#include <M5Core2.h> void setup() { M5.begin();}void loop() { Serial.printf("VBus Current:%f\n", M5.Axp.GetVBusCurrent()); delay(500);}
功能说明:
读取AXP192芯片温度
函数原型:
float GetTempInAXP192();
案例程序:
#include <M5Core2.h> void setup() { M5.begin();}void loop() { Serial.printf("AXP192 Temp:%f\n", M5.Axp.GetTempInAXP192()); delay(500);}
功能说明:
读取电池当前消耗功率
函数原型:
float GetBatPower();
案例程序:
#include <M5Core2.h> void setup() { M5.begin();}void loop() { Serial.printf("AXP192 Temp:%f\n", M5.Axp.GetTempInAXP192()); delay(500);}
功能说明:
读取电池充电电流
函数原型:
float GetBatChargeCurrent();
案例程序:
#include <M5Core2.h> void setup() { M5.begin();}void loop() { Serial.printf("Bat Charge Current:%f\n", M5.Axp.GetBatChargeCurrent()); delay(500);}
功能说明:
检查是否处于充电状态
函数原型:
bool isCharging();
案例程序:
#include <M5Core2.h> void setup() { M5.begin();}void loop() { Serial.printf("Charging state:%d\n", M5.Axp.isCharging()); delay(500);}