Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
AdRainty
rt-thread
提交
55402e19
R
rt-thread
项目概览
AdRainty
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
55402e19
编写于
1月 20, 2021
作者:
Trisuborn
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
优化互补PWM输出功能的实现逻辑,兼容原本API,增加互补PWM使能/失能命令
上级
63239801
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
26 addition
and
18 deletion
+26
-18
bsp/stm32/libraries/HAL_Drivers/drv_pwm.c
bsp/stm32/libraries/HAL_Drivers/drv_pwm.c
+4
-0
components/drivers/include/drivers/rt_drv_pwm.h
components/drivers/include/drivers/rt_drv_pwm.h
+4
-2
components/drivers/misc/rt_drv_pwm.c
components/drivers/misc/rt_drv_pwm.c
+18
-16
未找到文件。
bsp/stm32/libraries/HAL_Drivers/drv_pwm.c
浏览文件 @
55402e19
...
...
@@ -309,8 +309,12 @@ static rt_err_t drv_pwm_control(struct rt_device_pwm *device, int cmd, void *arg
switch
(
cmd
)
{
case
PWMN_CMD_ENABLE
:
configuration
->
complementary
=
RT_TRUE
;
case
PWM_CMD_ENABLE
:
return
drv_pwm_enable
(
htim
,
configuration
,
RT_TRUE
);
case
PWMN_CMD_DISABLE
:
configuration
->
complementary
=
RT_FALSE
;
case
PWM_CMD_DISABLE
:
return
drv_pwm_enable
(
htim
,
configuration
,
RT_FALSE
);
case
PWM_CMD_SET
:
...
...
components/drivers/include/drivers/rt_drv_pwm.h
浏览文件 @
55402e19
...
...
@@ -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__ */
components/drivers/misc/rt_drv_pwm.c
浏览文件 @
55402e19
...
...
@@ -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 pwm
1 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
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录