30#include "../../../SensorBuildOpt.h"
31#if !SENSORLIB_EXCLUDE_PMIC_AXP202
37const uint16_t AXP202Channel::ldo4Table_[16] = {
38 1250, 1300, 1400, 1500, 1600, 1700, 1800, 1900,
39 2000, 2500, 2700, 2800, 3000, 3100, 3200, 3300
71 if (val < 0)
return false;
73 val = (val & 0xF8) | 0x03;
103 if (val < 0)
return false;
104 return (val & 0x07) == 0x03;
117 if (mV < 700) mV = 700;
118 if (mV > 2275) mV = 2275;
119 uint8_t code = (mV - 700) / 25;
123 if (mV < 700) mV = 700;
124 if (mV > 3500) mV = 3500;
125 uint8_t code = (mV - 700) / 25;
129 if (mV < 1800) mV = 1800;
130 if (mV > 3300) mV = 3300;
131 uint8_t code = (mV - 1800) / 100;
135 if (mV < 700) mV = 700;
136 if (mV > 3500) mV = 3500;
137 uint8_t code = (mV - 700) / 25;
142 uint16_t bestDiff =
static_cast<uint16_t
>(ldo4Table_[0] > mV ? (ldo4Table_[0] - mV) : (mV - ldo4Table_[0]));
143 for (
int i = 0;
i < 16; ++
i) {
144 uint16_t diff =
static_cast<uint16_t
>(ldo4Table_[
i] > mV ? (ldo4Table_[
i] - mV) : (mV - ldo4Table_[
i]));
145 if (diff < bestDiff) {
153 if (mV < 1800) mV = 1800;
154 if (mV > 3300) mV = 3300;
155 uint8_t code = (mV - 1800) / 100;
172 if (val < 0)
return 0;
173 return ((val & 0x3F) * 25) + 700;
177 if (val < 0)
return 0;
178 return ((val & 0x7F) * 25) + 700;
182 if (val < 0)
return 0;
183 uint8_t code = (val >> 4) & 0x0F;
184 return (code * 100) + 1800;
188 if (val < 0)
return 0;
192 return ((val & 0x7F) * 25) + 700;
196 if (val < 0)
return 0;
197 uint8_t idx = val & 0x0F;
198 if (idx >= 16)
return 0;
199 return ldo4Table_[idx];
203 if (val < 0)
return 0;
204 uint8_t code = (val >> 4) & 0x0F;
205 return (code * 100) + 1800;
221 static const Info channelInfo[] = {
233 return channelInfo[channel];
static constexpr uint8_t CH_LDO3
static constexpr uint8_t CH_DCDC2
static constexpr uint8_t CH_EXTEN
bool setVoltage(uint8_t channel, uint16_t mV) override
Set the output voltage of a power channel.
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 of a power channel.
uint8_t count() const override
Get the number of available power channels.
static constexpr uint8_t CH_LDO4
AXP202Channel(AXP202Core &core)
Construct AXP202 channel control interface.
static constexpr uint8_t CH_LDO2
static constexpr uint8_t CH_LDOio
static constexpr uint8_t CHANNEL_COUNT
static constexpr uint8_t CH_DCDC3
Info getInfo(uint8_t channel) const override
Get information about a specific channel.
bool isEnabled(uint8_t channel) override
Check whether a power output channel is enabled.
@ 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 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 metadata for a single power output channel.
static constexpr uint8_t GPIO0_CTL
static constexpr uint8_t GPIO0_VOL
static constexpr uint8_t LDO24OUT_VOL
static constexpr uint8_t LDO234_DC23_CTL
static constexpr uint8_t DC3OUT_VOL
static constexpr uint8_t DC2OUT_VOL
static constexpr uint8_t LDO3OUT_VOL
static constexpr uint8_t BIT_DCDC3
static constexpr uint8_t BIT_EXTEN
static constexpr uint8_t BIT_DCDC2
static constexpr uint8_t BIT_LDO2
static constexpr uint8_t BIT_LDO4
static constexpr uint8_t BIT_LDO3