SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
PmicAXP192.hpp
Go to the documentation of this file.
1
55#pragma once
56
57#include "../../../SensorBuildOpt.h"
58#if !SENSORLIB_EXCLUDE_PMIC_AXP192
59
60#include "../../PmicBase.hpp"
61#include "../../PmicAdcBase.hpp"
62#include "../../PmicIrqBase.hpp"
63#include "../../PmicPowerBase.hpp"
64
65#include "AXP192Regs.hpp"
66#include "AXP192Core.hpp"
67#include "AXP192Adc.hpp"
68#include "../axp1xx/AXP1xxIrq.hpp"
69#include "../axp1xx/AXP1xxCharger.hpp"
70#include "AXP192Gpio.hpp"
71#include "AXP192Channel.hpp"
72
73#include "../axp1xx/AXP1xxPower.hpp"
74#include "../axp1xx/AXP1xxPwron.hpp"
75#include "../axp1xx/AXP1xxTimer.hpp"
76#include "../axp1xx/AXP1xxLed.hpp"
77
78static constexpr uint8_t AXP192_SLAVE_ADDRESS = 0x34;
79
92class PmicAXP192 : public PmicBase
93{
94public:
95 PmicAXP192() : _core(), _adc(_core)
96 , _irq(_core), _charger(_core)
97 , _led(_core)
98 , _power(_core)
99 , _gpio(_core), _pwron(_core)
100 , _timer(_core)
101 , _channel(_core)
102 {}
103
104#if defined(ARDUINO)
113 bool begin(TwoWire &wire, uint8_t addr, int sda = -1, int scl = -1)
114 {
115 return _core.begin(wire, addr, sda, scl);
116 }
117#elif defined(ESP_PLATFORM)
118#if defined(SENSORLIB_USE_I2C_LEGACY)
127 bool begin(i2c_port_t port_num, uint8_t addr, int sda = -1, int scl = -1)
128 {
129 return _core.begin(port_num, addr, sda, scl);
130 }
131#else
138 bool begin(i2c_master_bus_handle_t handle, uint8_t addr)
139 {
140 return _core.begin(handle, addr);
141 }
142#endif
143#endif
144
154 uint8_t addr)
155 {
156 return _core.begin(callback, hal_cb, addr);
157 }
158
159 void end()
160 {
161 }
162
178
183 const PmicConfig &getConfig() const override
184 {
185 static const PmicConfig config = {
186 .chipName = "AXP192",
187 .i2cAddress = 0x34,
188 .chipIdReg = 0x03,
189 .chipIdValue = 0x03,
190 .channelCount = 7,
199 // REG33H[3:0]: 16 discrete levels 100~1320mA (non-uniform ~80mA steps)
200 .chargeCurrentMin = 100,
201 .chargeCurrentMax = 1320,
202 .chargeCurrentStep = 0,
203 .chargeCurrentSteps = 16,
204 };
205 return config;
206 }
207
213 {
214 return _power;
215 }
216
222 {
223 return &_charger;
224 }
225
230 PmicAdcBase &getAdc() override
231 {
232 return _adc;
233 }
234
236 {
237 return &_gpio;
238 }
239
244 PmicLedBase &getLed() override
245 {
246 return _led;
247 }
248
254 {
255 return &_channel;
256 }
257
258 PmicIrqBase *getIrq() override
259 {
260 return &_irq;
261 }
262
267 const char *getChipName() const override
268 {
269 return "AXP192";
270 }
271
277 {
278 return _irq;
279 }
280
286 {
287 return _charger;
288 }
289
295 {
296 return _led;
297 }
298
304 {
305 return _gpio;
306 }
307
313 {
314 return _pwron;
315 }
316
322 {
323 return _timer;
324 }
325
331 {
332 return _adc;
333 }
334
340 {
341 return _core;
342 }
343
348 uint16_t getStatus()
349 {
350 int s0 = _core.readReg(axp192_regs::bmu::STATUS);
352 if (s0 < 0 || s1 < 0) return 0;
353 return (static_cast<uint16_t>(s0) << 8) | static_cast<uint16_t>(s1);
354 }
355
361 {
362 return _core.getRegBit(axp192_regs::bmu::STATUS, 5);
363 }
364
370 {
372 }
373
379 {
380 return _charger.isCharging();
381 }
382
387 uint8_t getChipID()
388 {
389 int id = _core.readReg(axp192_regs::bmu::IC_TYPE);
390 if (id < 0) return 0;
391 return static_cast<uint8_t>(id);
392 }
393
400 void shutdown()
401 {
403 }
404
410 void reset()
411 {
413 }
414
415private:
419 const AXP192Core &core() const
420 {
421 return _core;
422 }
423
424 AXP192Core _core;
425 AXP192Adc _adc;
430 AXP192Gpio _gpio;
433 AXP192Channel _channel;
434};
435
438
441
442#endif
@license MIT License
@license MIT License
@license MIT License
@license MIT License
@license MIT License
AXP192 ADC Interface (template wrapper)
Definition AXP192Adc.hpp:57
AXP192 Power Output Channel Control.
AXP192 GPIO Interface.
bool isCharging() override
Check whether the battery is currently charging.
bool begin(SensorCommCustom::CustomCallback cb, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr)
Initialize the sensor using custom callback interface.
AXP192 PMIC Unified Interface.
AXP1xxCharger< axp192_regs > & charger()
Access the charger subsystem.
const PmicConfig & getConfig() const override
Get PMIC configuration structure.
AXP192Gpio & gpio()
Access the GPIO interface.
bool isVbusGood()
Check if VBUS power is present and good.
PmicLedBase & getLed() override
Access the LED interface.
uint16_t getStatus()
Read combined status registers (STATUS + MODE_CHGSTATUS)
PmicGpioBase * getGpio() override
Get GPIO interface.
void shutdown()
Shut down the AXP192 (soft power-off)
bool begin(SensorCommCustom::CustomCallback callback, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr)
Initialise the AXP192 with custom communication callbacks.
AXP192Core & core()
Access the core communication object.
AXP1xxLed< axp192_regs > & led()
Access the LED module.
PmicCapability::Capability getCapabilities() const override
Get supported capabilities bitmask.
PmicChargerBase * getCharger() override
Access the charger interface.
bool isBatteryConnect()
Check if a battery is connected.
PmicChannelBase * getChannel() override
Access the power channel control interface.
void reset()
Reset the AXP192.
AXP192Adc & adc()
Access the chip-specific ADC interface.
AXP1xxIrq< axp192_regs > & irq()
Access the IRQ subsystem.
bool isCharging()
Check if the battery is currently charging.
AXP1xxPwron< axp192_regs > & pwron()
Access the power-on control subsystem.
PmicAdcBase & getAdc() override
Access the ADC interface.
AXP1xxTimer< axp192_regs > & timer()
Access the countdown timer subsystem.
uint8_t getChipID()
Read the AXP192 chip identification register.
void end()
Deinitialize PMIC and release resources.
const char * getChipName() const override
Get the chip name string.
PmicPowerBase & getPower() override
Access the power management interface.
PmicIrqBase * getIrq() override
Get interrupt 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
bool setRegBit(uint8_t reg, uint8_t bit)
@ PmicSupportCharger
Battery charger support.
@ PmicSupportGpio
General purpose I/O 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 MODE_CHGSTATUS
static constexpr uint8_t STATUS
static constexpr uint8_t IC_TYPE
static constexpr uint8_t OFF_CTL