2018-06-07 21:23:22 +08:00
|
|
|
/*
|
2023-04-18 10:26:23 +08:00
|
|
|
* Copyright (c) 2006-2023, RT-Thread Development Team
|
2018-06-07 21:23:22 +08:00
|
|
|
*
|
2018-10-14 19:37:18 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2018-06-07 21:23:22 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2018-05-07 aozima the first version
|
2022-05-19 10:18:55 +08:00
|
|
|
* 2022-05-14 Stanley Lwin add pwm function
|
2022-07-26 10:07:07 +08:00
|
|
|
* 2022-07-25 liYony fix complementary outputs and add usage information in finsh
|
2022-09-01 12:59:44 +08:00
|
|
|
* 2022-08-31 liYony Add complementary output section to framework for management
|
2022-09-26 10:41:00 +08:00
|
|
|
* 2022-09-24 qiyu Add dead-time and phase configuration
|
2023-12-23 14:47:25 +08:00
|
|
|
* 2023-12-23 1ridic Add second-level command completion
|
2018-06-07 21:23:22 +08:00
|
|
|
*/
|
|
|
|
|
2022-04-29 22:56:42 +08:00
|
|
|
#include <rtdevice.h>
|
2018-06-07 21:23:22 +08:00
|
|
|
|
|
|
|
static rt_err_t _pwm_control(rt_device_t dev, int cmd, void *args)
|
|
|
|
{
|
|
|
|
rt_err_t result = RT_EOK;
|
|
|
|
struct rt_device_pwm *pwm = (struct rt_device_pwm *)dev;
|
2022-09-01 12:59:44 +08:00
|
|
|
struct rt_pwm_configuration *configuration = (struct rt_pwm_configuration *)args;
|
2018-06-07 21:23:22 +08:00
|
|
|
|
2022-09-01 12:59:44 +08:00
|
|
|
switch (cmd)
|
2018-06-07 21:23:22 +08:00
|
|
|
{
|
2023-12-23 14:47:25 +08:00
|
|
|
case PWMN_CMD_ENABLE:
|
|
|
|
configuration->complementary = RT_TRUE;
|
|
|
|
break;
|
|
|
|
case PWMN_CMD_DISABLE:
|
|
|
|
configuration->complementary = RT_FALSE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (pwm->ops->control)
|
|
|
|
result = pwm->ops->control(pwm, cmd, args);
|
|
|
|
break;
|
2018-06-08 16:04:29 +08:00
|
|
|
}
|
2018-06-07 21:23:22 +08:00
|
|
|
|
2018-06-08 16:04:29 +08:00
|
|
|
return result;
|
2018-06-07 21:23:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
pos: channel
|
|
|
|
void *buffer: rt_uint32_t pulse[size]
|
|
|
|
size : number of pulse, only set to sizeof(rt_uint32_t).
|
|
|
|
*/
|
2023-02-06 07:35:33 +08:00
|
|
|
static rt_ssize_t _pwm_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size)
|
2018-06-07 21:23:22 +08:00
|
|
|
{
|
|
|
|
rt_err_t result = RT_EOK;
|
|
|
|
struct rt_device_pwm *pwm = (struct rt_device_pwm *)dev;
|
|
|
|
rt_uint32_t *pulse = (rt_uint32_t *)buffer;
|
2018-06-08 16:04:29 +08:00
|
|
|
struct rt_pwm_configuration configuration = {0};
|
|
|
|
|
2022-07-26 10:07:07 +08:00
|
|
|
configuration.channel = (pos > 0) ? (pos) : (-pos);
|
2018-06-07 21:23:22 +08:00
|
|
|
|
|
|
|
if (pwm->ops->control)
|
|
|
|
{
|
|
|
|
result = pwm->ops->control(pwm, PWM_CMD_GET, &configuration);
|
|
|
|
if (result != RT_EOK)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pulse = configuration.pulse;
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
pos: channel
|
|
|
|
void *buffer: rt_uint32_t pulse[size]
|
|
|
|
size : number of pulse, only set to sizeof(rt_uint32_t).
|
|
|
|
*/
|
2023-02-06 07:35:33 +08:00
|
|
|
static rt_ssize_t _pwm_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size)
|
2018-06-07 21:23:22 +08:00
|
|
|
{
|
|
|
|
rt_err_t result = RT_EOK;
|
|
|
|
struct rt_device_pwm *pwm = (struct rt_device_pwm *)dev;
|
|
|
|
rt_uint32_t *pulse = (rt_uint32_t *)buffer;
|
2018-06-08 16:04:29 +08:00
|
|
|
struct rt_pwm_configuration configuration = {0};
|
2018-06-07 21:23:22 +08:00
|
|
|
|
2022-07-26 10:07:07 +08:00
|
|
|
configuration.channel = (pos > 0) ? (pos) : (-pos);
|
2018-06-07 21:23:22 +08:00
|
|
|
|
|
|
|
if (pwm->ops->control)
|
|
|
|
{
|
|
|
|
result = pwm->ops->control(pwm, PWM_CMD_GET, &configuration);
|
|
|
|
if (result != RT_EOK)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
configuration.pulse = *pulse;
|
|
|
|
|
|
|
|
result = pwm->ops->control(pwm, PWM_CMD_SET, &configuration);
|
|
|
|
if (result != RT_EOK)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2018-11-24 17:23:12 +08:00
|
|
|
#ifdef RT_USING_DEVICE_OPS
|
|
|
|
static const struct rt_device_ops pwm_device_ops =
|
|
|
|
{
|
|
|
|
RT_NULL,
|
|
|
|
RT_NULL,
|
|
|
|
RT_NULL,
|
|
|
|
_pwm_read,
|
|
|
|
_pwm_write,
|
|
|
|
_pwm_control
|
|
|
|
};
|
|
|
|
#endif /* RT_USING_DEVICE_OPS */
|
|
|
|
|
2018-06-07 21:23:22 +08:00
|
|
|
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 result = RT_EOK;
|
|
|
|
|
2021-12-31 08:38:20 +08:00
|
|
|
rt_memset(device, 0, sizeof(struct rt_device_pwm));
|
2018-06-07 21:23:22 +08:00
|
|
|
|
2018-11-24 17:23:12 +08:00
|
|
|
#ifdef RT_USING_DEVICE_OPS
|
|
|
|
device->parent.ops = &pwm_device_ops;
|
|
|
|
#else
|
|
|
|
device->parent.init = RT_NULL;
|
|
|
|
device->parent.open = RT_NULL;
|
|
|
|
device->parent.close = RT_NULL;
|
|
|
|
device->parent.read = _pwm_read;
|
|
|
|
device->parent.write = _pwm_write;
|
|
|
|
device->parent.control = _pwm_control;
|
|
|
|
#endif /* RT_USING_DEVICE_OPS */
|
2018-06-07 21:23:22 +08:00
|
|
|
|
2022-04-06 21:12:39 +08:00
|
|
|
device->parent.type = RT_Device_Class_PWM;
|
2018-06-07 21:23:22 +08:00
|
|
|
device->ops = ops;
|
|
|
|
device->parent.user_data = (void *)user_data;
|
|
|
|
|
|
|
|
result = rt_device_register(&device->parent, name, RT_DEVICE_FLAG_RDWR);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-01-20 23:47:18 +08:00
|
|
|
rt_err_t rt_pwm_enable(struct rt_device_pwm *device, int channel)
|
2018-09-26 17:29:31 +08:00
|
|
|
{
|
|
|
|
rt_err_t result = RT_EOK;
|
|
|
|
struct rt_pwm_configuration configuration = {0};
|
|
|
|
|
|
|
|
if (!device)
|
|
|
|
{
|
|
|
|
return -RT_EIO;
|
|
|
|
}
|
|
|
|
|
2022-09-01 12:59:44 +08:00
|
|
|
/* Make it is positive num forever */
|
|
|
|
configuration.channel = (channel > 0) ? (channel) : (-channel);
|
|
|
|
|
|
|
|
/* If channel is a positive number (0 ~ n), it means using normal output pin.
|
|
|
|
* If channel is a negative number (0 ~ -n), it means using complementary output pin. */
|
2023-12-23 14:47:25 +08:00
|
|
|
if (channel > 0)
|
2022-09-01 12:59:44 +08:00
|
|
|
{
|
|
|
|
result = rt_device_control(&device->parent, PWMN_CMD_DISABLE, &configuration);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = rt_device_control(&device->parent, PWMN_CMD_ENABLE, &configuration);
|
|
|
|
}
|
|
|
|
|
2018-09-26 17:29:31 +08:00
|
|
|
result = rt_device_control(&device->parent, PWM_CMD_ENABLE, &configuration);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-01-20 23:47:18 +08:00
|
|
|
rt_err_t rt_pwm_disable(struct rt_device_pwm *device, int channel)
|
2018-06-07 21:23:22 +08:00
|
|
|
{
|
|
|
|
rt_err_t result = RT_EOK;
|
2018-06-08 16:04:29 +08:00
|
|
|
struct rt_pwm_configuration configuration = {0};
|
|
|
|
|
|
|
|
if (!device)
|
|
|
|
{
|
|
|
|
return -RT_EIO;
|
|
|
|
}
|
|
|
|
|
2022-09-01 12:59:44 +08:00
|
|
|
/* Make it is positive num forever */
|
|
|
|
configuration.channel = (channel > 0) ? (channel) : (-channel);
|
|
|
|
|
|
|
|
/* If channel is a positive number (0 ~ n), it means using normal output pin.
|
|
|
|
* If channel is a negative number (0 ~ -n), it means using complementary output pin. */
|
2023-12-23 14:47:25 +08:00
|
|
|
if (channel > 0)
|
2022-09-01 12:59:44 +08:00
|
|
|
{
|
|
|
|
result = rt_device_control(&device->parent, PWMN_CMD_DISABLE, &configuration);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
result = rt_device_control(&device->parent, PWMN_CMD_ENABLE, &configuration);
|
|
|
|
}
|
|
|
|
|
2018-09-26 17:29:31 +08:00
|
|
|
result = rt_device_control(&device->parent, PWM_CMD_DISABLE, &configuration);
|
2018-06-07 21:23:22 +08:00
|
|
|
|
2018-06-08 16:04:29 +08:00
|
|
|
return result;
|
2018-06-07 21:23:22 +08:00
|
|
|
}
|
|
|
|
|
2018-09-26 17:29:31 +08:00
|
|
|
rt_err_t rt_pwm_set(struct rt_device_pwm *device, int channel, rt_uint32_t period, rt_uint32_t pulse)
|
2018-06-07 21:23:22 +08:00
|
|
|
{
|
|
|
|
rt_err_t result = RT_EOK;
|
2018-06-08 16:04:29 +08:00
|
|
|
struct rt_pwm_configuration configuration = {0};
|
|
|
|
|
|
|
|
if (!device)
|
|
|
|
{
|
|
|
|
return -RT_EIO;
|
|
|
|
}
|
|
|
|
|
2022-07-26 10:07:07 +08:00
|
|
|
configuration.channel = (channel > 0) ? (channel) : (-channel);
|
2018-06-08 16:04:29 +08:00
|
|
|
configuration.period = period;
|
|
|
|
configuration.pulse = pulse;
|
2018-09-26 17:29:31 +08:00
|
|
|
result = rt_device_control(&device->parent, PWM_CMD_SET, &configuration);
|
2018-06-08 16:04:29 +08:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-07-04 10:40:42 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-07-26 10:07:07 +08:00
|
|
|
configuration.channel = (channel > 0) ? (channel) : (-channel);
|
2022-07-04 10:40:42 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-07-26 10:07:07 +08:00
|
|
|
configuration.channel = (channel > 0) ? (channel) : (-channel);
|
2022-07-04 10:40:42 +08:00
|
|
|
configuration.pulse = pulse;
|
|
|
|
result = rt_device_control(&device->parent, PWM_CMD_SET_PULSE, &configuration);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-09-26 10:41:00 +08:00
|
|
|
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;
|
|
|
|
}
|
2024-03-31 06:54:10 +08:00
|
|
|
|
|
|
|
static rt_err_t rt_pwm_get(struct rt_device_pwm *device, struct rt_pwm_configuration *cfg)
|
2021-01-19 17:14:32 +08:00
|
|
|
{
|
|
|
|
rt_err_t result = RT_EOK;
|
|
|
|
|
|
|
|
if (!device)
|
|
|
|
{
|
|
|
|
return -RT_EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
result = rt_device_control(&device->parent, PWM_CMD_GET, cfg);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-06-08 16:04:29 +08:00
|
|
|
#ifdef RT_USING_FINSH
|
2022-04-22 22:31:29 +08:00
|
|
|
#include <stdlib.h>
|
2022-05-19 10:18:55 +08:00
|
|
|
#include <string.h>
|
2018-06-08 16:04:29 +08:00
|
|
|
#include <finsh.h>
|
|
|
|
|
2023-12-26 10:39:49 +08:00
|
|
|
enum pwm_list_parameters
|
2023-12-23 14:47:25 +08:00
|
|
|
{
|
|
|
|
PWM_LIST_PROBE = 1,
|
|
|
|
PWM_LIST_ENABLE,
|
|
|
|
PWM_LIST_DISABLE,
|
|
|
|
PWM_LIST_GET,
|
|
|
|
PWM_LIST_SET,
|
|
|
|
PWM_LIST_PHASE,
|
|
|
|
PWM_LIST_DEAD_TIME,
|
2023-12-26 10:39:49 +08:00
|
|
|
};
|
2023-12-23 14:47:25 +08:00
|
|
|
|
|
|
|
CMD_OPTIONS_STATEMENT(pwm_list)
|
2024-03-31 06:54:10 +08:00
|
|
|
|
|
|
|
static int pwm_list(int argc, char **argv)
|
2018-06-08 16:04:29 +08:00
|
|
|
{
|
2022-05-19 10:18:55 +08:00
|
|
|
rt_err_t result = -RT_ERROR;
|
|
|
|
char *result_str;
|
|
|
|
static struct rt_device_pwm *pwm_device = RT_NULL;
|
2021-01-19 17:14:32 +08:00
|
|
|
struct rt_pwm_configuration cfg = {0};
|
|
|
|
|
2023-12-23 14:47:25 +08:00
|
|
|
if (argc > 1)
|
2021-01-19 17:14:32 +08:00
|
|
|
{
|
2023-12-23 14:47:25 +08:00
|
|
|
if (MSH_OPT_ID_GET(pwm_list) == PWM_LIST_PROBE)
|
2022-05-19 10:18:55 +08:00
|
|
|
{
|
2023-12-23 14:47:25 +08:00
|
|
|
if (argc == 3)
|
2022-05-19 10:18:55 +08:00
|
|
|
{
|
|
|
|
pwm_device = (struct rt_device_pwm *)rt_device_find(argv[2]);
|
|
|
|
result_str = (pwm_device == RT_NULL) ? "failure" : "success";
|
|
|
|
rt_kprintf("probe %s %s\n", argv[2], result_str);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-07-26 10:07:07 +08:00
|
|
|
rt_kprintf("pwm probe <device name> - probe pwm by name\n");
|
2022-05-19 10:18:55 +08:00
|
|
|
}
|
|
|
|
}
|
2023-12-23 14:47:25 +08:00
|
|
|
else if (pwm_device == RT_NULL)
|
|
|
|
{
|
|
|
|
rt_kprintf("Please using 'pwm probe <device name>' first.\n");
|
|
|
|
return -RT_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (MSH_OPT_ID_GET(pwm_list))
|
2022-05-19 10:18:55 +08:00
|
|
|
{
|
2023-12-23 14:47:25 +08:00
|
|
|
case PWM_LIST_ENABLE:
|
|
|
|
if (argc == 3)
|
2022-05-19 10:18:55 +08:00
|
|
|
{
|
2023-12-23 14:47:25 +08:00
|
|
|
result = rt_pwm_enable(pwm_device, atoi(argv[2]));
|
|
|
|
result_str = (result == RT_EOK) ? "success" : "failure";
|
|
|
|
rt_kprintf("%s channel %d is enabled %s \n", pwm_device->parent.parent.name, atoi(argv[2]), result_str);
|
2022-05-19 10:18:55 +08:00
|
|
|
}
|
2023-12-23 14:47:25 +08:00
|
|
|
else
|
2022-05-19 10:18:55 +08:00
|
|
|
{
|
2023-12-23 14:47:25 +08:00
|
|
|
rt_kprintf("pwm enable <channel> - enable pwm channel\n");
|
|
|
|
rt_kprintf(" e.g. MSH >pwm enable 1 - PWM_CH1 nomal\n");
|
|
|
|
rt_kprintf(" e.g. MSH >pwm enable -1 - PWM_CH1N complememtary\n");
|
2022-07-26 10:07:07 +08:00
|
|
|
}
|
2023-12-23 14:47:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PWM_LIST_DISABLE:
|
|
|
|
if (argc == 3)
|
2022-05-19 10:18:55 +08:00
|
|
|
{
|
2023-12-23 14:47:25 +08:00
|
|
|
result = rt_pwm_disable(pwm_device, atoi(argv[2]));
|
2022-05-19 10:18:55 +08:00
|
|
|
}
|
2023-12-23 14:47:25 +08:00
|
|
|
else
|
2022-05-19 10:18:55 +08:00
|
|
|
{
|
2023-12-23 14:47:25 +08:00
|
|
|
rt_kprintf("pwm disable <channel> - disable pwm channel\n");
|
2022-05-19 10:18:55 +08:00
|
|
|
}
|
2023-12-23 14:47:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PWM_LIST_GET:
|
|
|
|
cfg.channel = atoi(argv[2]);
|
|
|
|
result = rt_pwm_get(pwm_device, &cfg);
|
|
|
|
if (result == RT_EOK)
|
2022-05-19 10:18:55 +08:00
|
|
|
{
|
2023-12-23 14:47:25 +08:00
|
|
|
rt_kprintf("Info of device [%s] channel [%d]:\n", pwm_device, atoi(argv[2]));
|
|
|
|
rt_kprintf("period : %d\n", cfg.period);
|
|
|
|
rt_kprintf("pulse : %d\n", cfg.pulse);
|
|
|
|
rt_kprintf("Duty cycle : %d%%\n", (int)(((double)(cfg.pulse) / (cfg.period)) * 100));
|
2022-05-19 10:18:55 +08:00
|
|
|
}
|
2023-12-23 14:47:25 +08:00
|
|
|
else
|
2022-09-26 10:41:00 +08:00
|
|
|
{
|
2023-12-23 14:47:25 +08:00
|
|
|
rt_kprintf("Get info of device: [%s] error.\n", pwm_device);
|
2022-09-26 10:41:00 +08:00
|
|
|
}
|
2023-12-23 14:47:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PWM_LIST_SET:
|
|
|
|
if (argc == 5)
|
2022-09-26 10:41:00 +08:00
|
|
|
{
|
2023-12-23 14:47:25 +08:00
|
|
|
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, (rt_base_t)atoi(argv[2]));
|
2022-09-26 10:41:00 +08:00
|
|
|
}
|
2022-05-19 10:18:55 +08:00
|
|
|
else
|
|
|
|
{
|
2023-12-23 14:47:25 +08:00
|
|
|
rt_kprintf("Set info of device: [%s] error\n", pwm_device);
|
|
|
|
rt_kprintf("Usage: pwm set <channel> <period> <pulse>\n");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PWM_LIST_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]));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PWM_LIST_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]));
|
2022-05-19 10:18:55 +08:00
|
|
|
}
|
2023-12-23 14:47:25 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
goto _usage;
|
2022-05-19 10:18:55 +08:00
|
|
|
}
|
2021-01-19 17:14:32 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-12-23 14:47:25 +08:00
|
|
|
goto _usage;
|
2021-01-19 17:14:32 +08:00
|
|
|
}
|
2023-12-23 14:47:25 +08:00
|
|
|
return result;
|
2021-01-19 17:14:32 +08:00
|
|
|
|
2023-12-23 14:47:25 +08:00
|
|
|
_usage:
|
|
|
|
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;
|
|
|
|
return result;
|
2021-01-19 17:14:32 +08:00
|
|
|
}
|
2023-12-23 14:47:25 +08:00
|
|
|
CMD_OPTIONS_NODE_START(pwm_list)
|
|
|
|
CMD_OPTIONS_NODE(PWM_LIST_PROBE, probe, probe pwm by name)
|
|
|
|
CMD_OPTIONS_NODE(PWM_LIST_ENABLE, enable, enable pwm channel)
|
|
|
|
CMD_OPTIONS_NODE(PWM_LIST_DISABLE, disable, disable pwm channel)
|
|
|
|
CMD_OPTIONS_NODE(PWM_LIST_GET, get, get pwm channel info)
|
|
|
|
CMD_OPTIONS_NODE(PWM_LIST_SET, set, set pwm channel info)
|
|
|
|
CMD_OPTIONS_NODE(PWM_LIST_PHASE, phase, set pwm phase)
|
|
|
|
CMD_OPTIONS_NODE(PWM_LIST_DEAD_TIME, dead_time, set pwm dead time)
|
|
|
|
CMD_OPTIONS_NODE_END
|
|
|
|
MSH_CMD_EXPORT_ALIAS(pwm_list, pwm, control pwm device, optenable);
|
2018-06-08 16:04:29 +08:00
|
|
|
|
2021-08-23 17:30:05 +08:00
|
|
|
#endif /* RT_USING_FINSH */
|