Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
0e5b4a0f
R
rt-thread
项目概览
BaiXuePrincess
/
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看板
提交
0e5b4a0f
编写于
6月 08, 2018
作者:
wuyangyong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[DeviceDrivers] export pwm_enable/set to shell.
上级
cdfef483
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
78 addition
and
27 deletion
+78
-27
components/drivers/misc/_pwm.c
components/drivers/misc/_pwm.c
+78
-27
未找到文件。
components/drivers/misc/_pwm.c
浏览文件 @
0e5b4a0f
...
...
@@ -36,9 +36,9 @@ static rt_err_t _pwm_control(rt_device_t dev, int cmd, void *args)
if
(
pwm
->
ops
->
control
)
{
result
=
pwm
->
ops
->
control
(
pwm
,
cmd
,
args
);
}
}
return
result
;
return
result
;
}
...
...
@@ -52,9 +52,9 @@ static rt_size_t _pwm_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_
rt_err_t
result
=
RT_EOK
;
struct
rt_device_pwm
*
pwm
=
(
struct
rt_device_pwm
*
)
dev
;
rt_uint32_t
*
pulse
=
(
rt_uint32_t
*
)
buffer
;
struct
rt_pwm_configuration
configuration
=
{
0
};
configuration
.
channel
=
pos
;
struct
rt_pwm_configuration
configuration
=
{
0
};
configuration
.
channel
=
pos
;
if
(
pwm
->
ops
->
control
)
{
...
...
@@ -80,9 +80,9 @@ static rt_size_t _pwm_write(rt_device_t dev, rt_off_t pos, const void *buffer, r
rt_err_t
result
=
RT_EOK
;
struct
rt_device_pwm
*
pwm
=
(
struct
rt_device_pwm
*
)
dev
;
rt_uint32_t
*
pulse
=
(
rt_uint32_t
*
)
buffer
;
struct
rt_pwm_configuration
configuration
=
{
0
};
struct
rt_pwm_configuration
configuration
=
{
0
};
configuration
.
channel
=
pos
;
configuration
.
channel
=
pos
;
if
(
pwm
->
ops
->
control
)
{
...
...
@@ -131,33 +131,84 @@ rt_err_t rt_device_pwm_register(struct rt_device_pwm *device, const char *name,
rt_err_t
rt_pwm_enable
(
int
channel
)
{
rt_err_t
result
=
RT_EOK
;
struct
rt_device
*
device
=
rt_device_find
(
"pwm"
);
struct
rt_pwm_configuration
configuration
=
{
0
};
if
(
!
device
)
{
return
-
RT_EIO
;
}
configuration
.
channel
=
channel
;
struct
rt_device
*
device
=
rt_device_find
(
"pwm"
);
struct
rt_pwm_configuration
configuration
=
{
0
};
if
(
!
device
)
{
return
-
RT_EIO
;
}
configuration
.
channel
=
channel
;
result
=
rt_device_control
(
device
,
PWM_CMD_ENABLE
,
&
configuration
);
return
result
;
return
result
;
}
rt_err_t
rt_pwm_set
(
int
channel
,
rt_uint32_t
period
,
rt_uint32_t
pulse
)
{
rt_err_t
result
=
RT_EOK
;
struct
rt_device
*
pwm
=
rt_device_find
(
"pwm"
);
if
(
!
pwm
)
{
return
-
RT_EIO
;
}
return
result
;
struct
rt_device
*
device
=
rt_device_find
(
"pwm"
);
struct
rt_pwm_configuration
configuration
=
{
0
};
if
(
!
device
)
{
return
-
RT_EIO
;
}
configuration
.
channel
=
channel
;
configuration
.
period
=
period
;
configuration
.
pulse
=
pulse
;
result
=
rt_device_control
(
device
,
PWM_CMD_SET
,
&
configuration
);
return
result
;
}
#ifdef RT_USING_FINSH
#include <finsh.h>
FINSH_FUNCTION_EXPORT_ALIAS
(
rt_pwm_enable
,
pwm_enable
,
enable
pwm
by
channel
.);
FINSH_FUNCTION_EXPORT_ALIAS
(
rt_pwm_set
,
pwm_set
,
set
pwm
.);
#ifdef FINSH_USING_MSH
static
int
pwm_enable
(
int
argc
,
char
**
argv
)
{
int
result
=
0
;
if
(
argc
!=
2
)
{
rt_kprintf
(
"Usage: pwm_enable 1
\n
"
);
result
=
-
RT_ERROR
;
goto
_exit
;
}
result
=
rt_pwm_enable
(
atoi
(
argv
[
1
]));
_exit:
return
result
;
}
MSH_CMD_EXPORT
(
pwm_enable
,
pwm_enable
1
);
static
int
pwm_set
(
int
argc
,
char
**
argv
)
{
int
result
=
0
;
if
(
argc
!=
4
)
{
rt_kprintf
(
"Usage: pwm_set 1 100 50
\n
"
);
result
=
-
RT_ERROR
;
goto
_exit
;
}
result
=
rt_pwm_set
(
atoi
(
argv
[
1
]),
atoi
(
argv
[
2
]),
atoi
(
argv
[
3
]));
_exit:
return
result
;
}
MSH_CMD_EXPORT
(
pwm_set
,
pwm_set
1
100
50
);
#endif
/* FINSH_USING_MSH */
#ifdef finsh
#endif
/**/
#endif
/* RT_USING_FINSH */
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录