From 29414b3003eafb1fd82c14893fb64805dae818b8 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 17 Aug 2018 13:53:33 +0200 Subject: add timer-supported software i2c + arduino-nano timer --- include/arch/arduino-nano/driver/timer.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 include/arch/arduino-nano/driver/timer.h (limited to 'include/arch/arduino-nano/driver') 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 +#include + +#define ON_TIMER_INTERRUPT ISR(TIMER0_COMPA_vect) + +class Timer { + private: + Timer(const Timer ©); + + + 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; -- cgit v1.2.3