diff options
author | Daniel Friesel <derf@finalrewind.org> | 2018-08-17 13:53:33 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2018-08-17 13:53:33 +0200 |
commit | 29414b3003eafb1fd82c14893fb64805dae818b8 (patch) | |
tree | e291437527c024a28f9b16cf82689cc43ff43332 /include | |
parent | f6972a43581b24281b322a6f8d2bf02dafbe4433 (diff) |
add timer-supported software i2c + arduino-nano timer
Diffstat (limited to 'include')
-rw-r--r-- | include/arch/arduino-nano/driver/timer.h | 28 |
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 ©); + + + 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; |