提交 7050abdd 编写于 作者: jihaiyu's avatar jihaiyu

driver : change exmcu adc samples readme and yml

上级 0b568bce
......@@ -2,7 +2,7 @@
cmake_minimum_required(VERSION 3.20.0)
set(SUPPORT_BOARDS csk6012_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)
.. _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引脚上的电压,并通过日志输出
&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;
};
};
/*
* 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>;
};
};
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
sample:
name: EXMCU ADC sample
tests:
sample.board.csk6.drivers.exmcu.adc:
platform_allow: csk6011a_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
......@@ -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));
}
......
支持 Markdown
0% or
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册