SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
AXP2101Irq.hpp
Go to the documentation of this file.
1
31#pragma once
32#include "../../PmicIrqBase.hpp"
33#include "AXP2101Core.hpp"
34
54class AXP2101Irq : public PmicIrqBase
55{
56public:
57 // IRQ Status 0 (REG 48H) -- Battery temperature and gauge events
59 static constexpr uint64_t IRQ_BAT_UNDER_TEMP_WORK = (1ULL << 0);
61 static constexpr uint64_t IRQ_BAT_OVER_TEMP_WORK = (1ULL << 1);
63 static constexpr uint64_t IRQ_BAT_UNDER_TEMP_CHG = (1ULL << 2);
65 static constexpr uint64_t IRQ_BAT_OVER_TEMP_CHG = (1ULL << 3);
67 static constexpr uint64_t IRQ_GAUGE_NEW_SOC = (1ULL << 4);
69 static constexpr uint64_t IRQ_GAUGE_WDT_TIMEOUT = (1ULL << 5);
71 static constexpr uint64_t IRQ_WARNING_LEVEL1 = (1ULL << 6);
73 static constexpr uint64_t IRQ_WARNING_LEVEL2 = (1ULL << 7);
74
75 // IRQ Status 1 (REG 49H) -- Power path and key events
77 static constexpr uint64_t IRQ_PEKEY_POSITIVE_EDGE = (1ULL << 8);
79 static constexpr uint64_t IRQ_PEKEY_NEGATIVE_EDGE = (1ULL << 9);
81 static constexpr uint64_t IRQ_PEKEY_LONG_PRESS = (1ULL << 10);
83 static constexpr uint64_t IRQ_PEKEY_SHORT_PRESS = (1ULL << 11);
85 static constexpr uint64_t IRQ_BAT_REMOVE = (1ULL << 12);
87 static constexpr uint64_t IRQ_BAT_INSERT = (1ULL << 13);
89 static constexpr uint64_t IRQ_VBUS_REMOVE = (1ULL << 14);
91 static constexpr uint64_t IRQ_VBUS_INSERT = (1ULL << 15);
92
93 // IRQ Status 2 (REG 4AH) -- Fault and charge status events
95 static constexpr uint64_t IRQ_BAT_OVER_VOLT = (1ULL << 16);
97 static constexpr uint64_t IRQ_CHG_TIMEOUT = (1ULL << 17);
99 static constexpr uint64_t IRQ_DIE_OVER_TEMP = (1ULL << 18);
101 static constexpr uint64_t IRQ_BAT_CHG_START = (1ULL << 19);
103 static constexpr uint64_t IRQ_BAT_CHG_DONE = (1ULL << 20);
105 static constexpr uint64_t IRQ_BATFET_OVER_CURR = (1ULL << 21);
107 static constexpr uint64_t IRQ_LDO_OVER_CURR = (1ULL << 22);
109 static constexpr uint64_t IRQ_WDT_EXPIRE = (1ULL << 23);
110
112 static constexpr uint64_t IRQ_ALL_MASK = 0xFFFFFFULL;
114 static constexpr uint64_t IRQ_RESERVED_MASK = ~0xFFFFFFULL;
115
116 // *INDENT-OFF*
117
124 static bool inline isIrqSet(uint64_t irqMask, uint64_t status) { return (status & irqMask) != 0; }
125
127 static bool inline isBatOverTempWork(uint64_t mask) { return isIrqSet(IRQ_BAT_OVER_TEMP_WORK, mask); }
129 static bool inline isBatUnderTempWork(uint64_t mask) { return isIrqSet(IRQ_BAT_UNDER_TEMP_WORK, mask); }
131 static bool inline isBatOverTempChg(uint64_t mask) { return isIrqSet(IRQ_BAT_OVER_TEMP_CHG, mask); }
133 static bool inline isBatUnderTempChg(uint64_t mask) { return isIrqSet(IRQ_BAT_UNDER_TEMP_CHG, mask); }
135 static bool inline isGaugeNewSoc(uint64_t mask) { return isIrqSet(IRQ_GAUGE_NEW_SOC, mask); }
137 static bool inline isGaugeWdtTimeout(uint64_t mask) { return isIrqSet(IRQ_GAUGE_WDT_TIMEOUT, mask); }
139 static bool inline isWarningLevel1(uint64_t mask) { return isIrqSet(IRQ_WARNING_LEVEL1, mask); }
141 static bool inline isWarningLevel2(uint64_t mask) { return isIrqSet(IRQ_WARNING_LEVEL2, mask); }
142
144 static bool inline isVbusInsert(uint64_t mask) { return isIrqSet(IRQ_VBUS_INSERT, mask); }
146 static bool inline isVbusRemove(uint64_t mask) { return isIrqSet(IRQ_VBUS_REMOVE, mask); }
148 static bool inline isBatInsert(uint64_t mask) { return isIrqSet(IRQ_BAT_INSERT, mask); }
150 static bool inline isBatRemove(uint64_t mask) { return isIrqSet(IRQ_BAT_REMOVE, mask); }
152 static bool inline isPekeyShortPress(uint64_t mask) { return isIrqSet(IRQ_PEKEY_SHORT_PRESS, mask); }
154 static bool inline isPekeyLongPress(uint64_t mask) { return isIrqSet(IRQ_PEKEY_LONG_PRESS, mask); }
156 static bool inline isPkeyNegativeEdge(uint64_t mask) { return isIrqSet(IRQ_PEKEY_NEGATIVE_EDGE, mask); }
158 static bool inline isPkeyPositiveEdge(uint64_t mask) { return isIrqSet(IRQ_PEKEY_POSITIVE_EDGE, mask); }
159
161 static bool inline isWdtExpire(uint64_t mask) { return isIrqSet(IRQ_WDT_EXPIRE, mask); }
163 static bool inline isLdoOverCurr(uint64_t mask) { return isIrqSet(IRQ_LDO_OVER_CURR, mask); }
165 static bool inline isBatfetOverCurr(uint64_t mask) { return isIrqSet(IRQ_BATFET_OVER_CURR, mask); }
167 static bool inline isBatChgDone(uint64_t mask) { return isIrqSet(IRQ_BAT_CHG_DONE, mask); }
169 static bool inline isBatChgStart(uint64_t mask) { return isIrqSet(IRQ_BAT_CHG_START, mask); }
171 static bool inline isDieOverTemp(uint64_t mask) { return isIrqSet(IRQ_DIE_OVER_TEMP, mask); }
173 static bool inline isChgTimeout(uint64_t mask) { return isIrqSet(IRQ_CHG_TIMEOUT, mask); }
175 static bool inline isBatOverVolt(uint64_t mask) { return isIrqSet(IRQ_BAT_OVER_VOLT, mask); }
176
177 // *INDENT-ON*
178
179 explicit AXP2101Irq(AXP2101Core &core);
180 ~AXP2101Irq() = default;
181
187 bool enable(uint64_t mask) override;
188
194 bool disable(uint64_t mask) override;
195
204 uint64_t readStatus(bool clear = true) override;
205
210 bool clearStatus() override;
211
212private:
213 AXP2101Core &_core;
214};
@license MIT License
Core I2C communication layer for the AXP2101 PMIC.
Interrupt controller interface for the AXP2101 PMIC.
static constexpr uint64_t IRQ_WARNING_LEVEL2
Battery voltage crossed warning level 2 threshold.
static bool isBatfetOverCurr(uint64_t mask)
Check if BATFET over-current interrupt is set.
static bool isWarningLevel1(uint64_t mask)
Check if battery warning level 1 interrupt is set.
static constexpr uint64_t IRQ_PEKEY_LONG_PRESS
Power key held for a long press duration.
static bool isBatOverTempChg(uint64_t mask)
Check if battery over-temperature (charging range) interrupt is set.
static constexpr uint64_t IRQ_VBUS_REMOVE
VBUS power source removed.
static constexpr uint64_t IRQ_GAUGE_WDT_TIMEOUT
Coulomb gauge watchdog timer expired.
static bool isPekeyShortPress(uint64_t mask)
Check if power key short press interrupt is set.
static constexpr uint64_t IRQ_BAT_CHG_START
Battery charging has started.
static bool isPekeyLongPress(uint64_t mask)
Check if power key long press interrupt is set.
static constexpr uint64_t IRQ_BATFET_OVER_CURR
BATFET over-current condition detected.
static bool isWarningLevel2(uint64_t mask)
Check if battery warning level 2 interrupt is set.
static constexpr uint64_t IRQ_CHG_TIMEOUT
Battery charge cycle timed out.
static constexpr uint64_t IRQ_PEKEY_SHORT_PRESS
Power key pressed briefly (short press).
static constexpr uint64_t IRQ_PEKEY_POSITIVE_EDGE
Power key rising edge detected.
static constexpr uint64_t IRQ_ALL_MASK
Mask covering all defined interrupt bits.
static bool isGaugeNewSoc(uint64_t mask)
Check if gauge new state-of-charge interrupt is set.
static bool isBatOverVolt(uint64_t mask)
Check if battery over-voltage interrupt is set.
static bool isWdtExpire(uint64_t mask)
Check if watchdog timer expired interrupt is set.
~AXP2101Irq()=default
static constexpr uint64_t IRQ_BAT_OVER_TEMP_WORK
Battery temperature exceeded the working threshold.
static constexpr uint64_t IRQ_PEKEY_NEGATIVE_EDGE
Power key falling edge detected.
static bool isChgTimeout(uint64_t mask)
Check if charge timeout interrupt is set.
static bool isLdoOverCurr(uint64_t mask)
Check if LDO over-current interrupt is set.
static constexpr uint64_t IRQ_GAUGE_NEW_SOC
Coulomb gauge reported a new state-of-charge value.
static bool isBatInsert(uint64_t mask)
Check if battery insertion interrupt is set.
static bool isBatOverTempWork(uint64_t mask)
Check if battery over-temperature (working range) interrupt is set.
static constexpr uint64_t IRQ_VBUS_INSERT
VBUS power source inserted.
static bool isBatRemove(uint64_t mask)
Check if battery removal interrupt is set.
static bool isPkeyPositiveEdge(uint64_t mask)
Check if power key positive (rising) edge interrupt is set.
static bool isVbusInsert(uint64_t mask)
Check if VBUS insertion interrupt is set.
static bool isBatUnderTempWork(uint64_t mask)
Check if battery under-temperature (working range) interrupt is set.
static constexpr uint64_t IRQ_WARNING_LEVEL1
Battery voltage crossed warning level 1 threshold.
static constexpr uint64_t IRQ_LDO_OVER_CURR
LDO output over-current condition detected.
static constexpr uint64_t IRQ_BAT_INSERT
Battery inserted into the system.
bool enable(uint64_t mask) override
Enable one or more interrupt sources.
static bool isVbusRemove(uint64_t mask)
Check if VBUS removal interrupt is set.
uint64_t readStatus(bool clear=true) override
Read the current interrupt status.
static constexpr uint64_t IRQ_WDT_EXPIRE
Watchdog timer expired.
static constexpr uint64_t IRQ_BAT_REMOVE
Battery removed from the system.
static constexpr uint64_t IRQ_RESERVED_MASK
Mask for reserved / unused interrupt bits.
bool disable(uint64_t mask) override
Disable one or more interrupt sources.
static bool isBatChgDone(uint64_t mask)
Check if battery charge done interrupt is set.
static constexpr uint64_t IRQ_BAT_OVER_VOLT
Battery voltage exceeded the over-voltage threshold.
static constexpr uint64_t IRQ_BAT_CHG_DONE
Battery charging has completed.
static bool isPkeyNegativeEdge(uint64_t mask)
Check if power key negative (falling) edge interrupt is set.
static bool isIrqSet(uint64_t irqMask, uint64_t status)
Check whether a specific interrupt bit is set in a status word.
static bool isDieOverTemp(uint64_t mask)
Check if die over-temperature interrupt is set.
bool clearStatus() override
Clear all pending interrupt status registers.
static constexpr uint64_t IRQ_DIE_OVER_TEMP
Die temperature exceeded the thermal shutdown threshold.
static constexpr uint64_t IRQ_BAT_UNDER_TEMP_CHG
Battery temperature dropped below the charging threshold.
static constexpr uint64_t IRQ_BAT_OVER_TEMP_CHG
Battery temperature exceeded the charging threshold.
static constexpr uint64_t IRQ_BAT_UNDER_TEMP_WORK
Battery temperature dropped below the working threshold.
static bool isBatUnderTempChg(uint64_t mask)
Check if battery under-temperature (charging range) interrupt is set.
static bool isGaugeWdtTimeout(uint64_t mask)
Check if gauge watchdog timeout interrupt is set.
static bool isBatChgStart(uint64_t mask)
Check if battery charge start interrupt is set.