SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
axp517_charger.ino
Go to the documentation of this file.
1
29#include <PmicDrv.hpp>
30
31#ifndef PMIC_SDA
32#define PMIC_SDA 3
33#endif
34
35#ifndef PMIC_SCL
36#define PMIC_SCL 2
37#endif
38
39#ifndef PMIC_IRQ
40#define PMIC_IRQ 21
41#endif
42
44
45void setup()
46{
47 Serial.begin(115200);
48 delay(500);
49
50 Serial.println("\n=== AXP517 Charger Example ===\n");
51
52 if (!pmic.begin(Wire, AXP517_SLAVE_ADDRESS, PMIC_SDA, PMIC_SCL)) {
53 Serial.println("Failed to init AXP517!");
54 while (1) delay(1000);
55 }
56
57 pmic.enableModule(PmicAXP517::Module::CHARGE, true);
58
59 auto *charger = pmic.getCharger();
60 if (!charger) {
61 Serial.println("No charger!");
62 while (1) delay(1000);
63 }
64
65 Serial.println("\n--- Configure Charger ---");
66
67 charger->setChargeVoltage(4200);
68 Serial.print("CV: ");
69 Serial.print(charger->getChargeVoltage());
70 Serial.println(" mV");
71
72 charger->setFastChargeCurrent(1000);
73 Serial.print("ICC: ");
74 Serial.print(charger->getFastChargeCurrent());
75 Serial.println(" mA");
76
77 charger->setPreChargeCurrent(128);
78 Serial.print("IPRECHG: ");
79 Serial.print(charger->getPreChargeCurrent());
80 Serial.println(" mA");
81
82 charger->setTerminationCurrent(256);
83 Serial.print("ITERM: ");
84 Serial.print(charger->getTerminationCurrent());
85 Serial.println(" mA");
86
87 charger->enableCharging(true);
88 Serial.println("Charging enabled");
89
90 Serial.println("\n=== Setup Complete ===\n");
91}
92
93void loop()
94{
95 static uint32_t lastPrint = 0;
96
97 if (millis() - lastPrint > 2000) {
98 lastPrint = millis();
99
100 auto *charger = pmic.getCharger();
101 auto status = charger->getStatus();
102
103 Serial.println("\n--- Charger Status ---");
104
105 Serial.print("State: ");
106 Serial.println(status.charging ? "Charging" : "Idle");
107 Serial.print("Vbus: ");
108 Serial.println(status.vbusPresent ? "Present" : "Absent");
109 Serial.print("Done: ");
110 Serial.println(status.chargeDone ? "Yes" : "No");
111
112 // Current settings
113 Serial.print("CV: ");
114 Serial.print(charger->getChargeVoltage());
115 Serial.println(" mV");
116 Serial.print("ICC: ");
117 Serial.print(charger->getFastChargeCurrent());
118 Serial.println(" mA");
119 }
120
121 delay(100);
122}
@license MIT License
PmicAXP517 pmic
#define PMIC_SDA
#define PMIC_SCL
void setup()
void loop()
High-level driver facade for the X-Powers AXP517 PMIC.
PmicChargerBase * getCharger() override
Access the generic PMIC charger interface.
bool enableModule(Module module, bool enable)
Enable or disable a functional module.
bool begin(SensorCommCustom::CustomCallback callback, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr)
Initialization using a custom communication interface.
virtual Status getStatus()=0
Get current charger status.