Skip to content

Commit b12ebeb

Browse files
committed
example: Add GPIO Blink example
Signed-off-by: Ajay Bhargav <[email protected]>
1 parent 968b1b2 commit b12ebeb

File tree

8 files changed

+354
-0
lines changed

8 files changed

+354
-0
lines changed

examples/gpio-blink/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.pio
2+
.vscode
3+
.pioenvs
4+
.piolibdeps

examples/gpio-blink/.travis.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Continuous Integration (CI) is the practice, in software
2+
# engineering, of merging all developer working copies with a shared mainline
3+
# several times a day < https://docs.platformio.org/page/ci/index.html >
4+
#
5+
# Documentation:
6+
#
7+
# * Travis CI Embedded Builds with PlatformIO
8+
# < https://docs.travis-ci.com/user/integration/platformio/ >
9+
#
10+
# * PlatformIO integration with Travis CI
11+
# < https://docs.platformio.org/page/ci/travis.html >
12+
#
13+
# * User Guide for `platformio ci` command
14+
# < https://docs.platformio.org/page/userguide/cmd_ci.html >
15+
#
16+
#
17+
# Please choose one of the following templates (proposed below) and uncomment
18+
# it (remove "# " before each line) or use own configuration according to the
19+
# Travis CI documentation (see above).
20+
#
21+
22+
23+
#
24+
# Template #1: General project. Test it using existing `platformio.ini`.
25+
#
26+
27+
# language: python
28+
# python:
29+
# - "2.7"
30+
#
31+
# sudo: false
32+
# cache:
33+
# directories:
34+
# - "~/.platformio"
35+
#
36+
# install:
37+
# - pip install -U platformio
38+
# - platformio update
39+
#
40+
# script:
41+
# - platformio run
42+
43+
44+
#
45+
# Template #2: The project is intended to be used as a library with examples.
46+
#
47+
48+
# language: python
49+
# python:
50+
# - "2.7"
51+
#
52+
# sudo: false
53+
# cache:
54+
# directories:
55+
# - "~/.platformio"
56+
#
57+
# env:
58+
# - PLATFORMIO_CI_SRC=path/to/test/file.c
59+
# - PLATFORMIO_CI_SRC=examples/file.ino
60+
# - PLATFORMIO_CI_SRC=path/to/test/directory
61+
#
62+
# install:
63+
# - pip install -U platformio
64+
# - platformio update
65+
#
66+
# script:
67+
# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N

examples/gpio-blink/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

examples/gpio-blink/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

examples/gpio-blink/platformio.ini

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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:s20gsm]
12+
platform = siwigsm
13+
board = s20gsm
14+
framework = siwisdk
15+
monitor_speed = 115200

examples/gpio-blink/readme.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
How to build
2+
============
3+
4+
1. Install `Visual Studio Code <https://code.visualstudio.com/>`_
5+
2. Install `PlatformIO Extension for VSCode <https://platformio.org/platformio-ide>`_
6+
3. Install SiWi GSM Platform:
7+
* Open PlatformIO Home
8+
* Go to Platforms -> Advanced Installation
9+
* Paste repository link https://github.com/siwiembedded/platform-siwigsm.git
10+
* Click Install
11+
4. Download and Extract examples from github https://github.com/siwiembedded/siwigsm/archive/master.zip
12+
5. Extract and Open example folder with _VSCode_
13+
6. Run following command:
14+
.. code-block:: bash
15+
# Build Project
16+
$ platformio run
17+
18+
# Upload Project
19+
$ platformio run --target upload

examples/gpio-blink/src/main.c

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/**
2+
* @file main.c
3+
* GPIO Blink Project example
4+
* @author Ajay Bhargav
5+
*
6+
*/
7+
8+
#include <stdio.h>
9+
#include <unistd.h>
10+
11+
#include <lib.h>
12+
#include <ril.h>
13+
#include <os_api.h>
14+
#include <hw/gpio.h>
15+
16+
/**
17+
* Configure GPIO to test
18+
*/
19+
#define BLINK_GPIO GPIO_1
20+
21+
/**
22+
* URC Handler
23+
* @param param1 URC Code
24+
* @param param2 URC Parameter
25+
*/
26+
static void urc_callback(unsigned int param1, unsigned int param2)
27+
{
28+
switch (param1) {
29+
case URC_SYS_INIT_STATE_IND:
30+
if (param2 == SYS_STATE_SMSOK) {
31+
/* Ready for SMS */
32+
}
33+
break;
34+
case URC_SIM_CARD_STATE_IND:
35+
switch (param2) {
36+
case SIM_STAT_NOT_INSERTED:
37+
debug(DBG_OFF, "SYSTEM: SIM card not inserted!\n");
38+
break;
39+
case SIM_STAT_READY:
40+
debug(DBG_INFO, "SYSTEM: SIM card Ready!\n");
41+
break;
42+
case SIM_STAT_PIN_REQ:
43+
debug(DBG_OFF, "SYSTEM: SIM PIN required!\n");
44+
break;
45+
case SIM_STAT_PUK_REQ:
46+
debug(DBG_OFF, "SYSTEM: SIM PUK required!\n");
47+
break;
48+
case SIM_STAT_NOT_READY:
49+
debug(DBG_OFF, "SYSTEM: SIM card not recognized!\n");
50+
break;
51+
default:
52+
debug(DBG_OFF, "SYSTEM: SIM ERROR: %d\n", param2);
53+
}
54+
break;
55+
case URC_GSM_NW_STATE_IND:
56+
debug(DBG_OFF, "SYSTEM: GSM NW State: %d\n", param2);
57+
break;
58+
case URC_GPRS_NW_STATE_IND:
59+
break;
60+
case URC_CFUN_STATE_IND:
61+
break;
62+
case URC_COMING_CALL_IND:
63+
debug(DBG_OFF, "Incoming voice call from: %s\n", ((ST_ComingCall*)param2)->phoneNumber);
64+
/* Take action here, Answer/Hang-up */
65+
break;
66+
case URC_CALL_STATE_IND:
67+
switch (param2) {
68+
case CALL_STATE_BUSY:
69+
debug(DBG_OFF, "The number you dialed is busy now\n");
70+
break;
71+
case CALL_STATE_NO_ANSWER:
72+
debug(DBG_OFF, "The number you dialed has no answer\n");
73+
break;
74+
case CALL_STATE_NO_CARRIER:
75+
debug(DBG_OFF, "The number you dialed cannot reach\n");
76+
break;
77+
case CALL_STATE_NO_DIALTONE:
78+
debug(DBG_OFF, "No Dial tone\n");
79+
break;
80+
default:
81+
break;
82+
}
83+
break;
84+
case URC_NEW_SMS_IND:
85+
debug(DBG_OFF, "SMS: New SMS (%d)\n", param2);
86+
/* Handle New SMS */
87+
break;
88+
case URC_MODULE_VOLTAGE_IND:
89+
debug(DBG_INFO, "VBatt Voltage: %d\n", param2);
90+
break;
91+
case URC_ALARM_RING_IND:
92+
break;
93+
case URC_FILE_DOWNLOAD_STATUS:
94+
break;
95+
case URC_FOTA_STARTED:
96+
break;
97+
case URC_FOTA_FINISHED:
98+
break;
99+
case URC_FOTA_FAILED:
100+
break;
101+
case URC_STKPCI_RSP_IND:
102+
break;
103+
default:
104+
break;
105+
}
106+
}
107+
108+
/**
109+
* GPIO Blink Task
110+
* @param arg Task Argument
111+
*/
112+
static void gpio_blink_task(void *arg)
113+
{
114+
/*
115+
* Request GPIO as Output and Default Low
116+
*/
117+
int handle = gpio_request(BLINK_GPIO, GPIO_FLAG_OUTPUT | GPIO_FLAG_DEFLOW);
118+
119+
/*
120+
* Check for error
121+
*/
122+
if (handle <= 0) {
123+
printf("GPIO request failed: %d\n", handle);
124+
return;
125+
}
126+
127+
while (1) {
128+
/* GPIO write high */
129+
gpio_write(handle, GPIO_LEVEL_HIGH);
130+
sleep(1);
131+
/* GPIO write low */
132+
gpio_write(handle, GPIO_LEVEL_LOW);
133+
sleep(1);
134+
}
135+
}
136+
137+
/**
138+
* Application main entry point
139+
*/
140+
void user_main(void)
141+
{
142+
/*
143+
* Initialize library and Setup STDIO
144+
*/
145+
siwilib_init("/dev/ttyS0", urc_callback);
146+
147+
printf("System Ready\n");
148+
149+
/* Create Application tasks */
150+
os_create_task(gpio_blink_task, NULL, FALSE);
151+
152+
printf("System Initialization finished\n");
153+
}

examples/gpio-blink/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 PIO Unit Testing 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 PIO Unit Testing:
11+
- https://docs.platformio.org/page/plus/unit-testing.html

0 commit comments

Comments
 (0)