Class daisy::TimerHandle¶
ClassList > daisy > TimerHandle
Hardare timer peripheral support. More...
#include <tim.h>
Classes¶
Type | Name |
---|---|
struct | Config Configuration struct for the Peripheral. |
Public Types¶
Type | Name |
---|---|
typedef void(* | PeriodElapsedCallback User Callback type that will fire at the end of each timer period. This requires that Config::enable_irq is true before Init. |
enum | Result Return values for TIM funcitons. |
Public Functions¶
Type | Name |
---|---|
Result | DeInit () Deinitializes the timer. |
void | DelayMs (uint32_t del) Stay within this function for del milliseconds. |
void | DelayTick (uint32_t del) Stay within this function for del ticks. |
void | DelayUs (uint32_t del) Stay within this function for del microseconds. |
const Config & | GetConfig () const Returns a const reference to the Config struct. |
uint32_t | GetFreq () Returns the frequency of each tick of the timer in Hz. |
uint32_t | GetMs () Returns the ticks scaled as milliseconds. |
uint32_t | GetTick () Returns the number of counter position. |
uint32_t | GetUs () Returns the ticks scaled as microseconds. |
Result | Init (const Config & config) Initializes the timer according to the configuration. |
void | SetCallback (PeriodElapsedCallback cb, void * data=nullptr) Sets the PeriodElapsedCallback that will fire whenever the timer reaches the end of it's period. |
Result | SetPeriod (uint32_t ticks) Sets the period of the Timer. |
Result | SetPrescaler (uint32_t val) Sets the Prescalar applied to the TIM peripheral. |
Result | Start () Starts the TIM peripheral specified by Config . |
Result | Stop () Stops the TIM peripheral specified by Config . |
TimerHandle () |
|
TimerHandle (const TimerHandle & other) = default |
|
TimerHandle & | operator= (const TimerHandle & other) = default |
~TimerHandle () |
Detailed Description¶
Supports general-function TIM peripherals: * TIM2, TIM3, TIM4, TIM5
DaisySeed, and many internal peripherals utilize TIM2 for timing/delay purposes. It is configured to be at the maximum frequency: typically 200MHz or 240MHz (boost) for measuring/delaying for very short periods.
The GetUs/GetMs functions are available for convenience (and backwards compatibility), but to avoid wrapping errors on math when doing time-delta calculations, using ticks is recommended. The data can be converted to the final time-base after getting the difference in ticks. (Using GetFreq() can be used for these time-base calculations).
User callbacks can be set, and changed at any point during operation. However, the Config::enable_irq must be set to true when initializing for the interrupts to turn on and function.
Todo
Fix issues with realtime getters, and wrapping of the timer(s). * This very noticeable with default settings for the 16-bit counters.
Other General purpose timers
Non-internal clock sources
Use of the four-tim channels per tim * PWM, etc. * InputCapture/OutputCompare, etc.
HRTIM
Advanced timers (TIM1/TIM8)
Public Types Documentation¶
typedef PeriodElapsedCallback¶
User Callback type that will fire at the end of each timer period. This requires that Config::enable_irq is true before Init.
Parameters:
data
pointer to arbitrary user-provided data
enum Result¶
Return values for TIM funcitons.
Public Functions Documentation¶
function DeInit¶
Deinitializes the timer.
function DelayMs¶
Stay within this function for del milliseconds.
function DelayTick¶
Stay within this function for del ticks.
function DelayUs¶
Stay within this function for del microseconds.
function GetConfig¶
Returns a const reference to the Config struct.
function GetFreq¶
Returns the frequency of each tick of the timer in Hz.
function GetMs¶
Returns the ticks scaled as milliseconds.
Use care when using for measurements and ensure that the TIM period can handle the maximum desired measurement.
function GetTick¶
Returns the number of counter position.
This increments according to Config::CounterDir, and wraps around at the specified period (maxing out at 2^16 or 2^32 depending on the chosen TIM peripheral.
function GetUs¶
Returns the ticks scaled as microseconds.
Use care when using for measurements and ensure that the TIM period can handle the maximum desired measurement.
function Init¶
Initializes the timer according to the configuration.
function SetCallback¶
Sets the PeriodElapsedCallback that will fire whenever the timer reaches the end of it's period.
Parameters:
cb
user callbackdata
optional pointer to arbitrary data (defaults to nullptr)
function SetPeriod¶
Sets the period of the Timer.
This is the number of ticks it takes before it wraps back around. For self-managed timing, this can be left at the default. (0xffff for 16-bit and 0xffffffff for 32-bit timers). This can be changed "on-the-fly"
function SetPrescaler¶
Sets the Prescalar applied to the TIM peripheral.
This can be any number up to 0xffff This will adjust the rate of ticks: Calculated as APBN_Freq / prescalar per tick where APBN is APB1 for Most general purpose timers, and APB2 for HRTIM,a nd the advanced timers. This can be changed "on-the-fly"
function Start¶
Starts the TIM peripheral specified by Config .
function Stop¶
Stops the TIM peripheral specified by Config .
function TimerHandle [½]¶
function TimerHandle [2/2]¶
function operator=¶
function ~TimerHandle¶
The documentation for this class was generated from the following file external-docs/libDaisy/src/per/tim.h