FastArduino v1.10
C++ library to build fast but small Arduino/AVR projects
|
General API to handle an AVR timer. More...
#include <fastarduino/timer.h>
Public Types | |
using | TYPE = typename TRAIT::TYPE |
The type of this timer's counter (either uint8_t or uint16_t ). More... | |
using | CALCULATOR = Calculator< NTIMER > |
The Calculator type for this Timer. More... | |
using | PRESCALER = typename PRESCALERS_TRAIT::TYPE |
The enum type listing all available precaler values for this timer. More... | |
Public Member Functions | |
Timer (TimerMode timer_mode, PRESCALER prescaler, TimerInterrupt interrupts=TimerInterrupt(0)) | |
Construct a new Timer handler and initialize its mode. More... | |
void | set_interrupts (TimerInterrupt interrupts=TimerInterrupt(0)) |
Set the list of interrupts that must be triggered by this timer. More... | |
void | enable_interrupts (TimerInterrupt interrupts) |
Add new interrupts to be enabled to the current list of interrupts that must be triggered by this timer. More... | |
void | disable_interrupts (TimerInterrupt interrupts) |
Remove interrupts from the current list of enabled interrupts triggered by this timer. More... | |
bool | are_interrupts_enabled (TimerInterrupt interrupts) const |
Test if interrupts are currently enabled for this timers. More... | |
void | set_input_capture (TimerInputCapture input_capture) |
Set the input capture mode for this timer. More... | |
TimerInputCapture | input_capture () const |
Return the current TimerInputCapture used by this timer. More... | |
void | set_capture_noise_canceller (bool cancel_noise) |
Set or clear the noise canceller for input capture on this timer. More... | |
bool | has_capture_noise_canceller () const |
Tell whether noise canceller for this timer's input capture is active or not. More... | |
void | set_timer_mode (TimerMode timer_mode) |
Change timer mode. More... | |
TimerMode | get_timer_mode () const |
Get current time mode. More... | |
void | set_prescaler (PRESCALER prescaler) |
Change prescaler for this timer. More... | |
void | begin (TYPE max=0) |
Start this timer in the currently selected mode, with the provided prescaler value and max value. More... | |
void | begin_ (TYPE max=0) |
Start this timer in the currently selected mode, with the provided prescaler value and max value. More... | |
void | reset (TYPE ticks=0) |
Reset current counter to ticks . More... | |
void | reset_ (TYPE ticks=0) |
Reset current counter to ticks . More... | |
TYPE | ticks () |
Return the current counter value for this timer. More... | |
TYPE | ticks_ () |
Return the current counter value for this timer. More... | |
void | suspend_interrupts () |
Temporarily suspend this timer: the timer does not generate any interrupt any longer. More... | |
void | suspend_interrupts_ () |
Temporarily suspend this timer: the timer does not generate any interrupt any longer. More... | |
void | resume_interrupts () |
Resume this timer if it was previously suspended: the timer's counter is reset and the timer starts generating interrupts again. More... | |
void | resume_interrupts_ () |
Resume this timer if it was previously suspended: the timer's counter is reset and the timer starts generating interrupts again. More... | |
bool | is_interrupt_suspended () |
Check if this timer interrupts are currently suspended, i.e. More... | |
void | suspend_timer () |
Suspend this timer, ie stop this timer counting (ticks() will not change then). More... | |
void | suspend_timer_ () |
Suspend this timer, ie stop this timer counting (ticks() will not change then). More... | |
void | resume_timer () |
Resume this timer, ie restart counting (ticks() will start changing again). More... | |
void | resume_timer_ () |
Resume this timer, ie restart counting (ticks() will start changing again). More... | |
void | end () |
Completely stop this timer: timer interrupts are disabled and counter is stopped. More... | |
void | end_ () |
Completely stop this timer: timer interrupts are disabled and counter is stopped. More... | |
template<uint8_t COM> | |
void | set_output_mode (TimerOutputMode mode) |
Change the output mode for this timer; this enables connection between this timer to one of its associated digital output pins. More... | |
template<uint8_t COM> | |
void | set_max (TYPE max) |
Change the maximum value for this timer, in relation to one of its associated digital output pins. More... | |
Static Public Attributes | |
static constexpr const board::Timer | NTIMER = NTIMER_ |
The Board timer used by this Timer. More... | |
static constexpr const TYPE | TIMER_MAX = TRAIT::MAX_COUNTER - 1 |
The maximum value that can be set to this timer's counter. More... | |
static constexpr const TYPE | PWM_MAX = TRAIT::MAX_PWM |
The maximum value that can be set to this timer's counter in PWM mode. More... | |
static constexpr const board::DigitalPin | ICP_PIN = TRAIT::ICP_PIN |
The pin that is used for Input Capture feature, if supported by this timer, or board::DigitalPin::NONE if not. More... | |
General API to handle an AVR timer.
Note that many timer usages will require ISR registration with one of the macros defined in this header file.
NTIMER_ | the AVR timer to use for this Timer |
using timer::Timer< NTIMER_ >::TYPE = typename TRAIT::TYPE |
using timer::Timer< NTIMER_ >::CALCULATOR = Calculator<NTIMER> |
The Calculator type for this Timer.
using timer::Timer< NTIMER_ >::PRESCALER = typename PRESCALERS_TRAIT::TYPE |
|
inline |
Construct a new Timer handler and initialize its mode.
Note this constructor does not start the timer.
timer_mode | the mode to initalize this timer with |
prescaler | the prescale enum value to use for this timer |
interrupts | default interrupts that will be used when timer is started; note that some interrupts are not supported by all timers, if used here, they will silently be ignored. |
|
inline |
Set the list of interrupts that must be triggered by this timer.
If you do not want any interrupt triggered, then call this method with no argument. To select several interrupts, just "or" them together:
interrupts | interrupts that will be used when timer is started; note that some interrupts are not supported by all timers, if used here, they will silently be ignored. |
|
inline |
Add new interrupts to be enabled to the current list of interrupts that must be triggered by this timer.
To select several interrupts, just "or" them together:
interrupts | additional interrupts that will be used when timer is started; note that some interrupts are not supported by all timers, if used here, they will silently be ignored. |
|
inline |
Remove interrupts from the current list of enabled interrupts triggered by this timer.
To select several interrupts to be disabled, just "or" them together:
interrupts | interrupts that will not be used when timer is started |
|
inline |
Test if interrupts are currently enabled for this timers.
To select several interrupts to be tested, just "or" them together:
interrupts | interrupts to be checked |
|
inline |
Set the input capture mode for this timer.
Input Capture will work only if set_interrupts()
is called with TimerInterrupt::INPUT_CAPTURE
. Note that some timers do not support input capture; in this situation, using this method will generate a compiler error.
input_capture | new input capture mode to use |
|
inline |
|
inline |
Set or clear the noise canceller for input capture on this timer.
Note that some timers do not support input capture; in this situation, using this method will generate a compiler error.
cancel_noise | if true , set noise canceller for this timer's input capture; if false , clear noise canceller. |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Start this timer in the currently selected mode, with the provided prescaler
value and max
value.
This method enables timer interrupts (Compare Match),hence ISR registration is required. Note that this method is synchronized, i.e. it disables interrupts during its call and restores interrupts on return. If you do not need synchronization, then you should better use begin_()
instead.
max | the maximum value to use for this timer's counter |
|
inline |
Start this timer in the currently selected mode, with the provided prescaler
value and max
value.
This method enables timer interrupts (Compare Match),hence ISR registration is required. Note that this method is not synchronized, hence you should ensure it is called only while interrupts are not enabled. If you need synchronization, then you should better use begin()
instead.
max | the maximum value to use for this timer's counter |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Temporarily suspend this timer: the timer does not generate any interrupt any longer.
Note that this method is synchronized, i.e. it disables AVR interrupts during its call and restores interrupts on return. If you do not need synchronization, then you should better use suspend_interrupts_()
instead.
|
inline |
Temporarily suspend this timer: the timer does not generate any interrupt any longer.
Note that this method is not synchronized, hence you should ensure it is called only while AVR interrupts are not enabled. If you need synchronization, then you should better use suspend_interrupts()
instead.
|
inline |
Resume this timer if it was previously suspended: the timer's counter is reset and the timer starts generating interrupts again.
Note that this method is synchronized, i.e. it disables AVR interrupts during its call and restores interrupts on return. If you do not need synchronization, then you should better use resume_interrupts_()
instead.
|
inline |
Resume this timer if it was previously suspended: the timer's counter is reset and the timer starts generating interrupts again.
Note that this method is not synchronized, hence you should ensure it is called only while AVR interrupts are not enabled. If you need synchronization, then you should better use resume_interrupts()
instead.
|
inline |
|
inline |
Suspend this timer, ie stop this timer counting (ticks()
will not change then).
Note that this method is synchronized, i.e. it disables AVR interrupts during its call and restores interrupts on return. If you do not need synchronization, then you should better use suspend_timer_()
instead.
|
inline |
Suspend this timer, ie stop this timer counting (ticks()
will not change then).
Note that this method is not synchronized, hence you should ensure it is called only while AVR interrupts are not enabled. If you need synchronization, then you should better use suspend_timer()
instead.
|
inline |
Resume this timer, ie restart counting (ticks()
will start changing again).
Note that this method is synchronized, i.e. it disables AVR interrupts during its call and restores interrupts on return. If you do not need synchronization, then you should better use resume_timer_()
instead.
|
inline |
Resume this timer, ie restart counting (ticks()
will start changing again).
Note that this method is not synchronized, hence you should ensure it is called only while AVR interrupts are not enabled. If you need synchronization, then you should better use resume_timer()
instead.
|
inline |
Completely stop this timer: timer interrupts are disabled and counter is stopped.
Note that this method is synchronized, i.e. it disables interrupts during its call and restores interrupts on return. If you do not need synchronization, then you should better use end_()
instead.
|
inline |
Completely stop this timer: timer interrupts are disabled and counter is stopped.
Note that this method is not synchronized, hence you should ensure it is called only while interrupts are not enabled. If you need synchronization, then you should better use end()
instead.
|
inline |
Change the output mode for this timer; this enables connection between this timer to one of its associated digital output pins.
COM | the index of the output pin for this timer; your program will not compile if you use an incorrect value. |
mode | the new output mode for this timer and this pin |
|
inline |
Change the maximum value for this timer, in relation to one of its associated digital output pins.
Note that this method is always synchronized, i.e. it disables interrupts during its call and restores interrupts on return.
COM | the index of the output pin for this timer; your program will not compile if you use an incorrect value. |
max | the new maximum value for this timer and this pin |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |
|
staticconstexpr |