SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
AXP517Led.cpp
Go to the documentation of this file.
1
30#include "../../../SensorBuildOpt.h"
31#if !SENSORLIB_EXCLUDE_PMIC_AXP517
32
33#include "AXP517Led.hpp"
34#include "AXP517Regs.hpp"
35
36
37
38AXP517Led::AXP517Led(AXP517Core &core) : _core(core)
39{
40}
41
43{
44 switch (type) {
46 return _core.updateBits(axp517_regs::led::CHGLED_CFG, 0x80, 0x00) >= 0;
48 return _core.updateBits(axp517_regs::led::CHGLED_CFG, 0x80, 0x80) >= 0;
49 default:
50 break;
51 }
52 return false;
53}
54
56{
57 if (mode == Mode::DISABLE) {
58 return _core.clrRegBit(axp517_regs::ctrl::MODULE_EN1, 2); // Disable LED module
59 }
60 _core.setRegBit(axp517_regs::ctrl::MODULE_EN1, 2); // Ensure LED module is enabled
61 switch (mode) {
62 case Mode::AUTO:
63 return _core.updateBits(axp517_regs::led::CHGLED_CFG, 0x47, 0x00) >= 0;
64 case Mode::MANUAL:
65 return _core.updateBits(axp517_regs::led::CHGLED_CFG, 0x47, 0x06) >= 0;
66 case Mode::BREATH:
67 return _core.updateBits(axp517_regs::led::CHGLED_CFG, 0x47, 0x43) >= 0;
68 default:
69 return false;
70 }
71}
72
74{
76 return Mode::DISABLE; // LED module is disabled
77 }
78 int regVal = _core.readReg(axp517_regs::led::CHGLED_CFG);
79 if (regVal < 0) return Mode::VENDOR;
80 regVal &= 0x47;
81 switch (regVal) {
82 case 0x00: return Mode::AUTO;
83 case 0x06: return Mode::MANUAL;
84 case 0x43: return Mode::BREATH;
85 default: break;
86 }
87 return Mode::VENDOR;
88}
89
91{
92 uint8_t base = 0x06;
93 int val;
94 switch (state) {
95 case ManualState::HiZ: val = 0x00; break;
96 case ManualState::BLINK_1HZ: val = 0x08; break;
97 case ManualState::BLINK_4HZ: val = 0x10; break;
98 case ManualState::LEVEL_LOW: val = 0x18; break;
99 case ManualState::LEVEL_HIGH: val = 0x20; break;
100 default: return false;
101 }
102 return _core.updateBits(axp517_regs::led::CHGLED_CFG, 0x3F, base | val) >= 0;
103}
104
106{
107 int regVal = _core.readReg(axp517_regs::led::CHGLED_CFG);
108 if (regVal < 0) return ManualState::UNDEFINED;
109 uint8_t modeBits = regVal & 0x07;
110 if (modeBits != 0x06) {
112 }
113 uint8_t manualBits = (regVal >> 3) & 0x07;
114 switch (manualBits) {
115 case 0x00: return ManualState::HiZ;
116 case 0x01: return ManualState::BLINK_1HZ;
117 case 0x02: return ManualState::BLINK_4HZ;
118 case 0x03: return ManualState::LEVEL_LOW;
119 case 0x04: return ManualState::LEVEL_HIGH;
120 default: return ManualState::UNDEFINED;
121 }
122}
123
124#endif
@license MIT License
@license MIT License
AXP517 low-level core driver.
AXP517Led(AXP517Core &core)
Construct an AXP517 LED driver.
Definition AXP517Led.cpp:38
bool setOutputType(OutputType type) override
Set the LED output type.
Definition AXP517Led.cpp:42
bool setManualState(ManualState state) override
Set the LED manual state.
Definition AXP517Led.cpp:90
Mode getMode() override
Get LED operating mode.
Definition AXP517Led.cpp:73
ManualState getManualState() override
Get manual LED state (only meaningful when Mode::Manual is active).
bool setMode(Mode mode) override
Set the LED mode.
Definition AXP517Led.cpp:55
ManualState
Manual LED state (portable subset).
Mode
High-level LED operating mode (portable subset).
@ VENDOR
Unknown/implementation-specific mode.
@ BREATH
Breath/blink mode controlled by PMIC/hardware (if supported).
@ MANUAL
Manual control through registers.
@ AUTO
PMIC controls LED automatically (e.g.
@ DISABLE
LED is disabled (if supported).
bool clrRegBit(uint8_t reg, uint8_t bit)
bool getRegBit(uint8_t reg, uint8_t bit)
int readReg(uint8_t reg) const
int updateBits(uint8_t reg, uint8_t mask, uint8_t value_shifted)
bool setRegBit(uint8_t reg, uint8_t bit)
static constexpr uint8_t MODULE_EN1
Module enable control1.
static constexpr uint8_t CHGLED_CFG
CHGLED configure.