summaryrefslogtreecommitdiff
path: root/components/drivers
diff options
context:
space:
mode:
authorTrisuborn <[email protected]>2021-01-20 23:47:18 +0800
committerTrisuborn <[email protected]>2021-01-20 23:47:18 +0800
commit55402e19db41f6c8a706782572a177f61b4e93ef (patch)
treea8faf1132c9f7c817ec4aff70e66636bc1a8b5ba /components/drivers
parent63239801d9a2abe1b210faf6cd9f3b126924f7e0 (diff)
优化互补PWM输出功能的实现逻辑,兼容原本API,增加互补PWM使能/失能命令
Diffstat (limited to 'components/drivers')
-rw-r--r--components/drivers/include/drivers/rt_drv_pwm.h6
-rw-r--r--components/drivers/misc/rt_drv_pwm.c34
2 files changed, 22 insertions, 18 deletions
diff --git a/components/drivers/include/drivers/rt_drv_pwm.h b/components/drivers/include/drivers/rt_drv_pwm.h
index a4d64fbc12..59d670714d 100644
--- a/components/drivers/include/drivers/rt_drv_pwm.h
+++ b/components/drivers/include/drivers/rt_drv_pwm.h
@@ -18,6 +18,8 @@
#define PWM_CMD_DISABLE (128 + 1)
#define PWM_CMD_SET (128 + 2)
#define PWM_CMD_GET (128 + 3)
+#define PWMN_CMD_ENABLE (128 + 4)
+#define PWMN_CMD_DISABLE (128 + 5)/
struct rt_pwm_configuration
{
@@ -46,8 +48,8 @@ struct rt_device_pwm
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_uint8_t complementary);
-rt_err_t rt_pwm_disable(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 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);
#endif /* __DRV_PWM_H_INCLUDE__ */
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)
{