libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
hpm_pwm.hpp
1#pragma once
2
3#include "pwm.hpp"
4
5#include "hpm_soc.h"
6#include "hpm_clock_drv.h"
7#include "hpm_gptmr_drv.h"
8
9#if defined(PWM_SOC_CMP_MAX_COUNT) && defined(PWM_SOC_OUTPUT_TO_PWM_MAX_COUNT)
10#define LIBXR_HPM_PWM_SUPPORTED 1
11#include "hpm_pwm_drv.h"
12using LibXRHpmPwmType = PWM_Type;
13#else
14#define LIBXR_HPM_PWM_SUPPORTED 0
15using LibXRHpmPwmType = void;
16#endif
17
18#if !LIBXR_HPM_PWM_SUPPORTED
19#define LIBXR_HPM_GPTMR_PWM_FALLBACK 1
20#else
21#define LIBXR_HPM_GPTMR_PWM_FALLBACK 0
22#endif
23
24namespace LibXR
25{
26
31class HPMPWM : public PWM
32{
33 public:
44 HPMPWM(LibXRHpmPwmType* pwm, clock_name_t clock, uint8_t pwm_index, uint8_t cmp_index,
45 bool invert = false, bool auto_board_init = true);
46
52 ErrorCode SetDutyCycle(float value) override;
53
59 ErrorCode SetConfig(Configuration config) override;
60
65 ErrorCode Enable() override;
66
71 ErrorCode Disable() override;
72
73 private:
74 static constexpr uint8_t kInvalidCmpIndex = 0xFFu;
75 static uint8_t ResolveGptmrReloadCmpIndex(uint8_t duty_cmp_index);
76
77 LibXRHpmPwmType* pwm_;
78 GPTMR_Type* gptmr_;
79 clock_name_t clock_;
80 uint8_t pwm_index_;
81 uint8_t cmp_index_;
82 bool invert_;
83 bool auto_board_init_;
84 uint32_t reload_;
85 bool configured_;
86};
87
88} // namespace LibXR
HPM 平台 PWM 驱动实现 / PWM driver implementation for HPM platform.
Definition hpm_pwm.hpp:32
HPMPWM(LibXRHpmPwmType *pwm, clock_name_t clock, uint8_t pwm_index, uint8_t cmp_index, bool invert=false, bool auto_board_init=true)
构造 HPM PWM 对象 / Construct an HPM PWM object.
Definition hpm_pwm.cpp:31
ErrorCode Disable() override
停止 PWM 输出 / Stop PWM output.
Definition hpm_pwm.cpp:207
ErrorCode SetDutyCycle(float value) override
设置占空比 / Set PWM duty cycle.
Definition hpm_pwm.cpp:45
ErrorCode Enable() override
启动 PWM 输出 / Start PWM output.
Definition hpm_pwm.cpp:189
ErrorCode SetConfig(Configuration config) override
配置 PWM 频率 / Configure PWM frequency.
Definition hpm_pwm.cpp:88
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