M5Unified
AXP192_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_AXP192_CLASS_H__
5 #define __M5_AXP192_CLASS_H__
6 
7 #include "I2C_Class.hpp"
8 
9 namespace m5
10 {
11  class AXP192_Class : public I2C_Device
12  {
13  public:
14 
15  static constexpr std::uint8_t DEFAULT_ADDRESS = 0x34;
16 
17  AXP192_Class(std::uint8_t i2c_addr = DEFAULT_ADDRESS, std::uint32_t freq = 400000, I2C_Class* i2c = &In_I2C)
18  : I2C_Device ( i2c_addr, freq, i2c )
19  {}
20 
21  bool begin(void);
22 
25  std::int8_t getBatteryLevel(void);
26 
29  void setBatteryCharge(bool enable);
30 
33  void setChargeCurrent(std::uint16_t max_mA);
34 
37  void setChargeVoltage(std::uint16_t max_mV);
38 
40  bool isCharging(void);
41 
42  inline void setDCDC1(int voltage) { _set_DCDC(0, voltage); }
43  inline void setDCDC2(int voltage) { _set_DCDC(1, voltage); }
44  inline void setDCDC3(int voltage) { _set_DCDC(2, voltage); }
45 
48  inline void setLDO0(int voltage) { _set_LDO(0, voltage); }
49 
52  inline void setLDO2(int voltage) { _set_LDO(2, voltage); }
53 
56  inline void setLDO3(int voltage) { _set_LDO(3, voltage); }
57 
58  inline void setGPIO(uint8_t gpio_num, bool state) { if (gpio_num < 3) { _set_GPIO0_2(gpio_num, state); } else { _set_GPIO3_4(gpio_num - 3, state); } }
59  inline void setGPIO0(bool state) { _set_GPIO0_2(0, state); }
60  inline void setGPIO1(bool state) { _set_GPIO0_2(1, state); }
61  inline void setGPIO2(bool state) { _set_GPIO0_2(2, state); }
62  inline void setGPIO3(bool state) { _set_GPIO3_4(0, state); }
63  inline void setGPIO4(bool state) { _set_GPIO3_4(1, state); }
64 
65  void powerOff(void);
66 
67  void setAdcState(bool enable);
68  void setAdcRate( std::uint8_t rate );
69 
70  void setEXTEN(bool enable);
71  void setBACKUP(bool enable);
72 
73  bool isACIN(void);
74  bool isVBUS(void);
75  bool getBatState(void);
76  bool getEXTEN(void);
77 
78  float getBatteryVoltage(void);
79  float getBatteryDischargeCurrent(void);
80  float getBatteryChargeCurrent(void);
81  float getBatteryPower(void);
82  float getACINVoltage(void);
83  float getACINCurrent(void);
84  float getVBUSVoltage(void);
85  float getVBUSCurrent(void);
86  float getAPSVoltage(void);
87  float getInternalTemperature(void);
88 
89  std::uint8_t getPekPress(void);
90 
91  [[deprecated("use getACINVoltage()")]]
92  inline float getACINVolatge(void) { return getACINVoltage(); }
93 
94  private:
95  std::size_t readRegister12(std::uint8_t addr);
96  std::size_t readRegister13(std::uint8_t addr);
97  std::size_t readRegister16(std::uint8_t addr);
98  std::size_t readRegister24(std::uint8_t addr);
99  std::size_t readRegister32(std::uint8_t addr);
100 
101  void _set_DCDC(std::uint8_t num, int voltage);
102  void _set_LDO(std::uint8_t num, int voltage);
103  void _set_LDO2_LDO3(std::uint8_t num, int voltage);
104  void _set_GPIO0_2(std::uint8_t num, bool state);
105  void _set_GPIO3_4(std::uint8_t num, bool state);
106  };
107 }
108 
109 #endif
float getBatteryVoltage(void)
bool begin(void)
void setLDO0(int voltage)
void setDCDC3(int voltage)
void setLDO2(int voltage)
void setGPIO3(bool state)
float getACINCurrent(void)
float getInternalTemperature(void)
void setGPIO(uint8_t gpio_num, bool state)
void setGPIO1(bool state)
std::int8_t getBatteryLevel(void)
void setBACKUP(bool enable)
void setDCDC1(int voltage)
std::uint8_t getPekPress(void)
float getVBUSVoltage(void)
float getVBUSCurrent(void)
void setLDO3(int voltage)
float getAPSVoltage(void)
void setGPIO4(bool state)
bool isCharging(void)
Get whether the battery is currently charging or not.
void setChargeCurrent(std::uint16_t max_mA)
static constexpr std::uint8_t DEFAULT_ADDRESS
void setGPIO0(bool state)
float getACINVoltage(void)
void setDCDC2(int voltage)
void setBatteryCharge(bool enable)
float getBatteryPower(void)
void setChargeVoltage(std::uint16_t max_mV)
float getBatteryChargeCurrent(void)
AXP192_Class(std::uint8_t i2c_addr=DEFAULT_ADDRESS, std::uint32_t freq=400000, I2C_Class *i2c=&In_I2C)
void setAdcState(bool enable)
void setGPIO2(bool state)
bool getBatState(void)
void setEXTEN(bool enable)
float getBatteryDischargeCurrent(void)
void setAdcRate(std::uint8_t rate)
bool getEXTEN(void)
float getACINVolatge(void)
void powerOff(void)
Definition: M5Unified.cpp:48
I2C_Class In_I2C
for internal I2C device
Definition: I2C_Class.cpp:10