SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
PmicAXP2101.hpp
Go to the documentation of this file.
1
31#pragma once
32
33#include "../../../SensorBuildOpt.h"
34#if !SENSORLIB_EXCLUDE_PMIC_AXP2101
35
36#include "../../PmicBase.hpp"
37#include "../../PmicAdcBase.hpp"
38#include "../../PmicIrqBase.hpp"
39#include "../../PmicPowerBase.hpp"
40
41#include "AXP2101Regs.hpp"
42#include "AXP2101Core.hpp"
43#include "AXP2101Adc.hpp"
44#include "AXP2101Irq.hpp"
45#include "AXP2101Charger.hpp"
46#include "AXP2101Led.hpp"
47#include "AXP2101Power.hpp"
48#include "AXP2101Pwron.hpp"
49#include "AXP2101Watchdog.hpp"
50#include "AXP2101Channel.hpp"
51
52static constexpr uint8_t AXP2101_SLAVE_ADDRESS = 0x34;
53
71class PmicAXP2101 : public PmicBase
72{
73public:
75
79 PmicAXP2101() : _core(), _adc(_core)
80 , _irq(_core), _charger(_core)
81 , _led(_core), _power(_core)
82 , _pwron(_core), _watchdog(_core), _channel(_core)
83 {}
84
85#if defined(ARDUINO)
94 bool begin(TwoWire &wire, uint8_t addr, int sda = -1, int scl = -1)
95 {
96 return _core.begin(wire, addr, sda, scl);
97 }
98#elif defined(ESP_PLATFORM)
99#if defined(SENSORLIB_USE_I2C_LEGACY)
108 bool begin(i2c_port_t port_num, uint8_t addr, int sda = -1, int scl = -1)
109 {
110 return _core.begin(port_num, addr, sda, scl);
111 }
112#else
119 bool begin(i2c_master_bus_handle_t handle, uint8_t addr)
120 {
121 return _core.begin(handle, addr);
122 }
123#endif
124#endif
125
135 uint8_t addr)
136 {
137 return _core.begin(callback, hal_cb, addr);
138 }
139
143 void end()
144 {
145 }
146
161
166 const PmicConfig &getConfig() const override
167 {
168 static const PmicConfig config = {
169 .chipName = "AXP2101",
170 .i2cAddress = 0x34,
171 .chipIdReg = 0x03,
172 .chipIdValue = 0x4A,
173 .channelCount = 14,
181 // REG62H[4:0]: 0~200mA step=25, 200~1000mA step=100 (non-uniform)
182 .chargeCurrentMin = 0,
183 .chargeCurrentMax = 1000,
184 .chargeCurrentStep = 0,
185 .chargeCurrentSteps = 14,
186 };
187 return config;
188 }
189
190
196 {
197 return _power;
198 }
199
205 {
206 return &_charger;
207 }
208
213 PmicAdcBase &getAdc() override
214 {
215 return _adc;
216 }
217
222 PmicLedBase &getLed() override
223 {
224 return _led;
225 }
226
232 {
233 return &_channel;
234 }
235
236 PmicIrqBase *getIrq() override
237 {
238 return &_irq;
239 }
240
245 const char *getChipName() const override
246 {
247 return "AXP2101";
248 }
249
250 // ---- Chip-specific module accessors ----
251
257 {
258 return _irq;
259 }
260
266 {
267 return _charger;
268 }
269
275 {
276 return _led;
277 }
278
284 {
285 return _pwron;
286 }
287
293 {
294 return _watchdog;
295 }
296
302 {
303 return _adc;
304 }
305
311 {
312 return _core;
313 }
314
320 {
321 return _power;
322 }
323
324 // ---- Module enable/disable ----
325
335 bool enableModule(Module module, bool enable)
336 {
337 return _core.enableModule(module, enable);
338 }
339
349 {
350 return _core.isModuleEnabled(module);
351 }
352
353 // ---- Status & basic info ----
354
360 uint16_t getStatus()
361 {
362 int s1 = _core.readReg(axp2101_regs::bmu::STATUS1);
363 int s2 = _core.readReg(axp2101_regs::bmu::STATUS2);
364 if (s1 < 0 || s2 < 0) return 0;
365 return (static_cast<uint16_t>(s1) << 8) | static_cast<uint16_t>(s2);
366 }
367
373 {
374 return _core.getRegBit(axp2101_regs::bmu::STATUS1, 5);
375 }
376
382 {
383 return _core.getRegBit(axp2101_regs::bmu::STATUS1, 3);
384 }
385
391 {
392 return _charger.isCharging();
393 }
394
399 uint8_t getChipID()
400 {
401 int id = _core.readReg(axp2101_regs::bmu::IC_TYPE);
402 if (id < 0) return 0;
403 return static_cast<uint8_t>(id);
404 }
405
409 void shutdown()
410 {
411 _power.softShutdown();
412 }
413
417 void reset()
418 {
419 _power.resetSoC();
420 }
421
422private:
427 const AXP2101Core &core() const
428 {
429 return _core;
430 }
431
432 AXP2101Core _core;
433 AXP2101Adc _adc;
434 AXP2101Irq _irq;
435 AXP2101Charger _charger;
436 AXP2101Led _led;
437 AXP2101Power _power;
438 AXP2101Pwron _pwron;
439 AXP2101Watchdog _watchdog;
440 AXP2101Channel _channel;
441};
442
443#endif
@license MIT License
@license MIT License
@license MIT License
@license MIT License
@license MIT License
@license MIT License
@license MIT License
@license MIT License
@license MIT License
ADC control for the AXP2101 PMIC.
Power output channel (DCDC / LDO) control for the AXP2101 PMIC.
bool isCharging() override
Check if the charger is actively charging.
Core I2C communication layer for the AXP2101 PMIC.
bool isModuleEnabled(Module module)
Check whether an internal module is enabled.
bool enableModule(Module module, bool enable)
Enable or disable an internal functional module.
Module
Identifiers for AXP2101 internal functional modules.
Interrupt controller interface for the AXP2101 PMIC.
Charging indicator LED control for the AXP2101 PMIC.
void softShutdown()
Initiate a soft shutdown (REG 0x10 bit 0).
void resetSoC()
Trigger a system-on-chip reset (REG 0x10 bit 1).
Power-on / power-button timing control for the AXP2101 PMIC.
I2C watchdog timer control for the AXP2101 PMIC.
bool begin(SensorCommCustom::CustomCallback cb, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr)
Initialize the sensor using custom callback interface.
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.
const PmicConfig & getConfig() const override
Get the PMIC configuration descriptor.
bool isCharging()
Check if the battery is currently charging.
bool begin(SensorCommCustom::CustomCallback callback, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr)
Initialise the AXP2101 with custom communication callbacks.
void end()
De-initialise the PMIC (no-op for AXP2101).
AXP2101Charger & charger()
Get the chip-specific charger interface.
PmicPowerBase & getPower() override
Get the power management interface.
AXP2101Adc & adc()
Get the chip-specific ADC interface.
void reset()
Reset (restart) the SoC system.
AXP2101Power & power()
Get the chip-specific power management interface.
const char * getChipName() const override
Get the human-readable chip name.
PmicChargerBase * getCharger() override
Get the charger interface (pointer for optional support).
PmicAXP2101()
Construct the AXP2101 PMIC interface, initialising all sub-modules.
bool enableModule(Module module, bool enable)
Enable or disable an internal functional module.
PmicIrqBase * getIrq() override
Get interrupt interface.
PmicAdcBase & getAdc() override
Get the ADC interface.
bool isVbusGood()
Check if a valid VBUS power source is present.
AXP2101Led & led()
Get the chip-specific LED module.
PmicCapability::Capability getCapabilities() const override
Get the supported PMIC capabilities bitmask.
AXP2101Watchdog & watchdog()
Get the chip-specific watchdog interface.
PmicLedBase & getLed() override
Get the LED interface.
void shutdown()
Soft power-off the PMIC.
bool isModuleEnabled(Module module)
Check whether an internal module is enabled.
AXP2101Irq & irq()
Get the chip-specific IRQ controller.
uint16_t getStatus()
Read the combined STATUS1 and STATUS2 registers.
uint8_t getChipID()
Read the AXP2101 chip ID / version register.
AXP2101Core & core()
Get the core I2C communication interface.
PMIC Base Abstract Class.
Definition PmicBase.hpp:130
PMIC power output channel base interface.
PMIC charger capability interface.
uint32_t(*)(Operation op, void *param1, void *param2) CustomHalCallback
bool(*)(uint8_t addr, uint8_t reg, uint8_t *buf, size_t len, bool writeReg, bool isWrite) CustomCallback
bool getRegBit(uint8_t reg, uint8_t bit)
int readReg(uint8_t reg) const
@ PmicSupportCharger
Battery charger support.
@ PmicSupportIrq
Interrupt handling support.
@ PmicSupportPower
Power management (input limits, boost, etc.)
@ PmicSupportAdc
Analog-to-Digital converter for monitoring.
@ PmicSupportChannel
Power output channel control (DCDC/LDO)
@ PmicSupportLed
LED driver support.
@ PmicSupportPowerBtn
Power-on/Power-off control support.
PMIC static configuration data.
Definition PmicBase.hpp:108
const char * chipName
e.g. "AXP2101"
Definition PmicBase.hpp:109
static constexpr uint8_t STATUS2
static constexpr uint8_t IC_TYPE
static constexpr uint8_t STATUS1