libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
tim.h
Go to the documentation of this file.
1#pragma once
2#ifndef DSY_TIM_H
3#define DSY_TIM_H
4
5#include <cstdint>
6
7namespace daisy
8{
38{
39 public:
44 struct Config
45 {
47 enum class Peripheral
48 {
49 TIM_2 = 0,
50 TIM_3,
51 TIM_4,
52 TIM_5,
53 };
54
59 enum class CounterDir
60 {
61 UP = 0,
62 DOWN,
63 };
64
74 /* @brief Constructor for default states */
78 period(0xffffffff),
80 {
81 }
82 };
83
85 enum class Result
86 {
87 OK,
88 ERR,
89 };
90
95 typedef void (*PeriodElapsedCallback)(void* data);
96
97 TimerHandle() : pimpl_(nullptr) {}
98 TimerHandle(const TimerHandle& other) = default;
101
104
107
109 const Config& GetConfig() const;
110
119
130
133
136
139
146
153
160
163
166
169
175 void SetCallback(PeriodElapsedCallback cb, void* data = nullptr);
176
177 class Impl;
178
179 private:
180 Impl* pimpl_;
181};
182
183} // namespace daisy
184
185#endif
Definition leddriver.h:33
Hardare timer peripheral support.
Definition tim.h:38
uint32_t GetTick()
Returns the number of counter position.
Result SetPeriod(uint32_t ticks)
Sets the period of the Timer.
Result Start()
Starts the TIM peripheral specified by Config.
void DelayUs(uint32_t del)
Stay within this function for del microseconds.
uint32_t GetFreq()
Returns the frequency of each tick of the timer in Hz.
uint32_t GetMs()
Returns the ticks scaled as milliseconds.
void(* PeriodElapsedCallback)(void *data)
User Callback type that will fire at the end of each timer period. This requires that Config::enable_...
Definition tim.h:95
Result Stop()
Stops the TIM peripheral specified by Config.
void DelayMs(uint32_t del)
Stay within this function for del milliseconds.
TimerHandle & operator=(const TimerHandle &other)=default
void SetCallback(PeriodElapsedCallback cb, void *data=nullptr)
Sets the PeriodElapsedCallback that will fire whenever the timer reaches the end of it's period.
~TimerHandle()
Definition tim.h:100
Result DeInit()
Deinitializes the timer.
Result
Return values for TIM funcitons.
Definition tim.h:86
TimerHandle()
Definition tim.h:97
uint32_t GetUs()
Returns the ticks scaled as microseconds.
void DelayTick(uint32_t del)
Stay within this function for del ticks.
Result Init(const Config &config)
Initializes the timer according to the configuration.
TimerHandle(const TimerHandle &other)=default
Result SetPrescaler(uint32_t val)
Sets the Prescalar applied to the TIM peripheral.
const Config & GetConfig() const
Returns a const reference to the Config struct.
Hardware defines and helpers for daisy field platform.
Definition index.h:2
Configuration struct for the Peripheral.
Definition tim.h:45
CounterDir
Direction of the auto-reload counter.
Definition tim.h:60
CounterDir dir
Definition tim.h:66
uint32_t period
period in ticks at TIM frequency that counter will reset based on dir
Definition tim.h:71
Peripheral periph
Definition tim.h:65
Peripheral
Hardware Timer to configure, and use.
Definition tim.h:48
Config()
Definition tim.h:75
bool enable_irq
Definition tim.h:72