-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer8bit.h
64 lines (55 loc) · 1.45 KB
/
timer8bit.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* @file timer8bit.h
* @author Paul Nykiel
* @date 14.04.19
* @brief Definition of the library functions for the 8-bit timer as software interrupt.
* @ingroup HAL
*/
#ifndef AVR_HAL_TIMER8BIT_H
#define AVR_HAL_TIMER8BIT_H
#include <stdint.h>
/**
* Type of the callback used for signalling a timer overflow.
*/
typedef void (*timer_8bit_callback_t)(void);
/**
* Possible prescaler value for the 8 bit timer.
*
* For timer 0 the following options are invalid:
* * prescaler_32
* * prescaler_128
*
* For timer 2 the following options are invalid:
* * external_falling
* * external_rising
*/
typedef enum {
no_clock,
prescaler_1,
prescaler_8,
prescaler_32,
prescaler_64,
prescaler_128,
prescaler_256,
prescaler_1024,
external_falling,
external_rising
} timer_8bit_clock_option_t;
/**
* ID of the 8-bit timers.
*/
typedef enum { TIMER_ID_0 = 0, TIMER_ID_2 = 1 } timer_8bit_id_t;
/**
* Initialize, enable and start the timer.
* @param num id of the timer
* @param timer_clock_option the prescaler
* @param callback a functor that gets called on every overflow
*/
void timer_8bit_init(timer_8bit_id_t num, timer_8bit_clock_option_t timer_clock_option, timer_8bit_callback_t callback);
/**
* Read the current value of the timer
* @param num id of the timer
* @return a value in [0, 255] representing the value of the timer
*/
uint8_t timer_8bit_get_count(timer_8bit_id_t num);
#endif // AVR_HAL_TIMER8BIT_H