libxr
Embedded C++ framework for bare-metal, RTOS and Linux
Loading...
Searching...
No Matches
mspm0_pwm.hpp
1#pragma once
2
3#include "pwm.hpp"
4#include "ti_msp_dl_config.h" // IWYU pragma: keep; required for GPTIMER_Regs and DL_TIMER_CC_INDEX
5
6namespace LibXR
7{
8
9class MSPM0PWM : public PWM
10{
11 public:
12 struct Resources
13 {
14 GPTIMER_Regs* timer;
15 DL_TIMER_CC_INDEX channel;
16 uint32_t clock_freq;
17 };
18
20
29 static uint32_t SourceClockFromSysCfg(GPTIMER_Regs* timer, uint32_t timer_clock_hz);
30
31 ErrorCode SetDutyCycle(float value);
32
34
36
38
39 private:
40 GPTIMER_Regs* timer_;
41 DL_TIMER_CC_INDEX channel_;
42 uint32_t clock_freq_;
43};
44
52#define MSPM0_PWM_CH(name, ch) \
53 ::LibXR::MSPM0PWM::Resources \
54 { \
55 name##_INST, DL_TIMER_CC_##ch##_INDEX, \
56 ::LibXR::MSPM0PWM::SourceClockFromSysCfg(name##_INST, name##_INST_CLK_FREQ) \
57 }
58
59} // namespace LibXR
ErrorCode Disable()
禁用 PWM 输出 / Disables the PWM output.
static uint32_t SourceClockFromSysCfg(GPTIMER_Regs *timer, uint32_t timer_clock_hz)
由 SysConfig 的定时器时钟反推源时钟 / Source clock from SysConfig's timer clock.
Definition mspm0_pwm.cpp:56
ErrorCode SetDutyCycle(float value)
设置 PWM 信号的占空比 / Sets the duty cycle of the PWM signal.
Definition mspm0_pwm.cpp:16
ErrorCode SetConfig(Configuration config)
配置 PWM 参数 / Configures the PWM settings.
Definition mspm0_pwm.cpp:64
ErrorCode Enable()
启用 PWM 输出 / Enables the PWM output.
PWM(脉冲宽度调制)控制的抽象基类。 Abstract base class for PWM (Pulse Width Modulation) control.
Definition pwm.hpp:14
LibXR 命名空间 / LibXR namespace.
Definition ch32_can.hpp:14
ErrorCode
定义错误码枚举 / Defines an enumeration for error codes
PWM 配置参数 / Configuration parameters for PWM.
Definition pwm.hpp:23