-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Add Arduino as Component examples #8878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
me-no-dev
merged 11 commits into
espressif:master
from
P-R-O-C-H-Y:component-template-example
Nov 29, 2023
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3cac2bf
Example for IDF component registry
P-R-O-C-H-Y 244c15b
Added readme
P-R-O-C-H-Y c4a499a
updated readme
P-R-O-C-H-Y 24e635d
Merge branch 'master' into component-template-example
P-R-O-C-H-Y 8ca7476
remove idf dependency
P-R-O-C-H-Y 2109d48
add empty lines on file end
P-R-O-C-H-Y 81aec6f
idf_component.yml version change
P-R-O-C-H-Y 81cce0c
Updated readme for local development
P-R-O-C-H-Y ca82405
Merge branch 'master' into component-template-example
SuGlider 8cf40d8
Merge branch 'master' into component-template-example
P-R-O-C-H-Y 818fdea
Merge branch 'master' into component-template-example
SuGlider File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,4 +65,6 @@ dependencies: | |
version: "^1.4.2" | ||
rules: | ||
- if: "target in [esp32s3]" | ||
examples: | ||
- path: ../idf_component_examples/ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# For more information about build system see | ||
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html | ||
# The following five lines of boilerplate have to be in your project's | ||
# CMakeLists in this exact order for cmake to work correctly | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
project(main) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 | | ||
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- | | ||
|
||
# _Hello world example_ | ||
|
||
This is the simplest buildable example made to be used as a template for new projects running Arduino-esp32 as an ESP-IDF component. | ||
See [Arduino-esp32](https://components.espressif.com/components/espressif/arduino-esp32) in ESP Registry. | ||
|
||
## How to use example | ||
|
||
To create a ESP-IDF project from this example with the latest relase of Arduino-esp32, you can simply run command: `idf.py create-project-from-example "espressif/arduino-esp32:hello_world"`. | ||
ESP-IDF will download all dependencies needed from the component registry and setup the project for you. | ||
|
||
If you want to use cloned Arduino-esp32 repository, you can build this example directly. | ||
Go to the example folder `arduino-esp32/idf_component_examples/Hello_world`. | ||
First you need to comment line 6 `pre_release: true` in examples `/main/idf_component.yml`. | ||
Then just run command: `idf.py build`. | ||
|
||
## Example folder contents | ||
|
||
The project **Hello_world** contains one source file in C++ language [main.cpp](main/main.cpp). The file is located in folder [main](main). | ||
|
||
ESP-IDF projects are built using CMake. The project build configuration is contained in `CMakeLists.txt` | ||
files that provide set of directives and instructions describing the project's source files and targets | ||
(executable, library, or both). | ||
|
||
Below is short explanation of remaining files in the project folder. | ||
|
||
``` | ||
├── CMakeLists.txt | ||
├── main | ||
│ ├── CMakeLists.txt | ||
│ ├── idf_component.yml | ||
│ └── main.cpp | ||
└── README.md This is the file you are currently reading | ||
``` | ||
|
||
## How to add Arduino libraries | ||
|
||
In the project create folder `components/` and clone the library there. | ||
In the library folder create new CMakeLists.txt file, add lines shown below to the file and edit the SRCS to match the library source files. | ||
|
||
``` | ||
idf_component_register(SRCS "user_library.cpp" "another_source.c" | ||
INCLUDE_DIRS "." | ||
REQUIRES arduino-esp32 | ||
) | ||
``` | ||
|
||
Below is structure of the project folder with the Arduino libraries. | ||
|
||
``` | ||
├── CMakeLists.txt | ||
├── components | ||
│ ├── user_library | ||
│ │ ├── CMakeLists.txt This needs to be added | ||
│ │ ├── ... | ||
├── main | ||
│ ├── CMakeLists.txt | ||
│ ├── idf_component.yml | ||
│ └── main.cpp | ||
└── README.md This is the file you are currently reading | ||
``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
idf_component_register(SRCS "main.cpp" | ||
INCLUDE_DIRS ".") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
## IDF Component Manager Manifest File | ||
dependencies: | ||
espressif/arduino-esp32: | ||
version: '*' | ||
override_path: '../../../' | ||
pre_release: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include "Arduino.h" | ||
|
||
void setup(){ | ||
Serial.begin(115200); | ||
} | ||
|
||
void loop(){ | ||
Serial.println("Hello world!"); | ||
delay(1000); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# | ||
# Arduino ESP32 | ||
# | ||
CONFIG_AUTOSTART_ARDUINO=y | ||
# end of Arduino ESP32 | ||
|
||
# | ||
# FREERTOS | ||
# | ||
CONFIG_FREERTOS_HZ=1000 | ||
# end of FREERTOS | ||
# end of Component config |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tested it in a separated folder.
It is also necessary to comment out the line 5
override_path: '../../../'
as it may not exist.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it should be removed by the ESP Registry so if you get it from there as an example, this won't exist. On other components it is done same way, for development purposes. If I understood correctly :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't test it using the ESP component registry, but just copying it to my
~userName
folder and then running it fromidf.py flash
.Let's publish it and then we can test it with the ESP Registry tool. As you said it should work fine.
Some users may try it doing the same I did. This is the reason for the comment.