mirror of
https://github.com/m5stack/M5Stack.git
synced 2026-05-20 10:06:46 -07:00
integrate to Power class. (#124)
*power function integrate to Power class. *fixed M5.begin() : add I2C initialize flag. *Check result after send I2C Request *change method of send to power-ic register. (read->mask->write)
This commit is contained in:
+22
-54
@@ -7,7 +7,7 @@ M5Stack::M5Stack() : isInited(0) {
|
||||
|
||||
}
|
||||
|
||||
void M5Stack::begin(bool LCDEnable, bool SDEnable, bool SerialEnable) {
|
||||
void M5Stack::begin(bool LCDEnable, bool SDEnable, bool SerialEnable,bool I2CEnable) {
|
||||
|
||||
// Correct init once
|
||||
if (isInited) return;
|
||||
@@ -35,12 +35,13 @@ void M5Stack::begin(bool LCDEnable, bool SDEnable, bool SerialEnable) {
|
||||
// Speaker.begin();
|
||||
|
||||
// Set wakeup button
|
||||
setWakeupButton(BUTTON_A_PIN);
|
||||
Power.setWakeupButton(BUTTON_A_PIN);
|
||||
|
||||
// I2C init
|
||||
#ifdef M5STACK_FIRE
|
||||
Wire.begin(21, 22);
|
||||
#endif
|
||||
if(I2CEnable)
|
||||
{
|
||||
Wire.begin(21, 22);
|
||||
}
|
||||
|
||||
if (SerialEnable) {
|
||||
Serial.println("OK");
|
||||
@@ -58,59 +59,26 @@ void M5Stack::update() {
|
||||
Speaker.update();
|
||||
}
|
||||
|
||||
#ifdef M5STACK_FIRE
|
||||
// ================ Power IC IP5306 ===================
|
||||
#define IP5306_ADDR 117
|
||||
#define IP5306_REG_SYS_CTL0 0x00
|
||||
#define IP5306_REG_READ1 0x71
|
||||
#define CHARGE_FULL_BIT 3
|
||||
|
||||
void M5Stack::setPowerBoostKeepOn(bool en)
|
||||
{
|
||||
Wire.beginTransmission(IP5306_ADDR);
|
||||
Wire.write(IP5306_REG_SYS_CTL0);
|
||||
if (en) Wire.write(0x37); // Set bit1: 1 enable 0 disable boost keep on
|
||||
else Wire.write(0x35); // 0x37 is default reg value
|
||||
Wire.endTransmission();
|
||||
/**
|
||||
* Function has been move to Power class.(for compatibility)
|
||||
* This name will be removed in a future release.
|
||||
*/
|
||||
void M5Stack::setPowerBoostKeepOn(bool en){
|
||||
M5.Power.setPowerBoostKeepOn(en);
|
||||
}
|
||||
|
||||
uint8_t M5Stack::isChargeFull()
|
||||
{
|
||||
uint8_t data;
|
||||
Wire.beginTransmission(IP5306_ADDR);
|
||||
Wire.write(IP5306_REG_READ1);
|
||||
Wire.endTransmission(false);
|
||||
Wire.requestFrom(IP5306_ADDR, 1);
|
||||
data = Wire.read();
|
||||
if (data & (1 << CHARGE_FULL_BIT)) return true;
|
||||
else return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
// ================== Low power mode =====================
|
||||
/**
|
||||
* Function has been move to Power class.(for compatibility)
|
||||
* This name will be removed in a future release.
|
||||
*/
|
||||
void M5Stack::setWakeupButton(uint8_t button) {
|
||||
_wakeupPin = button;
|
||||
M5.Power.setWakeupButton(button);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function has been move to Power class.(for compatibility)
|
||||
* This name will be removed in a future release.
|
||||
*/
|
||||
void M5Stack::powerOFF() {
|
||||
|
||||
#ifdef M5STACK_FIRE
|
||||
// Keep power keep boost on
|
||||
setPowerBoostKeepOn(true);
|
||||
#endif
|
||||
|
||||
// power off the Lcd
|
||||
Lcd.setBrightness(0);
|
||||
Lcd.sleep();
|
||||
|
||||
// ESP32 into deep sleep
|
||||
esp_sleep_enable_ext0_wakeup((gpio_num_t)_wakeupPin , LOW);
|
||||
|
||||
while(digitalRead(_wakeupPin) == LOW) {
|
||||
delay(10);
|
||||
}
|
||||
esp_deep_sleep_start();
|
||||
M5.Power.deepSleep();
|
||||
}
|
||||
|
||||
|
||||
M5Stack M5;
|
||||
|
||||
Reference in New Issue
Block a user