mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-02-06 00:45:22 +08:00
[TMS320F28379] implement PWM driver (#6457)
增加c28x芯片的pwm驱动 已经在TMS320F28379中通过测试 pwm设备框架增加如下方法: #define PWM_CMD_SET_DEAD_TIME (RT_DEVICE_CTRL_BASE(PWM) + 8) #define PWM_CMD_SET_PHASE (RT_DEVICE_CTRL_BASE(PWM) + 9) #define PWM_CMD_ENABLE_IRQ (RT_DEVICE_CTRL_BASE(PWM) + 10) #define PWM_CMD_DISABLE_IRQ (RT_DEVICE_CTRL_BASE(PWM) + 11)
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
* 2022-05-14 Stanley Lwin add pwm function
|
||||
* 2022-07-25 liYony fix complementary outputs and add usage information in finsh
|
||||
* 2022-08-31 liYony Add complementary output section to framework for management
|
||||
* 2022-09-24 qiyu Add dead-time and phase configuration
|
||||
*/
|
||||
|
||||
#include <rtdevice.h>
|
||||
@@ -247,6 +248,40 @@ rt_err_t rt_pwm_set_pulse(struct rt_device_pwm *device, int channel, rt_uint32_t
|
||||
return result;
|
||||
}
|
||||
|
||||
rt_err_t rt_pwm_set_dead_time(struct rt_device_pwm *device, int channel, rt_uint32_t dead_time)
|
||||
{
|
||||
rt_err_t result = RT_EOK;
|
||||
struct rt_pwm_configuration configuration = {0};
|
||||
|
||||
if (!device)
|
||||
{
|
||||
return -RT_EIO;
|
||||
}
|
||||
|
||||
configuration.channel = (channel > 0) ? (channel) : (-channel);
|
||||
configuration.dead_time = dead_time;
|
||||
result = rt_device_control(&device->parent, PWM_CMD_SET_DEAD_TIME, &configuration);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
rt_err_t rt_pwm_set_phase(struct rt_device_pwm *device, int channel, rt_uint32_t phase)
|
||||
{
|
||||
rt_err_t result = RT_EOK;
|
||||
struct rt_pwm_configuration configuration = {0};
|
||||
|
||||
if (!device)
|
||||
{
|
||||
return -RT_EIO;
|
||||
}
|
||||
|
||||
configuration.channel = (channel > 0) ? (channel) : (-channel);
|
||||
configuration.phase = phase;
|
||||
result = rt_device_control(&device->parent, PWM_CMD_SET_PHASE, &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;
|
||||
@@ -342,7 +377,7 @@ static int pwm(int argc, char **argv)
|
||||
if(argc == 5)
|
||||
{
|
||||
result = rt_pwm_set(pwm_device, atoi(argv[2]), atoi(argv[3]), atoi(argv[4]));
|
||||
rt_kprintf("pwm info set on %s at channel %d\n",pwm_device,atoi(argv[2]));
|
||||
rt_kprintf("pwm info set on %s at channel %d\n",pwm_device,(rt_base_t)atoi(argv[2]));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -350,22 +385,48 @@ static int pwm(int argc, char **argv)
|
||||
rt_kprintf("Usage: pwm set <channel> <period> <pulse>\n");
|
||||
}
|
||||
}
|
||||
|
||||
else if(!strcmp(argv[1], "phase"))
|
||||
{
|
||||
if(argc == 4)
|
||||
{
|
||||
result = rt_pwm_set_phase(pwm_device, atoi(argv[2]),atoi(argv[3]));
|
||||
result_str = (result == RT_EOK) ? "success" : "failure";
|
||||
rt_kprintf("%s phase is set %d \n", pwm_device->parent.parent.name, (rt_base_t)atoi(argv[3]));
|
||||
}
|
||||
}
|
||||
else if(!strcmp(argv[1], "dead_time"))
|
||||
{
|
||||
if(argc == 4)
|
||||
{
|
||||
result = rt_pwm_set_dead_time(pwm_device, atoi(argv[2]),atoi(argv[3]));
|
||||
result_str = (result == RT_EOK) ? "success" : "failure";
|
||||
rt_kprintf("%s dead_time is set %d \n", pwm_device->parent.parent.name, (rt_base_t)atoi(argv[3]));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("pwm get <channel> - get pwm channel info\n");
|
||||
rt_kprintf("Usage: \n");
|
||||
rt_kprintf("pwm probe <device name> - probe pwm by name\n");
|
||||
rt_kprintf("pwm enable <channel> - enable pwm channel\n");
|
||||
rt_kprintf("pwm disable <channel> - disable pwm channel\n");
|
||||
rt_kprintf("pwm get <channel> - get pwm channel info\n");
|
||||
rt_kprintf("pwm set <channel> <period> <pulse> - set pwm channel info\n");
|
||||
rt_kprintf("pwm phase <channel> <phase> - set pwm phase\n");
|
||||
rt_kprintf("pwm dead_time <channel> <dead_time> - set pwm dead time\n");
|
||||
result = - RT_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("Usage: \n");
|
||||
rt_kprintf("pwm probe <device name> - probe pwm by name\n");
|
||||
rt_kprintf("pwm enable <channel> - enable pwm channel\n");
|
||||
rt_kprintf("pwm disable <channel> - disable pwm channel\n");
|
||||
rt_kprintf("pwm get <channel> - get pwm channel info\n");
|
||||
rt_kprintf("pwm set <channel> <period> <pulse> - set pwm channel info\n");
|
||||
|
||||
rt_kprintf("pwm probe <device name> - probe pwm by name\n");
|
||||
rt_kprintf("pwm enable <channel> - enable pwm channel\n");
|
||||
rt_kprintf("pwm disable <channel> - disable pwm channel\n");
|
||||
rt_kprintf("pwm get <channel> - get pwm channel info\n");
|
||||
rt_kprintf("pwm set <channel> <period> <pulse> - set pwm channel info\n");
|
||||
rt_kprintf("pwm phase <channel> <phase> - set pwm phase\n");
|
||||
rt_kprintf("pwm dead_time <channel> <dead_time> - set pwm dead time\n");
|
||||
result = - RT_ERROR;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user