(forgot this; split platform dependent/agnostic timer code)

partial-rewrite
Ben Blazak 2013-05-24 12:35:51 -07:00
parent d3e9291d49
commit 1197f4d682
1 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,40 @@
/* ----------------------------------------------------------------------------
* Copyright (c) 2013 Ben Blazak <benblazak.dev@gmail.com>
* Released under The MIT License (see "doc/licenses/MIT.md")
* Project located at <https://github.com/benblazak/ergodox-firmware>
* ------------------------------------------------------------------------- */
/** description
* Implements the device agnostic portion of the timer interface defined in
* ".../firmware/lib/timer.h"
*/
#include <stdint.h>
#include "../../../firmware/lib/data-types/list.h"
#include "./event-list.h"
// ----------------------------------------------------------------------------
#define DEFINE_TIMER(name) \
static uint16_t _##name##__counter; \
static list__list_t * _##name##__scheduled_events = &(list__list_t){}; \
\
uint16_t timer__get_##name(void) { \
return _##name##__counter; \
} \
uint8_t timer__schedule_##name(uint16_t name, void(*function)(void)) { \
return event_list__append( \
_##name##__scheduled_events, name, function ); \
} \
void timer___tick_##name(void) { \
_##name##__counter++; \
event_list__tick(_##name##__scheduled_events); \
}
// ----------------------------------------------------------------------------
DEFINE_TIMER(cycles);
// TODO: make a timer for keypresses?