|
rt_err_t | rt_device_pwm_register (struct rt_device_pwm *device, const char *name, const struct rt_pwm_ops *ops, const void *user_data) |
|
rt_err_t | rt_pwm_enable (struct rt_device_pwm *device, int channel) |
|
rt_err_t | rt_pwm_disable (struct rt_device_pwm *device, int channel) |
|
rt_err_t | rt_pwm_set (struct rt_device_pwm *device, int channel, rt_uint32_t period, rt_uint32_t pulse) |
|
rt_err_t | rt_pwm_set_period (struct rt_device_pwm *device, int channel, rt_uint32_t period) |
|
rt_err_t | rt_pwm_set_pulse (struct rt_device_pwm *device, int channel, rt_uint32_t pulse) |
|
rt_err_t | rt_pwm_set_dead_time (struct rt_device_pwm *device, int channel, rt_uint32_t dead_time) |
|
rt_err_t | rt_pwm_set_phase (struct rt_device_pwm *device, int channel, rt_uint32_t phase) |
|
PWM driver api.
#include <rtthread.h>
#include <rtdevice.h>
#define PWM_DEV_NAME "pwm3"
#define PWM_DEV_CHANNEL 4
static int pwm_led_sample(int argc, char *argv[])
{
rt_uint32_t period, pulse, dir;
period = 500000;
dir = 1;
pulse = 0;
if (pwm_dev == RT_NULL)
{
rt_kprintf("pwm sample run failed! can't find %s device!\n", PWM_DEV_NAME);
return -RT_ERROR;
}
rt_pwm_set(pwm_dev, PWM_DEV_CHANNEL, period, pulse);
while (1)
{
if (dir)
{
pulse += 5000;
}
else
{
pulse -= 5000;
}
if (pulse >= period)
{
dir = 0;
}
if (0 == pulse)
{
dir = 1;
}
rt_pwm_set(pwm_dev, PWM_DEV_CHANNEL, period, pulse);
}
}
rt_err_t rt_pwm_enable(struct rt_device_pwm *device, int channel)
enable the PWM channel
rt_err_t rt_pwm_set(struct rt_device_pwm *device, int channel, rt_uint32_t period, rt_uint32_t pulse)
set the PWM channel
rt_err_t rt_thread_mdelay(rt_int32_t ms)
This function will let current thread delay for some milliseconds.
Definition: thread.c:754
#define MSH_CMD_EXPORT(...)
Definition: finsh.h:142
PWM device.
Definition: dev_pwm.h:131