M5Unified
Power_Class.hpp
Go to the documentation of this file.
1 // Copyright (c) M5Stack. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3 
4 #ifndef __M5_Power_Class_H__
5 #define __M5_Power_Class_H__
6 
7 #include "m5unified_common.h"
8 
9 #include "I2C_Class.hpp"
10 #include "AXP192_Class.hpp"
11 #include "AXP2101_Class.hpp"
12 #include "IP5306_Class.hpp"
13 #include "INA3221_Class.hpp"
14 #include "RTC8563_Class.hpp"
15 
16 #if __has_include (<driver/adc.h>)
17 #include <driver/adc.h>
18 #endif
19 
20 namespace m5
21 {
22  class M5Unified;
23 
25  { ext_none = 0
26  // For individual control of external ports of M5Station
27  , ext_PA = 0b00000001
28  , ext_PB1 = 0b00000010
29  , ext_PB2 = 0b00000100
30  , ext_PC1 = 0b00001000
31  , ext_PC2 = 0b00010000
32  , ext_USB = 0b00100000 // M5Station external USB. ※ Not for CoreS3 main USB.
33  , ext_MAIN = 0b10000000
34  };
35 
37  {
38  friend M5Unified;
39  public:
40 
41  enum pmic_t
42  { pmic_unknown
47  };
48 
50  { is_discharging = 0
53  };
54 
55  bool begin(void);
56 
60  void setExtOutput(bool enable, ext_port_mask_t port_mask = (ext_port_mask_t)0xFF);
61 
63  [[deprecated("Change to setExtOutput")]]
64  void setExtPower(bool enable, ext_port_mask_t port_mask = (ext_port_mask_t)0xFF) { setExtOutput(enable, port_mask); }
65 
68  bool getExtOutput(void);
69 
74  void setUsbOutput(bool enable);
75 
80  bool getUsbOutput(void);
81 
84  void setLed(uint8_t brightness = 255);
85 
87  void powerOff(void);
88 
91  void timerSleep(int seconds);
92 
97  void timerSleep(const rtc_time_t& time);
98 
104  void timerSleep(const rtc_date_t& date, const rtc_time_t& time);
105 
108  void deepSleep(std::uint64_t micro_seconds = 0, bool touch_wakeup = true);
109 
112  void lightSleep(std::uint64_t micro_seconds = 0, bool touch_wakeup = true);
113 
116  std::int32_t getBatteryLevel(void);
117 
120  void setBatteryCharge(bool enable);
121 
125  void setChargeCurrent(std::uint16_t max_mA);
126 
130  void setChargeVoltage(std::uint16_t max_mV);
131 
135 
138  int16_t getBatteryVoltage(void);
139 
142  int32_t getBatteryCurrent(void);
143 
148  uint8_t getKeyState(void);
149 
152  void setVibration(uint8_t level);
153 
154  pmic_t getType(void) const { return _pmic; }
155 
156 #if defined (CONFIG_IDF_TARGET_ESP32S3)
157 
159 
160 #elif defined (CONFIG_IDF_TARGET_ESP32C3)
161 
162 #else
163 
168 
169 #endif
170 
171  private:
172  void _powerOff(bool withTimer);
173  void _timerSleep(void);
174 
175  float _adc_ratio = 0;
176  std::uint8_t _pwrHoldPin = 255;
177  std::uint8_t _wakeupPin = 255;
178  std::uint8_t _rtcIntPin = 255;
179  pmic_t _pmic = pmic_t::pmic_unknown;
180 #if !defined (M5UNIFIED_PC_BUILD)
181  adc1_channel_t _batAdc;
182 #endif
183  };
184 }
185 
186 #endif
AXP2101_Class Axp2101
void setExtOutput(bool enable, ext_port_mask_t port_mask=(ext_port_mask_t) 0xFF)
void timerSleep(int seconds)
void setExtPower(bool enable, ext_port_mask_t port_mask=(ext_port_mask_t) 0xFF)
deprecated : Change to "setExtOutput"
Definition: Power_Class.hpp:64
std::int32_t getBatteryLevel(void)
int32_t getBatteryCurrent(void)
void setChargeCurrent(std::uint16_t max_mA)
bool begin(void)
Definition: Power_Class.cpp:46
void setVibration(uint8_t level)
IP5306_Class Ip5306
void deepSleep(std::uint64_t micro_seconds=0, bool touch_wakeup=true)
void setLed(uint8_t brightness=255)
is_charging_t isCharging(void)
void lightSleep(std::uint64_t micro_seconds=0, bool touch_wakeup=true)
void setUsbOutput(bool enable)
int16_t getBatteryVoltage(void)
uint8_t getKeyState(void)
INA3221_Class Ina3221
pmic_t getType(void) const
void setBatteryCharge(bool enable)
bool getExtOutput(void)
bool getUsbOutput(void)
AXP192_Class Axp192
void powerOff(void)
all power off.
void setChargeVoltage(std::uint16_t max_mV)
Definition: M5Unified.cpp:48
ext_port_mask_t
Definition: Power_Class.hpp:25
@ ext_PA
Definition: Power_Class.hpp:27
@ ext_PB2
Definition: Power_Class.hpp:29
@ ext_MAIN
Definition: Power_Class.hpp:33
@ ext_PC1
Definition: Power_Class.hpp:30
@ ext_PB1
Definition: Power_Class.hpp:28
@ ext_none
Definition: Power_Class.hpp:25
@ ext_PC2
Definition: Power_Class.hpp:31
@ ext_USB
Definition: Power_Class.hpp:32