diff options
author | Birte Kristina Friesel <birte.friesel@uos.de> | 2024-02-08 13:46:48 +0100 |
---|---|---|
committer | Birte Kristina Friesel <birte.friesel@uos.de> | 2024-02-08 13:46:48 +0100 |
commit | ec871ef8ae230bcb779c8535c3c4526817fd5d93 (patch) | |
tree | 558e731639f7ece070d7abd14c3c82afa11f9647 /include/arch/stm32f746zg-nucleo/driver/counter.h | |
parent | 18db600341bcf1c21e4282515d458b898639f349 (diff) |
Add preliminary STM32F746ZG-Nucleo support
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 |