SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
AXP517Bc12.cpp
Go to the documentation of this file.
1
30#include "../../../SensorBuildOpt.h"
31#if !SENSORLIB_EXCLUDE_PMIC_AXP517
32
33#include "AXP517Bc12.hpp"
34#include "AXP517Regs.hpp"
35
36
38 : _core(core)
39{
40}
41
43{
44 // REG 2BH: BC1.2 control3, bit6: auto dpdm detect enable
45 const uint8_t reg = axp517_regs::bc12::CTRL3;
46 const uint8_t bit = 6;
47 return enable ? _core.setRegBit(reg, bit) : _core.clrRegBit(reg, bit);
48}
49
51{
52 // REG 2BH: BC1.2 control3, bit7: force dpdm detection (write 1, self-clear)
53 const uint8_t reg = axp517_regs::bc12::CTRL3;
54 int cur = _core.readReg(reg);
55 if (cur < 0) return false;
56 cur |= 0x80;
57 return _core.writeReg(reg, (uint8_t)cur) >= 0;
58}
59
61{
62 const uint8_t reg = axp517_regs::bc12::CTRL0;
63 int cur = _core.readReg(reg);
64 if (cur < 0) return false;
65 return (cur & 0x04) != 0;
66}
67
69{
70 Result out{};
71 out.detecting = isDetecting();
73 if (v < 0) {
74 out.type = PortType::Unknown;
75 return out;
76 }
77
78 uint8_t code = (uint8_t)((v >> 5) & 0x07);
79 out.raw = code;
80 out.type = mapResult(code);
81 return out;
82}
83
84PmicBc12Base::PortType AXP517Bc12::mapResult(uint8_t code)
85{
86 switch (code) {
87 case 0b001: return PortType::SDP;
88 case 0b010: return PortType::CDP;
89 case 0b011: return PortType::DCP;
90 case 0b000: return PortType::None;
91 default: return PortType::Unknown;
92 }
93}
94
95#endif
@license MIT License
@license MIT License
Result readResult() override
Read the current BC1.2 detection result.
bool enableAutoDetect(bool enable) override
Enable or disable automatic BC1.2 detection.
AXP517Bc12(AXP517Core &core)
Construct an AXP517 BC1.2 driver.
bool isDetecting() override
Check if BC1.2 detection is currently in progress.
bool triggerDetect() override
Trigger a BC1.2 detection cycle.
AXP517 low-level core driver.
PortType
Common detected port/source type.
@ SDP
Standard Downstream Port (USB 500mA/900mA)
@ None
no valid detection / not connected
@ DCP
Dedicated Charging Port.
@ CDP
Charging Downstream Port.
bool clrRegBit(uint8_t reg, uint8_t bit)
int readReg(uint8_t reg) const
int writeReg(uint8_t reg, uint8_t val)
bool setRegBit(uint8_t reg, uint8_t bit)
bool detecting
detection in progress
static constexpr uint8_t CTRL3
BC1.2 control3.
static constexpr uint8_t CTRL0
BC1.2 control0.
static constexpr uint8_t BC_DETECT
BC_detect (status/result)