Added software timers

Accessory state machine framework functional
This commit is contained in:
2025-06-18 17:53:00 -05:00
parent aaa7f0dc29
commit 658cedfa3b
18 changed files with 614 additions and 580 deletions

36
source/soft_timer.h Normal file
View File

@@ -0,0 +1,36 @@
#ifndef SOFT_TIMER_H
#define SOFT_TIMER_H
#include <stdint.h>
#include <stdbool.h>
#define MAX_TIMERS 8
typedef enum {
TIMER_MODE_ONE_SHOT,
TIMER_MODE_PERIODIC
} timer_mode_t;
typedef void (*timer_callback_t)(void* context);
typedef struct {
uint32_t timeout_ticks;
uint32_t remaining_ticks;
bool active;
bool inUse;
bool fired;
timer_mode_t mode;
timer_callback_t callback;
void* callback_context;
} soft_timer_t;
void stimer_init(void);
int stimer_start(uint32_t timeout_ticks, timer_mode_t mode, timer_callback_t cb, void* ctx);
void stimer_stop(int timer_id);
void stimer_end(int timer_id);
bool stimer_fired(int timer_id);
bool stimer_clearFired(int timer_id);
void stimer_update(void); // Should be called from timer ISR
bool stimer_is_active(int timer_id);
#endif