Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
人间散章
rt-thread
提交
3ecfe9c6
R
rt-thread
项目概览
人间散章
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
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,发现更多精彩内容 >>
未验证
提交
3ecfe9c6
编写于
5月 18, 2022
作者:
S
Stanley Lwin
提交者:
GitHub
5月 19, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[rt_drv_pwm.c] add finsh pwm function (#5944)
* add finsh pwm function
上级
08737c2a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
97 addition
and
114 deletion
+97
-114
components/drivers/misc/rt_drv_pwm.c
components/drivers/misc/rt_drv_pwm.c
+97
-114
未找到文件。
components/drivers/misc/rt_drv_pwm.c
浏览文件 @
3ecfe9c6
/*
/*
* Copyright (c) 2006-202
1
, RT-Thread Development Team
* Copyright (c) 2006-202
2
, RT-Thread Development Team
*
*
* SPDX-License-Identifier: Apache-2.0
* SPDX-License-Identifier: Apache-2.0
*
*
* Change Logs:
* Change Logs:
* Date Author Notes
* Date Author Notes
* 2018-05-07 aozima the first version
* 2018-05-07 aozima the first version
* 2022-05-14 Stanley Lwin add pwm function
*/
*/
#include <drivers/rt_drv_pwm.h>
#include <drivers/rt_drv_pwm.h>
...
@@ -192,130 +193,112 @@ rt_err_t rt_pwm_get(struct rt_device_pwm *device, struct rt_pwm_configuration *c
...
@@ -192,130 +193,112 @@ rt_err_t rt_pwm_get(struct rt_device_pwm *device, struct rt_pwm_configuration *c
#ifdef RT_USING_FINSH
#ifdef RT_USING_FINSH
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <finsh.h>
#include <finsh.h>
static
int
pwm
_enable
(
int
argc
,
char
**
argv
)
static
int
pwm
(
int
argc
,
char
**
argv
)
{
{
int
result
=
0
;
rt_err_t
result
=
-
RT_ERROR
;
struct
rt_device_pwm
*
device
=
RT_NULL
;
char
*
result_str
;
static
struct
rt_device_pwm
*
pwm_device
=
RT_NULL
;
if
(
argc
!=
3
)
{
rt_kprintf
(
"Usage: pwm_enable pwm1 1
\n
"
);
rt_kprintf
(
" pwm_enable <pwm_dev> <channel/-channel>
\n
"
);
result
=
-
RT_ERROR
;
goto
_exit
;
}
device
=
(
struct
rt_device_pwm
*
)
rt_device_find
(
argv
[
1
]);
if
(
!
device
)
{
result
=
-
RT_EIO
;
goto
_exit
;
}
/* 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
/-
channel
>
);
static
int
pwm_disable
(
int
argc
,
char
**
argv
)
{
int
result
=
0
;
struct
rt_device_pwm
*
device
=
RT_NULL
;
if
(
argc
!=
3
)
{
rt_kprintf
(
"Usage: pwm_disable pwm1 1
\n
"
);
rt_kprintf
(
" pwm_disable <pwm_dev> <channel/-channel>
\n
"
);
result
=
-
RT_ERROR
;
goto
_exit
;
}
device
=
(
struct
rt_device_pwm
*
)
rt_device_find
(
argv
[
1
]);
if
(
!
device
)
{
result
=
-
RT_EIO
;
goto
_exit
;
}
/* 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
/-
channel
>
);
static
int
pwm_set
(
int
argc
,
char
**
argv
)
{
int
result
=
0
;
struct
rt_device_pwm
*
device
=
RT_NULL
;
if
(
argc
!=
5
)
{
rt_kprintf
(
"Usage: pwm_set pwm1 1 100 50
\n
"
);
rt_kprintf
(
"Usage: pwm_set <pwm_dev> <channel> <period> <pulse>
\n
"
);
result
=
-
RT_ERROR
;
goto
_exit
;
}
device
=
(
struct
rt_device_pwm
*
)
rt_device_find
(
argv
[
1
]);
if
(
!
device
)
{
result
=
-
RT_EIO
;
goto
_exit
;
}
result
=
rt_pwm_set
(
device
,
atoi
(
argv
[
2
]),
atoi
(
argv
[
3
]),
atoi
(
argv
[
4
]));
_exit:
return
result
;
}
MSH_CMD_EXPORT
(
pwm_set
,
pwm_set
<
pwm_dev
>
<
channel
>
<
period
>
<
pulse
>
);
static
int
pwm_get
(
int
argc
,
char
**
argv
)
{
int
result
=
0
;
struct
rt_device_pwm
*
device
=
RT_NULL
;
struct
rt_pwm_configuration
cfg
=
{
0
};
struct
rt_pwm_configuration
cfg
=
{
0
};
if
(
argc
!=
3
)
if
(
argc
>
1
)
{
{
rt_kprintf
(
"Usage: pwm_get pwm1 1
\n
"
);
if
(
!
strcmp
(
argv
[
1
],
"probe"
))
rt_kprintf
(
" pwm_get <pwm_dev> <channel>
\n
"
);
{
result
=
-
RT_ERROR
;
if
(
argc
==
3
)
goto
_exit
;
{
}
pwm_device
=
(
struct
rt_device_pwm
*
)
rt_device_find
(
argv
[
2
]);
result_str
=
(
pwm_device
==
RT_NULL
)
?
"failure"
:
"success"
;
device
=
(
struct
rt_device_pwm
*
)
rt_device_find
(
argv
[
1
]);
rt_kprintf
(
"probe %s %s
\n
"
,
argv
[
2
],
result_str
);
if
(
!
device
)
}
{
else
result
=
-
RT_EIO
;
{
goto
_exit
;
rt_kprintf
(
"pwm probe <device name> - probe pwm by name
\n
"
);
}
}
}
cfg
.
channel
=
atoi
(
argv
[
2
]);
else
result
=
rt_pwm_get
(
device
,
&
cfg
);
{
if
(
result
!=
RT_EOK
)
if
(
pwm_device
==
RT_NULL
)
{
{
rt_kprintf
(
"Get info of device: [%s] error.
\n
"
,
argv
[
1
]);
rt_kprintf
(
"Please using 'pwm probe <device name>' first.
\n
"
);
return
-
RT_ERROR
;
}
if
(
!
strcmp
(
argv
[
1
],
"enable"
))
{
if
(
argc
==
3
)
{
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
);
}
else
{
rt_kprintf
(
"pwm enable <channel> - enable pwm channel
\n
"
);
}
}
else
if
(
!
strcmp
(
argv
[
1
],
"disable"
))
{
if
(
argc
==
3
)
{
result
=
rt_pwm_disable
(
pwm_device
,
atoi
(
argv
[
2
]));
}
else
{
rt_kprintf
(
"pwm disable <channel> - disable pwm channel
\n
"
);
}
}
else
if
(
!
strcmp
(
argv
[
1
],
"get"
))
{
cfg
.
channel
=
atoi
(
argv
[
2
]);
result
=
rt_pwm_get
(
pwm_device
,
&
cfg
);
if
(
result
==
RT_EOK
)
{
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
));
}
else
{
rt_kprintf
(
"Get info of device: [%s] error.
\n
"
,
pwm_device
);
}
}
else
if
(
!
strcmp
(
argv
[
1
],
"set"
))
{
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
]));
}
else
{
rt_kprintf
(
"Set info of device: [%s] error
\n
"
,
pwm_device
);
rt_kprintf
(
"Usage: pwm set <channel> <period> <pulse>
\n
"
);
}
}
else
{
rt_kprintf
(
"pwm get <channel> - get pwm channel info
\n
"
);
}
}
}
}
else
else
{
{
rt_kprintf
(
"Get info of device: [%s]:
\n
"
,
argv
[
1
]);
rt_kprintf
(
"Usage:
\n
"
);
rt_kprintf
(
"period : %d
\n
"
,
cfg
.
period
);
rt_kprintf
(
"pwm probe <device name> - probe pwm by name
\n
"
);
rt_kprintf
(
"pulse : %d
\n
"
,
cfg
.
pulse
);
rt_kprintf
(
"pwm enable <channel> - enable pwm channel
\n
"
);
rt_kprintf
(
"Duty cycle : %d%%
\n
"
,
(
int
)(((
double
)(
cfg
.
pulse
)
/
(
cfg
.
period
))
*
100
));
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
"
);
result
=
-
RT_ERROR
;
}
}
_exit:
return
RT_EOK
;
return
result
;
}
}
MSH_CMD_EXPORT
(
pwm
_get
,
pwm_get
<
pwm_dev
>
<
channel
>
);
MSH_CMD_EXPORT
(
pwm
,
pwm
<
device
name
>
<
option
>
<
channel
>
);
#endif
/* RT_USING_FINSH */
#endif
/* RT_USING_FINSH */
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录