Skip to content

Commit c8db58a

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 80be486 commit c8db58a

File tree

1 file changed

+199
-0
lines changed

1 file changed

+199
-0
lines changed
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
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+
* It is Licensed as GNU LESSER GENERAL PUBLIC LICENSE Version 2.1
33+
34+
**2. Arduino-Core-Zephyr (Zephyr-Specific Implementation)**
35+
36+
The `Arduino-Core-Zephyr <https://github.com/zephyrproject-rtos/arduino-core-zephyr>`_ module
37+
provides the **Zephyr-specific implementation** of the Arduino API. This is where hardware-dependent
38+
Arduino functions are implemented using Zephyr's native APIs and drivers.
39+
40+
Key characteristics:
41+
42+
* Contains the ``cores/arduino`` directory with Zephyr implementations (``zephyrCommon.cpp``, ``zephyrSerial.cpp``, etc.)
43+
* Provides board-specific variants with pin mappings and Device Tree overlays
44+
* Includes Zephyr build system integration (CMake, Kconfig, west.yml)
45+
* Links to ArduinoCore-API to inherit the common implementations
46+
* See the `project documentation <https://github.com/zephyrproject-rtos/arduino-core-zephyr/tree/main/documentation>`_ for implementation details
47+
* It is Licensed under Apache-2.0
48+
49+
Features Provided
50+
=================
51+
52+
Together, these components provide:
53+
54+
* Standard Arduino API functions like ``pinMode()``, ``digitalWrite()``, ``analogRead()``, etc.
55+
* Support for Arduino-style ``setup()`` and ``loop()`` functions
56+
* Pin mapping between Arduino pin numbers and Zephyr's GPIO definitions
57+
* Support for common Arduino communication protocols (Serial, I2C, SPI)
58+
* Compatibility with existing Arduino libraries
59+
* Board variant support for various hardware platforms already present in Zephyr
60+
61+
By bringing Arduino-style programming to Zephyr, this module provides a gentler learning curve
62+
for those transitioning from Arduino to Zephyr while still benefiting from Zephyr's advanced
63+
features, scalability, and broad hardware support.
64+
65+
Usage with Zephyr
66+
*****************
67+
68+
Adding the Arduino Core API to a Zephyr Project
69+
===============================================
70+
71+
#. To pull in the Arduino Core for Zephyr as a Zephyr module, either add it as
72+
a West project in the west.yaml file or pull it in by adding a submanifest
73+
(e.g. ``zephyr/submanifests/arduino-core.yaml``) file with the following content
74+
and run west update:
75+
76+
.. code-block:: yaml
77+
78+
# Arduino API repository
79+
- name: Arduino-Core-Zephyr
80+
path: modules/lib/arduinocore-zephyr
81+
revision: main
82+
url: https://github.com/zephyrproject-rtos/arduino-core-zephyr
83+
84+
#. Run the following command to update your project:
85+
86+
.. code-block:: bash
87+
88+
west update
89+
90+
#. For Linux users, there's an ``install.sh`` script in the module that will automatically
91+
link the ArduinoCore-API. If you can't use this script, follow the manual steps below.
92+
93+
.. note::
94+
95+
Skip the next step if the install.sh script succeeded. The next step is for Linux
96+
users who may have a difference in where the module is installed or have some custom
97+
Zephyr setup with custom paths.
98+
99+
#. Complete the core setup by linking the API folder from the ArduinoCore-API repository into
100+
the arduinocore-zephyr folder:
101+
102+
.. code-block:: bash
103+
104+
git clone https://github.com/arduino/ArduinoCore-API # Any location
105+
cd /<path>/<to>/<zephyrproject>/modules/lib/arduinocore-zephyr
106+
ln -s /<your>/<location>/arduinocore-zephyr/api cores/arduino/.
107+
108+
The ``cores`` folder is located inside ``<zephyr-project-path>/modules/lib/arduinocore-zephyr/cores``.
109+
110+
Using Arduino Core API in Your Application
111+
==========================================
112+
113+
#. In your application's ``prj.conf`` file, enable the Arduino API configs similar to how it's being
114+
done in the `blinky_arduino sample`_.
115+
116+
#. Create your application using Arduino-style code:
117+
118+
.. code-block:: cpp
119+
120+
#include <Arduino.h>
121+
122+
void setup() {
123+
pinMode(LED_BUILTIN, OUTPUT);
124+
}
125+
126+
void loop() {
127+
digitalWrite(LED_BUILTIN, HIGH);
128+
delay(1000);
129+
digitalWrite(LED_BUILTIN, LOW);
130+
delay(1000);
131+
}
132+
133+
#. Build your application with the target board:
134+
135+
.. code-block:: bash
136+
137+
west build -b <board_name> path/to/your/app
138+
139+
Supported Boards
140+
================
141+
142+
The Arduino Core API module currently has variants for these boards:
143+
144+
* :zephyr:board:`arduino_mkrzero`
145+
* :zephyr:board:`arduino_nano_33_ble` (including Sense variant)
146+
* :zephyr:board:`arduino_nano_33_iot`
147+
* :zephyr:board:`beagleconnect_freedom`
148+
* :zephyr:board:`cc3220sf_launchxl`
149+
* :zephyr:board:`nrf52840dk`
150+
* :zephyr:board:`rpi_pico`
151+
152+
Adding Custom Board Support
153+
===========================
154+
155+
To add support for a custom board:
156+
157+
#. Create a new folder in the ``variants/`` directory with your board's name
158+
#. Add an overlay file and a pinmap header file that match the board name
159+
#. Add your new headerfile to an ``#ifdef`` statement in the ``variant.h`` file
160+
161+
For detailed instructions on adding board variants, refer to the `board variants documentation`_.
162+
163+
Using External Arduino Libraries
164+
================================
165+
166+
To use external Arduino libraries with your Zephyr project:
167+
168+
#. Add your library's source files (e.g., ``MyLibrary.h`` and ``MyLibrary.cpp``) to your project's ``src`` folder
169+
#. Update your application's ``CMakeLists.txt`` to include these files:
170+
171+
.. code-block:: cmake
172+
173+
target_sources(app PRIVATE src/MyLibrary.cpp)
174+
175+
#. Include the library in your source code:
176+
177+
.. code-block:: cpp
178+
179+
#include "MyLibrary.h"
180+
181+
For more details on using external libraries, see the `Arduino libraries documentation`_.
182+
183+
References
184+
**********
185+
186+
#. `Arduino-Core-Zephyr GitHub Repository`_
187+
#. `ArduinoCore-API Repository`_
188+
#. `Golioth Article: Zephyr + Arduino: a Google Summer of Code story`_
189+
190+
.. target-notes::
191+
192+
.. _Arduino Core API: https://github.com/zephyrproject-rtos/arduino-core-zephyr
193+
.. _board variants documentation: https://github.com/zephyrproject-rtos/arduino-core-zephyr/blob/main/documentation/variants.md
194+
.. _Arduino libraries documentation: https://github.com/zephyrproject-rtos/arduino-core-zephyr/blob/main/documentation/arduino_libs.md
195+
.. _Arduino-Core-Zephyr GitHub Repository: https://github.com/zephyrproject-rtos/arduino-core-zephyr
196+
.. _ArduinoCore-API Repository: https://github.com/arduino/ArduinoCore-API
197+
.. _Google Summer of Code 2022 project: https://dhruvag2000.github.io/Blog-GSoC22/
198+
.. _Golioth Article\: Zephyr + Arduino\: a Google Summer of Code story: https://blog.golioth.io/zephyr-arduino-a-google-summer-of-code-story/
199+
.. _blinky_arduino sample: https://github.com/zephyrproject-rtos/arduino-core-zephyr/blob/next/samples/blinky_arduino/prj.conf

0 commit comments

Comments
 (0)