51 Serial.println(
"\n=== AXP2101 Basic Example ===\n");
54 Serial.println(
"Failed to init AXP2101!");
55 while (1) delay(1000);
57 Serial.println(
"AXP2101 initialized");
59 Serial.print(
"Chip ID: 0x");
67 Serial.println(
"\n--- Channel Test (DCDC1 & ALDO1) ---");
72 Serial.print(
"DCDC1: ");
74 Serial.println(
" mV");
79 Serial.print(
"ALDO1: ");
81 Serial.println(
" mV");
83 Serial.print(
"Total channels: ");
92 Serial.print(info.name);
94 Serial.print(info.minMillivolt);
96 Serial.print(info.maxMillivolt);
98 Serial.print(
" Step: ");
99 Serial.print(info.stepMillivolt);
100 Serial.println(
" mV");
103 Serial.println(
"\n--- Charger Test ---");
109 charger->setFastChargeCurrent(500);
110 charger->enableCharging(
true);
111 Serial.print(
"CV: ");
112 Serial.print(charger->getChargeVoltage());
113 Serial.println(
" mV");
114 Serial.print(
"ICC: ");
115 Serial.print(charger->getFastChargeCurrent());
116 Serial.println(
" mA");
119 Serial.println(
"\n--- Power Button Test ---");
121 uint16_t onLevel[] = {512, 1000, 2000};
122 for (
int i = 0;
i < 3;
i++) {
123 if (button.setOnDurationMs(onLevel[
i])) {
125 uint16_t readLevel = 0;
126 button.getOnDurationMs(readLevel);
127 Serial.print(
"On Level ");
130 Serial.println(readLevel);
131 if (readLevel == onLevel[
i]) {
132 Serial.println(
"On Level set successfully");
134 Serial.print(
"On Level set failed");
135 Serial.print(
"Expected: ");
136 Serial.print(onLevel[
i]);
137 Serial.print(
", Got: ");
138 Serial.println(readLevel);
143 uint16_t offLevel[] = {6000, 8000, 10000};
144 for (
int i = 0;
i < 3;
i++) {
145 if (button.setOffDurationMs(offLevel[
i])) {
147 uint16_t readLevel = 0;
148 button.getOffDurationMs(readLevel);
149 Serial.print(
"Get Off Level ");
152 Serial.println(readLevel);
153 if (readLevel == offLevel[
i]) {
154 Serial.println(
"Off Level set successfully");
156 Serial.print(
"Off Level set failed");
157 Serial.print(
"Expected: ");
158 Serial.print(offLevel[
i]);
159 Serial.print(
", Got: ");
160 Serial.println(readLevel);
165 Serial.println(
"\n--- ADC Test ---");
176 Serial.println(
"\n=== Setup Complete ===\n");
181 static uint32_t lastPrint = 0;
183 if (millis() - lastPrint > 2000) {
184 lastPrint = millis();
186 Serial.println(
"\n--- Status ---");
188 Serial.print(
"VBUS good: ");
190 Serial.print(
"Battery: ");
196 Serial.print(
"Charging: ");
197 Serial.println(status.charging ?
"Yes" :
"No");
198 Serial.print(
"Vbus: ");
199 Serial.println(status.vbusPresent ?
"Present" :
"Absent");
200 Serial.print(
"CHG Status: ");
201 switch (status.chargingStatus) {
203 Serial.println(
"Fast Charging");
206 Serial.println(
"Pre Charging");
209 Serial.println(
"No Charging");
212 Serial.println(
"Termination Charging");
215 Serial.println(
"Unknown Charging Status");
223 Serial.print(
"BAT%: ");
228 Serial.print(
"VBUS: ");
230 Serial.println(
" mV");
233 Serial.print(
"VBAT: ");
235 Serial.println(
" mV");
238 Serial.print(
"TEMP: ");
240 Serial.println(
" C");
243 Serial.print(
"VSYS: ");
245 Serial.println(
" mV");
bool enableChannels(uint32_t mask) override
Enable one or more ADC channels.
static constexpr uint8_t CH_ALDO1
static constexpr uint8_t CH_DCDC1
Top-level unified interface for the AXP2101 PMIC.
PmicChannelBase * getChannel() override
Get the power output channel interface.
AXP2101Pwron & pwron()
Get the chip-specific power button interface.
bool isBatteryConnect()
Check if a battery is connected.
bool begin(SensorCommCustom::CustomCallback callback, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr)
Initialise the AXP2101 with custom communication callbacks.
AXP2101Adc & adc()
Get the chip-specific ADC interface.
PmicChargerBase * getCharger() override
Get the charger interface (pointer for optional support).
bool enableModule(Module module, bool enable)
Enable or disable an internal functional module.
bool isVbusGood()
Check if a valid VBUS power source is present.
uint8_t getChipID()
Read the AXP2101 chip ID / version register.
@ BAT_PERCENTAGE
Battery percentage.
@ DIE_TEMPERATURE
Die temperature.
@ BAT_VOLTAGE
Battery voltage.
@ BAT_TEMPERATURE
Battery temperature.
@ VBUS_VOLTAGE
VBUS voltage.
@ VSYS_VOLTAGE
VSYS voltage.
virtual uint16_t getVoltage(uint8_t channel)=0
Get the current output voltage of a channel.
virtual bool setVoltage(uint8_t channel, uint16_t mV)=0
Set the output voltage of a channel.
virtual uint8_t count() const =0
Get the number of power output channels available on this PMIC.
virtual bool enable(uint8_t channel, bool enable)=0
Enable or disable a power output channel.
virtual Info getInfo(uint8_t channel) const =0
Get static metadata for a specific channel.
virtual bool setChargeVoltage(uint16_t mV)=0
Set charge voltage (CV mode voltage)
virtual Status getStatus()=0
Get current charger status.
@ NO_CHARGING
Not charging, battery idle or disconnected.
@ PRE_CHARGE
Pre-charge phase (low current for weak battery)
@ TERMINATION
Charging terminated (battery full)
@ FAST_CHARGE
Fast charge phase (constant current)