SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
PmicAXP517.hpp
Go to the documentation of this file.
1
31#pragma once
32
33#include "../../../SensorBuildOpt.h"
34#if !SENSORLIB_EXCLUDE_PMIC_AXP517
35
36#include "../../PmicBase.hpp"
37#include "../../PmicAdcBase.hpp"
38#include "../../PmicIrqBase.hpp"
39#include "../../PmicPowerBase.hpp"
40
41#include "AXP517Core.hpp"
42#include "AXP517Adc.hpp"
43#include "AXP517Irq.hpp"
44#include "AXP517Charger.hpp"
45#include "AXP517Bc12.hpp"
46#include "AXP517Led.hpp"
47#include "AXP517Power.hpp"
48#include "AXP517Gpio.hpp"
49#include "AXP517Tcpc.hpp"
50#include "AXP517Pd.hpp"
52
53static constexpr uint8_t AXP517_SLAVE_ADDRESS = 0x34;
54
62class PmicAXP517 : public PmicBase
63{
64public:
66
70 PmicAXP517() : _core(), _adc(_core)
71 , _irq(_core), _charger(_core)
72 , _bc12(_core), _led(_core)
73 , _power(_core), _gpio(_core),
74 _bc12_2(_core), _tcpc(_core), _pd(_tcpc),
75 _pdNegotiator(_tcpc, _pd)
76 {}
77
78
79#if defined(ARDUINO)
88 bool begin(TwoWire &wire, uint8_t addr, int sda = -1, int scl = -1)
89 {
90 return _core.begin(wire, addr, sda, scl);
91 }
92
102 bool begin(TwoWire &wire, uint8_t addr, int sda, int scl, int irqPin)
103 {
104 if (!_core.begin(wire, addr, sda, scl)) return false;
105 return configurePdIrqPin(irqPin);
106 }
107#elif defined(ESP_PLATFORM)
108#if defined(SENSORLIB_USE_I2C_LEGACY)
109
118 bool begin(i2c_port_t port_num, uint8_t addr, int sda = -1, int scl = -1)
119 {
120 return _core.begin(port_num, addr, sda, scl);
121 }
122
132 bool begin(i2c_port_t port_num, uint8_t addr, int sda, int scl, int irqPin)
133 {
134 if (!_core.begin(port_num, addr, sda, scl)) return false;
135 return configurePdIrqPin(irqPin);
136 }
137#else
138
145 bool begin(i2c_master_bus_handle_t handle, uint8_t addr)
146 {
147 return _core.begin(handle, addr);
148 }
149
157 bool begin(i2c_master_bus_handle_t handle, uint8_t addr, int irqPin)
158 {
159 if (!_core.begin(handle, addr)) return false;
160 return configurePdIrqPin(irqPin);
161 }
162#endif
163#endif
173 uint8_t addr)
174 {
175 return _core.begin(callback, hal_cb, addr);
176 }
177
188 uint8_t addr,
189 int irqPin)
190 {
191 if (!_core.begin(callback, hal_cb, addr)) return false;
192 return configurePdIrqPin(irqPin);
193 }
194
199 void end()
200 {
201 }
202
212
216 const PmicConfig &getConfig() const override
217 {
218 static const PmicConfig config = {
219 .chipName = "AXP517",
220 .i2cAddress = 0x34,
221 .chipIdReg = 0x00,
222 .chipIdValue = 0,
223 .channelCount = 0,
232 // REG62H[6:0]: ICC = 64*N mA, N=0..80
233 .chargeCurrentMin = 0,
234 .chargeCurrentMax = 5120,
235 .chargeCurrentStep = 64,
236 .chargeCurrentSteps = 81,
237 };
238 return config;
239 }
240
243 {
244 return _adc;
245 }
246
249 {
250 return _irq;
251 }
252
255 {
256 return _power;
257 }
258
261 {
262 return &_charger;
263 }
264
266 PmicAdcBase &getAdc() override
267 {
268 return _adc;
269 }
270
273 {
274 return &_gpio;
275 }
276
278 PmicIrqBase *getIrq() override
279 {
280 return &_irq;
281 }
282
285 {
286 return _charger;
287 }
288
291 {
292 return _bc12;
293 }
294
296 PmicLedBase &getLed() override
297 {
298 return _led;
299 }
300
303 {
304 return _led;
305 }
306
309 {
310 return _power;
311 }
312
315 {
316 return _gpio;
317 }
318
321 {
322 return _bc12_2;
323 }
324
327 {
328 return _tcpc;
329 }
330
333 {
334 return _pd;
335 }
336
339 {
340 return _pdNegotiator;
341 }
342
345 {
346 return _pdNegotiator;
347 }
348
354 bool setPdIrqPin(int irqPin)
355 {
356 return _pdNegotiator.setIrqPin(irqPin);
357 }
358
364 bool initPdSink(int irqPin)
365 {
366 return _pdNegotiator.initSink(irqPin);
367 }
368
377 bool requestPd(uint16_t targetMv, uint32_t timeoutMs = 6000,
378 AXP517PdNegotiator::SourceCaps *outCaps = nullptr)
379 {
381 req.targetMv = targetMv;
382 return _pdNegotiator.negotiate(req, outCaps, timeoutMs);
383 }
384
393 bool enableModule(Module module, bool enable)
394 {
395 return _core.enableModule(module, enable);
396 }
397
405 {
406 return _core.isModuleEnabled(module);
407 }
408
413 {
414 return _core;
415 }
416
421 const char *getChipName() const override
422 {
423 return "AXP517";
424 }
425
426private:
428 const AXP517Core &core() const
429 {
430 return _core;
431 }
432
438 bool configurePdIrqPin(int irqPin)
439 {
440 if (irqPin < 0) return true;
441 return _pdNegotiator.setIrqPin(irqPin);
442 }
443
444private:
445 AXP517Core _core;
446 AXP517Adc _adc;
447 AXP517Irq _irq;
448 AXP517Charger _charger;
449 AXP517Bc12 _bc12;
450 AXP517Led _led;
451 AXP517Power _power;
452 AXP517Gpio _gpio;
453 AXP517Bc12 _bc12_2;
454 AXP517Tcpc _tcpc;
455 AXP517Pd _pd;
456 AXP517PdNegotiator _pdNegotiator;
457};
458
459#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
@license MIT License
@license MIT License
AXP517 ADC driver.
Definition AXP517Adc.hpp:44
AXP517 BC1.2 detection module.
AXP517 battery charger driver.
AXP517 low-level core driver.
bool isModuleEnabled(Module module)
Check if a module is enabled.
bool enableModule(Module module, bool enable)
Enable or disable a module.
Module
Functional module switches exposed by AXP517.
AXP517 GPIO module (REG 0x11).
AXP517 interrupt controller helper.
Definition AXP517Irq.hpp:45
AXP517 charge LED driver.
Definition AXP517Led.hpp:43
Minimal interrupt-driven USB-PD sink negotiation state machine.
bool negotiate(const RequestParams &req, SourceCaps *outCaps=nullptr, uint32_t timeoutMs=6000)
Run a blocking fixed PDO negotiation.
bool setIrqPin(int irqPin)
Configure the PMIC/TCPC IRQ pin used for PD negotiation.
bool initSink(int irqPin)
Initialize the TCPC sink and configure the PD receive path.
USB-PD message builder and FIFO helper for AXP517.
Definition AXP517Pd.hpp:45
AXP517 power-path driver.
AXP517 Type-C Port Controller helper.
bool begin(SensorCommCustom::CustomCallback cb, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr)
Initialize the sensor using custom callback interface.
High-level driver facade for the X-Powers AXP517 PMIC.
AXP517Power & power()
Access the AXP517 power-path driver.
PmicChargerBase * getCharger() override
Access the generic PMIC charger interface.
bool isModuleEnabled(Module module)
Check if a module is enabled.
AXP517Tcpc & tcpc()
Access the low-level AXP517 TCPC helper.
AXP517Adc & adc()
Access the AXP517 ADC driver.
PmicIrqBase * getIrq() override
Access the generic PMIC IRQ interface.
PmicLedBase & getLed() override
Access the generic PMIC LED interface.
const PmicConfig & getConfig() const override
Return static PMIC configuration metadata.
bool setPdIrqPin(int irqPin)
Configure the IRQ pin required for USB-PD negotiation.
bool begin(SensorCommCustom::CustomCallback callback, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr, int irqPin)
Initialize using custom callbacks and configure the PD IRQ pin.
AXP517Gpio & gpio()
Access the AXP517 GPIO driver.
void end()
Deinitialize the driver.
PmicAdcBase & getAdc() override
Access the generic PMIC ADC interface.
AXP517PdNegotiator & pdNegotiator()
Access the USB-PD sink negotiator.
bool requestPd(uint16_t targetMv, uint32_t timeoutMs=6000, AXP517PdNegotiator::SourceCaps *outCaps=nullptr)
Request a fixed USB-PD voltage from the attached source.
bool enableModule(Module module, bool enable)
Enable or disable a functional module.
AXP517Core & core()
Access the shared low-level AXP517 core.
AXP517Pd & pdProtocol()
Access the low-level USB-PD protocol helper.
AXP517PdNegotiator & pd()
Access the USB-PD sink negotiator.
PmicAXP517()
Construct an uninitialized AXP517 facade.
PmicCapability::Capability getCapabilities() const override
Return the capabilities supported by this driver.
AXP517Bc12 & bc12()
Access the AXP517 BC1.2 driver.
AXP517Charger & charger()
Access the AXP517 charger driver.
AXP517Led & led()
Access the AXP517 LED driver.
const char * getChipName() const override
Return the chip name string.
PmicPowerBase & getPower() override
Access the generic PMIC power-path interface.
PmicGpioBase * getGpio() override
Access the generic PMIC GPIO interface.
bool initPdSink(int irqPin)
Initialize the TCPC and PD sink receive path.
AXP517Bc12 & bc12_2()
Access the secondary BC1.2 driver alias.
bool begin(SensorCommCustom::CustomCallback callback, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr)
Initialization using a custom communication interface.
AXP517Irq & irq()
Access the AXP517 IRQ driver.
PMIC Base Abstract Class.
Definition PmicBase.hpp:130
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
@ 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.
@ PmicSupportLed
LED driver support.
@ PmicSupportTypeC
USB Type-C support.
@ PmicSupportBc12
BC1.2 (USB Battery Charging) support.
Requested sink operating point.
uint16_t targetMv
Optional fixed PDO voltage to select.
Parsed Source_Capabilities message.
PMIC static configuration data.
Definition PmicBase.hpp:108
const char * chipName
e.g. "AXP2101"
Definition PmicBase.hpp:109