CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
ISleepController.h
Go to the documentation of this file.
1#pragma once
2
3#include "cdc_core/IService.h"
4#include <cstdint>
5
6namespace cdc::hal {
7
11enum class SleepMode : uint8_t {
12 NONE, // Not sleeping
13 LIGHT_SLEEP, // CPU paused, peripherals active, fast wake
14 DEEP_SLEEP // Full power down, causes reset on wake
15};
16
20enum class WakeupSource : uint8_t {
22 TIMER, // Timer wakeup
23 GPIO, // GPIO wakeup (keypad)
24 TOUCHPAD, // Touch wakeup
25 EXT0, // EXT0 wakeup
26 EXT1 // EXT1 wakeup
27};
28
32using SleepCallback = void (*)(void* context);
33
38 const char* moduleName; // For debugging/unregister
40 void* context;
41 uint8_t priority; // Lower = called first (0-255)
42};
43
55public:
56 virtual ~ISleepController() = default;
57
67 virtual void enterLightSleep() = 0;
68
82 [[noreturn]] virtual void enterDeepSleep() = 0;
83
87 virtual WakeupSource getWakeupSource() const = 0;
88
93 virtual bool wasInDeepSleep() const = 0;
94
98 virtual void clearDeepSleepFlag() = 0;
99
104 virtual void setLightSleepInterval(uint32_t seconds) = 0;
105
109 virtual uint32_t getLightSleepInterval() const = 0;
110
114 virtual void prepareGpioForSleep() = 0;
115
119 virtual void stabilizeGpioAfterWakeup() = 0;
120
121 // === Callback Registration ===
122
129 virtual bool registerPreSleepCallback(const SleepCallbackEntry& entry) = 0;
130
138 virtual bool registerWakeupCallback(const SleepCallbackEntry& entry) = 0;
139
144 virtual void unregisterCallbacks(const char* moduleName) = 0;
145};
146
147// Factory function
149
150} // namespace cdc::hal
virtual void unregisterCallbacks(const char *moduleName)=0
virtual bool registerWakeupCallback(const SleepCallbackEntry &entry)=0
virtual uint32_t getLightSleepInterval() const =0
virtual void clearDeepSleepFlag()=0
virtual bool wasInDeepSleep() const =0
virtual void enterDeepSleep()=0
virtual void enterLightSleep()=0
virtual void setLightSleepInterval(uint32_t seconds)=0
virtual bool registerPreSleepCallback(const SleepCallbackEntry &entry)=0
virtual void stabilizeGpioAfterWakeup()=0
virtual WakeupSource getWakeupSource() const =0
virtual ~ISleepController()=default
virtual void prepareGpioForSleep()=0
void(*)(void *context) SleepCallback
ISleepController * getSleepControllerInstance()
Returns the singleton sleep controller service instance.