4
0
mirror of https://github.com/RT-Thread/rt-thread.git synced 2025-02-23 17:58:54 +08:00

69 lines
1.6 KiB
C
Raw Normal View History

/*
* Copyright (c) 2022-2024, Xiaohua Semiconductor Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2024-12-30 CDT first version
*/
/*
* PWM 使
* pwm_sample
* pwm_sample x
* x list device pwm_sample pwm_a1
*/
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#ifdef BSP_USING_PWM
#define PWM_DEV_CHANNEL 1
struct rt_device_pwm *pwm_dev;
static rt_int32_t pwm_sample(int argc, char *argv[])
{
rt_uint32_t period = 50000;
rt_uint32_t pulse = 45000;
if (argc != 2)
{
return -RT_ERROR;
}
pwm_dev = (struct rt_device_pwm *)rt_device_find(argv[1]);
if (pwm_dev == RT_NULL)
{
rt_kprintf("pwm sample run failed! can't find %s device!\n", argv[1]);
return -RT_ERROR;
}
rt_pwm_set(pwm_dev, PWM_DEV_CHANNEL, period, pulse);
rt_pwm_enable(pwm_dev, PWM_DEV_CHANNEL);
rt_pwm_set(pwm_dev, PWM_DEV_CHANNEL + 1, period, pulse);
rt_pwm_enable(pwm_dev, PWM_DEV_CHANNEL + 1);
// rt_pwm_set_period(pwm_dev,PWM_DEV_CHANNEL,100000);
while (1)
{
rt_thread_mdelay(50);
pulse += 5000;
rt_pwm_set_pulse(pwm_dev, PWM_DEV_CHANNEL, pulse);
rt_pwm_set_pulse(pwm_dev, PWM_DEV_CHANNEL + 1, pulse);
if (pulse >= period)
{
pulse = 0;
}
}
}
MSH_CMD_EXPORT(pwm_sample, pwm_sample [opt])
#endif
/*
EOF
*/