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{
12class CH32PWM : public PWM
13{
14 public:
18 CH32PWM(TIM_TypeDef* tim, uint16_t channel, bool active_high, GPIO_TypeDef* gpio,
19 uint16_t pin, uint32_t pin_remap = 0, bool complementary = false);
20
21 ErrorCode SetDutyCycle(float value) override;
22 ErrorCode SetConfig(Configuration config) override;
23 ErrorCode Enable() override;
24 ErrorCode Disable() override;
25
26 private:
27 TIM_TypeDef* tim_;
28 uint16_t channel_;
29 bool active_high_;
30 bool complementary_;
31
32 GPIO_TypeDef* gpio_;
33 uint16_t pin_;
34 uint32_t pin_remap_;
35
36 static bool IsAdvancedTimer(TIM_TypeDef* t);
37 static bool OnAPB2(TIM_TypeDef* t);
38 static uint32_t GetTimerClockHz(TIM_TypeDef* t);
39
40 static inline uint32_t ReadARR32(TIM_TypeDef* t) { return t->ATRLR; }
41
42 void ApplyCompare(uint32_t pulse);
43 void OcInitForChannel(uint32_t pulse);
44 void EnableChannel(bool en);
45 void EnableChannelN(bool en);
46
48 static void EnableGPIOClock(GPIO_TypeDef* gpio);
49 static void EnableTIMClock(TIM_TypeDef* tim);
50 void ConfigureGPIO();
51};
52
53} // namespace LibXR
CH32 PWM 驱动实现 / CH32 PWM driver implementation.
Definition ch32_pwm.hpp:13
ErrorCode Enable() override
Enables the PWM output. 启用 PWM 输出。
ErrorCode Disable() override
Disables the PWM output. 禁用 PWM 输出。
ErrorCode SetDutyCycle(float value) override
Sets the duty cycle of the PWM signal. 设置 PWM 信号的占空比。
static void EnableGPIOClock(GPIO_TypeDef *gpio)
时钟与 GPIO 初始化辅助 / Clock and GPIO configuration helpers
ErrorCode SetConfig(Configuration config) override
Configures the PWM settings. 配置 PWM 参数。
CH32PWM(TIM_TypeDef *tim, uint16_t channel, bool active_high, GPIO_TypeDef *gpio, uint16_t pin, uint32_t pin_remap=0, bool complementary=false)
构造 PWM 对象 / Construct PWM object
Abstract base class for PWM (Pulse Width Modulation) control. PWM(脉冲宽度调制)控制的抽象基类。
Definition pwm.hpp:14
LibXR 命名空间
Definition ch32_can.hpp:14
Configuration parameters for PWM. PWM 配置参数。
Definition pwm.hpp:23