From ec15c42ab8f5919d62d563798c62e12bed9c843e Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 15 Nov 2018 15:37:32 +0100 Subject: arduino-nano: Add counter driver. Conflicts with timer_s=1 / loop=1 --- include/arch/arduino-nano/driver/counter.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 include/arch/arduino-nano/driver/counter.h (limited to 'include/arch') diff --git a/include/arch/arduino-nano/driver/counter.h b/include/arch/arduino-nano/driver/counter.h new file mode 100644 index 0000000..d387a35 --- /dev/null +++ b/include/arch/arduino-nano/driver/counter.h @@ -0,0 +1,27 @@ +#include +#include + +class Counter { + private: + Counter(const Counter ©); + + public: + uint8_t overflowed; + + Counter() : overflowed(0) {} + + inline void start() { + overflowed = 0; + TCNT1 = 0; + TCCR1A = 0; + TCCR1B = _BV(CS10); + TIMSK1 = _BV(TOIE1); + } + + inline uint16_t stop() { + TCCR1B = 0; + return TCNT1; + } +}; + +extern Counter counter; -- cgit v1.2.3