summaryrefslogtreecommitdiff
path: root/include/arch/arduino-nano
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-11-15 15:37:32 +0100
committerDaniel Friesel <derf@finalrewind.org>2018-11-15 15:37:32 +0100
commitec15c42ab8f5919d62d563798c62e12bed9c843e (patch)
tree2804cf0b51d0d805cd77a1504ad7a42126e3cf09 /include/arch/arduino-nano
parentb2554d7bb3bbd1faf42737731f749b8a434e0db3 (diff)
arduino-nano: Add counter driver. Conflicts with timer_s=1 / loop=1
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;