SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
axp517_bc12.ino
Go to the documentation of this file.
1
30#include <PmicDrv.hpp>
31
32#ifndef PMIC_SDA
33#define PMIC_SDA 3
34#endif
35
36#ifndef PMIC_SCL
37#define PMIC_SCL 2
38#endif
39
40#ifndef PMIC_IRQ
41#define PMIC_IRQ 21
42#endif
43
45
47{
48 switch (type) {
49 case PmicBc12Base::PortType::SDP: return "SDP (Standard Downstream Port)";
50 case PmicBc12Base::PortType::CDP: return "CDP (Charging Downstream Port)";
51 case PmicBc12Base::PortType::DCP: return "DCP (Dedicated Charging Port)";
52 case PmicBc12Base::PortType::Apple_1A: return "Apple 1A";
53 case PmicBc12Base::PortType::Apple_2A: return "Apple 2A";
54 case PmicBc12Base::PortType::Apple_2_4A: return "Apple 2.4A";
55 case PmicBc12Base::PortType::None: return "None";
56 case PmicBc12Base::PortType::Unknown: return "Unknown";
57 default: return "Invalid";
58 }
59}
60
61void setup()
62{
63 Serial.begin(115200);
64 delay(500);
65
66 Serial.println("\n=== AXP517 BC1.2 Example ===\n");
67
68 if (!pmic.begin(Wire, AXP517_SLAVE_ADDRESS, PMIC_SDA, PMIC_SCL)) {
69 Serial.println("Failed to init AXP517!");
70 while (1) delay(1000);
71 }
72
73 pmic.enableModule(PmicAXP517::Module::BC12, true);
74
75 // Enable auto detection
77 Serial.println("BC1.2 Auto Detect: Enabled");
78
79 Serial.println("\nConnect USB device to test...\n");
80}
81
82void loop()
83{
84 static uint32_t lastCheck = 0;
86
87 if (millis() - lastCheck > 500) {
88 lastCheck = millis();
89
90 auto result = pmic.bc12().readResult();
91
92 if (result.type != lastType) {
93 Serial.println("\n=== BC1.2 Result ===");
94 Serial.print("Status: ");
95 Serial.println(result.detecting ? "Detected" : "Not detected");
96 Serial.print("Port Type: ");
97 Serial.println(portTypeName(result.type));
98 Serial.print("Raw Code: 0x");
99 Serial.println(result.raw, HEX);
100 lastType = result.type;
101 }
102 }
103
104 delay(100);
105}
@license MIT License
PmicAXP517 pmic
const char * portTypeName(PmicBc12Base::PortType type)
#define PMIC_SDA
#define PMIC_SCL
void setup()
void loop()
Result readResult() override
Read the current BC1.2 detection result.
bool enableAutoDetect(bool enable) override
Enable or disable automatic BC1.2 detection.
High-level driver facade for the X-Powers AXP517 PMIC.
bool enableModule(Module module, bool enable)
Enable or disable a functional module.
AXP517Bc12 & bc12()
Access the AXP517 BC1.2 driver.
bool begin(SensorCommCustom::CustomCallback callback, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr)
Initialization using a custom communication interface.
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.