Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DODO�
arduino-esp32
提交
e92634a9
A
arduino-esp32
项目概览
DODO�
/
arduino-esp32
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
arduino-esp32
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e92634a9
编写于
12月 14, 2016
作者:
M
me-no-dev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add analogSetAttenuation and analogSetPinAttenuation
上级
7defc6eb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
46 addition
and
7 deletion
+46
-7
cores/esp32/esp32-hal-adc.c
cores/esp32/esp32-hal-adc.c
+24
-6
cores/esp32/esp32-hal-adc.h
cores/esp32/esp32-hal-adc.h
+22
-1
未找到文件。
cores/esp32/esp32-hal-adc.c
浏览文件 @
e92634a9
...
...
@@ -22,7 +22,7 @@
#include "soc/rtc_cntl_reg.h"
#include "soc/sens_reg.h"
static
uint8_t
__analogAttenuation
=
0
;
//0
db
static
uint8_t
__analogAttenuation
=
3
;
//11
db
static
uint8_t
__analogWidth
=
3
;
//12 bits
static
uint8_t
__analogCycles
=
8
;
static
uint8_t
__analogSamples
=
0
;
//1 sample
...
...
@@ -66,15 +66,16 @@ void __analogSetClockDiv(uint8_t clockDiv){
SET_PERI_REG_BITS
(
SENS_SAR_READ_CTRL2_REG
,
SENS_SAR2_CLK_DIV
,
__analogClockDiv
,
SENS_SAR2_CLK_DIV_S
);
}
void
__analogSetAttenuation
(
uint8_t
attenuation
){
void
__analogSetAttenuation
(
adc_attenuation_t
attenuation
)
{
__analogAttenuation
=
attenuation
&
3
;
uint32_t
att_data
=
0
;
int
i
=
8
;
int
i
=
10
;
while
(
i
--
){
att_data
|=
__analogAttenuation
<<
(
i
*
2
);
}
SET_PERI_REG_BITS
(
SENS_SAR_MEAS_START1_REG
,
SENS_MEAS1_DATA_SAR
,
att_data
,
SENS_MEAS1_DATA_SAR_S
);
SET_PERI_REG_BITS
(
SENS_SAR_MEAS_START2_REG
,
SENS_MEAS2_DATA_SAR
,
att_data
,
SENS_MEAS2_DATA_SAR_S
);
WRITE_PERI_REG
(
SENS_SAR_ATTEN1_REG
,
att_data
&
0xFFFF
);
//ADC1 has 8 channels
WRITE_PERI_REG
(
SENS_SAR_ATTEN2_REG
,
att_data
);
}
void
IRAM_ATTR
__analogInit
(){
...
...
@@ -82,6 +83,7 @@ void IRAM_ATTR __analogInit(){
if
(
initialized
){
return
;
}
__analogSetAttenuation
(
__analogAttenuation
);
__analogSetCycles
(
__analogCycles
);
__analogSetSamples
(
__analogSamples
+
1
);
//in samples
...
...
@@ -108,6 +110,20 @@ void IRAM_ATTR __analogInit(){
initialized
=
true
;
}
void
__analogSetPinAttenuation
(
uint8_t
pin
,
adc_attenuation_t
attenuation
)
{
int8_t
channel
=
digitalPinToAnalogChannel
(
pin
);
if
(
channel
<
0
||
attenuation
>
3
){
return
;
}
__analogInit
();
if
(
channel
>
7
){
SET_PERI_REG_BITS
(
SENS_SAR_ATTEN2_REG
,
3
,
attenuation
,
((
channel
-
10
)
*
2
));
}
else
{
SET_PERI_REG_BITS
(
SENS_SAR_ATTEN1_REG
,
3
,
attenuation
,
(
channel
*
2
));
}
}
uint16_t
IRAM_ATTR
__analogRead
(
uint8_t
pin
)
{
int8_t
channel
=
digitalPinToAnalogChannel
(
pin
);
...
...
@@ -150,6 +166,7 @@ uint16_t IRAM_ATTR __analogRead(uint8_t pin)
while
(
GET_PERI_REG_MASK
(
SENS_SAR_MEAS_START1_REG
,
SENS_MEAS1_DONE_SAR
)
==
0
)
{};
//read done
return
GET_PERI_REG_BITS2
(
SENS_SAR_MEAS_START1_REG
,
SENS_MEAS1_DATA_SAR
,
SENS_MEAS1_DATA_SAR_S
);
}
int
__hallRead
()
//hall sensor without LNA
{
int
Sens_Vp0
;
...
...
@@ -179,5 +196,6 @@ extern void analogSetWidth(uint8_t bits) __attribute__ ((weak, alias("__analogSe
extern
void
analogSetCycles
(
uint8_t
cycles
)
__attribute__
((
weak
,
alias
(
"__analogSetCycles"
)));
extern
void
analogSetSamples
(
uint8_t
samples
)
__attribute__
((
weak
,
alias
(
"__analogSetSamples"
)));
extern
void
analogSetClockDiv
(
uint8_t
clockDiv
)
__attribute__
((
weak
,
alias
(
"__analogSetClockDiv"
)));
//extern void analogSetAttenuation(uint8_t attenuation) __attribute__ ((weak, alias("__analogSetAttenuation")));
extern
void
analogSetAttenuation
(
adc_attenuation_t
attenuation
)
__attribute__
((
weak
,
alias
(
"__analogSetAttenuation"
)));
extern
void
analogSetPinAttenuation
(
uint8_t
pin
,
adc_attenuation_t
attenuation
)
__attribute__
((
weak
,
alias
(
"__analogSetPinAttenuation"
)));
extern
int
hallRead
()
__attribute__
((
weak
,
alias
(
"__hallRead"
)));
cores/esp32/esp32-hal-adc.h
浏览文件 @
e92634a9
...
...
@@ -26,13 +26,22 @@ extern "C" {
#include "esp32-hal.h"
typedef
enum
{
ADC_0db
,
ADC_2_5db
,
ADC_6db
,
ADC_11db
}
adc_attenuation_t
;
/*
* Get ADC value for pin
* */
uint16_t
analogRead
(
uint8_t
pin
);
/*
* Sets the sample bits (9 - 12)
* Sets the sample bits
* Default is 12bit (0 - 4095)
* Range is 9 - 12
* */
void
analogSetWidth
(
uint8_t
bits
);
...
...
@@ -61,6 +70,18 @@ void analogSetSamples(uint8_t samples);
* */
void
analogSetClockDiv
(
uint8_t
clockDiv
);
/*
* Set the attenuation for all channels
* Default is 11db
* */
void
analogSetAttenuation
(
adc_attenuation_t
attenuation
);
/*
* Set the attenuation for particular pin
* Default is 11db
* */
void
analogSetPinAttenuation
(
uint8_t
pin
,
adc_attenuation_t
attenuation
);
/*
* Get value for HALL sensor (without LNA)
* connected to pins 36(SVP) and 39(SVN)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录