libyggdrasil  v1.0.0
timer.hpp
Go to the documentation of this file.
1  /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * _____.___. .___ .__.__ *
3  * \__ | | ____ ____ __| _/___________ _____|__| | *
4  * / | |/ ___\ / ___\ / __ |\_ __ \__ \ / ___/ | | *
5  * \____ / /_/ > /_/ > /_/ | | | \// __ \_\___ \| | |__ *
6  * / ______\___ /\___ /\____ | |__| (____ /____ >__|____/ *
7  * \/ /_____//_____/ \/ \/ \/ *
8  * - Common - *
9  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
10  * This software can be used by students and other personal of the *
11  * Bern University of Applied Sciences under the terms of the MIT *
12  * license. *
13  * For other persons this software is under the terms of the GNU *
14  * General Public License version 2. *
15  * *
16  * Copyright © 2021, Bern University of Applied Sciences. *
17  * All rights reserved. *
18  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
26 #pragma once
27 
28 #include <cpp/common/registers.hpp>
30 
31 namespace bsp::drv {
32 
40  template<auto Context, template<auto, typename> typename TimerImpl, typename Size>
41  struct Timer {
42  Timer() = delete;
43  Timer(const Timer&) = delete;
44  Timer(Timer &&) = delete;
45 
46  using Impl = TimerImpl<Context, Size>;
47 
53  template<u8 Number>
54  static inline auto& Channel = Impl::template Channel<Number>;
55 
59  static inline auto& Encoder = Impl::Encoder;
60 
64  static inline auto& ProfileCounter = Impl::ProfileCounter;
65 
72  static auto init(auto ... args) {
73  return Impl::init(args...);
74  }
75 
82  static auto deinit(auto ... args) {
83  return Impl::deinit(args...);
84  }
85 
86 
90  static inline void enable() {
91  Impl::enable();
92  }
93 
97  static inline void disable() {
98  Impl::disable();
99  }
100 
101 
107  static inline Size getCount() {
108  return Impl::getCount();
109  }
110 
116  static inline void setCount(Size cnt) {
117  Impl::setCount(cnt);
118  }
119 
123  static inline void resetCount() {
124  Impl::setCount(0);
125  }
126 
133  static inline u32 getPwmFrequency() {
134  return Impl::getPwmFrequency();
135  }
136 
145  static inline bool setPwmFrequency(u32 f_hz, Size resolution = 0) {
146  return Impl::setPwmFrequency(f_hz, resolution);
147  }
148 
149  };
150 
151 }
bsp::drv::Timer::getPwmFrequency
static u32 getPwmFrequency()
Get the pwm frequency.
Definition: timer.hpp:133
bsp::drv::Timer::ProfileCounter
static auto & ProfileCounter
Timer used as profile counter.
Definition: timer.hpp:64
bsp::drv::Timer::setPwmFrequency
static bool setPwmFrequency(u32 f_hz, Size resolution=0)
Set the pwm frequency and (optional) the maximal ticks within on cycle for all channels.
Definition: timer.hpp:145
bsp::drv::Timer::Channel
static auto & Channel
Timer channel.
Definition: timer.hpp:54
bsp::drv::Timer::resetCount
static void resetCount()
Set the counter value to 0.
Definition: timer.hpp:123
bsp::drv::Timer::Impl
TimerImpl< Context, Size > Impl
Definition: timer.hpp:46
bsp::drv::Timer::disable
static void disable()
Disable the counter.
Definition: timer.hpp:97
u32
uint32_t u32
Definition: types.h:38
registers.hpp
Zero-cost abstraction for accessing registers and bits/bitfields within them.
bsp::drv::Timer::init
static auto init(auto ... args)
Timer initialization.
Definition: timer.hpp:72
bsp::drv::Timer::enable
static void enable()
Enable the counter.
Definition: timer.hpp:90
bsp::drv::Timer::getCount
static Size getCount()
Get the counter value.
Definition: timer.hpp:107
bsp::drv::Timer::deinit
static auto deinit(auto ... args)
Timer deinitialization.
Definition: timer.hpp:82
bsp::drv::Timer::Encoder
static auto & Encoder
Timer in encoder mode.
Definition: timer.hpp:59
bsp::drv::Timer::Timer
Timer(Timer &&)=delete
attributes.hpp
Commonly used C++ and GNU attributes.
bsp::drv::Timer
Base class for Timer abstraction.
Definition: timer.hpp:41
bsp::drv::Timer::setCount
static void setCount(Size cnt)
Set the counter value.
Definition: timer.hpp:116
bsp::drv
Definition: display.hpp:37
bsp::drv::Timer::Timer
Timer()=delete
bsp::drv::Timer::Timer
Timer(const Timer &)=delete