41 #include <avr/interrupt.h> 58 #error "F_CPU not defined for timer.h" 76 template <u
int16_t prescaler>
95 static_assert(prescaler == 1 || prescaler == 8 || prescaler == 64 ||
96 prescaler == 256 || prescaler == 1024,
97 "Invalid prescaler (1, 8, 64, 256, 1024)");
98 return prescaler == 1 ? (1 << CS10) :
99 prescaler == 8 ? (1 << CS11) :
100 prescaler == 64 ? (1 << CS11) | (1 << CS10) :
101 prescaler == 256 ? (1 << CS12) :
102 prescaler == 1024 ? (1 << CS12) | (1 << CS10) : 0;
120 template <u
int16_t us>
123 return ((uint64_t)F_CPU * us) / (1000000UL * prescaler);
142 CLASS_IRQ(InputCaptureInterrupt, TIMER1_CAPT_vect);
145 virtual void _pulseWidthReceived(uint16_t) = 0;
149 void TimerInputCaptureBase::InputCaptureInterrupt()
151 s_baseInstance->_pulseWidthReceived(TCNT1);
184 template <u
int16_t prescaler,
class TObserver>
212 s_baseInstance =
this;
215 void _pulseWidthReceived(uint16_t pulseWidth)
217 s_instance.pulseWidthReceived(pulseWidth);
221 template <u
int16_t prescaler,
class TObserver>
static TimerInputCapture & instance()
Returns the Avr::TimerInputCapture instance.
Definition: timer.h:194
static constexpr uint8_t clockSelect()
Calculates the clock select value for the given prescaler.
Definition: timer.h:93
static constexpr uint16_t usToTicks()
Converts us to ticks for the given CPU frequency and prescaler.
Definition: timer.h:121
void bitFlip(T &value, uint8_t bit)
Flips the bit in the given value.
Definition: utils.h:79
#define TICIE1
Timer 1 Input Capture Interrupt Enable.
Definition: timer.h:54
Bit manipulation utilities.
Compile time calculation of clock select and conversion of time (in us) to system clock ticks given t...
Definition: timer.h:77
#define TIMSK1
Timer/Counter Interrupt Mask Register.
Definition: timer.h:50
Namespace containing all symbols of the AVR C++ utilities library.
Definition: adc.h:48
void bitSet(T &value, uint8_t bit)
Sets the bit in the given value to 1.
Definition: utils.h:54
#define CLASS_IRQ(name, vector)
Creates an interrupt service routine as static member function of a class.
Definition: interrupt.h:65
Utilities for interrupt service routines.