-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadc_demo.c
More file actions
95 lines (85 loc) · 3.25 KB
/
Copy pathadc_demo.c
File metadata and controls
95 lines (85 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*****************************************************************/ /**
* @file adc_demo.c
* @brief
* @author bronson.zhan@quectel.com
* @date 2025-04-28
*
* @copyright Copyright (c) 2023 Quectel Wireless Solution, Co., Ltd.
* All Rights Reserved. Quectel Wireless Solution Proprietary and Confidential.
*
* @par EDIT HISTORY FOR MODULE
* <table>
* <tr><th>Date <th>Version <th>Author <th>Description
* <tr><td>2025-04-28 <td>1.0 <td>Bronson.Zhan <td> Init
* </table>
**********************************************************************/
#include "qosa_sys.h"
#include "qosa_adc.h"
#include "qosa_def.h"
#include "qosa_log.h"
#include "adc_demo.h"
#include "unirtos_app_init_registry.h"
/*===========================================================================
* Macro Definition
===========================================================================*/
#define QOS_LOG_TAG LOG_TAG_DEMO
/*===========================================================================
* Variate
===========================================================================*/
static qosa_task_t g_unir_adc_demo_task = QOSA_NULL;
/*===========================================================================
* Static API Functions
===========================================================================*/
/**
* @brief ADC processing function
*
* This function continuously reads voltage values from ADC0 and ADC1 channels
* and performs measurements at different scale ranges.
* The function iterates through all available ADC scale ranges, sets the scale,
* reads the voltage value, and prints logs.
*
* @note Note: Not all platforms support scale setting
*/
static void unir_adc_demo_process(void *ctx)
{
int adc_val = 0;
qosa_adc_aux_scale_e adc_scale = QOSA_ADC_SCALE_LEVEL_0;
while (1)
{
// Iterate through all ADC scale levels
for (adc_scale = QOSA_ADC_SCALE_LEVEL_0; adc_scale < QOSA_ADC_SCALE_MAX; adc_scale++)
{
// Set scale for ADC0 and ADC1 channels
qosa_adc_ioctl(QOSA_ADC0_CHANNEL, QOSA_ADC_IOCTL_SET_SCALE, (void *)&adc_scale);
qosa_adc_ioctl(QOSA_ADC1_CHANNEL, QOSA_ADC_IOCTL_SET_SCALE, (void *)&adc_scale);
// Read ADC0 channel voltage value and print
qosa_adc_get_volt(QOSA_ADC0_CHANNEL, &adc_val);
QLOGD("QOSA_ADC0_CHANNEL val: %d\r\n", adc_val);
// Read ADC1 channel voltage value and print
qosa_adc_get_volt(QOSA_ADC1_CHANNEL, &adc_val);
QLOGD("QOSA_ADC1_CHANNEL val: %d\r\n", adc_val);
// Delay 2 seconds before next measurement
qosa_task_sleep_ms(2000);
}
}
}
/*===========================================================================
* Public API Functions
===========================================================================*/
void unir_adc_demo_init(void)
{
QLOGV("enter UniRTOS ADC DEMO !!!");
if (g_unir_adc_demo_task == QOSA_NULL)
{
qosa_task_create(
&g_unir_adc_demo_task,
CONFIG_UNIRTOS_ADC_DEMO_TASK_STACK_SIZE,
UNIR_ADC_DEMO_TASK_PRIO,
"adc_demo",
unir_adc_demo_process,
QOSA_NULL,
1
);
}
}
UNIRTOS_APP_EXPORT(130, "adc_demo", unir_adc_demo_init);