SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
AXP1xxPwron.hpp
Go to the documentation of this file.
1
40#pragma once
41#include "../../PmicButtonBase.hpp"
42#include "../../../platform/SensorCommWrapper.hpp"
43
44template<typename Regs>
46{
47public:
52 explicit AXP1xxPwron(SensorCommWrapper &core) : _core(core) {}
53
64 bool setOnDurationMs(uint16_t ms) override
65 {
66 uint8_t idx = (ms >= 2000) ? 3 :
67 (ms >= 1000) ? 2 :
68 (ms >= 512) ? 1 : 0;
69 return _core.updateBits(Regs::pmu::POK_SET, 0x03, idx) >= 0;
70 }
71
78 bool getOnDurationMs(uint16_t &ms) const override
79 {
80 const uint16_t kOnLevelMs[] = {128, 512, 1000, 2000};
81 int v = _core.readReg(Regs::pmu::POK_SET);
82 if (v < 0) return false;
83 ms = kOnLevelMs[static_cast<uint8_t>(v) & 0x03];
84 return true;
85 }
86
97 bool setOffDurationMs(uint16_t ms) override
98 {
99 uint8_t idx = (ms >= 10000) ? 3 :
100 (ms >= 8000) ? 2 :
101 (ms >= 6000) ? 1 : 0;
102 return _core.updateBits(Regs::pmu::POK_SET, 0x0C, idx << 2) >= 0;
103 }
104
111 bool getOffDurationMs(uint16_t &ms) const override
112 {
113 const uint16_t kOffLevelMs[] = {4000, 6000, 8000, 10000};
114 int v = _core.readReg(Regs::pmu::POK_SET);
115 if (v < 0) return false;
116 ms = kOffLevelMs[(static_cast<uint8_t>(v) >> 2) & 0x03];
117 return true;
118 }
119
130 bool setIrqDurationMs(uint16_t ms) override
131 {
132 uint8_t idx = (ms >= 2500) ? 3 :
133 (ms >= 2000) ? 2 :
134 (ms >= 1500) ? 1 : 0;
135 return _core.updateBits(Regs::pmu::POK_SET, 0x30, idx << 4) >= 0;
136 }
137
144 bool getIrqDurationMs(uint16_t &ms) const override
145 {
146 const uint16_t kIrqLevelMs[] = {1000, 1500, 2000, 2500};
147 int v = _core.readReg(Regs::pmu::POK_SET);
148 if (v < 0) return false;
149 ms = kIrqLevelMs[(static_cast<uint8_t>(v) >> 4) & 0x03];
150 return true;
151 }
152
153private:
154 SensorCommWrapper &_core;
155};
bool getOffDurationMs(uint16_t &ms) const override
Get the power-off press duration threshold.
bool setIrqDurationMs(uint16_t ms) override
Set the interrupt-trigger press duration threshold.
bool setOnDurationMs(uint16_t ms) override
Set the power-on press duration threshold.
bool getOnDurationMs(uint16_t &ms) const override
Get the power-on press duration threshold.
bool setOffDurationMs(uint16_t ms) override
Set the power-off press duration threshold.
AXP1xxPwron(SensorCommWrapper &core)
Construct power-on key control interface.
bool getIrqDurationMs(uint16_t &ms) const override
Get the interrupt-trigger press duration threshold.
int readReg(uint8_t reg) const
int updateBits(uint8_t reg, uint8_t mask, uint8_t value_shifted)