Skip to content
GitLab
LSCloud-logo1
Created with Sketch.
LSCloud-logo2
Created with Sketch.
项目
项目组
代码片段
帮助
正在加载...
帮助
关于聆思
登录
切换导航
csk
项目概览
项目概览
详情
动态
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
合并请求
1
合并请求
1
CI / CD
CI / CD
流水线
作业
计划
小工具
烧录包信息打印
烧录包校验
烧录包打包
生成LPK包
收起侧边栏
关闭侧边栏
动态
分支图
作业
提交
打开侧边栏
csk6_zephyr
csk
提交
7050abdd
提交
7050abdd
编写于
1年前
作者:
jihaiyu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
driver : change exmcu adc samples readme and yml
上级
0b568bce
变更
7
Hide whitespace changes
内联
并排
7 个文件被修改
(
47 行新增
以及
191 行删除
)
+47
-191
samples/driver/exmcu_adc/CMakeLists.txt
samples/driver/exmcu_adc/CMakeLists.txt
+2
-2
samples/driver/exmcu_adc/README.rst
samples/driver/exmcu_adc/README.rst
+2
-22
samples/driver/exmcu_adc/app.overlay
samples/driver/exmcu_adc/app.overlay
+0
-111
samples/driver/exmcu_adc/boards/csk6_duomotai_devkit.overlay
samples/driver/exmcu_adc/boards/csk6_duomotai_devkit.overlay
+27
-0
samples/driver/exmcu_adc/prj.conf
samples/driver/exmcu_adc/prj.conf
+0
-5
samples/driver/exmcu_adc/sample.yaml
samples/driver/exmcu_adc/sample.yaml
+5
-15
samples/driver/exmcu_adc/src/main.c
samples/driver/exmcu_adc/src/main.c
+11
-36
未找到文件。
samples/driver/exmcu_adc/CMakeLists.txt
浏览文件 @
7050abdd
...
...
@@ -2,7 +2,7 @@
cmake_minimum_required
(
VERSION 3.20.0
)
set
(
SUPPORT_BOARDS csk6
012_nano csk6011a_nano
)
set
(
SUPPORT_BOARDS csk6
_duomotai_devkit
)
if
(
NOT
${
BOARD
}
IN_LIST SUPPORT_BOARDS
)
message
(
"Please choose one of the following boards:"
)
foreach
(
item
${
SUPPORT_BOARDS
}
)
...
...
@@ -12,6 +12,6 @@ if(NOT ${BOARD} IN_LIST SUPPORT_BOARDS)
endif
()
find_package
(
Zephyr HINTS $ENV{ZEPHYR_BASE}
)
project
(
ADC
)
project
(
exmcu_adc
)
target_sources
(
app PRIVATE src/main.c
)
This diff is collapsed.
Click to expand it.
samples/driver/exmcu_adc/README.rst
浏览文件 @
7050abdd
.. _adc-sample:
Analog-to-Digital Converter (ADC)
EXMCU ADC
#################################
Overview
********
This sample demonstrates how to use the ADC driver API.
Building and Running
********************
The ADC peripheral and pinmux is configured in the board's ``.dts`` file. Make
sure that the ADC is enabled (``status = "okay";``).
In addition to that, this sample requires an ADC channel specified in the
``io-channels`` property of the ``zephyr,user`` node. This is usually done with
a devicetree overlay.
Building and Running
=========================================
Sample output
=============
该示例演示如何调用adc接口来实现扩展MCU的ADC功能。运行该应用后,会间隔采集EXT_PA2引脚上的电压,并通过日志输出
This diff is collapsed.
Click to expand it.
samples/driver/exmcu_adc/app.overlay
已删除
100644 → 0
浏览文件 @
0b568bce
&i2c0 {
status = "okay";
pinctrl-0 = <&pinctrl_i2c0_scl_default &pinctrl_i2c0_sda_default>;
pinctrl-names = "default";
csk6_ch32v003: csk6_ch32v003@6c {
/**
* Please make sure that the external MCU firmware has been loaded
* SCL --> external MCU PC5
* SDA --> external MCU PC6
*/
compatible = "listenai,csk-i2c-ch32v003";
reg = <0x6c>;
status = "okay";
#address-cells = <1>;
#size-cells = <0>;
exadc: adc@0 {
/**
* external adc channel map
*
* CH0 --> PA2
* CH1 --> PA1
* CH2 --> PC4
* CH3 --> PD2
* CH4 --> PD3
* CH5 --> PD5
* CH6 --> PD6
* CH7 --> PD4
*
*/
compatible = "listenai,csk-adc-ch32v003";
reg = <0>;
status = "okay";
#io-channel-cells = <1>;
};
/* CH32V003-GPIOA */
exgpioa: gpio@0 {
compatible = "listenai,csk-gpio-ch32003-port";
reg = <0x00>;
status = "okay";
ngpios = <8>;
#gpio-cells = <2>;
gpio-controller;
pin_mask = <0x00>;
};
/* CH32V003-GPIOB */
exgpiob: gpio@1 {
compatible = "listenai,csk-gpio-ch32003-port";
reg = <0x01>;
status = "okay";
ngpios = <8>;
#gpio-cells = <2>;
gpio-controller;
pin_mask = <0x00>;
};
/* CH32V003-GPIOC */
exgpioc: gpio@2 {
compatible = "listenai,csk-gpio-ch32003-port";
reg = <0x02>;
status = "okay";
ngpios = <8>;
#gpio-cells = <2>;
gpio-controller;
pin_mask = <0x00>;
};
/* CH32V003-GPIOD */
exgpiod: gpio@3 {
compatible = "listenai,csk-gpio-ch32003-port";
reg = <0x03>;
status = "okay";
ngpios = <8>;
#gpio-cells = <2>;
gpio-controller;
pin_mask = <0x00>;
};
};
};
/ {
/**
* PC2<---->PD2
* PC3<---->PD3
* PC4<---->PD4
*
* external adc channel map
*
* CH0 --> PA2
* CH1 --> PA1
* CH2 --> PC4
* CH3 --> PD2
* CH4 --> PD3
* CH5 --> PD5
* CH6 --> PD6
* CH7 --> PD4
*
*/
zephyr,user {
io-channels = <&exadc 3>, <&exadc 4>, <&exadc 7>;
};
aliases {
csk6-exmcu = &csk6_ch32v003;
};
};
This diff is collapsed.
Click to expand it.
samples/driver/exmcu_adc/boards/csk6_duomotai_devkit.overlay
0 → 100644
浏览文件 @
7050abdd
/*
* Copyright (c) 2023 Anhui(Shenzhen) Listenai Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/
/ {
/**
*
* external adc channel map
*
* CH0 --> PA2
* CH1 --> PA1
* CH2 --> PC4
* CH3 --> PD2
* CH4 --> PD3
* CH5 --> PD5
* CH6 --> PD6
* CH7 --> PD4
*
*/
zephyr,user {
/* this sample use ch0*/
io-channels = <&exadc 0>;
};
};
This diff is collapsed.
Click to expand it.
samples/driver/exmcu_adc/prj.conf
浏览文件 @
7050abdd
CONFIG_ADC
=
y
CONFIG_LOG
=
y
# CONFIG_LOG_MODE_MINIMAL=y
CONFIG_ADC_CSK6_CH32V003
=
y
CONFIG_I2C_CSK6
=
y
CONFIG_I2C
=
y
CONFIG_GPIO_CSK6_CH32V003
=
y
CONFIG_GPIO
=
y
This diff is collapsed.
Click to expand it.
samples/driver/exmcu_adc/sample.yaml
浏览文件 @
7050abdd
sample
:
name
:
EXMCU ADC sample
tests
:
sample.board.csk6.drivers.exmcu.
adc
:
platform_allow
:
csk6
011a_nano csk6012_nano
csk.samples.driver.exmcu_
adc
:
platform_allow
:
csk6
_duomotai_devkit
tags
:
csk6
harness
:
console
harness_config
:
fixture
:
ch32v003
type
:
multi_line
regex
:
-
"
ADC
CHECK
SUCCESS,
1"
-
"
ADC
CHECK
SUCCESS,
2"
-
"
ADC
CHECK
SUCCESS,
3"
-
"
ADC
CHECK
SUCCESS,
4"
-
"
ADC
CHECK
SUCCESS,
5"
-
"
ADC
CHECK
SUCCESS,
6"
-
"
ADC
CHECK
SUCCESS,
7"
-
"
ADC
CHECK
SUCCESS,
8"
build_only
:
true
\ No newline at end of file
This diff is collapsed.
Click to expand it.
samples/driver/exmcu_adc/src/main.c
浏览文件 @
7050abdd
...
...
@@ -24,8 +24,14 @@
/* Get the numbers of up to two channels */
static
uint8_t
channel_ids
[
ADC_NUM_CHANNELS
]
=
{
DT_IO_CHANNELS_INPUT_BY_IDX
(
DT_PATH
(
zephyr_user
),
0
),
DT_IO_CHANNELS_INPUT_BY_IDX
(
DT_PATH
(
zephyr_user
),
1
),
DT_IO_CHANNELS_INPUT_BY_IDX
(
DT_PATH
(
zephyr_user
),
2
),
#if ADC_NUM_CHANNELS == 2
DT_IO_CHANNELS_INPUT_BY_IDX
(
DT_PATH
(
zephyr_user
),
1
)
#endif
#if ADC_NUM_CHANNELS == 3
DT_IO_CHANNELS_INPUT_BY_IDX
(
DT_PATH
(
zephyr_user
),
1
),
DT_IO_CHANNELS_INPUT_BY_IDX
(
DT_PATH
(
zephyr_user
),
2
)
#endif
};
static
int16_t
sample_buffer
[
ADC_NUM_CHANNELS
];
...
...
@@ -45,28 +51,18 @@ struct adc_sequence sequence = {
.
resolution
=
ADC_RESOLUTION
,
};
void
main
(
void
)
int
main
(
void
)
{
int
err
;
const
struct
device
*
dev_adc
=
DEVICE_DT_GET
(
ADC_NODE
);
const
struct
device
*
dev_gpio
=
DEVICE_DT_GET
(
DT_NODELABEL
(
exgpioc
));
printk
(
"ADC Sample start, ch:%d
\n
"
,
ADC_NUM_CHANNELS
);
if
(
!
device_is_ready
(
dev_adc
))
{
printk
(
"ADC device not found
\n
"
);
return
;
}
if
(
!
device_is_ready
(
dev_gpio
))
{
printk
(
"dev_gpio device not found
\n
"
);
return
;
return
0
;
}
gpio_pin_configure
(
dev_gpio
,
2
,
GPIO_OUTPUT
);
gpio_pin_configure
(
dev_gpio
,
3
,
GPIO_OUTPUT
);
gpio_pin_configure
(
dev_gpio
,
4
,
GPIO_OUTPUT
);
/*
* Configure channels individually prior to sampling
*/
...
...
@@ -81,27 +77,17 @@ void main(void)
int32_t
adc_vref
=
adc_ref_internal
(
dev_adc
);
printk
(
"adc_vref %d.
\n
"
,
adc_vref
);
uint32_t
cnt
=
0
;
while
(
1
)
{
cnt
++
;
printk
(
"
\n
-----ADC TEST OUTPUT %s-----
\n
"
,
cnt
%
2
==
1
?
"HIGH"
:
"LOW"
);
gpio_pin_set_raw
(
dev_gpio
,
2
,
cnt
%
2
==
1
);
gpio_pin_set_raw
(
dev_gpio
,
3
,
cnt
%
2
==
1
);
gpio_pin_set_raw
(
dev_gpio
,
4
,
cnt
%
2
==
1
);
k_msleep
(
100
);
/*
* Read sequence of channels (fails if not supported by MCU)
*/
err
=
adc_read
(
dev_adc
,
&
sequence
);
if
(
err
!=
0
)
{
printk
(
"ADC reading failed with error %d.
\n
"
,
err
);
return
;
return
0
;
}
uint8_t
check
=
1
;
for
(
uint8_t
i
=
0
;
i
<
ADC_NUM_CHANNELS
;
i
++
)
{
int32_t
raw_value
=
sample_buffer
[
i
];
...
...
@@ -115,21 +101,10 @@ void main(void)
adc_raw_to_millivolts
(
adc_vref
,
ADC_GAIN_1
,
ADC_RESOLUTION
,
&
mv_value
);
printk
(
" adc(%d)= %d mV "
,
raw_value
,
mv_value
);
if
(
cnt
%
2
==
1
)
{
check
&=
mv_value
>
(
adc_vref
/
2
);
}
else
{
check
&=
(
mv_value
<
(
adc_vref
/
2
));
}
}
}
printk
(
"
\n
"
);
if
(
check
)
{
printk
(
"ADC CHECK SUCCESS, %d
\n
"
,
cnt
);
}
else
{
printk
(
"ADC CHECK FAILED
\n
"
);
}
k_sleep
(
K_MSEC
(
1000
));
}
...
...
This diff is collapsed.
Click to expand it.
编辑
预览
支持
Markdown
0%
请重试
or
添加新附件
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录