tutrcos
読み取り中…
検索中…
一致する文字列を見つけられません
tim.hpp
[詳解]
1#pragma once
2
3#include "main.h"
4
5#include <cstdint>
6
7namespace tutrcos {
8namespace peripheral {
9
10class TIM {
11public:
12 TIM(TIM_HandleTypeDef *htim) : htim_{htim} {}
13
14 bool start_timer() { return HAL_TIM_Base_Start(htim_) == HAL_OK; }
15
16 bool stop_timer() { return HAL_TIM_Base_Stop(htim_) == HAL_OK; }
17
18 bool start_pwm(uint32_t channel) {
19 return HAL_TIM_PWM_Start(htim_, channel) == HAL_OK;
20 }
21
22 bool stop_pwm(uint32_t channel) {
23 return HAL_TIM_PWM_Stop(htim_, channel) == HAL_OK;
24 }
25
26 bool start_encoder(uint32_t channel) {
27 return HAL_TIM_Encoder_Start(htim_, channel) == HAL_OK;
28 }
29
30 bool stop_encoder(uint32_t channel) {
31 return HAL_TIM_Encoder_Stop(htim_, channel) == HAL_OK;
32 }
33
34 uint32_t get_counter() { return __HAL_TIM_GET_COUNTER(htim_); }
35
36 void set_counter(uint32_t count) { __HAL_TIM_SET_COUNTER(htim_, count); }
37
38 uint32_t get_compare(uint32_t channel) {
39 return __HAL_TIM_GET_COMPARE(htim_, channel);
40 }
41
42 void set_compare(uint32_t channel, uint32_t compare) {
43 __HAL_TIM_SET_COMPARE(htim_, channel, compare);
44 }
45
46 TIM_HandleTypeDef *get_hal_handle() { return htim_; }
47
48private:
49 TIM_HandleTypeDef *htim_;
50};
51
52} // namespace peripheral
53} // namespace tutrcos
Definition tim.hpp:10
uint32_t get_counter()
Definition tim.hpp:34
TIM_HandleTypeDef * get_hal_handle()
Definition tim.hpp:46
bool stop_encoder(uint32_t channel)
Definition tim.hpp:30
bool stop_pwm(uint32_t channel)
Definition tim.hpp:22
uint32_t get_compare(uint32_t channel)
Definition tim.hpp:38
TIM(TIM_HandleTypeDef *htim)
Definition tim.hpp:12
bool start_timer()
Definition tim.hpp:14
bool start_pwm(uint32_t channel)
Definition tim.hpp:18
bool start_encoder(uint32_t channel)
Definition tim.hpp:26
bool stop_timer()
Definition tim.hpp:16
void set_compare(uint32_t channel, uint32_t compare)
Definition tim.hpp:42
void set_counter(uint32_t count)
Definition tim.hpp:36
Definition kernel.hpp:7