summaryrefslogtreecommitdiff
path: root/components/drivers/misc
diff options
context:
space:
mode:
authorBreederBai <[email protected]>2022-07-04 10:40:42 +0800
committerGitHub <[email protected]>2022-07-04 10:40:42 +0800
commitb2bc0dcd16f1b51b8d615a9961765f95b34c54ee (patch)
treec7a5b9df8044ec2f898d6e67838342db9bf2e4aa /components/drivers/misc
parent78faea4b8dd3456131405fd72059476dc426ca2e (diff)
[rt_drv_pwm]增加API:增加单独设置PWM频率和脉宽的函数 (#6130)
* [rt_drv_pwm]增加API:增加单独设置PWM频率和脉宽的函数
Diffstat (limited to 'components/drivers/misc')
-rw-r--r--components/drivers/misc/rt_drv_pwm.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/components/drivers/misc/rt_drv_pwm.c b/components/drivers/misc/rt_drv_pwm.c
index 64eb613a84..53aaad8223 100644
--- a/components/drivers/misc/rt_drv_pwm.c
+++ b/components/drivers/misc/rt_drv_pwm.c
@@ -177,6 +177,40 @@ rt_err_t rt_pwm_set(struct rt_device_pwm *device, int channel, rt_uint32_t perio
return result;
}
+rt_err_t rt_pwm_set_period(struct rt_device_pwm *device, int channel, rt_uint32_t period)
+{
+ rt_err_t result = RT_EOK;
+ struct rt_pwm_configuration configuration = {0};
+
+ if (!device)
+ {
+ return -RT_EIO;
+ }
+
+ configuration.channel = channel;
+ configuration.period = period;
+ result = rt_device_control(&device->parent, PWM_CMD_SET_PERIOD, &configuration);
+
+ return result;
+}
+
+rt_err_t rt_pwm_set_pulse(struct rt_device_pwm *device, int channel, rt_uint32_t pulse)
+{
+ rt_err_t result = RT_EOK;
+ struct rt_pwm_configuration configuration = {0};
+
+ if (!device)
+ {
+ return -RT_EIO;
+ }
+
+ configuration.channel = channel;
+ configuration.pulse = pulse;
+ result = rt_device_control(&device->parent, PWM_CMD_SET_PULSE, &configuration);
+
+ return result;
+}
+
rt_err_t rt_pwm_get(struct rt_device_pwm *device, struct rt_pwm_configuration *cfg)
{
rt_err_t result = RT_EOK;