Sound Byte Libs 1ee2ca6
C++ firmware library for audio applications on 32-bit ARM Cortex-M processors
Loading...
Searching...
No Matches
Public Member Functions | List of all members
sbl::core::patterns::timing::IntervalTimer< TimerImpl > Class Template Reference

Generic interrupt-driven interval timer. More...

#include <interval_timer.hpp>

Collaboration diagram for sbl::core::patterns::timing::IntervalTimer< TimerImpl >:

Public Member Functions

 IntervalTimer (uint32_t timer_instance)
 Construct interval timer.
 
void setIntervalMicros (uint32_t interval_us)
 Set interval in microseconds.
 
uint32_t getIntervalMicros () const
 Get current interval in microseconds.
 
void start ()
 Start the interval timer.
 
void stop ()
 Stop the interval timer.
 
bool isRunning () const
 Check if timer is running.
 
bool hasTriggered ()
 Check if interval has triggered.
 
void handleTimerInterrupt ()
 Timer interrupt handler - call from ISR.
 
 IntervalTimer (uint32_t interval_ms)
 Constructor with interval period.
 
void start ()
 Start the interval timer.
 
bool tick ()
 Check if interval has elapsed and auto-reset.
 
void stop ()
 Stop the interval timer.
 
void setInterval (uint32_t interval_ms)
 Update interval period.
 
uint32_t getInterval () const
 Get current interval.
 

Detailed Description

template<typename TimerImpl>
class sbl::core::patterns::timing::IntervalTimer< TimerImpl >

Generic interrupt-driven interval timer.

Interval timer for periodic tasks.

Provides precise interval timing using hardware timer interrupts. No musical or domain-specific logic - just generic interval generation. Applications convert their domain values (BPM, frequencies) to microseconds.

Usage:

  1. Construct with timer instance
  2. Set interval in microseconds and start()
  3. Poll hasTriggered() in main loop
  4. Interrupt handling is automatic via registry
Template Parameters
TimerImplHardware timer implementation

Similar to NonBlockingDelay but automatically resets after each period. Useful for periodic tasks like blinking LEDs, sampling sensors, etc.

Template Parameters
SystemTimeImplHAL system time implementation

Definition at line 38 of file interval_timer.hpp.

Constructor & Destructor Documentation

◆ IntervalTimer() [1/2]

template<typename TimerImpl >
sbl::core::patterns::timing::IntervalTimer< TimerImpl >::IntervalTimer ( uint32_t  timer_instance)
inlineexplicit

Construct interval timer.

Parameters
timer_instanceHardware timer instance to use

Definition at line 44 of file interval_timer.hpp.

◆ IntervalTimer() [2/2]

template<typename TimerImpl >
sbl::core::patterns::timing::IntervalTimer< TimerImpl >::IntervalTimer ( uint32_t  interval_ms)
inlineexplicit

Constructor with interval period.

Parameters
interval_msInterval period in milliseconds

Definition at line 115 of file non_blocking_delay.hpp.

Member Function Documentation

◆ getInterval()

Get current interval.

Returns
Current interval in milliseconds

Definition at line 160 of file non_blocking_delay.hpp.

◆ getIntervalMicros()

template<typename TimerImpl >
uint32_t sbl::core::patterns::timing::IntervalTimer< TimerImpl >::getIntervalMicros ( ) const
inline

Get current interval in microseconds.

Returns
Current interval duration

Definition at line 76 of file interval_timer.hpp.

◆ handleTimerInterrupt()

template<typename TimerImpl >
void sbl::core::patterns::timing::IntervalTimer< TimerImpl >::handleTimerInterrupt ( )
inline

Timer interrupt handler - call from ISR.

Called automatically via interrupt registry. Just sets internal flag - no callbacks or complex logic in ISR.

Definition at line 162 of file interval_timer.hpp.

◆ hasTriggered()

Check if interval has triggered.

Returns
true if interval occurred since last check

This is a one-shot check - returns true once per trigger. Call from main loop for event handling.

Definition at line 148 of file interval_timer.hpp.

◆ isRunning()

template<typename TimerImpl >
bool sbl::core::patterns::timing::IntervalTimer< TimerImpl >::isRunning ( ) const
inline

Check if timer is running.

Returns
true if running, false if stopped

Definition at line 137 of file interval_timer.hpp.

◆ setInterval()

template<typename TimerImpl >
void sbl::core::patterns::timing::IntervalTimer< TimerImpl >::setInterval ( uint32_t  interval_ms)
inline

Update interval period.

Parameters
interval_msNew interval in milliseconds

Definition at line 152 of file non_blocking_delay.hpp.

◆ setIntervalMicros()

template<typename TimerImpl >
void sbl::core::patterns::timing::IntervalTimer< TimerImpl >::setIntervalMicros ( uint32_t  interval_us)
inline

Set interval in microseconds.

Parameters
interval_usInterval duration in microseconds

Generic timing - no domain-specific logic. Applications convert their values to microseconds:

  • Audio: sample_rate -> (1,000,000 / sample_rate) us
  • BPM: bpm -> (60,000,000 / bpm) us
  • Hz: freq -> (1,000,000 / freq) us

Definition at line 62 of file interval_timer.hpp.

◆ start() [1/2]

Start the interval timer.

Definition at line 83 of file interval_timer.hpp.

◆ start() [2/2]

Start the interval timer.

Definition at line 121 of file non_blocking_delay.hpp.

◆ stop() [1/2]

Stop the interval timer.

Definition at line 114 of file interval_timer.hpp.

◆ stop() [2/2]

Stop the interval timer.

Definition at line 144 of file non_blocking_delay.hpp.

◆ tick()

Check if interval has elapsed and auto-reset.

Returns
true if interval has elapsed (resets automatically)

Definition at line 130 of file non_blocking_delay.hpp.


The documentation for this class was generated from the following files: