summaryrefslogtreecommitdiff
path: root/include/arch/arduino-nano
diff options
context:
space:
mode:
Diffstat (limited to 'include/arch/arduino-nano')
-rw-r--r--include/arch/arduino-nano/driver/counter.h27
1 files changed, 27 insertions, 0 deletions
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 <avr/io.h>
+#include <avr/interrupt.h>
+
+class Counter {
+ private:
+ Counter(const Counter &copy);
+
+ 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;