Files
TX/source/soft_timer.h
Brent Perteet 658cedfa3b Added software timers
Accessory state machine framework functional
2025-06-18 17:53:00 -05:00

37 lines
819 B
C

#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