31#include "../../../SensorBuildOpt.h"
32#if !SENSORLIB_EXCLUDE_PMIC_AXP2101
47 if (mv < 4100 || mv > 4800)
return false;
48 uint8_t code = (mv - 4100) / 100;
55 if (val < 0)
return 0;
56 return 4100 + (((val >> 4) & 0x07) * 100);
61 if (mv < 3880) mv = 3880;
62 if (mv > 5080) mv = 5080;
63 uint8_t code = (mv - 3880) / 80;
70 if (val < 0)
return 0;
71 return 3880 + ((val & 0x0F) * 80);
76 static const uint16_t values[] = {100, 500, 900, 1000, 1500, 2000};
77 static const uint8_t codes[] = {0, 1, 2, 3, 4, 5};
80 for (
int i = 0;
i < 6; ++
i) {
81 uint32_t diff = (mA > values[
i]) ? (mA - values[
i]) : (values[
i] - mA);
82 if (
i == 0 || diff < best) {
92 static const uint16_t values[] = {100, 500, 900, 1000, 1500, 2000};
94 if (val < 0)
return 0;
95 uint8_t code = val & 0x07;
96 return (code <= 5) ? values[code] : values[5];
117 if (millivolt < 2600 || millivolt > 3300 || (millivolt % 100))
120 if (val < 0)
return false;
122 val |= (millivolt - 2600) / 100;
129 if (val < 0)
return 0;
130 return ((val & 0x07) * 100) + 2600;
213 if (opt > 3)
return false;
215 if (val < 0)
return false;
224 if (val < 0)
return 0;
277 if (dc_id > 4)
return;
287 if (dc_id > 4)
return false;
296 return (val < 0) ? 0 :
static_cast<uint8_t
>(val);
302 return (val < 0) ? 0 :
static_cast<uint8_t
>(val);
309 if (len != 128 || !data)
return false;
314 for (
int i = 0;
i < 128; ++
i) {
324 if (len != 128 || !data)
return false;
326 memset(buffer, 0,
sizeof(buffer));
329 for (
int i = 0;
i < 128; ++
i) {
336 return memcmp(data, buffer, 128) == 0;
343 if (percentage < 5 || percentage > 20)
return;
347 val |= ((percentage - 5) << 4);
354 if (val < 0)
return 0;
355 return ((val >> 4) & 0x0F) + 5;
360 if (percentage > 15) percentage = 15;
371 if (val < 0)
return 0;
390 if (opt > 2)
return false;
392 if (val < 0)
return false;
401 if (val < 0)
return 0;
402 return (val >> 1) & 0x03;
410 if (dc_id == 0 || dc_id > 4)
return false;
417 if (dc_id == 0 || dc_id > 4)
return false;
467 if (opt > 3)
return false;
474 if (val < 0)
return 0;
504 if (channel > 13 || seq > 3)
return false;
511 static const uint8_t regs[] = {
527 static const uint8_t bits[] = {
534 return _core.
updateBits(regs[channel], 0x03 << bits[channel], seq << bits[channel]) >= 0;
539 if (channel > 13)
return 3;
541 static const uint8_t regs[] = {
550 static const uint8_t bits[] = {
551 0, 2, 4, 6, 0, 2, 4, 6, 0, 2, 4, 6, 0, 2,
554 int val = _core.
readReg(regs[channel]);
555 if (val < 0)
return 3;
556 return (val >> bits[channel]) & 0x03;
Core I2C communication layer for the AXP2101 PMIC.
void enablePowerSequence()
Enable power-on sequencing (REG 0x25 bit 2).
void softShutdown()
Initiate a soft shutdown (REG 0x10 bit 0).
void setLowBatShutdownThreshold(uint8_t percentage)
Set the low-battery shutdown threshold (REG 0x1A bits 3:0).
void disableLongPressShutdown()
Disable long-press power-off (REG 0x22 bit 1).
bool setDCDCUVPDebounce(uint8_t opt)
Set DCDC UVP debounce time (REG 81 bits 1:0).
void enablePwrOk()
Enable PWROK output (REG 0x25 bit 4).
bool isFastPowerOnEnabled()
Check if fast power-on sequence is enabled (REG 2B bit 7).
void disablePwrOk()
Disable PWROK output (REG 0x25 bit 4).
void disableInternalDischarge()
Disable internal battery discharge resistor (REG 0x10 bit 5).
uint8_t getDCDCUVPDebounce()
Get DCDC UVP debounce time (REG 81 bits 1:0).
uint32_t getInputCurrentLimit() const override
Get the VBUS input current limit (REG 0x16 bits 2:0).
bool getFrequencySpreadRange()
Get the frequency spread range (REG 81 bit 6).
bool isFastWakeupEnabled()
Check if fast wakeup is enabled (REG 2B bit 6).
bool enableFastWakeup(bool enable)
Enable fast wakeup (REG 2B bit 6).
bool enableWakeup()
Enable wakeup function (REG 0x26 bit 1).
bool enableSleep()
Enable sleep mode (REG 0x26 bit 0).
bool isDCDCForcePWM(uint8_t dc_id)
Check if a DCDC converter is in forced-PWM mode (REG 81 bits 2-5).
uint16_t getSysPowerDownVoltage()
Get the VSYS power-off voltage threshold (REG 0x24 bits 2:0).
void setDCOverVoltageProtection(bool enable)
Enable or disable DC over-voltage protection (REG 0x23 bit 5).
bool compareGaugeData(uint8_t *data, uint8_t len)
Compare data against the fuel-gauge backup registers.
void setDCLowVoltageProtection(uint8_t dc_id, bool enable)
Enable or disable under-voltage protection for a DCDC (REG 0x23 bits 0-4).
void disablePowerSequence()
Disable power-on sequencing (REG 0x25 bit 2).
void enableOverTempShutdown()
Enable automatic shutdown on over-temperature (REG 0x22 bit 2).
bool isShipModeEnabled() const override
Check whether ship mode is currently active (REG 0x12 bit 3).
uint32_t getMinimumSystemVoltage() const override
Get the minimum VSYS system voltage (REG 0x14 bits 6:4).
bool setFrequencySpreadRange(bool wide)
Set frequency spread range (REG 81 bit 6).
bool enableDieTempDetection(bool enable)
Enable or disable die temperature detection.
bool setDieTempLevel1Threshold(uint8_t opt)
Set die over-temperature Level1 threshold (REG 13 bits 2:1).
void resetSoC()
Trigger a system-on-chip reset (REG 0x10 bit 1).
uint8_t getPwrOkDelay()
Get the PWROK delay time (REG 0x25 bits 1:0).
bool setInputCurrentLimit(uint32_t mA) override
Set the VBUS input current limit (REG 0x16 bits 2:0).
uint8_t getPowerOnStatus()
Read the power-on source status register (REG 0x20, read-only).
void setLowBatWarnThreshold(uint8_t percentage)
Set the low-battery warning threshold (REG 0x1A bits 7:4).
bool setDCDCForcePWM(uint8_t dc_id, bool force)
Force a DCDC converter to always-PWM mode (REG 81 bits 2-5).
void disableOverTempShutdown()
Disable automatic shutdown on over-temperature (REG 0x22 bit 2).
bool setSysPowerDownVoltage(uint16_t millivolt)
Set the VSYS power-off voltage threshold (REG 0x24 bits 2:0).
AXP2101Power(AXP2101Core &core)
Construct an AXP2101Power instance.
bool isFrequencySpreadEnabled()
Check if frequency spread spectrum is enabled (REG 81 bit 7).
bool writeGaugeData(uint8_t *data, uint8_t len)
Write user data to the fuel-gauge backup registers.
uint8_t getFastPowerOnSequence(uint8_t channel)
Get fast power-on start sequence for a channel (REG 28-2B).
uint32_t getInputVoltageLimit() const override
Get the VBUS input voltage limit (REG 0x15 bits 3:0).
bool disableWakeup()
Disable wakeup function (REG 0x26 bit 1).
bool isDCDCForceCCM()
Check if all DCDC1-4 are in forced CCM mode (REG 80 bit 6).
bool setDVMRampSlow(bool slow)
Set DVM voltage ramp rate (REG 80 bit 5).
bool isDVMRampSlow()
Check if DVM ramp is set to slow (REG 80 bit 5).
bool setInputVoltageLimit(uint32_t mv) override
Set the VBUS input voltage limit (REG 0x15 bits 3:0).
bool enableFastPowerOn(bool enable)
Enable fast power-on sequence (REG 2B bit 7).
bool isDieTempDetectionEnabled()
Check if die temperature detection is enabled.
bool setDCDCForceCCM(bool enable)
Force all DCDC1-4 to CCM (continuous conduction mode) (REG 80 bit 6).
uint8_t getLowBatShutdownThreshold()
Get the low-battery shutdown threshold (REG 0x1A bits 3:0).
bool disableSleep()
Disable sleep mode (REG 0x26 bit 0).
bool enableShipMode(bool enable) override
Enable or disable ship mode (REG 0x12 bit 3).
bool isDCLowVoltageProtectionEnabled(uint8_t dc_id)
Check if under-voltage protection is enabled for a DCDC (REG 0x23 bits 0-4).
bool setMinimumSystemVoltage(uint32_t mv) override
Set the minimum VSYS system voltage (REG 0x14 bits 6:4).
bool setFastPowerOnSequence(uint8_t channel, uint8_t seq)
Set fast power-on start sequence for a channel (REG 28-2B).
void enablePowerOffDelay()
Enable power-off delay (REG 0x25 bit 3).
void disablePowerOffDelay()
Disable power-off delay (REG 0x25 bit 3).
bool isDCOverVoltageProtectionEnabled()
Check if DC over-voltage protection is enabled (REG 0x23 bit 5).
uint8_t getDieTempLevel1Threshold()
Get die over-temperature Level1 threshold (REG 13 bits 2:1).
void enableLongPressShutdown()
Enable long-press power-off (REG 0x22 bit 1).
bool setFrequencySpreadEnable(bool enable)
Enable DCDC frequency spread spectrum (REG 81 bit 7).
uint8_t getLowBatWarnThreshold()
Get the low-battery warning threshold (REG 0x1A bits 7:4).
uint8_t getPowerOffStatus()
Read the power-off source status register (REG 0x21, read-only).
bool setPwrOkDelay(uint8_t opt)
Set the PWROK delay time (REG 0x25 bits 1:0).
void enableInternalDischarge()
Enable internal battery discharge resistor (REG 0x10 bit 5).
void setLongPressAction(bool restart)
Set the long-press power key action (REG 0x22 bit 0).
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 LOW_BAT_WARN_SET
static constexpr uint8_t RESET_FUEL_GAUGE
static constexpr uint8_t COMMON_CFG
static constexpr uint8_t DIE_TEMP_CFG
static constexpr uint8_t MIN_SYS_VOLTAGE
static constexpr uint8_t INPUT_CURR_LIMIT
static constexpr uint8_t INPUT_VOLT_LIMIT
static constexpr uint8_t BATFET_CTRL
static constexpr uint8_t ONOFF_DVM_CTRL
static constexpr uint8_t FORCE_PWM_CTRL
static constexpr uint8_t BAT_PARAMS
static constexpr uint8_t FUEL_GAUGE_CTRL
static constexpr uint8_t FAST_PWRON_CTRL
static constexpr uint8_t FAST_PWRON_SET2
static constexpr uint8_t PWROK_SEQU_CTRL
static constexpr uint8_t DC_OVP_UVP_CTRL
static constexpr uint8_t FAST_PWRON_SET0
static constexpr uint8_t PWROFF_EN
static constexpr uint8_t FAST_PWRON_SET1
static constexpr uint8_t PWRON_STATUS
static constexpr uint8_t SLEEP_WAKEUP_CTRL
static constexpr uint8_t PWROFF_STATUS
static constexpr uint8_t VOFF_SET