first commit
This commit is contained in:
10
application/samples/peripheral/adc/CMakeLists.txt
Executable file
10
application/samples/peripheral/adc/CMakeLists.txt
Executable file
@ -0,0 +1,10 @@
|
||||
#===============================================================================
|
||||
# @brief cmake file
|
||||
# Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
|
||||
#===============================================================================
|
||||
|
||||
if((DEFINED CONFIG_ADC_USING_V154) OR (DEFINED CONFIG_ADC_USING_V155))
|
||||
set(SOURCES "${SOURCES}" "${CMAKE_CURRENT_SOURCE_DIR}/adc_demo_inc.c" PARENT_SCOPE)
|
||||
else()
|
||||
set(SOURCES "${SOURCES}" "${CMAKE_CURRENT_SOURCE_DIR}/adc_demo.c" PARENT_SCOPE)
|
||||
endif()
|
25
application/samples/peripheral/adc/Kconfig
Executable file
25
application/samples/peripheral/adc/Kconfig
Executable file
@ -0,0 +1,25 @@
|
||||
#===============================================================================
|
||||
# @brief Kconfig file.
|
||||
# Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
|
||||
#===============================================================================
|
||||
config HADC_SELF_CALIBRATION
|
||||
bool
|
||||
prompt "HADC calibration, or use record code."
|
||||
default y
|
||||
depends on ADC_USING_V152
|
||||
|
||||
config HADC_SAMPLE
|
||||
bool
|
||||
prompt "Enable HADC sample."
|
||||
default y
|
||||
depends on ADC_USING_V152
|
||||
|
||||
config TIMING_SAMPLE
|
||||
bool
|
||||
prompt "Create timing sample irq."
|
||||
default n
|
||||
|
||||
config ADC_CHANNEL
|
||||
int
|
||||
prompt "Choose ADC channel."
|
||||
default 5
|
11
application/samples/peripheral/adc/adc.code-workspace
Executable file
11
application/samples/peripheral/adc/adc.code-workspace
Executable file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"folders": [
|
||||
{
|
||||
"path": "../../../../"
|
||||
}
|
||||
],
|
||||
"settings": {
|
||||
"debug.onTaskErrors": "debugAnyway",
|
||||
"workspace.samplePath": "./samples/peripheral/adc"
|
||||
}
|
||||
}
|
53
application/samples/peripheral/adc/adc_demo_inc.c
Executable file
53
application/samples/peripheral/adc/adc_demo_inc.c
Executable file
@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved.
|
||||
*
|
||||
* Description: ADC Sample Source. \n
|
||||
*
|
||||
* History: \n
|
||||
* 2023-07-06, Create file. \n
|
||||
*/
|
||||
#include "pinctrl.h"
|
||||
#include "adc.h"
|
||||
#include "adc_porting.h"
|
||||
#include "common_def.h"
|
||||
#include "soc_osal.h"
|
||||
#include "app_init.h"
|
||||
#include "tcxo.h"
|
||||
|
||||
#define DELAY_10000MS 10000
|
||||
#define CYCLES 10
|
||||
#define ADC_TASK_PRIO 26
|
||||
#define ADC_TASK_STACK_SIZE 0x1000
|
||||
|
||||
static void *adc_task(const char *arg)
|
||||
{
|
||||
unused(arg);
|
||||
osal_printk("start adc sample\r\n");
|
||||
uapi_adc_init(ADC_CLOCK_NONE);
|
||||
uint8_t adc_channel = CONFIG_ADC_CHANNEL;
|
||||
uint16_t voltage = 0;
|
||||
uint32_t cnt = 0;
|
||||
while (cnt++ < CYCLES) {
|
||||
adc_port_read(adc_channel, &voltage);
|
||||
osal_printk("voltage: %d mv\r\n", voltage);
|
||||
osal_msleep(DELAY_10000MS);
|
||||
}
|
||||
/* 当前测量的电压值和实际值可能有较大差别,请确认是否有分压电阻,如果有分压电阻,则差别符合预期 */
|
||||
uapi_adc_deinit();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void adc_entry(void)
|
||||
{
|
||||
osal_task *task_handle = NULL;
|
||||
osal_kthread_lock();
|
||||
task_handle = osal_kthread_create((osal_kthread_handler)adc_task, 0, "AdcTask", ADC_TASK_STACK_SIZE);
|
||||
if (task_handle != NULL) {
|
||||
osal_kthread_set_priority(task_handle, ADC_TASK_PRIO);
|
||||
}
|
||||
osal_kthread_unlock();
|
||||
}
|
||||
|
||||
/* Run the adc_entry. */
|
||||
app_run(adc_entry);
|
Reference in New Issue
Block a user