Skip to content

Commit 982677b

Browse files
committed
doc: develop: manifests: external: add arduino core
Add documentation for the Arduino Core API for zephyr which sits as an external module as of today. Signed-off-by: Dhruva Gole <d-gole@ti.com>
1 parent 282e2c7 commit 982677b

File tree

1 file changed

+194
-0
lines changed

1 file changed

+194
-0
lines changed
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
.. _external_module_arduino_core_api:
2+
3+
Arduino Core API
4+
################
5+
6+
Introduction
7+
************
8+
9+
The Arduino-Core-Zephyr module started as a `Google Summer of Code 2022 project`_
10+
to provide Arduino-style APIs for Zephyr RTOS applications. This module acts as an abstraction
11+
layer, allowing developers familiar with Arduino programming to leverage Zephyr's capabilities
12+
without having to learn entirely new APIs and libraries.
13+
14+
Understanding the Components
15+
============================
16+
17+
This module consists of two key components that work together:
18+
19+
**1. ArduinoCore-API (Common Arduino API Definition)**
20+
21+
The `ArduinoCore-API <https://github.com/arduino/ArduinoCore-API>`_ is Arduino's official
22+
hardware abstraction layer that defines the common Arduino API. It contains the abstract API
23+
definitions **and** implementations for hardware-independent functionality.
24+
25+
Key characteristics:
26+
27+
* Contains both API definitions (headers) and hardware-agnostic implementations
28+
* Provides classes like ``String``, ``Print``, ``Stream``, ``IPAddress`` with full implementations
29+
* Defines interfaces for hardware-specific classes (e.g., ``HardwareSerial``, ``HardwareSPI``)
30+
* Shared across all modern Arduino platforms for consistency
31+
* See the `ArduinoCore-API README <https://github.com/arduino/ArduinoCore-API#arduinocore-api>`_ for implementation details
32+
33+
**2. Arduino-Core-Zephyr (Zephyr-Specific Implementation)**
34+
35+
The `Arduino-Core-Zephyr <https://github.com/zephyrproject-rtos/arduino-core-zephyr>`_ module
36+
provides the **Zephyr-specific implementation** of the Arduino API. This is where hardware-dependent
37+
Arduino functions are implemented using Zephyr's native APIs and drivers.
38+
39+
Key characteristics:
40+
41+
* Contains the ``cores/arduino`` directory with Zephyr implementations (``zephyrCommon.cpp``, ``zephyrSerial.cpp``, etc.)
42+
* Provides board-specific variants with pin mappings and Device Tree overlays
43+
* Includes Zephyr build system integration (CMake, Kconfig, west.yml)
44+
* Links to ArduinoCore-API to inherit the common implementations
45+
* See the `project documentation <https://github.com/zephyrproject-rtos/arduino-core-zephyr/tree/main/documentation>`_ for implementation details
46+
47+
Features Provided
48+
=================
49+
50+
Together, these components provide:
51+
52+
* Standard Arduino API functions like ``pinMode()``, ``digitalWrite()``, ``analogRead()``, etc.
53+
* Support for Arduino-style ``setup()`` and ``loop()`` functions
54+
* Pin mapping between Arduino pin numbers and Zephyr's GPIO definitions
55+
* Support for common Arduino communication protocols (Serial, I2C, SPI)
56+
* Compatibility with existing Arduino libraries
57+
* Board variant support for various hardware platforms already present in Zephyr
58+
59+
By bringing Arduino-style programming to Zephyr, this module provides a gentler learning curve
60+
for those transitioning from Arduino to Zephyr while still benefiting from Zephyr's advanced
61+
features, scalability, and broad hardware support.
62+
63+
Usage with Zephyr
64+
*****************
65+
66+
Adding the Arduino Core API to a Zephyr Project
67+
===============================================
68+
69+
#. To pull in the Arduino Core for Zephyr as a Zephyr module, either add it as
70+
a West project in the west.yaml file or pull it in by adding a submanifest
71+
(e.g. ``zephyr/submanifests/arduino-core.yaml``) file with the following content
72+
and run west update:
73+
74+
.. code-block:: yaml
75+
76+
# Arduino API repository
77+
- name: Arduino-Core-Zephyr
78+
path: modules/lib/arduinocore-zephyr
79+
revision: main
80+
url: https://github.com/zephyrproject-rtos/arduino-core-zephyr
81+
82+
#. Run the following command to update your project:
83+
84+
.. code-block:: bash
85+
86+
west update
87+
88+
#. For Linux users, there's an ``install.sh`` script in the module that will automatically
89+
link the ArduinoCore-API. If you can't use this script, follow the manual steps below.
90+
91+
#. Complete the core setup by linking the API folder from the ArduinoCore-API repository into
92+
the arduinocore-zephyr folder:
93+
94+
.. code-block:: bash
95+
96+
git clone https://github.com/arduino/ArduinoCore-API # Any location
97+
cd /<path>/<to>/<zephyrproject>/modules/lib/arduinocore-zephyr
98+
ln -s /<your>/<location>/arduinocore-zephyr/api cores/arduino/.
99+
100+
The ``cores`` folder is located inside ``<zephyr-project-path>/modules/lib/arduinocore-zephyr/cores``.
101+
102+
Using Arduino Core API in Your Application
103+
==========================================
104+
105+
#. In your application's ``prj.conf`` file, enable the Arduino API:
106+
107+
.. code-block:: cfg
108+
109+
CONFIG_GPIO=y
110+
CONFIG_ARDUINO_API=y
111+
112+
#. Create your application using Arduino-style code:
113+
114+
.. code-block:: cpp
115+
116+
#include <Arduino.h>
117+
118+
void setup() {
119+
pinMode(LED_BUILTIN, OUTPUT);
120+
}
121+
122+
void loop() {
123+
digitalWrite(LED_BUILTIN, HIGH);
124+
delay(1000);
125+
digitalWrite(LED_BUILTIN, LOW);
126+
delay(1000);
127+
}
128+
129+
#. Build your application with the target board:
130+
131+
.. code-block:: bash
132+
133+
west build -b <board_name> path/to/your/app
134+
135+
Supported Boards
136+
================
137+
138+
The Arduino Core API module currently has variants for these boards:
139+
140+
* :zephyr:board:`arduino_mkrzero`
141+
* :zephyr:board:`arduino_nano_33_ble` (including Sense variant)
142+
* :zephyr:board:`arduino_nano_33_iot`
143+
* :zephyr:board:`beagleconnect_freedom`
144+
* :zephyr:board:`cc3220sf_launchxl`
145+
* :zephyr:board:`nrf52840dk`
146+
* :zephyr:board:`rpi_pico`
147+
148+
Adding Custom Board Support
149+
===========================
150+
151+
To add support for a custom board:
152+
153+
#. Create a new folder in the ``variants/`` directory with your board's name
154+
#. Add an overlay file and a pinmap header file that match the board name
155+
#. Add your new headerfile to an ``#ifdef`` statement in the ``variant.h`` file
156+
157+
For detailed instructions on adding board variants, refer to the `board variants documentation`_.
158+
159+
Using External Arduino Libraries
160+
================================
161+
162+
To use external Arduino libraries with your Zephyr project:
163+
164+
#. Add your library's source files (e.g., ``MyLibrary.h`` and ``MyLibrary.cpp``) to your project's ``src`` folder
165+
#. Update your application's ``CMakeLists.txt`` to include these files:
166+
167+
.. code-block:: cmake
168+
169+
target_sources(app PRIVATE src/MyLibrary.cpp)
170+
171+
#. Include the library in your source code:
172+
173+
.. code-block:: cpp
174+
175+
#include "MyLibrary.h"
176+
177+
For more details on using external libraries, see the `Arduino libraries documentation`_.
178+
179+
References
180+
**********
181+
182+
#. `Arduino-Core-Zephyr GitHub Repository`_
183+
#. `ArduinoCore-API Repository`_
184+
#. `Golioth Article: Zephyr + Arduino: a Google Summer of Code story`_
185+
186+
.. target-notes::
187+
188+
.. _Arduino Core API: https://github.com/zephyrproject-rtos/arduino-core-zephyr
189+
.. _board variants documentation: https://github.com/zephyrproject-rtos/arduino-core-zephyr/blob/main/documentation/variants.md
190+
.. _Arduino libraries documentation: https://github.com/zephyrproject-rtos/arduino-core-zephyr/blob/main/documentation/arduino_libs.md
191+
.. _Arduino-Core-Zephyr GitHub Repository: https://github.com/zephyrproject-rtos/arduino-core-zephyr
192+
.. _ArduinoCore-API Repository: https://github.com/arduino/ArduinoCore-API
193+
.. _Google Summer of Code 2022 project: https://dhruvag2000.github.io/Blog-GSoC22/
194+
.. _Golioth Article\: Zephyr + Arduino\: a Google Summer of Code story: https://blog.golioth.io/zephyr-arduino-a-google-summer-of-code-story/

0 commit comments

Comments
 (0)