Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
tools-mirror
Micropython
提交
da5e269e
M
Micropython
项目概览
tools-mirror
/
Micropython
12 个月 前同步成功
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
Micropython
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
da5e269e
编写于
3月 24, 2014
作者:
D
Damien George
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
stmhal: Make pyb.ADC the ADC class (not a function).
上级
1403298a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
52 addition
and
53 deletion
+52
-53
stmhal/adc.c
stmhal/adc.c
+48
-51
stmhal/adc.h
stmhal/adc.h
+2
-1
stmhal/pybmodule.c
stmhal/pybmodule.c
+2
-1
未找到文件。
stmhal/adc.c
浏览文件 @
da5e269e
...
...
@@ -93,13 +93,11 @@ void adc_init_single(pyb_obj_adc_t *adc_obj) {
HAL_ADC_ConfigChannel
(
adcHandle
,
&
sConfig
);
}
uint32_t
adc_read_channel
(
ADC_HandleTypeDef
*
adcHandle
)
{
uint32_t
adc_read_channel
(
ADC_HandleTypeDef
*
adcHandle
)
{
uint32_t
rawValue
=
0
;
HAL_ADC_Start
(
adcHandle
);
if
(
HAL_ADC_PollForConversion
(
adcHandle
,
10
)
==
HAL_OK
)
\
&&
HAL_ADC_GetState
(
adcHandle
)
==
HAL_ADC_STATE_EOC_REG
)
{
if
(
HAL_ADC_PollForConversion
(
adcHandle
,
10
)
==
HAL_OK
&&
HAL_ADC_GetState
(
adcHandle
)
==
HAL_ADC_STATE_EOC_REG
)
{
rawValue
=
HAL_ADC_GetValue
(
adcHandle
);
}
HAL_ADC_Stop
(
adcHandle
);
...
...
@@ -110,35 +108,21 @@ uint32_t adc_read_channel(ADC_HandleTypeDef *adcHandle)
/******************************************************************************/
/* Micro Python bindings : adc object (single channel) */
static
void
adc_print
(
void
(
*
print
)(
void
*
env
,
const
char
*
fmt
,
...),
void
*
env
,
mp_obj_t
self_in
,
mp_print_kind_t
kind
)
{
STATIC
void
adc_print
(
void
(
*
print
)(
void
*
env
,
const
char
*
fmt
,
...),
void
*
env
,
mp_obj_t
self_in
,
mp_print_kind_t
kind
)
{
pyb_obj_adc_t
*
self
=
self_in
;
print
(
env
,
"<ADC on "
);
mp_obj_print_helper
(
print
,
env
,
self
->
pin_name
,
PRINT_STR
);
print
(
env
,
" channel=%lu>"
,
self
->
channel
);
}
static
mp_obj_t
adc_read
(
mp_obj_t
self_in
)
{
pyb_obj_adc_t
*
self
=
self_in
;
uint32_t
data
=
adc_read_channel
(
&
self
->
handle
);
return
mp_obj_new_int
(
data
);
}
static
MP_DEFINE_CONST_FUN_OBJ_1
(
adc_read_obj
,
adc_read
);
static
const
mp_method_t
adc_methods
[]
=
{
{
"read"
,
&
adc_read_obj
},
{
NULL
,
NULL
},
};
static
const
mp_obj_type_t
adc_type
=
{
{
&
mp_type_type
},
.
name
=
MP_QSTR_ADC
,
.
print
=
adc_print
,
.
methods
=
adc_methods
,
};
STATIC
mp_obj_t
adc_make_new
(
mp_obj_t
type_in
,
uint
n_args
,
uint
n_kw
,
const
mp_obj_t
*
args
)
{
// check number of arguments
if
(
!
(
n_args
==
1
&&
n_kw
==
0
))
{
nlr_jump
(
mp_obj_new_exception_msg
(
&
mp_type_ValueError
,
"ADC accepts 1 argument"
));
}
mp_obj_t
pyb_ADC
(
mp_obj_t
pin_obj
)
{
// 1st argument is the pin name
mp_obj_t
pin_obj
=
args
[
0
];
uint32_t
channel
;
...
...
@@ -162,7 +146,7 @@ mp_obj_t pyb_ADC(mp_obj_t pin_obj) {
pyb_obj_adc_t
*
o
=
m_new_obj
(
pyb_obj_adc_t
);
memset
(
o
,
0
,
sizeof
(
*
o
));
o
->
base
.
type
=
&
adc_type
;
o
->
base
.
type
=
&
pyb_
adc_type
;
o
->
pin_name
=
pin_obj
;
o
->
channel
=
channel
;
adc_init_single
(
o
);
...
...
@@ -170,7 +154,27 @@ mp_obj_t pyb_ADC(mp_obj_t pin_obj) {
return
o
;
}
MP_DEFINE_CONST_FUN_OBJ_1
(
pyb_ADC_obj
,
pyb_ADC
);
STATIC
mp_obj_t
adc_read
(
mp_obj_t
self_in
)
{
pyb_obj_adc_t
*
self
=
self_in
;
uint32_t
data
=
adc_read_channel
(
&
self
->
handle
);
return
mp_obj_new_int
(
data
);
}
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
adc_read_obj
,
adc_read
);
STATIC
const
mp_method_t
adc_methods
[]
=
{
{
"read"
,
&
adc_read_obj
},
{
NULL
,
NULL
},
};
const
mp_obj_type_t
pyb_adc_type
=
{
{
&
mp_type_type
},
.
name
=
MP_QSTR_ADC
,
.
print
=
adc_print
,
.
make_new
=
adc_make_new
,
.
methods
=
adc_methods
,
};
/******************************************************************************/
/* adc all object */
...
...
@@ -223,8 +227,7 @@ void adc_init_all(pyb_obj_adc_all_t *adc_all, uint32_t resolution) {
HAL_ADC_Init
(
adcHandle
);
}
uint32_t
adc_config_and_read_channel
(
ADC_HandleTypeDef
*
adcHandle
,
uint32_t
channel
)
{
uint32_t
adc_config_and_read_channel
(
ADC_HandleTypeDef
*
adcHandle
,
uint32_t
channel
)
{
ADC_ChannelConfTypeDef
sConfig
;
sConfig
.
Channel
=
channel
;
sConfig
.
Rank
=
1
;
...
...
@@ -235,35 +238,29 @@ uint32_t adc_config_and_read_channel(ADC_HandleTypeDef *adcHandle, uint32_t chan
return
adc_read_channel
(
adcHandle
);
}
int
adc_read_core_temp
(
ADC_HandleTypeDef
*
adcHandle
)
{
int
adc_read_core_temp
(
ADC_HandleTypeDef
*
adcHandle
)
{
int32_t
raw_value
=
adc_config_and_read_channel
(
adcHandle
,
ADC_CHANNEL_TEMPSENSOR
);
return
((
raw_value
-
CORE_TEMP_V25
)
/
CORE_TEMP_AVG_SLOPE
)
+
25
;
}
float
adc_read_core_vbat
(
ADC_HandleTypeDef
*
adcHandle
)
{
float
adc_read_core_vbat
(
ADC_HandleTypeDef
*
adcHandle
)
{
uint32_t
raw_value
=
adc_config_and_read_channel
(
adcHandle
,
ADC_CHANNEL_VBAT
);
return
raw_value
*
VBAT_DIV
/
4096
.
0
f
*
3
.
3
f
;
}
float
adc_read_core_vref
(
ADC_HandleTypeDef
*
adcHandle
)
{
float
adc_read_core_vref
(
ADC_HandleTypeDef
*
adcHandle
)
{
uint32_t
raw_value
=
adc_config_and_read_channel
(
adcHandle
,
ADC_CHANNEL_VREFINT
);
return
raw_value
*
VBAT_DIV
/
4096
.
0
f
*
3
.
3
f
;
}
/******************************************************************************/
/* Micro Python bindings : adc_all object */
static
void
adc_all_print
(
void
(
*
print
)(
void
*
env
,
const
char
*
fmt
,
...),
void
*
env
,
mp_obj_t
self_in
,
mp_print_kind_t
kind
)
{
STATIC
void
adc_all_print
(
void
(
*
print
)(
void
*
env
,
const
char
*
fmt
,
...),
void
*
env
,
mp_obj_t
self_in
,
mp_print_kind_t
kind
)
{
print
(
env
,
"<ADC all>"
);
}
static
mp_obj_t
adc_all_read_channel
(
mp_obj_t
self_in
,
mp_obj_t
channel
)
{
STATIC
mp_obj_t
adc_all_read_channel
(
mp_obj_t
self_in
,
mp_obj_t
channel
)
{
pyb_obj_adc_all_t
*
self
=
self_in
;
uint32_t
chan
=
mp_obj_get_int
(
channel
);
...
...
@@ -271,33 +268,33 @@ static mp_obj_t adc_all_read_channel(mp_obj_t self_in, mp_obj_t channel) {
return
mp_obj_new_int
(
data
);
}
static
mp_obj_t
adc_all_read_core_temp
(
mp_obj_t
self_in
)
{
STATIC
mp_obj_t
adc_all_read_core_temp
(
mp_obj_t
self_in
)
{
pyb_obj_adc_all_t
*
self
=
self_in
;
int
data
=
adc_read_core_temp
(
&
self
->
handle
);
return
mp_obj_new_int
(
data
);
}
static
mp_obj_t
adc_all_read_core_vbat
(
mp_obj_t
self_in
)
{
STATIC
mp_obj_t
adc_all_read_core_vbat
(
mp_obj_t
self_in
)
{
pyb_obj_adc_all_t
*
self
=
self_in
;
float
data
=
adc_read_core_vbat
(
&
self
->
handle
);
return
mp_obj_new_float
(
data
);
}
static
mp_obj_t
adc_all_read_core_vref
(
mp_obj_t
self_in
)
{
STATIC
mp_obj_t
adc_all_read_core_vref
(
mp_obj_t
self_in
)
{
pyb_obj_adc_all_t
*
self
=
self_in
;
float
data
=
adc_read_core_vref
(
&
self
->
handle
);
return
mp_obj_new_float
(
data
);
}
static
MP_DEFINE_CONST_FUN_OBJ_2
(
adc_all_read_channel_obj
,
adc_all_read_channel
);
static
MP_DEFINE_CONST_FUN_OBJ_1
(
adc_all_read_core_temp_obj
,
adc_all_read_core_temp
);
static
MP_DEFINE_CONST_FUN_OBJ_1
(
adc_all_read_core_vbat_obj
,
adc_all_read_core_vbat
);
static
MP_DEFINE_CONST_FUN_OBJ_1
(
adc_all_read_core_vref_obj
,
adc_all_read_core_vref
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_2
(
adc_all_read_channel_obj
,
adc_all_read_channel
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
adc_all_read_core_temp_obj
,
adc_all_read_core_temp
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
adc_all_read_core_vbat_obj
,
adc_all_read_core_vbat
);
STATIC
MP_DEFINE_CONST_FUN_OBJ_1
(
adc_all_read_core_vref_obj
,
adc_all_read_core_vref
);
static
const
mp_method_t
adc_all_methods
[]
=
{
STATIC
const
mp_method_t
adc_all_methods
[]
=
{
{
"read_channel"
,
&
adc_all_read_channel_obj
},
{
"read_core_temp"
,
&
adc_all_read_core_temp_obj
},
{
"read_core_vbat"
,
&
adc_all_read_core_vbat_obj
},
...
...
@@ -305,14 +302,14 @@ static const mp_method_t adc_all_methods[] = {
{
NULL
,
NULL
},
};
static
const
mp_obj_type_t
adc_all_type
=
{
STATIC
const
mp_obj_type_t
adc_all_type
=
{
{
&
mp_type_type
},
.
name
=
MP_QSTR_ADC
,
.
print
=
adc_all_print
,
.
methods
=
adc_all_methods
,
};
mp_obj_t
pyb_ADC_all
(
mp_obj_t
resolution
)
{
STATIC
mp_obj_t
pyb_ADC_all
(
mp_obj_t
resolution
)
{
pyb_obj_adc_all_t
*
o
=
m_new_obj
(
pyb_obj_adc_all_t
);
o
->
base
.
type
=
&
adc_all_type
;
adc_init_all
(
o
,
mp_obj_get_int
(
resolution
));
...
...
stmhal/adc.h
浏览文件 @
da5e269e
extern
const
mp_obj_type_t
pyb_adc_type
;
MP_DECLARE_CONST_FUN_OBJ
(
pyb_ADC_all_obj
);
MP_DECLARE_CONST_FUN_OBJ
(
pyb_ADC_obj
);
stmhal/pybmodule.c
浏览文件 @
da5e269e
...
...
@@ -265,8 +265,9 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_I2C), (mp_obj_t)&pyb_I2C_obj },
#endif
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_Usart
),
(
mp_obj_t
)
&
pyb_Usart_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_ADC
),
(
mp_obj_t
)
&
pyb_adc_type
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_ADC_all
),
(
mp_obj_t
)
&
pyb_ADC_all_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_ADC
),
(
mp_obj_t
)
&
pyb_ADC_obj
},
#if MICROPY_HW_ENABLE_DAC
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_DAC
),
(
mp_obj_t
)
&
pyb_dac_type
},
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录