SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
axp517_basic.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 Basic Example ===\n");
51
52 // Initialize PMIC using PmicDrv facade
53 if (!pmic.begin(Wire, AXP517_SLAVE_ADDRESS, PMIC_SDA, PMIC_SCL)) {
54 Serial.println("Failed to init AXP517!");
55 while (1) delay(1000);
56 }
57 Serial.println("AXP517 initialized");
58
59 // Enable modules
60 pmic.enableModule(PmicAXP517::Module::BUCK, true);
61 pmic.enableModule(PmicAXP517::Module::BOOST, true);
62 pmic.enableModule(PmicAXP517::Module::CHARGE, true);
63 pmic.enableModule(PmicAXP517::Module::TYPEC, true);
64 pmic.enableModule(PmicAXP517::Module::BC12, true);
65 Serial.println("Modules enabled");
66
67 Serial.println("\n--- Charger Test ---");
68
69 // Configure charger via facade
70 auto *charger = pmic.getCharger();
71 if (charger) {
72 charger->setChargeVoltage(4200);
73 charger->setFastChargeCurrent(1000);
74 charger->setPreChargeCurrent(128);
75 charger->enableCharging(true);
76 Serial.println("Charger configured");
77 Serial.print("CV: ");
78 Serial.print(charger->getChargeVoltage());
79 Serial.println(" mV");
80 Serial.print("ICC: ");
81 Serial.print(charger->getFastChargeCurrent());
82 Serial.println(" mA");
83 }
84
85 Serial.println("\n--- ADC Test ---");
86
87
88 // Enable ADC channels
89 auto &adc = pmic.adc();
97 );
98
99 // Enable LED set blinking
102
103 Serial.println("\n=== Setup Complete ===\n");
104}
105
106void loop()
107{
108 static uint32_t lastPrint = 0;
109
110 if (millis() - lastPrint > 2000) {
111 lastPrint = millis();
112
113 Serial.println("\n--- Status ---");
114
115 // Charger status
116 auto *charger = pmic.getCharger();
117 if (charger) {
118 auto status = charger->getStatus();
119 Serial.print("Charger: ");
120 Serial.println(status.charging ? "Charging" : "Idle");
121 Serial.print("Vbus: ");
122 Serial.println(status.vbusPresent ? "Present" : "Absent");
123 }
124
125 // ADC readings
126 auto &adc = pmic.adc();
127 float val = 0;
128 if (adc.read(PmicAdcBase::Channel::VBUS_VOLTAGE, val)) {
129 Serial.print("VBUS: ");
130 Serial.print(val);
131 Serial.println(" mV");
132 }
133 if (adc.read(PmicAdcBase::Channel::BAT_VOLTAGE, val)) {
134 Serial.print("VBAT: ");
135 Serial.print(val);
136 Serial.println(" mV");
137 }
138 if (adc.read(PmicAdcBase::Channel::BAT_CURRENT, val)) {
139 Serial.print("IBAT: ");
140 Serial.print(val);
141 Serial.println(" mA");
142 }
143 if (adc.read(PmicAdcBase::Channel::DIE_TEMPERATURE, val)) {
144 Serial.print("TEMP: ");
145 Serial.print(val);
146 Serial.println(" C");
147 }
148 if (adc.read(PmicAdcBase::Channel::VSYS_VOLTAGE, val)) {
149 Serial.print("VSYS: ");
150 Serial.print(val);
151 Serial.println(" mV");
152 }
153 }
154
155 delay(100);
156}
@license MIT License
PmicAXP517 pmic
#define PMIC_SDA
#define PMIC_SCL
void setup()
void loop()
bool enableChannels(uint32_t mask) override
Enable one or more ADC channels.
Definition AXP517Adc.cpp:55
bool setManualState(ManualState state) override
Set the LED manual state.
Definition AXP517Led.cpp:90
bool setMode(Mode mode) override
Set the LED mode.
Definition AXP517Led.cpp:55
High-level driver facade for the X-Powers AXP517 PMIC.
PmicChargerBase * getCharger() override
Access the generic PMIC charger interface.
AXP517Adc & adc()
Access the AXP517 ADC driver.
bool enableModule(Module module, bool enable)
Enable or disable a functional module.
AXP517Led & led()
Access the AXP517 LED driver.
bool begin(SensorCommCustom::CustomCallback callback, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr)
Initialization using a custom communication interface.
@ DIE_TEMPERATURE
Die temperature.
@ BAT_VOLTAGE
Battery voltage.
@ BAT_TEMPERATURE
Battery temperature.
@ BAT_CURRENT
Battery current.
@ VBUS_CURRENT
VBUS current.
@ VBUS_VOLTAGE
VBUS voltage.
@ VSYS_VOLTAGE
VSYS voltage.
virtual bool setChargeVoltage(uint16_t mV)=0
Set charge voltage (CV mode voltage)
virtual Status getStatus()=0
Get current charger status.
@ MANUAL
Manual control through registers.