SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
AXP2101Watchdog.cpp
Go to the documentation of this file.
1
31#include "../../../SensorBuildOpt.h"
32#if !SENSORLIB_EXCLUDE_PMIC_AXP2101
33
34#include "AXP2101Watchdog.hpp"
35#include "AXP2101Regs.hpp"
36
37
39{
40}
41
43{
44 return _core.enableModule(AXP2101Core::Module::WATCHDOG, enable);
45}
46
51
53{
54 uint8_t val;
55 switch (timeout_s) {
56 case 1: val = 0; break;
57 case 2: val = 1; break;
58 case 4: val = 2; break;
59 case 8: val = 3; break;
60 case 16: val = 4; break;
61 case 32: val = 5; break;
62 case 64: val = 6; break;
63 case 128: val = 7; break;
64 default: return false;
65 }
66 return _core.updateBits(axp2101_regs::ctrl::WDT_CTRL, 0x07, val) >= 0;
67}
68
70{
72 if (val < 0) return 0;
73 const uint16_t timeouts[] = {1, 2, 4, 8, 16, 32, 64, 128};
74 uint8_t idx = val & 0x07;
75 if (idx >= 8) return 0;
76 return timeouts[idx];
77}
78
83
84#endif
@license MIT License
Core I2C communication layer for the AXP2101 PMIC.
bool isModuleEnabled(Module module)
Check whether an internal module is enabled.
bool enableModule(Module module, bool enable)
Enable or disable an internal functional module.
@ WATCHDOG
Watchdog timer (REG 0x18 bit 0)
bool enableWatchdog(bool enable) override
Enable or disable the watchdog timer.
bool setWatchdogTimeout(uint16_t timeout_s) override
Set the watchdog timeout duration.
bool isWatchdogEnabled() const override
Check whether the watchdog timer is enabled.
bool resetWatchdog() override
Reset (pet) the watchdog timer.
uint16_t getWatchdogTimeout() const override
Get the current watchdog timeout setting.
AXP2101Watchdog(AXP2101Core &core)
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 WDT_CTRL