Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Mozi
rt-thread
提交
277bb736
R
rt-thread
项目概览
Mozi
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
0
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,发现更多精彩内容 >>
未验证
提交
277bb736
编写于
10月 11, 2021
作者:
B
Bernard Xiong
提交者:
GitHub
10月 11, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5074 from fzxhub/master
在bsp的lpc408x中增加ADC驱动的支持
上级
bea0b197
a5f7da8e
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
148 addition
and
0 deletion
+148
-0
bsp/lpc408x/README.md
bsp/lpc408x/README.md
+1
-0
bsp/lpc408x/drivers/Kconfig
bsp/lpc408x/drivers/Kconfig
+5
-0
bsp/lpc408x/drivers/SConscript
bsp/lpc408x/drivers/SConscript
+3
-0
bsp/lpc408x/drivers/drv_adc.c
bsp/lpc408x/drivers/drv_adc.c
+123
-0
bsp/lpc408x/drivers/drv_adc.h
bsp/lpc408x/drivers/drv_adc.h
+16
-0
未找到文件。
bsp/lpc408x/README.md
浏览文件 @
277bb736
...
...
@@ -51,6 +51,7 @@ finsh />
| ETH | 支持 | |
| LCD | 支持 | |
| SDRAM | 支持 | |
| ADC | 支持 | |
### IO 在板级支持包中的映射情况
...
...
bsp/lpc408x/drivers/Kconfig
浏览文件 @
277bb736
...
...
@@ -12,6 +12,11 @@ menu "Hardware Drivers Config"
select RT_USING_HWTIMER
default n
config BSP_USING_ADC
bool "Using ADC"
select RT_USING_ADC
default n
menu "UART Drivers"
config BSP_USING_UART0
bool "Enable UART0 P0.2/P0.3(T/R)"
...
...
bsp/lpc408x/drivers/SConscript
浏览文件 @
277bb736
...
...
@@ -23,6 +23,9 @@ if GetDepend(['BSP_USING_SDRAM']):
if
GetDepend
(
'BSP_USING_UART0'
)
or
GetDepend
(
'BSP_USING_UART2'
):
src
+=
[
'drv_uart.c'
]
if
GetDepend
(
'BSP_USING_ADC'
):
src
+=
[
'drv_adc.c'
]
group
=
DefineGroup
(
'Drivers'
,
src
,
depend
=
[
''
],
CPPPATH
=
CPPPATH
)
Return
(
'group'
)
bsp/lpc408x/drivers/drv_adc.c
0 → 100644
浏览文件 @
277bb736
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-09-27 fzxhub the first version
*/
#include <rtthread.h>
#include <rtdevice.h>
#include "board.h"
#include "drv_adc.h"
#ifdef RT_USING_ADC
#ifdef BSP_USING_ADC
struct
lpc_adc
{
LPC_ADC_TypeDef
*
ADC
;
};
/*
* channel:0-7
*/
static
rt_err_t
lpc_adc_enabled
(
struct
rt_adc_device
*
device
,
rt_uint32_t
channel
,
rt_bool_t
enabled
)
{
struct
lpc_adc
*
adc
;
RT_ASSERT
(
device
!=
RT_NULL
);
adc
=
(
struct
lpc_adc
*
)
device
->
parent
.
user_data
;
//enabled ADC
if
(
enabled
==
RT_FALSE
)
adc
->
ADC
->
CR
&=
~
(
1
<<
21
);
else
adc
->
ADC
->
CR
|=
(
1
<<
21
);
//Select the channel
adc
->
ADC
->
CR
|=
(
1
<<
channel
);
return
RT_EOK
;
}
static
rt_err_t
lpc_adc_convert
(
struct
rt_adc_device
*
device
,
rt_uint32_t
channel
,
rt_uint32_t
*
value
)
{
rt_uint32_t
data
;
struct
lpc_adc
*
adc
;
RT_ASSERT
(
device
!=
RT_NULL
);
adc
=
(
struct
lpc_adc
*
)
device
->
parent
.
user_data
;
adc
->
ADC
->
CR
=
(
LPC_ADC
->
CR
&
0x00FFFF00
)
|
(
1
<<
channel
)
|
(
1
<<
24
);
while
((
adc
->
ADC
->
GDR
&
0x80000000
)
==
0
);
adc
->
ADC
->
CR
=
adc
->
ADC
->
CR
|
(
1
<<
24
);
while
((
adc
->
ADC
->
GDR
&
0x80000000
)
==
0
);
data
=
adc
->
ADC
->
GDR
;
data
=
(
data
>>
4
)
&
0xFFF
;
*
value
=
data
;
return
RT_EOK
;
}
static
const
struct
rt_adc_ops
lpc_adc_ops
=
{
lpc_adc_enabled
,
lpc_adc_convert
,
};
struct
lpc_adc
lpc_adc0
=
{
LPC_ADC
,
};
struct
rt_adc_device
adc0
;
int
rt_hw_adc_init
(
void
)
{
rt_err_t
ret
=
RT_EOK
;
struct
lpc_adc
*
adc
;
adc
=
&
lpc_adc0
;
adc0
.
ops
=
&
lpc_adc_ops
;
adc0
.
parent
.
user_data
=
adc
;
//ADC port
LPC_IOCON
->
P0_23
=
0x01
;
//ADC0[0]
LPC_IOCON
->
P0_24
=
0x01
;
//ADC0[1]
LPC_IOCON
->
P0_25
=
0x01
;
//ADC0[2]
LPC_IOCON
->
P0_26
=
0x01
;
//ADC0[3]
LPC_IOCON
->
P1_30
=
0x03
;
//ADC0[4]
LPC_IOCON
->
P1_31
=
0x03
;
//ADC0[5]
LPC_IOCON
->
P0_12
=
0x03
;
//ADC0[6]
LPC_IOCON
->
P0_13
=
0x03
;
//ADC0[7]
//clock
LPC_SC
->
PCONP
|=
(
1U
<<
12
);
//config
LPC_ADC
->
CR
=
0
;
LPC_ADC
->
CR
=
(
1
<<
0
)
|
// SEL
((
PeripheralClock
/
1000000
-
1
)
<<
8
)
|
// CLKDIV = Fpclk / 1000000 - 1
(
0
<<
16
)
|
// BURST
(
0
<<
17
)
|
// CLKS
(
1
<<
21
)
|
// PDN
(
0
<<
22
)
|
// TEST1
(
1
<<
24
)
|
// START
(
0
<<
27
);
// EDGE
//waiting
while
((
LPC_ADC
->
GDR
&
0x80000000
)
==
0
);
ret
=
rt_hw_adc_register
(
&
adc0
,
"adc0"
,
&
lpc_adc_ops
,
adc
);
return
ret
;
}
INIT_BOARD_EXPORT
(
rt_hw_adc_init
);
#endif
/* BSP_USING_ADC */
#endif
/* RT_USING_ADC */
bsp/lpc408x/drivers/drv_adc.h
0 → 100644
浏览文件 @
277bb736
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-09-27 fzxhub the first version
*/
#ifndef DRV_ADC_H__
#define DRV_ADC_H__
int
rt_hw_adc_init
(
void
);
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录