Skip to content

Commit a466b81

Browse files
committed
Add ADC example application files
Signed-off-by: Ajay Bhargav <ajay.bhargav@waybyte.in>
1 parent bd8205c commit a466b81

File tree

6 files changed

+277
-0
lines changed

6 files changed

+277
-0
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.pio
2+
.vscode/.browse.c_cpp.db*
3+
.vscode/c_cpp_properties.json
4+
.vscode/launch.json
5+
.vscode/ipch

include/README

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
This directory is intended for project header files.
3+
4+
A header file is a file containing C declarations and macro definitions
5+
to be shared between several project source files. You request the use of a
6+
header file in your project source file (C, C++, etc) located in `src` folder
7+
by including it, with the C preprocessing directive `#include'.
8+
9+
```src/main.c
10+
11+
#include "header.h"
12+
13+
int main (void)
14+
{
15+
...
16+
}
17+
```
18+
19+
Including a header file produces the same results as copying the header file
20+
into each source file that needs it. Such copying would be time-consuming
21+
and error-prone. With a header file, the related declarations appear
22+
in only one place. If they need to be changed, they can be changed in one
23+
place, and programs that include the header file will automatically use the
24+
new version when next recompiled. The header file eliminates the labor of
25+
finding and changing all the copies as well as the risk that a failure to
26+
find one copy will result in inconsistencies within a program.
27+
28+
In C, the usual convention is to give header files names that end with `.h'.
29+
It is most portable to use only letters, digits, dashes, and underscores in
30+
header file names, and at most one dot.
31+
32+
Read more about using header files in official GCC documentation:
33+
34+
* Include Syntax
35+
* Include Operation
36+
* Once-Only Headers
37+
* Computed Includes
38+
39+
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

lib/README

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
2+
This directory is intended for project specific (private) libraries.
3+
PlatformIO will compile them to static libraries and link into executable file.
4+
5+
The source code of each library should be placed in a an own separate directory
6+
("lib/your_library_name/[here are source files]").
7+
8+
For example, see a structure of the following two libraries `Foo` and `Bar`:
9+
10+
|--lib
11+
| |
12+
| |--Bar
13+
| | |--docs
14+
| | |--examples
15+
| | |--src
16+
| | |- Bar.c
17+
| | |- Bar.h
18+
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
19+
| |
20+
| |--Foo
21+
| | |- Foo.c
22+
| | |- Foo.h
23+
| |
24+
| |- README --> THIS FILE
25+
|
26+
|- platformio.ini
27+
|--src
28+
|- main.c
29+
30+
and a contents of `src/main.c`:
31+
```
32+
#include <Foo.h>
33+
#include <Bar.h>
34+
35+
int main (void)
36+
{
37+
...
38+
}
39+
40+
```
41+
42+
PlatformIO Library Dependency Finder will find automatically dependent
43+
libraries scanning project source files.
44+
45+
More information about PlatformIO Library Dependency Finder
46+
- https://docs.platformio.org/page/librarymanager/ldf.html

platformio.ini

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
; PlatformIO Project Configuration File
2+
;
3+
; Build options: build flags, source filter
4+
; Upload options: custom upload port, speed and extra flags
5+
; Library options: dependencies, extra library storages
6+
; Advanced options: extra scripting
7+
;
8+
; Please visit documentation for the other options and examples
9+
; https://docs.platformio.org/page/projectconf.html
10+
11+
[env:ec200u]
12+
platform = logicrom
13+
board = ec200u
14+
framework = logicromsdk
15+
16+
[env:quectel_mc60]
17+
platform = logicrom
18+
board = quectelmc60
19+
framework = logicromsdk

src/main.c

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/**
2+
* @file main.c
3+
* @brief Exmaple application for ADC driver
4+
* @version 0.1
5+
* @date 2022-07-25
6+
*
7+
* @copyright Copyright (c) 2022 Waybyte Solutions
8+
*
9+
*/
10+
11+
#include <stdio.h>
12+
#include <unistd.h>
13+
14+
#include <lib.h>
15+
#include <ril.h>
16+
#include <os_api.h>
17+
#include <hw/adc.h>
18+
19+
#ifdef SOC_RDA8910
20+
#define STDIO_PORT "/dev/ttyUSB0"
21+
#else
22+
#define STDIO_PORT "/dev/ttyS0"
23+
#endif
24+
25+
/**
26+
* URC Handler
27+
* @param param1 URC Code
28+
* @param param2 URC Parameter
29+
*/
30+
static void urc_callback(unsigned int param1, unsigned int param2)
31+
{
32+
switch (param1) {
33+
case URC_SYS_INIT_STATE_IND:
34+
if (param2 == SYS_STATE_SMSOK) {
35+
/* Ready for SMS */
36+
}
37+
break;
38+
case URC_SIM_CARD_STATE_IND:
39+
switch (param2) {
40+
case SIM_STAT_NOT_INSERTED:
41+
debug(DBG_OFF, "SYSTEM: SIM card not inserted!\n");
42+
break;
43+
case SIM_STAT_READY:
44+
debug(DBG_INFO, "SYSTEM: SIM card Ready!\n");
45+
break;
46+
case SIM_STAT_PIN_REQ:
47+
debug(DBG_OFF, "SYSTEM: SIM PIN required!\n");
48+
break;
49+
case SIM_STAT_PUK_REQ:
50+
debug(DBG_OFF, "SYSTEM: SIM PUK required!\n");
51+
break;
52+
case SIM_STAT_NOT_READY:
53+
debug(DBG_OFF, "SYSTEM: SIM card not recognized!\n");
54+
break;
55+
default:
56+
debug(DBG_OFF, "SYSTEM: SIM ERROR: %d\n", param2);
57+
}
58+
break;
59+
case URC_GSM_NW_STATE_IND:
60+
debug(DBG_OFF, "SYSTEM: GSM NW State: %d\n", param2);
61+
break;
62+
case URC_GPRS_NW_STATE_IND:
63+
break;
64+
case URC_CFUN_STATE_IND:
65+
break;
66+
case URC_COMING_CALL_IND:
67+
debug(DBG_OFF, "Incoming voice call from: %s\n", ((struct ril_callinfo_t *)param2)->number);
68+
/* Take action here, Answer/Hang-up */
69+
break;
70+
case URC_CALL_STATE_IND:
71+
switch (param2) {
72+
case CALL_STATE_BUSY:
73+
debug(DBG_OFF, "The number you dialed is busy now\n");
74+
break;
75+
case CALL_STATE_NO_ANSWER:
76+
debug(DBG_OFF, "The number you dialed has no answer\n");
77+
break;
78+
case CALL_STATE_NO_CARRIER:
79+
debug(DBG_OFF, "The number you dialed cannot reach\n");
80+
break;
81+
case CALL_STATE_NO_DIALTONE:
82+
debug(DBG_OFF, "No Dial tone\n");
83+
break;
84+
default:
85+
break;
86+
}
87+
break;
88+
case URC_NEW_SMS_IND:
89+
debug(DBG_OFF, "SMS: New SMS (%d)\n", param2);
90+
/* Handle New SMS */
91+
break;
92+
case URC_MODULE_VOLTAGE_IND:
93+
debug(DBG_INFO, "VBatt Voltage: %d\n", param2);
94+
break;
95+
case URC_ALARM_RING_IND:
96+
break;
97+
case URC_FILE_DOWNLOAD_STATUS:
98+
break;
99+
case URC_FOTA_STARTED:
100+
break;
101+
case URC_FOTA_FINISHED:
102+
break;
103+
case URC_FOTA_FAILED:
104+
break;
105+
case URC_STKPCI_RSP_IND:
106+
break;
107+
default:
108+
break;
109+
}
110+
}
111+
112+
/**
113+
* Sample Task
114+
* @param arg Task Argument
115+
*/
116+
static void adc_task(void *arg)
117+
{
118+
/*
119+
* Configure ADC Channels
120+
*/
121+
adc_config(ADC_CH0);
122+
adc_config(ADC_CH1);
123+
adc_config(ADC_CH2);
124+
125+
while (1) {
126+
/*
127+
* Read ADC Channels
128+
*/
129+
printf("ADC Channel 0: %d, %dmV\n", adc_read(ADC_CH0), adc_read_mv(ADC_CH0));
130+
printf("ADC Channel 1: %d, %dmV\n", adc_read(ADC_CH1), adc_read_mv(ADC_CH1));
131+
printf("ADC Channel 2: %d, %dmV\n", adc_read(ADC_CH2), adc_read_mv(ADC_CH2));
132+
sleep(1);
133+
}
134+
}
135+
136+
/**
137+
* Application main entry point
138+
*/
139+
int main(int argc, char *argv[])
140+
{
141+
/*
142+
* Initialize library and Setup STDIO
143+
*/
144+
logicrom_init(STDIO_PORT, urc_callback);
145+
146+
printf("System Ready\n");
147+
148+
/* Create ADC task */
149+
os_task_create(adc_task, NULL, FALSE);
150+
151+
printf("System Initialization finished\n");
152+
153+
while (1) {
154+
/* main task loop */
155+
sleep(1);
156+
}
157+
}

test/README

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
This directory is intended for PlatformIO Test Runner and project tests.
3+
4+
Unit Testing is a software testing method by which individual units of
5+
source code, sets of one or more MCU program modules together with associated
6+
control data, usage procedures, and operating procedures, are tested to
7+
determine whether they are fit for use. Unit testing finds problems early
8+
in the development cycle.
9+
10+
More information about PlatformIO Unit Testing:
11+
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html

0 commit comments

Comments
 (0)