31#include "../../../SensorBuildOpt.h"
32#if !SENSORLIB_EXCLUDE_PMIC_AXP2101
42bool AXP2101Pwron::updateBits(uint8_t mask, uint8_t value)
45 if (v < 0)
return false;
46 uint8_t cur =
static_cast<uint8_t
>(v);
47 uint8_t next = (cur & ~mask) | (value & mask);
48 if (next == cur)
return true;
54 uint8_t idx = (ms >= 2000) ? 3 :
57 return updateBits(0x03, idx);
62 const uint16_t kOnLevelMs[] = {128, 512, 1000, 2000};
64 if (v < 0)
return false;
65 ms = kOnLevelMs[
static_cast<uint8_t
>(v) & 0x03];
71 uint8_t idx = (ms >= 10000) ? 3 :
74 return updateBits(0x0C, idx << 2);
79 const uint16_t kOffLevelMs[] = {4000, 6000, 8000, 10000};
81 if (v < 0)
return false;
82 ms = kOffLevelMs[(
static_cast<uint8_t
>(v) >> 2) & 0x03];
88 uint8_t idx = (ms >= 2500) ? 3 :
91 return updateBits(0x30, idx << 4);
96 const uint16_t kIrqLevelMs[] = {1000, 1500, 2000, 2500};
98 if (v < 0)
return false;
99 ms = kIrqLevelMs[(
static_cast<uint8_t
>(v) >> 4) & 0x03];
Core I2C communication layer for the AXP2101 PMIC.
bool getIrqDurationMs(uint16_t &ms) const override
Get the short-press / IRQ trigger delay.
bool setIrqDurationMs(uint16_t ms) override
Set the short-press / IRQ trigger delay.
bool setOffDurationMs(uint16_t ms) override
Set the power-off delay (held duration to turn off).
bool setOnDurationMs(uint16_t ms) override
Set the power-on delay (held duration to turn on).
bool getOnDurationMs(uint16_t &ms) const override
Get the power-on delay setting.
AXP2101Pwron(AXP2101Core &core)
bool getOffDurationMs(uint16_t &ms) const override
Get the power-off delay setting.
int readReg(uint8_t reg) const
int writeReg(uint8_t reg, uint8_t val)
static constexpr uint8_t IRQ_OFF_ON_LEVEL