libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::CH32PWM Class Reference

CH32 PWM 驱动实现 / CH32 PWM driver implementation. More...

#include <ch32_pwm.hpp>

Inheritance diagram for LibXR::CH32PWM:
[legend]
Collaboration diagram for LibXR::CH32PWM:
[legend]

Public Member Functions

 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
 
ErrorCode SetDutyCycle (float value) override
 Sets the duty cycle of the PWM signal. 设置 PWM 信号的占空比。
 
ErrorCode SetConfig (Configuration config) override
 Configures the PWM settings. 配置 PWM 参数。
 
ErrorCode Enable () override
 Enables the PWM output. 启用 PWM 输出。
 
ErrorCode Disable () override
 Disables the PWM output. 禁用 PWM 输出。
 
- Public Member Functions inherited from LibXR::PWM

Private Member Functions

void ApplyCompare (uint32_t pulse)
 
void OcInitForChannel (uint32_t pulse)
 
void EnableChannel (bool en)
 
void EnableChannelN (bool en)
 
void ConfigureGPIO ()
 

Static Private Member Functions

static bool IsAdvancedTimer (TIM_TypeDef *t)
 
static bool OnAPB2 (TIM_TypeDef *t)
 
static uint32_t GetTimerClockHz (TIM_TypeDef *t)
 
static uint32_t ReadARR32 (TIM_TypeDef *t)
 
static void EnableGPIOClock (GPIO_TypeDef *gpio)
 时钟与 GPIO 初始化辅助 / Clock and GPIO configuration helpers
 
static void EnableTIMClock (TIM_TypeDef *tim)
 

Private Attributes

TIM_TypeDef * tim_
 
uint16_t channel_
 
bool active_high_
 
bool complementary_
 
GPIO_TypeDef * gpio_
 
uint16_t pin_
 
uint32_t pin_remap_
 

Detailed Description

CH32 PWM 驱动实现 / CH32 PWM driver implementation.

Definition at line 12 of file ch32_pwm.hpp.

Member Function Documentation

◆ Disable()

ErrorCode LibXR::CH32PWM::Disable ( )
overridevirtual

Disables the PWM output. 禁用 PWM 输出。

Returns
ErrorCode indicating success or failure. 返回操作结果的错误码。

Implements LibXR::PWM.

◆ Enable()

ErrorCode LibXR::CH32PWM::Enable ( )
overridevirtual

Enables the PWM output. 启用 PWM 输出。

Returns
ErrorCode indicating success or failure. 返回操作结果的错误码。

Implements LibXR::PWM.

◆ ReadARR32()

static uint32_t LibXR::CH32PWM::ReadARR32 ( TIM_TypeDef * t)
inlinestaticprivate

Definition at line 40 of file ch32_pwm.hpp.

40{ return t->ATRLR; }

◆ SetConfig()

ErrorCode LibXR::CH32PWM::SetConfig ( Configuration config)
overridevirtual

Configures the PWM settings. 配置 PWM 参数。

Parameters
configThe configuration structure containing PWM settings. 配置结构体,包含 PWM 设置。
Returns
ErrorCode indicating success or failure. 返回操作结果的错误码。

Implements LibXR::PWM.

◆ SetDutyCycle()

ErrorCode LibXR::CH32PWM::SetDutyCycle ( float value)
overridevirtual

Sets the duty cycle of the PWM signal. 设置 PWM 信号的占空比。

Parameters
valueThe duty cycle as a floating-point value (0.0 to 1.0). 占空比,浮点值(0.0 到 1.0)。
Returns
ErrorCode indicating success or failure. 返回操作结果的错误码。

Implements LibXR::PWM.

Field Documentation

◆ active_high_

bool LibXR::CH32PWM::active_high_
private

Definition at line 29 of file ch32_pwm.hpp.

◆ channel_

uint16_t LibXR::CH32PWM::channel_
private

Definition at line 28 of file ch32_pwm.hpp.

◆ complementary_

bool LibXR::CH32PWM::complementary_
private

Definition at line 30 of file ch32_pwm.hpp.

◆ gpio_

GPIO_TypeDef* LibXR::CH32PWM::gpio_
private

Definition at line 32 of file ch32_pwm.hpp.

◆ pin_

uint16_t LibXR::CH32PWM::pin_
private

Definition at line 33 of file ch32_pwm.hpp.

◆ pin_remap_

uint32_t LibXR::CH32PWM::pin_remap_
private

Definition at line 34 of file ch32_pwm.hpp.

◆ tim_

TIM_TypeDef* LibXR::CH32PWM::tim_
private

Definition at line 27 of file ch32_pwm.hpp.


The documentation for this class was generated from the following file: