31#include "../../../SensorBuildOpt.h"
32#if !SENSORLIB_EXCLUDE_PMIC_AXP2101
45 if (isDCDC(channel)) {
52 uint8_t bit = (ldoIdx <= 7) ? ldoIdx : 0;
60 if (isDCDC(channel)) {
66 uint8_t bit = (ldoIdx <= 7) ? ldoIdx : 0;
74 static const uint8_t dcdcRegs[] = {
78 static const uint8_t ldoRegs[] = {
84 if (isDCDC(channel)) {
85 uint8_t reg = dcdcRegs[channel];
88 if (mV < 1500) mV = 1500;
89 if (mV > 3400) mV = 3400;
90 return _core.
updateBits(reg, 0x1F, (mV - 1500) / 100) >= 0;
93 if (mV >= 500 && mV <= 1200) {
94 return _core.
updateBits(reg, 0x7F, (mV - 500) / 10) >= 0;
95 }
else if (mV >= 1220 && mV <= 1540) {
96 return _core.
updateBits(reg, 0x7F, (mV - 1220) / 20 + 71) >= 0;
101 if (mV >= 500 && mV <= 1200) {
102 return _core.
updateBits(reg, 0x7F, (mV - 500) / 10) >= 0;
103 }
else if (mV >= 1220 && mV <= 1540) {
104 return _core.
updateBits(reg, 0x7F, (mV - 1220) / 20 + 71) >= 0;
105 }
else if (mV >= 1600 && mV <= 3400) {
106 return _core.
updateBits(reg, 0x7F, (mV - 1600) / 100 + 88) >= 0;
111 if (mV >= 500 && mV <= 1200) {
112 return _core.
updateBits(reg, 0x7F, (mV - 500) / 10) >= 0;
113 }
else if (mV >= 1220 && mV <= 1840) {
114 return _core.
updateBits(reg, 0x7F, (mV - 1220) / 20 + 71) >= 0;
120 return _core.
updateBits(reg, 0x1F, 0x19) >= 0;
122 if (mV < 1400) mV = 1400;
123 if (mV > 3700) mV = 3700;
124 return _core.
updateBits(reg, 0x1F, (mV - 1400) / 100) >= 0;
131 uint8_t reg = ldoRegs[ldoIdx];
135 if (mV < 500) mV = 500;
136 if (mV > 3500) mV = 3500;
137 return _core.
updateBits(reg, 0x1F, (mV - 500) / 100) >= 0;
141 if (mV < 500) mV = 500;
142 if (mV > 1400) mV = 1400;
143 return _core.
updateBits(reg, 0x1F, (mV - 500) / 50) >= 0;
147 if (mV < 500) mV = 500;
148 if (mV > 3300) mV = 3300;
149 return _core.
updateBits(reg, 0x1F, (mV - 500) / 100) >= 0;
153 if (mV < 500) mV = 500;
154 if (mV > 1400) mV = 1400;
155 return _core.
updateBits(reg, 0x1F, (mV - 500) / 50) >= 0;
165 static const uint8_t dcdcRegs[] = {
169 static const uint8_t ldoRegs[] = {
175 if (isDCDC(channel)) {
176 int val = _core.
readReg(dcdcRegs[channel]);
177 if (val < 0)
return 0;
181 return (val & 0x1F) * 100 + 1500;
183 if (val < 71)
return val * 10 + 500;
184 return (val - 71) * 20 + 1220;
186 if (val < 71)
return val * 10 + 500;
187 if (val < 88)
return (val - 71) * 20 + 1220;
188 return (val - 88) * 100 + 1600;
190 if (val < 71)
return val * 10 + 500;
191 return (val - 71) * 20 + 1220;
194 if (val == 0x19)
return 1200;
195 return val * 100 + 1400;
201 int val = _core.
readReg(ldoRegs[ldoIdx]);
202 if (val < 0)
return 0;
203 uint8_t code = val & 0x1F;
206 return code * 50 + 500;
210 return code * 50 + 500;
212 return code * 100 + 500;
222 static const Info channelInfo[] = {
241 return channelInfo[channel];
static constexpr uint8_t CH_ALDO4
static constexpr uint8_t CH_ALDO1
uint8_t count() const override
Get the total number of available power channels.
Info getInfo(uint8_t channel) const override
Get information about a specific power channel.
static constexpr uint8_t CH_DCDC1
static constexpr uint8_t CH_CPUSLDO
static constexpr uint8_t CH_ALDO3
static constexpr uint8_t CH_DCDC2
static constexpr uint8_t DCDC_COUNT
Number of DCDC converters.
static constexpr uint8_t CH_DCDC5
static constexpr uint8_t CH_ALDO2
AXP2101Channel(AXP2101Core &core)
bool enable(uint8_t channel, bool enable) override
Enable or disable a power output channel.
uint16_t getVoltage(uint8_t channel) override
Get the current output voltage setting for a channel.
static constexpr uint8_t CH_DCDC3
static constexpr uint8_t CH_DLDO2
static constexpr uint8_t CH_BLDO1
static constexpr uint8_t CH_BLDO2
static constexpr uint8_t CH_DCDC4
bool setVoltage(uint8_t channel, uint16_t mV) override
Set the output voltage for a DCDC or LDO channel.
static constexpr uint8_t CH_DLDO1
bool isEnabled(uint8_t channel) override
Check whether a power output channel is enabled.
static constexpr uint8_t CHANNEL_COUNT
Total number of power channels.
Core I2C communication layer for the AXP2101 PMIC.
@ LDO
Linear low-dropout regulator.
@ DCDC
Switching buck/boost converter.
bool clrRegBit(uint8_t reg, uint8_t bit)
bool getRegBit(uint8_t reg, uint8_t bit)
int readReg(uint8_t reg) const
int updateBits(uint8_t reg, uint8_t mask, uint8_t value_shifted)
bool setRegBit(uint8_t reg, uint8_t bit)
Static metadata for a single power output channel.
static constexpr uint8_t VOL0_CTRL
static constexpr uint8_t ONOFF_DVM_CTRL
static constexpr uint8_t VOL3_CTRL
static constexpr uint8_t VOL4_CTRL
static constexpr uint8_t VOL2_CTRL
static constexpr uint8_t VOL1_CTRL
static constexpr uint8_t VOL8_CTRL
static constexpr uint8_t ONOFF_CTRL1
static constexpr uint8_t VOL0_CTRL
static constexpr uint8_t VOL5_CTRL
static constexpr uint8_t VOL7_CTRL
static constexpr uint8_t VOL4_CTRL
static constexpr uint8_t VOL3_CTRL
static constexpr uint8_t VOL2_CTRL
static constexpr uint8_t ONOFF_CTRL0
static constexpr uint8_t VOL6_CTRL
static constexpr uint8_t VOL1_CTRL