/*
|| @author         Paul Stoffregen (paul at pjrc dot com)
|| @contribution   Brett Hagman <bhagman@wiring.org.co>
|| @url            http://wiring.org.co/
||
|| @description
|| | A Software PWM Library
|| |
|| | Simple timer abstractions.
|| #
||
|| @license Please see the accompanying LICENSE.txt file for this project.
||
|| @name Software PWM Library support
|| @type Library support
|| @target Atmel AVR 8 Bit
||
|| @version 1.0.1
||
*/

#include <avr/io.h>
#include <avr/interrupt.h>


#define SOFTPWM_TIMER_INTERRUPT    TIMER2_COMP_vect
#define SOFTPWM_TIMER_SET(val)     (TCNT0 = (val))
#define SOFTPWM_TIMER_INIT(ocr) ({\
  TIFR = (1 << TOV2);    /* clear interrupt flag */ \
  TCCR2 = (1 << CS21) | (1 << WGM21);   /* start timer (ck/8 prescalar) */ /* CTC mode */ \
  OCR0 = (ocr);          /* We want to have at least 30Hz or else it gets choppy */ \
  TIMSK = (1 << OCIE2); /* enable timer2 output compare match interrupt */ \
})
