SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
axp192_basic.ino
Go to the documentation of this file.
1
31#include <PmicXPowers.hpp>
32
33#ifndef PMIC_SDA
34#define PMIC_SDA 3
35#endif
36
37#ifndef PMIC_SCL
38#define PMIC_SCL 2
39#endif
40
41#ifndef PMIC_IRQ
42#define PMIC_IRQ 21
43#endif
44
46
47void setup()
48{
49 Serial.begin(115200);
50 delay(500);
51
52 Serial.println("\n=== AXP192 Basic Example ===\n");
53
54 if (!pmic.begin(Wire, AXP192_SLAVE_ADDRESS, PMIC_SDA, PMIC_SCL)) {
55 Serial.println("Failed to init AXP192!");
56 while (1) delay(1000);
57 }
58 Serial.println("AXP192 initialized");
59
60
61 Serial.println("\n--- Channel Test ---");
62
63 // Enable DCDC1 at 3.3V via unified channel API
66 Serial.print("DCDC1: ");
68 Serial.println(" mV");
69
70 // Enable DCDC3 at 3.3V
73 Serial.print("DCDC3: ");
75 Serial.println(" mV");
76
77 Serial.print("Total channels: ");
78 Serial.println(pmic.getChannel()->count());
79
80 for (uint8_t i = 0; i < pmic.getChannel()->count(); i++) {
81 auto info = pmic.getChannel()->getInfo(i);
82 Serial.print(" Ch");
83 Serial.print(i);
84 Serial.print(": ");
85 Serial.print(info.name);
86 Serial.print(" ");
87 Serial.print(info.minMillivolt);
88 Serial.print("-");
89 Serial.print(info.maxMillivolt);
90 Serial.print(" mV");
91 Serial.print(" Step: ");
92 Serial.print(info.stepMillivolt);
93 Serial.println(" mV");
94 }
95
96 Serial.println("\n--- Charger Test ---");
97
98 auto *charger = pmic.getCharger();
99 if (charger) {
100 // The Charge input parameter is fuzzed and set to the value closest to the input.
101 charger->setChargeVoltage(4200);
102 charger->setFastChargeCurrent(500);
103 charger->enableCharging(true);
104 Serial.print("CV: ");
105 Serial.print(charger->getChargeVoltage());
106 Serial.println(" mV");
107 Serial.print("ICC: ");
108 Serial.print(charger->getFastChargeCurrent());
109 Serial.println(" mA");
110 }
111
112 Serial.println("\n--- ADC Test ---");
113
114
115 // Enable ADC channels
116 auto &adc = pmic.adc();
117 adc.enableChannels(
124 );
125
126 // Enable LED set blinking
129
130 Serial.println("\n=== Setup Complete ===\n");
131}
132
133void loop()
134{
135 static uint32_t lastPrint = 0;
136
137 if (millis() - lastPrint > 2000) {
138 lastPrint = millis();
139
140 Serial.println("\n--- Status ---");
141
142 auto *charger = pmic.getCharger();
143 if (charger) {
144 auto status = charger->getStatus();
145 Serial.print("Charging: ");
146 Serial.println(status.charging ? "Yes" : "No");
147 Serial.print("Vbus: ");
148 Serial.println(status.vbusPresent ? "Present" : "Absent");
149 }
150
151 auto &adc = pmic.adc();
152 float val = 0;
153 if (adc.read(PmicAdcBase::Channel::VBUS_VOLTAGE, val)) {
154 Serial.print("VBUS: ");
155 Serial.print(val);
156 Serial.println(" mV");
157 }
158 if (adc.read(PmicAdcBase::Channel::VBUS_CURRENT, val)) {
159 Serial.print("VBUS: ");
160 Serial.print(val);
161 Serial.println(" mA");
162 }
163 if (adc.read(PmicAdcBase::Channel::BAT_VOLTAGE, val)) {
164 Serial.print("VBAT: ");
165 Serial.print(val);
166 Serial.println(" mV");
167 }
168 if (adc.read(PmicAdcBase::Channel::BAT_CURRENT, val)) {
169 Serial.print("IBAT: ");
170 Serial.print(val);
171 Serial.println(" mA");
172 }
173 if (adc.read(PmicAdcBase::Channel::DIE_TEMPERATURE, val)) {
174 Serial.print("TEMP: ");
175 Serial.print(val);
176 Serial.println(" C");
177 }
178 if (adc.read(PmicAdcBase::Channel::VSYS_VOLTAGE, val)) {
179 Serial.print("VSYS: ");
180 Serial.print(val);
181 Serial.println(" mV");
182 }
183 }
184
185 delay(100);
186}
@license MIT License
#define PMIC_SDA
#define PMIC_SCL
void setup()
PmicAXP192 pmic
void loop()
static constexpr uint8_t CH_DCDC1
static constexpr uint8_t CH_DCDC3
bool setMode(Mode mode) override
Set LED operating mode.
Definition AXP1xxLed.hpp:74
bool setManualState(ManualState state) override
Set the LED state in manual mode.
AXP192 PMIC Unified Interface.
bool begin(SensorCommCustom::CustomCallback callback, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr)
Initialise the AXP192 with custom communication callbacks.
AXP1xxLed< axp192_regs > & led()
Access the LED module.
PmicChargerBase * getCharger() override
Access the charger interface.
PmicChannelBase * getChannel() override
Access the power channel control interface.
AXP192Adc & adc()
Access the chip-specific ADC 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 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.
@ MANUAL
Manual control through registers.
bool enableChannels(uint32_t mask) override
Enable one or more ADC channels.
uint8_t i