SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
AXP202PowerEx.hpp
Go to the documentation of this file.
1
12#pragma once
13#include "AXP202Core.hpp"
14#include "AXP202Regs.hpp"
15
17{
18public:
19 enum class LDO3Mode : uint8_t {
20 LDO = 0,
21 DCIN = 1,
22 };
23
24 explicit AXP202PowerEx(AXP202Core &core) : _core(core) {}
25
26 // ---- Power Key Configuration (REG 36H) ----
27
35
43
44 // ---- LDO3 Operating Mode (REG 29H) ----
45
52 {
53 switch (mode) {
54 case LDO3Mode::LDO:
56 case LDO3Mode::DCIN:
58 default:
59 return false;
60 }
61 }
62
63 // ---- DCDC Operating Mode (REG 80H) ----
64
70 bool setDCDC2PWMMode(bool pwm)
71 {
72 return pwm ? _core.setRegBit(axp202_regs::pmu::DCDC_MODESET, 2)
74 }
75
77 {
79 }
80
86 bool setDCDC3PWMMode(bool pwm)
87 {
88 return pwm ? _core.setRegBit(axp202_regs::pmu::DCDC_MODESET, 1)
90 }
91
93 {
95 }
96
97 // ---- APS Warning Thresholds (REG 3AH, 3BH) ----
98
104 bool setAPSWarningLevel1(uint8_t opt)
105 {
106 return _core.updateBits(axp202_regs::pmu::APS_WARNING1, 0xFF, opt) >= 0;
107 }
108
110 {
112 return (val < 0) ? 0 : static_cast<uint8_t>(val & 0xFF);
113 }
114
120 bool setAPSWarningLevel2(uint8_t opt)
121 {
122 return _core.updateBits(axp202_regs::pmu::APS_WARNING2, 0xFF, opt) >= 0;
123 }
124
126 {
128 return (val < 0) ? 0 : static_cast<uint8_t>(val & 0xFF);
129 }
130
131 // ---- Over-Temperature Shutdown (REG 8FH) ----
132
139 {
140 return enable ? _core.setRegBit(axp202_regs::pmu::HOTOVER_CTL, 2)
142 }
143
148
149 // ---- DCDC Frequency (REG 37H) ----
155 bool setDCDCFrequency(uint8_t freq)
156 {
157 return _core.writeReg(axp202_regs::pmu::DCDC_FREQSET, freq) >= 0;
158 }
159
161 {
163 return (val < 0) ? 0 : static_cast<uint8_t>(val);
164 }
165
166 // ---- VBUS Detection/SRP (REG 8BH) ----
167
173 bool enableVBUSDetection(bool enable)
174 {
175 return enable ? _core.setRegBit(axp202_regs::pmu::VBUS_DET_SRP, 3)
177 }
178
180 {
182 }
183
184private:
185 AXP202Core &_core;
186};
@license MIT License
@license MIT License
bool isOverTemperatureShutdownEnabled()
bool setDCDC3PWMMode(bool pwm)
Force DCDC3 to PWM mode (REG 80H bit 1)
bool setDCDCFrequency(uint8_t freq)
Set DCDC switching frequency (REG 37H)
bool enableOverTemperatureShutdown(bool enable)
Enable over-temperature shutdown (REG 8FH bit 2)
void disableLongPressShutdown()
Disable automatic power-off when the power key is held.
bool setDCDC2PWMMode(bool pwm)
Force DCDC2 to PWM mode (REG 80H bit 2)
bool setAPSWarningLevel2(uint8_t opt)
Set APS warning level 2 voltage (REG 3BH)
bool isVBUSDetectionEnabled()
AXP202PowerEx(AXP202Core &core)
uint8_t getDCDCFrequency()
bool setAPSWarningLevel1(uint8_t opt)
Set APS warning level 1 voltage (REG 3AH)
uint8_t getAPSWarningLevel2()
uint8_t getAPSWarningLevel1()
bool setLDO3Mode(LDO3Mode mode)
Select the LDO3 regulated output or DCIN pass-through path.
bool enableVBUSDetection(bool enable)
Enable VBUS Valid detection (REG 8BH bit 3)
void enableLongPressShutdown()
Enable automatic power-off when the power key is held.
bool clrRegBit(uint8_t reg, uint8_t bit)
bool getRegBit(uint8_t reg, uint8_t bit)
int readReg(uint8_t reg) const
int writeReg(uint8_t reg, uint8_t val)
int updateBits(uint8_t reg, uint8_t mask, uint8_t value_shifted)
bool setRegBit(uint8_t reg, uint8_t bit)
static constexpr uint8_t VBUS_DET_SRP
static constexpr uint8_t APS_WARNING2
static constexpr uint8_t HOTOVER_CTL
static constexpr uint8_t POK_SET
static constexpr uint8_t DCDC_FREQSET
static constexpr uint8_t APS_WARNING1
static constexpr uint8_t LDO3OUT_VOL
static constexpr uint8_t DCDC_MODESET