diff options
Diffstat (limited to 'include/arch/stm32f746zg-nucleo/driver/counter.h')
-rw-r--r-- | include/arch/stm32f746zg-nucleo/driver/counter.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/include/arch/stm32f746zg-nucleo/driver/counter.h b/include/arch/stm32f746zg-nucleo/driver/counter.h new file mode 100644 index 0000000..ef993bd --- /dev/null +++ b/include/arch/stm32f746zg-nucleo/driver/counter.h @@ -0,0 +1,40 @@ +/* + * Copyright 2024 Birte Kristina Friesel + * + * SPDX-License-Identifier: BSD-2-Clause + */ +#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 |