SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
AXP2101Led.cpp
Go to the documentation of this file.
1
31#include "../../../SensorBuildOpt.h"
32#if !SENSORLIB_EXCLUDE_PMIC_AXP2101
33
34#include "AXP2101Led.hpp"
35#include "AXP2101Regs.hpp"
36
37
39{
40}
41
42// Bit 6 (0x40) is RO per datasheet — CHGLED is always open-drain.
44{
45 (void)type;
46 return false;
47}
48
50{
51 switch (mode) {
52 case Mode::AUTO:
53 return _core.updateBits(axp2101_regs::chg::CHGLED_CFG, 0x06, 0x00) >= 0;
54 case Mode::MANUAL:
55 return _core.updateBits(axp2101_regs::chg::CHGLED_CFG, 0x06, 0x04) >= 0;
56 case Mode::DISABLE:
57 return _core.updateBits(axp2101_regs::chg::CHGLED_CFG, 0x01, 0x00) >= 0;
58 default:
59 return false;
60 }
61}
62
64{
66 if (val < 0) return Mode::VENDOR;
67 if ((val & 0x01) == 0) return Mode::DISABLE;
68 switch (val & 0x06) {
69 case 0x04: return Mode::MANUAL;
70 default: return Mode::AUTO;
71 }
72}
73
74// Datasheet REG69H bits 5:4:
75// 00 = HiZ 01 = 1 Hz blink 10 = 4 Hz blink 11 = drive low
76// On open-drain: LEVEL_HIGH and HiZ are both HiZ (LED off),
77// LEVEL_LOW = drive low (LED on).
78// Readback aliases 0x00 → LEVEL_HIGH so toggle patterns work.
80{
81 uint8_t code;
82 switch (state) {
84 case ManualState::HiZ: code = 0x00; break;
85 case ManualState::BLINK_1HZ: code = 0x01; break;
86 case ManualState::BLINK_4HZ: code = 0x02; break;
87 case ManualState::LEVEL_LOW: code = 0x03; break;
88 default: return false;
89 }
90 if (_core.updateBits(axp2101_regs::chg::CHGLED_CFG, 0x06, 0x04) < 0) {
91 return false;
92 }
93 return _core.updateBits(axp2101_regs::chg::CHGLED_CFG, 0x30, code << 4) >= 0;
94}
95
97{
99 if (val < 0) return ManualState::UNDEFINED;
100 if ((val & 0x06) != 0x04) {
102 }
103 uint8_t code = (val >> 4) & 0x03;
104 switch (code) {
105 case 0x00: return ManualState::LEVEL_HIGH;
106 case 0x01: return ManualState::BLINK_1HZ;
107 case 0x02: return ManualState::BLINK_4HZ;
108 case 0x03: return ManualState::LEVEL_LOW;
109 default: return ManualState::UNDEFINED;
110 }
111}
112
113#endif
@license MIT License
Core I2C communication layer for the AXP2101 PMIC.
bool setOutputType(OutputType type) override
Set the LED output driver type.
bool setManualState(ManualState state) override
For manual mode, set the LED output state.
Mode getMode() override
Get the current LED operating mode.
AXP2101Led(AXP2101Core &core)
bool setMode(Mode mode) override
Set the LED operating mode.
ManualState getManualState() override
Get the current manual LED state.
ManualState
Manual LED state (portable subset).
Mode
High-level LED operating mode (portable subset).
@ VENDOR
Unknown/implementation-specific mode.
@ MANUAL
Manual control through registers.
@ AUTO
PMIC controls LED automatically (e.g.
@ DISABLE
LED is disabled (if supported).
int readReg(uint8_t reg) const
int updateBits(uint8_t reg, uint8_t mask, uint8_t value_shifted)
static constexpr uint8_t CHGLED_CFG