@ -21,6 +21,43 @@
# define DIRECT_WRITE_LOW(base, mask) ((*((base)+2)) &= ~(mask))
# define DIRECT_WRITE_LOW(base, mask) ((*((base)+2)) &= ~(mask))
# define DIRECT_WRITE_HIGH(base, mask) ((*((base)+2)) |= (mask))
# define DIRECT_WRITE_HIGH(base, mask) ((*((base)+2)) |= (mask))
# if defined (__AVR_ATtiny85__)
# define CLEARINTERRUPT GIFR |= (1 << INTF0)
# include "UserTimer.h" //ATtiny-support based on TinyCore1 Arduino-core for ATtiny at http://github.com/Coding-Badly/TinyCore1.git
__attribute__ ( ( always_inline ) ) static inline void UserTimer_Init ( void )
{
UserTimer_SetToPowerup ( ) ;
UserTimer_SetWaveformGenerationMode ( UserTimer_ ( CTC_OCR ) ) ;
}
__attribute__ ( ( always_inline ) ) static inline void UserTimer_Run ( short skipTicks )
{
UserTimer_SetCount ( 0 ) ;
UserTimer_SetOutputCompareMatchAndClear ( skipTicks ) ;
UserTimer_ClockSelect ( UserTimer_ ( Prescale_Value_64 ) ) ;
}
# define UserTimer_Stop() UserTimer_ClockSelect(UserTimer_(Stopped))
# elif defined (__AVR_ATmega328P__)
# define CLEARINTERRUPT EIFR |= (1 << INTF0)
# define USERTIMER_COMPA_vect TIMER1_COMPA_vect
__attribute__ ( ( always_inline ) ) static inline void UserTimer_Init ( void )
{
TCCR1A = 0 ;
TCCR1B = 0 ;
// enable timer compare interrupt
TIMSK1 | = ( 1 < < OCIE1A ) ;
}
__attribute__ ( ( always_inline ) ) static inline void UserTimer_Run ( short skipTicks )
{
TCNT1 = 0 ;
OCR1A = skipTicks ;
// turn on CTC mode with 64 prescaler
TCCR1B = ( 1 < < WGM12 ) | ( 1 < < CS11 ) | ( 1 < < CS10 ) ;
}
# define UserTimer_Stop() TCCR1B = 0
# endif
# elif defined(__MK20DX128__) || defined(__MK20DX256__)
# elif defined(__MK20DX128__) || defined(__MK20DX256__)
# define PIN_TO_BASEREG(pin) (portOutputRegister(pin))
# define PIN_TO_BASEREG(pin) (portOutputRegister(pin))
# define PIN_TO_BITMASK(pin) (1)
# define PIN_TO_BITMASK(pin) (1)
@ -110,7 +147,7 @@ public:
inline void attachInterrupt ( void ( * handler ) ( ) , int mode )
inline void attachInterrupt ( void ( * handler ) ( ) , int mode )
{
{
EIFR | = ( 1 < < INTF0 ) ; // clear any pending interrupt (we want to call the handler only for interrupts happending after it is attached)
CLEARINTERRUPT ; // clear any pending interrupt (we want to call the handler only for interrupts happending after it is attached)
: : attachInterrupt ( interruptNumber_ , handler , mode ) ;
: : attachInterrupt ( interruptNumber_ , handler , mode ) ;
}
}
inline void detachInterrupt ( ) { : : detachInterrupt ( interruptNumber_ ) ; }
inline void detachInterrupt ( ) { : : detachInterrupt ( interruptNumber_ ) ; }