stm32f103
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
timer_device.h
Go to the documentation of this file.
1 #ifndef STM32F103_LIB_TIMER_DEVICE_H_
2 #define STM32F103_LIB_TIMER_DEVICE_H_
3 
4 #include <cstdint>
5 #include <memory>
6 
7 #include "timer.h"
8 
15 class TimerDevice {
16  public:
20  using Listener = std::function<void()>;
21 
25  enum Timers {
54  };
55 
59  struct Config {
63  TIM_TypeDef* tim;
67  uint32_t rcc;
71  IRQn irqn;
72 
76  uint16_t prescaler;
80  uint16_t period;
81 
88  };
89 
94  explicit TimerDevice(const Config& config);
95 
103  void SetListener(Listener&& listener);
104 
111  static Listener& InvokeListener(const Timers tim_device) { return listeners_[tim_device]; }
112 
113  private:
117  static std::array<std::function<void()>, 7> listeners_;
118 
122  Timers timer_id_;
126  std::unique_ptr<Timer> timer_;
127 };
128 
134 void TimerDeviceTriggerListener(const TimerDevice::Timers tim_device);
135 
136 #endif // STM32F103_LIB_TIMER_DEVICE_H_
TIM6.
Definition: timer_device.h:49
TIM3.
Definition: timer_device.h:37
uint16_t prescaler
Prescaler value.
Definition: timer_device.h:76
static Listener & InvokeListener(const Timers tim_device)
Invokes the external listener.
Definition: timer_device.h:111
TIM5.
Definition: timer_device.h:45
void SetListener(Listener &&listener)
Sets and enables listener for this device.
Definition: timer_device.cpp:85
Timers timer
Which timer to use.
Definition: timer_device.h:87
uint16_t period
Period value.
Definition: timer_device.h:80
Timers
TIM devices enumeration.
Definition: timer_device.h:25
TIM1.
Definition: timer_device.h:29
uint32_t rcc
RCC: Reset & Clock Control.
Definition: timer_device.h:67
TIM2.
Definition: timer_device.h:33
TimerDevice(const Config &config)
Constructor for Timer Device.
Definition: timer_device.cpp:71
TIM4.
Definition: timer_device.h:41
std::function< void()> Listener
TIM Listener type definition.
Definition: timer_device.h:20
TIM7.
Definition: timer_device.h:53
void TimerDeviceTriggerListener(const TimerDevice::Timers tim_device)
Bridging fuinction between IRQ Handler and external user-defined listener.
Definition: timer_device.cpp:64
Implements device-level abstraction for TIM deivces.
Definition: timer_device.h:15
Configuration for TIM device.
Definition: timer_device.h:59
TIM_TypeDef * tim
Timer.
Definition: timer_device.h:63
IRQn irqn
Interrupt Handler.
Definition: timer_device.h:71