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/timer.h28
1 files changed, 28 insertions, 0 deletions
diff --git a/include/arch/arduino-nano/driver/timer.h b/include/arch/arduino-nano/driver/timer.h
new file mode 100644
index 0000000..267cb1d
--- /dev/null
+++ b/include/arch/arduino-nano/driver/timer.h
@@ -0,0 +1,28 @@
+#include <avr/io.h>
+#include <avr/interrupt.h>
+
+#define ON_TIMER_INTERRUPT ISR(TIMER0_COMPA_vect)
+
+class Timer {
+ private:
+ Timer(const Timer &copy);
+
+
+ public:
+ Timer() {}
+
+ inline void setup(unsigned char const frequency) {
+ OCR0A = frequency ? 255 / frequency : 1;
+ TCCR0A = _BV(WGM01);
+ }
+ inline void start(unsigned char const interrupt) {
+ TCNT0 = 0;
+ TCCR0B = _BV(CS01) | _BV(CS00);
+ if (interrupt) {
+ TIMSK0 = _BV(OCIE0A);
+ }
+ }
+ inline void stop() { TCCR0B = 0; TIMSK0 = 0; }
+};
+
+extern Timer timer;