diff options
| author | Trisuborn <[email protected]> | 2021-01-20 23:47:18 +0800 |
|---|---|---|
| committer | Trisuborn <[email protected]> | 2021-01-20 23:47:18 +0800 |
| commit | 55402e19db41f6c8a706782572a177f61b4e93ef (patch) | |
| tree | a8faf1132c9f7c817ec4aff70e66636bc1a8b5ba /components/drivers/misc | |
| parent | 63239801d9a2abe1b210faf6cd9f3b126924f7e0 (diff) | |
优化互补PWM输出功能的实现逻辑,兼容原本API,增加互补PWM使能/失能命令
Diffstat (limited to 'components/drivers/misc')
| -rw-r--r-- | components/drivers/misc/rt_drv_pwm.c | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/components/drivers/misc/rt_drv_pwm.c b/components/drivers/misc/rt_drv_pwm.c index 03ef3353a3..572580c45c 100644 --- a/components/drivers/misc/rt_drv_pwm.c +++ b/components/drivers/misc/rt_drv_pwm.c @@ -126,7 +126,7 @@ rt_err_t rt_device_pwm_register(struct rt_device_pwm *device, const char *name, return result; } -rt_err_t rt_pwm_enable(struct rt_device_pwm *device, int channel, rt_uint8_t complementary) +rt_err_t rt_pwm_enable(struct rt_device_pwm *device, int channel) { rt_err_t result = RT_EOK; struct rt_pwm_configuration configuration = {0}; @@ -136,14 +136,14 @@ rt_err_t rt_pwm_enable(struct rt_device_pwm *device, int channel, rt_uint8_t com return -RT_EIO; } - configuration.channel = channel; - configuration.complementary = complementary ? (RT_TRUE) : (RT_FALSE); + configuration.channel = (channel > 0) ? (channel) : (-channel); /* Make it is positive num forever */ + configuration.complementary = (channel > 0) ? (RT_FALSE) : (RT_TRUE); /* If nagetive, it's complementary */ result = rt_device_control(&device->parent, PWM_CMD_ENABLE, &configuration); return result; } -rt_err_t rt_pwm_disable(struct rt_device_pwm *device, int channel, rt_uint8_t complementary) +rt_err_t rt_pwm_disable(struct rt_device_pwm *device, int channel) { rt_err_t result = RT_EOK; struct rt_pwm_configuration configuration = {0}; @@ -153,8 +153,8 @@ rt_err_t rt_pwm_disable(struct rt_device_pwm *device, int channel, rt_uint8_t co return -RT_EIO; } - configuration.channel = channel; - configuration.complementary = complementary ? (RT_TRUE) : (RT_FALSE); + configuration.channel = (channel > 0) ? (channel) : (-channel); /* Make it is positive num forever */ + configuration.complementary = (channel > 0) ? (RT_FALSE) : (RT_TRUE); /* If nagetive, it's complementary */ result = rt_device_control(&device->parent, PWM_CMD_DISABLE, &configuration); return result; @@ -204,10 +204,10 @@ static int pwm_enable(int argc, char **argv) int result = 0; struct rt_device_pwm *device = RT_NULL; - if (argc != 4) + if (argc != 3) { - rt_kprintf("Usage: pwm_enable pwm1 1 1\n"); - rt_kprintf(" pwm_enable <pwm_dev> <channel> <complementary> \n"); + rt_kprintf("Usage: pwm_enable pwm1 1\n"); + rt_kprintf(" pwm_enable <pwm_dev> <channel/-channel>\n"); result = -RT_ERROR; goto _exit; } @@ -219,22 +219,23 @@ static int pwm_enable(int argc, char **argv) goto _exit; } - result = rt_pwm_enable(device, atoi(argv[2]), atoi(argv[3])); + /* If channel is complementary(1), make the channel number to nagetive */ + result = rt_pwm_enable(device, atoi(argv[2])); _exit: return result; } -MSH_CMD_EXPORT(pwm_enable, pwm_enable <pwm_dev> <channel> <complementary>); +MSH_CMD_EXPORT(pwm_enable, pwm_enable <pwm_dev> <channel/-channel>); static int pwm_disable(int argc, char **argv) { int result = 0; struct rt_device_pwm *device = RT_NULL; - if (argc != 4) + if (argc != 3) { - rt_kprintf("Usage: pwm_enable pwm1 1 1\n"); - rt_kprintf(" pwm_disable <pwm_dev> <channel> <complementary> \n"); + rt_kprintf("Usage: pwm_disable pwm1 1\n"); + rt_kprintf(" pwm_disable <pwm_dev> <channel/-channel> \n"); result = -RT_ERROR; goto _exit; } @@ -246,12 +247,13 @@ static int pwm_disable(int argc, char **argv) goto _exit; } - result = rt_pwm_disable(device, atoi(argv[2]), atoi(argv[3])); + /* If channel is complementary(1), make the channel number to nagetive */ + result = rt_pwm_disable(device, atoi(argv[2])); _exit: return result; } -MSH_CMD_EXPORT(pwm_disable, pwm_disable <pwm_dev> <channel> <complementary>); +MSH_CMD_EXPORT(pwm_disable, pwm_disable <pwm_dev> <channel/-channel>); static int pwm_set(int argc, char **argv) { |
