SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
AXP1xxLed.hpp
Go to the documentation of this file.
1
37#pragma once
38#include "../../PmicLedBase.hpp"
39#include "../../../platform/SensorCommWrapper.hpp"
40
41template<typename Regs>
42class AXP1xxLed : public PmicLedBase
43{
44public:
49 explicit AXP1xxLed(SensorCommWrapper &core) : _core(core) {}
50
56 bool setOutputType(OutputType type) override
57 {
58 (void)type;
59 return true;
60 }
61
74 bool setMode(Mode mode) override
75 {
76 switch (mode) {
77 case Mode::AUTO:
78 return _core.clrRegBit(Regs::pmu::OFF_CTL, 3);
79 case Mode::MANUAL:
80 return _core.setRegBit(Regs::pmu::OFF_CTL, 3);
81 case Mode::DISABLE:
82 return _core.setRegBit(Regs::pmu::OFF_CTL, 3) &&
83 _core.updateBits(Regs::pmu::OFF_CTL, 0x30, 0x00) >= 0;
84 default:
85 return false;
86 }
87 }
88
93 Mode getMode() override
94 {
95 if (!_core.getRegBit(Regs::pmu::OFF_CTL, 3)) {
96 return Mode::AUTO;
97 }
98 return Mode::MANUAL;
99 }
100
117 bool setManualState(ManualState state) override
118 {
119 if (!_core.setRegBit(Regs::pmu::OFF_CTL, 3)) {
120 return false;
121 }
122 uint8_t val;
123 switch (state) {
124 case ManualState::HiZ: val = 0x00; break;
125 case ManualState::BLINK_1HZ: val = 0x10; break;
126 case ManualState::BLINK_4HZ: val = 0x20; break;
127 case ManualState::LEVEL_LOW: val = 0x30; break;
128 case ManualState::LEVEL_HIGH: return false;
129 default: return false;
130 }
131 return _core.updateBits(Regs::pmu::OFF_CTL, 0x30, val) >= 0;
132 }
133
140 {
141 if (!_core.getRegBit(Regs::pmu::OFF_CTL, 3)) {
143 }
144 int val = _core.readReg(Regs::pmu::OFF_CTL);
145 if (val < 0) return ManualState::UNDEFINED;
146 uint8_t manualBits = val & 0x30;
147 switch (manualBits) {
148 case 0x00: return ManualState::HiZ;
149 case 0x10: return ManualState::BLINK_1HZ;
150 case 0x20: return ManualState::BLINK_4HZ;
151 case 0x30: return ManualState::LEVEL_LOW;
152 default: return ManualState::UNDEFINED;
153 }
154 }
155
156private:
157 SensorCommWrapper &_core;
158};
bool setOutputType(OutputType type) override
Set LED output type (no-op, always succeeds).
Definition AXP1xxLed.hpp:56
AXP1xxLed(SensorCommWrapper &core)
Construct LED control interface.
Definition AXP1xxLed.hpp:49
Mode getMode() override
Get the current LED operating mode.
Definition AXP1xxLed.hpp:93
ManualState getManualState() override
Get the current LED state in manual mode.
bool setMode(Mode mode) override
Set LED operating mode.
Definition AXP1xxLed.hpp:74
bool setManualState(ManualState state) override
Set the LED state in manual mode.
ManualState
Manual LED state (portable subset).
Mode
High-level LED operating mode (portable subset).
@ 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)