From 129b53ec9fc934a5cd66ab9ad25c81e058264321 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 12 Aug 2020 14:23:36 +0200 Subject: stm32f446re: Add counter --- include/arch/stm32f446re-nucleo/driver/counter.h | 35 ++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 include/arch/stm32f446re-nucleo/driver/counter.h (limited to 'include/arch/stm32f446re-nucleo/driver') 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 + +#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 -- cgit v1.2.3