M5Unified
AXP2101_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_AXP2101_CLASS_H__
5 #define __M5_AXP2101_CLASS_H__
6 
7 #include "I2C_Class.hpp"
8 
9 namespace m5
10 {
11  class AXP2101_Class : public I2C_Device
12  {
13  public:
14  static constexpr uint8_t AXP2101_EFUS_OP_CFG = 0xF0;
15  static constexpr uint8_t AXP2101_EFREQ_CTRL = 0xF1;
16  static constexpr uint8_t AXP2101_TWI_ADDR_EXT = 0xFF;
17 
18  static constexpr std::uint8_t DEFAULT_ADDRESS = 0x34;
19 
20  AXP2101_Class(std::uint8_t i2c_addr = DEFAULT_ADDRESS, std::uint32_t freq = 400000, I2C_Class* i2c = &In_I2C)
21  : I2C_Device ( i2c_addr, freq, i2c )
22  {}
23 
24  bool begin(void);
25 
28  std::int8_t getBatteryLevel(void);
29 
32  void setBatteryCharge(bool enable);
33 
36  void setChargeCurrent(std::uint16_t max_mA);
37 
40  void setChargeVoltage(std::uint16_t max_mV);
41 
43  int getChargeStatus(void);
44 
46  bool isCharging(void);
47 
48 
49  inline void setALDO1(int voltage) { _set_LDO(0, voltage); }
50  inline void setALDO2(int voltage) { _set_LDO(1, voltage); }
51  inline void setALDO3(int voltage) { _set_LDO(2, voltage); }
52  inline void setALDO4(int voltage) { _set_LDO(3, voltage); }
53  inline void setBLDO1(int voltage) { _set_LDO(4, voltage); }
54  inline void setBLDO2(int voltage) { _set_LDO(5, voltage); }
55  inline void setDLDO1(int voltage) { _set_DLDO(0, voltage); }
56  inline void setDLDO2(int voltage) { _set_DLDO(1, voltage); }
57 
58  inline bool getALDO1Enabled(void) { return _get_LDOEn(0); }
59  inline bool getALDO2Enabled(void) { return _get_LDOEn(1); }
60  inline bool getALDO3Enabled(void) { return _get_LDOEn(2); }
61  inline bool getALDO4Enabled(void) { return _get_LDOEn(3); }
62  inline bool getBLDO1Enabled(void) { return _get_LDOEn(4); }
63  inline bool getBLDO2Enabled(void) { return _get_LDOEn(5); }
64 
65  void powerOff(void);
66 
67  void setAdcState(bool enable);
68  void setAdcRate( std::uint8_t rate );
69 
70  void setBACKUP(bool enable);
71 
72  bool isACIN(void);
73  bool isVBUS(void);
74  bool getBatState(void);
75 
76  float getBatteryVoltage(void);
77  float getBatteryDischargeCurrent(void);
78  float getBatteryChargeCurrent(void);
79  float getBatteryPower(void);
80  float getACINVoltage(void);
81  float getACINCurrent(void);
82  float getVBUSVoltage(void);
83  float getVBUSCurrent(void);
84  float getAPSVoltage(void);
85  float getInternalTemperature(void);
86 
88  std::uint8_t getPekPress(void);
89 
90  void setReg0x20Bit0(bool);
91 
92  private:
93  std::size_t readRegister12(std::uint8_t addr);
94  std::size_t readRegister14(std::uint8_t addr);
95  std::size_t readRegister16(std::uint8_t addr);
96 
97  void _set_LDO(std::uint8_t num, int voltage);
98  void _set_DLDO(std::uint8_t num, int voltage);
99  bool _get_LDOEn(std::uint8_t num);
100  };
101 }
102 
103 #endif
void setALDO4(int voltage)
AXP2101_Class(std::uint8_t i2c_addr=DEFAULT_ADDRESS, std::uint32_t freq=400000, I2C_Class *i2c=&In_I2C)
void setBLDO1(int voltage)
float getACINVoltage(void)
void setALDO2(int voltage)
bool getALDO4Enabled(void)
static constexpr std::uint8_t DEFAULT_ADDRESS
float getInternalTemperature(void)
int getChargeStatus(void)
void setALDO3(int voltage)
static constexpr uint8_t AXP2101_TWI_ADDR_EXT
float getBatteryVoltage(void)
float getVBUSVoltage(void)
std::uint8_t getPekPress(void)
float getACINCurrent(void)
float getVBUSCurrent(void)
bool isCharging(void)
Get whether the battery is currently charging or not.
void setBatteryCharge(bool enable)
float getBatteryPower(void)
static constexpr uint8_t AXP2101_EFREQ_CTRL
bool getBatState(void)
std::int8_t getBatteryLevel(void)
void setChargeCurrent(std::uint16_t max_mA)
float getAPSVoltage(void)
bool getALDO1Enabled(void)
void setAdcRate(std::uint8_t rate)
void setDLDO1(int voltage)
bool getALDO2Enabled(void)
bool getALDO3Enabled(void)
void setALDO1(int voltage)
bool getBLDO2Enabled(void)
void setDLDO2(int voltage)
float getBatteryChargeCurrent(void)
void setChargeVoltage(std::uint16_t max_mV)
void setReg0x20Bit0(bool)
static constexpr uint8_t AXP2101_EFUS_OP_CFG
void setBACKUP(bool enable)
void setBLDO2(int voltage)
float getBatteryDischargeCurrent(void)
void setAdcState(bool enable)
bool getBLDO1Enabled(void)
Definition: M5Unified.cpp:48
I2C_Class In_I2C
for internal I2C device
Definition: I2C_Class.cpp:10