COSA
An Object-Oriented Platform for Arduino Programming
InputCapture.hh
Go to the documentation of this file.
1 
21 #ifndef COSA_INPUT_CAPTURE_HH
22 #define COSA_INPUT_CAPTURE_HH
23 
24 #include "Cosa/Types.h"
25 
26 #if !defined(BOARD_ATTINY)
27 #include "Cosa/Interrupt.hh"
28 #include "Cosa/Power.hh"
29 
41 public:
45  } __attribute__((packed));
46 
53 
57  static void begin()
58  {
60  }
61 
65  static void end()
66  {
68  }
69 
75  {
76  // Check trigger mode setting
77  if (TCCR1B & _BV(ICES1))
78  return (ON_RISING_MODE);
79  return (ON_FALLING_MODE);
80  }
81 
87  {
88  // Set trigger on rising or falling on input capture pin
89  if (mode == ON_RISING_MODE)
90  TCCR1B |= _BV(ICES1);
91  else
92  TCCR1B &= ~_BV(ICES1);
93  }
94 
99  uint16_t count()
100  {
101  uint16_t res;
102  synchronized res = TCNT1;
103  return (res);
104  }
105 
113  virtual void on_interrupt(uint16_t arg = 0);
114 
120  virtual void enable();
121 
127  virtual void disable();
128 
134  virtual void clear();
135 
136 private:
137  static InputCapture* s_capture;
138  friend void TIMER1_CAPT_vect(void);
139 };
140 
141 #endif
142 #endif
InterruptMode mode() const
Definition: InputCapture.hh:74
static void timer1_disable()
Definition: Power.hh:87
virtual void disable()
static void end()
Definition: InputCapture.hh:65
void mode(InterruptMode mode)
Definition: InputCapture.hh:86
uint16_t count()
Definition: InputCapture.hh:99
virtual void on_interrupt(uint16_t arg=0)
static void begin()
Definition: InputCapture.hh:57
friend void TIMER1_CAPT_vect(void)
static void timer1_enable()
Definition: Power.hh:81
virtual void clear()
virtual void enable()
InputCapture(InterruptMode mode=ON_FALLING_MODE)