COSA
An Object-Oriented Platform for Arduino Programming
InputCapture.cpp
Go to the documentation of this file.
1 
21 #include "Cosa/InputCapture.hh"
22 
23 #if !defined(BOARD_ATTINY)
24 
25 InputCapture* InputCapture::s_capture = NULL;
26 
28 {
29  // This is the active input capture
30  s_capture = this;
31 
32  // Use no prescale; timer runs at system clock frequency
33  TCCR1B = _BV(CS10);
34 
35  // Set trigger on rising or falling on input capture pin
36  if (mode == ON_RISING_MODE)
37  TCCR1B |= _BV(ICES1);
38  else
39  TCCR1B &= ~_BV(ICES1);
40 }
41 
42 void
44 {
45  UNUSED(arg);
46 }
47 
48 void
50 {
51  // Enable input capture interrupt
52  TIMSK1 |= _BV(ICIE1);
53 }
54 
55 void
57 {
58  // Disable input capture interrupt
59  TIMSK1 &= ~_BV(ICIE1);
60 }
61 
62 void
64 {
65  // Clear input capture interrupt flag if set
66  TIFR1 = _BV(ICF1);
67 }
68 
70 {
71  if (UNLIKELY(InputCapture::s_capture == NULL)) return;
72  InputCapture::s_capture->on_interrupt(ICR1);
73 }
74 #endif
#define NULL
Definition: Types.h:101
virtual void disable()
#define TIMSK1
Definition: ATtinyX5.hh:229
virtual void on_interrupt(uint16_t arg=0)
#define UNUSED(x)
Definition: ATmega328P.hh:31
friend void TIMER1_CAPT_vect(void)
virtual void clear()
virtual void enable()
#define UNLIKELY(x)
Definition: Types.h:153
ISR(TIMER1_CAPT_vect)
InputCapture(InterruptMode mode=ON_FALLING_MODE)