blob: 6cb329e995b9008e6ec9770d184d867ecd73e16d (
plain)
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
|
#ifndef COUNTER_H
#define COUNTER_H
#include <libopencm3/stm32/timer.h>
#include "arch.h"
typedef uint32_t counter_value_t;
typedef uint32_t counter_overflow_t;
class Counter {
private:
Counter(const Counter ©);
public:
counter_value_t value;
volatile counter_overflow_t overflow;
Counter() : overflow(0) {}
inline void start() {
overflow = 0;
timer_set_counter(TIM2, 0);
timer_enable_counter(TIM2);
}
inline void stop() {
timer_disable_counter(TIM2);
value = timer_get_counter(TIM2);
}
};
extern Counter counter;
#endif
|