summaryrefslogtreecommitdiff
path: root/include/arch/stm32f446re-nucleo
diff options
context:
space:
mode:
Diffstat (limited to 'include/arch/stm32f446re-nucleo')
-rw-r--r--include/arch/stm32f446re-nucleo/driver/counter.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/include/arch/stm32f446re-nucleo/driver/counter.h b/include/arch/stm32f446re-nucleo/driver/counter.h
new file mode 100644
index 0000000..6cb329e
--- /dev/null
+++ b/include/arch/stm32f446re-nucleo/driver/counter.h
@@ -0,0 +1,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 &copy);
+
+ 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