libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
ch32_pwm.hpp
1#pragma once
2
3#include "pwm.hpp"
4
5#include DEF2STR(LIBXR_CH32_CONFIG_FILE)
6
7namespace LibXR
8{
9class CH32PWM : public PWM
10{
11 public:
12 CH32PWM(TIM_TypeDef* tim, uint16_t channel, bool active_high, GPIO_TypeDef* gpio,
13 uint16_t pin, uint32_t pin_remap = 0, bool complementary = false);
14
15 ErrorCode SetDutyCycle(float value) override;
16 ErrorCode SetConfig(Configuration config) override;
17 ErrorCode Enable() override;
18 ErrorCode Disable() override;
19
20 private:
21 TIM_TypeDef* tim_;
22 uint16_t channel_;
23 bool active_high_;
24 bool complementary_;
25
26 GPIO_TypeDef* gpio_;
27 uint16_t pin_;
28 uint32_t pin_remap_;
29
30 static bool IsAdvancedTimer(TIM_TypeDef* t);
31 static bool OnAPB2(TIM_TypeDef* t);
32 static uint32_t GetTimerClockHz(TIM_TypeDef* t);
33
34 static inline uint32_t ReadARR32(TIM_TypeDef* t) { return t->ATRLR; }
35
36 void ApplyCompare(uint32_t pulse);
37 void OcInitForChannel(uint32_t pulse);
38 void EnableChannel(bool en);
39 void EnableChannelN(bool en);
40
41 // 时钟/引脚配置
42 static void EnableGPIOClock(GPIO_TypeDef* gpio);
43 static void EnableTIMClock(TIM_TypeDef* tim);
44 void ConfigureGPIO();
45};
46
47} // namespace LibXR
ErrorCode Enable() override
Enables the PWM output. 启用 PWM 输出。
Definition ch32_pwm.cpp:228
ErrorCode Disable() override
Disables the PWM output. 禁用 PWM 输出。
Definition ch32_pwm.cpp:246
ErrorCode SetDutyCycle(float value) override
Sets the duty cycle of the PWM signal. 设置 PWM 信号的占空比。
Definition ch32_pwm.cpp:157
ErrorCode SetConfig(Configuration config) override
Configures the PWM settings. 配置 PWM 参数。
Definition ch32_pwm.cpp:171
Abstract base class for PWM (Pulse Width Modulation) control. PWM(脉冲宽度调制)控制的抽象基类。
Definition pwm.hpp:14
LibXR 命名空间
Configuration parameters for PWM. PWM 配置参数。
Definition pwm.hpp:23