SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
AXP1xxTimer.hpp
Go to the documentation of this file.
1
40#pragma once
41
42#include "../../PmicTimerBase.hpp"
43#include "../../../platform/SensorCommWrapper.hpp"
44
45template<typename Regs>
47{
48public:
49 explicit AXP1xxTimer(SensorCommWrapper &core) : _core(core) {}
50
61 bool setTimer(uint8_t minutes) override
62 {
63 if (minutes > 127) return false;
64 // Write timer value to bits[6:0]; also clear timeout flag (bit 7 = W1C)
65 uint8_t val = minutes | 0x80;
66 return _core.writeReg(Regs::timer::TIMER_CTL, val) >= 0;
67 }
68
73 uint8_t getTimer() const override
74 {
75 int val = _core.readReg(Regs::timer::TIMER_CTL);
76 if (val < 0) return 0;
77 return static_cast<uint8_t>(val & 0x7F);
78 }
79
85 bool isTimedOut() const override
86 {
87 return _core.getRegBit(Regs::timer::TIMER_CTL, 7);
88 }
89
95 bool clearTimeout() override
96 {
97 return _core.setRegBit(Regs::timer::TIMER_CTL, 7);
98 }
99
100private:
101 SensorCommWrapper &_core;
102};
bool isTimedOut() const override
Check whether the timer has expired (bit 7 of REG8AH).
bool clearTimeout() override
Clear the timeout status flag (write 1 to bit 7 of REG8AH).
bool setTimer(uint8_t minutes) override
Start the timer with the given duration, or stop it.
AXP1xxTimer(SensorCommWrapper &core)
uint8_t getTimer() const override
Read the current timer value from REG8AH bits[6:0].
bool getRegBit(uint8_t reg, uint8_t bit)
int readReg(uint8_t reg) const
int writeReg(uint8_t reg, uint8_t val)
bool setRegBit(uint8_t reg, uint8_t bit)