From 3cac2bf7a438099f205d92fea11c4de43eb8516c Mon Sep 17 00:00:00 2001 From: Jan Prochazka <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 13 Nov 2023 10:50:02 +0100 Subject: [PATCH 1/7] Example for IDF component registry --- idf_component.yml | 2 ++ idf_component_examples/Hello_world/CMakeLists.txt | 8 ++++++++ .../Hello_world/main/CMakeLists.txt | 2 ++ .../Hello_world/main/idf_component.yml | 6 ++++++ idf_component_examples/Hello_world/main/main.cpp | 10 ++++++++++ .../Hello_world/sdkconfig.defaults | 12 ++++++++++++ 6 files changed, 40 insertions(+) create mode 100644 idf_component_examples/Hello_world/CMakeLists.txt create mode 100644 idf_component_examples/Hello_world/main/CMakeLists.txt create mode 100644 idf_component_examples/Hello_world/main/idf_component.yml create mode 100644 idf_component_examples/Hello_world/main/main.cpp create mode 100644 idf_component_examples/Hello_world/sdkconfig.defaults diff --git a/idf_component.yml b/idf_component.yml index c9367c676aa..d3f5126be7c 100644 --- a/idf_component.yml +++ b/idf_component.yml @@ -39,4 +39,6 @@ dependencies: version: "^1.4.2" rules: - if: "target in [esp32s3]" +examples: + - path: ../idf_component_examples/ diff --git a/idf_component_examples/Hello_world/CMakeLists.txt b/idf_component_examples/Hello_world/CMakeLists.txt new file mode 100644 index 00000000000..664d45871d0 --- /dev/null +++ b/idf_component_examples/Hello_world/CMakeLists.txt @@ -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) diff --git a/idf_component_examples/Hello_world/main/CMakeLists.txt b/idf_component_examples/Hello_world/main/CMakeLists.txt new file mode 100644 index 00000000000..5c66350a0cf --- /dev/null +++ b/idf_component_examples/Hello_world/main/CMakeLists.txt @@ -0,0 +1,2 @@ +idf_component_register(SRCS "main.cpp" + INCLUDE_DIRS ".") \ No newline at end of file diff --git a/idf_component_examples/Hello_world/main/idf_component.yml b/idf_component_examples/Hello_world/main/idf_component.yml new file mode 100644 index 00000000000..f23e6fa0aad --- /dev/null +++ b/idf_component_examples/Hello_world/main/idf_component.yml @@ -0,0 +1,6 @@ +## IDF Component Manager Manifest File +dependencies: + espressif/arduino-esp32: + version: '>=3.0.0-aplha2' + override_path: '../../../' + idf: ">=5.1" \ No newline at end of file diff --git a/idf_component_examples/Hello_world/main/main.cpp b/idf_component_examples/Hello_world/main/main.cpp new file mode 100644 index 00000000000..a3f6a679aa1 --- /dev/null +++ b/idf_component_examples/Hello_world/main/main.cpp @@ -0,0 +1,10 @@ +#include "Arduino.h" + +void setup(){ + Serial.begin(115200); +} + +void loop(){ + Serial.println("Hello world!"); + delay(1000); +} \ No newline at end of file diff --git a/idf_component_examples/Hello_world/sdkconfig.defaults b/idf_component_examples/Hello_world/sdkconfig.defaults new file mode 100644 index 00000000000..123868187e8 --- /dev/null +++ b/idf_component_examples/Hello_world/sdkconfig.defaults @@ -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 \ No newline at end of file From 244c15b0c959ab21fa14b96c25322e90648147ad Mon Sep 17 00:00:00 2001 From: Jan Prochazka <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 13 Nov 2023 10:50:16 +0100 Subject: [PATCH 2/7] Added readme --- idf_component_examples/Hello_world/README.md | 45 ++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 idf_component_examples/Hello_world/README.md diff --git a/idf_component_examples/Hello_world/README.md b/idf_component_examples/Hello_world/README.md new file mode 100644 index 00000000000..9e42f62ef39 --- /dev/null +++ b/idf_component_examples/Hello_world/README.md @@ -0,0 +1,45 @@ +| 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 `arduino-esp32/idf_component_examples/Hello_world` folder and 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 +│   └── 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 an + +idf_component_register(SRCS "new_library.cpp" "another_source.c" + INCLUDE_DIRS "." + REQUIRES arduino-esp32 + ) + +For more informations check [Documentation - Adding arduino library](https://espressif-docs.readthedocs-hosted.com/projects/arduino-esp32/en/latest/esp-idf_component.html#adding-arduino-library) \ No newline at end of file From c4a499a389cb280926dbab695d06b940ddb761b5 Mon Sep 17 00:00:00 2001 From: Jan Prochazka <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Mon, 13 Nov 2023 11:05:19 +0100 Subject: [PATCH 3/7] updated readme --- idf_component_examples/Hello_world/README.md | 22 ++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/idf_component_examples/Hello_world/README.md b/idf_component_examples/Hello_world/README.md index 9e42f62ef39..7d3214e8d99 100644 --- a/idf_component_examples/Hello_world/README.md +++ b/idf_component_examples/Hello_world/README.md @@ -12,7 +12,7 @@ To create a ESP-IDF project from this example with the latest relase of Arduino- 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 `arduino-esp32/idf_component_examples/Hello_world` folder and run command: `idf.py build`. +Go to the example folder `arduino-esp32/idf_component_examples/Hello_world` and run command: `idf.py build`. ## Example folder contents @@ -35,11 +35,25 @@ Below is short explanation of remaining files in the project folder. ## 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 an +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 "new_library.cpp" "another_source.c" +``` +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. -For more informations check [Documentation - Adding arduino library](https://espressif-docs.readthedocs-hosted.com/projects/arduino-esp32/en/latest/esp-idf_component.html#adding-arduino-library) \ No newline at end of file +``` +├── CMakeLists.txt +├── components +│   ├── user_library +│   │   ├── CMakeLists.txt This needs to be added +│   │   ├── ... +├── main +│   ├── CMakeLists.txt +│   └── main.cpp +└── README.md This is the file you are currently reading +``` \ No newline at end of file From 8ca74765363329ff6c97d63d5d1122c1c059db6e Mon Sep 17 00:00:00 2001 From: Jan Prochazka <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Tue, 14 Nov 2023 12:46:24 +0100 Subject: [PATCH 4/7] remove idf dependency --- idf_component_examples/Hello_world/main/idf_component.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/idf_component_examples/Hello_world/main/idf_component.yml b/idf_component_examples/Hello_world/main/idf_component.yml index f23e6fa0aad..554205d90c9 100644 --- a/idf_component_examples/Hello_world/main/idf_component.yml +++ b/idf_component_examples/Hello_world/main/idf_component.yml @@ -3,4 +3,3 @@ dependencies: espressif/arduino-esp32: version: '>=3.0.0-aplha2' override_path: '../../../' - idf: ">=5.1" \ No newline at end of file From 2109d4809f85033beb9bfa3d7270fe98f7706a34 Mon Sep 17 00:00:00 2001 From: Jan Prochazka <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Tue, 14 Nov 2023 12:46:42 +0100 Subject: [PATCH 5/7] add empty lines on file end --- idf_component_examples/Hello_world/main/CMakeLists.txt | 2 +- idf_component_examples/Hello_world/main/main.cpp | 2 +- idf_component_examples/Hello_world/sdkconfig.defaults | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/idf_component_examples/Hello_world/main/CMakeLists.txt b/idf_component_examples/Hello_world/main/CMakeLists.txt index 5c66350a0cf..9eb7ec47a07 100644 --- a/idf_component_examples/Hello_world/main/CMakeLists.txt +++ b/idf_component_examples/Hello_world/main/CMakeLists.txt @@ -1,2 +1,2 @@ idf_component_register(SRCS "main.cpp" - INCLUDE_DIRS ".") \ No newline at end of file + INCLUDE_DIRS ".") diff --git a/idf_component_examples/Hello_world/main/main.cpp b/idf_component_examples/Hello_world/main/main.cpp index a3f6a679aa1..450fa4078f5 100644 --- a/idf_component_examples/Hello_world/main/main.cpp +++ b/idf_component_examples/Hello_world/main/main.cpp @@ -7,4 +7,4 @@ void setup(){ void loop(){ Serial.println("Hello world!"); delay(1000); -} \ No newline at end of file +} diff --git a/idf_component_examples/Hello_world/sdkconfig.defaults b/idf_component_examples/Hello_world/sdkconfig.defaults index 123868187e8..bb723653f8a 100644 --- a/idf_component_examples/Hello_world/sdkconfig.defaults +++ b/idf_component_examples/Hello_world/sdkconfig.defaults @@ -9,4 +9,4 @@ CONFIG_AUTOSTART_ARDUINO=y # CONFIG_FREERTOS_HZ=1000 # end of FREERTOS -# end of Component config \ No newline at end of file +# end of Component config From 81aec6f2426fa45ca343cb75ba89dfc6e73b3099 Mon Sep 17 00:00:00 2001 From: Jan Prochazka <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Tue, 14 Nov 2023 13:47:35 +0100 Subject: [PATCH 6/7] idf_component.yml version change --- idf_component_examples/Hello_world/main/idf_component.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/idf_component_examples/Hello_world/main/idf_component.yml b/idf_component_examples/Hello_world/main/idf_component.yml index 554205d90c9..42e1b06e52d 100644 --- a/idf_component_examples/Hello_world/main/idf_component.yml +++ b/idf_component_examples/Hello_world/main/idf_component.yml @@ -1,5 +1,6 @@ ## IDF Component Manager Manifest File dependencies: espressif/arduino-esp32: - version: '>=3.0.0-aplha2' + version: '*' override_path: '../../../' + pre_release: true From 81cce0c8bbfb82d353b0f377605e0460ace36958 Mon Sep 17 00:00:00 2001 From: Jan Prochazka <90197375+P-R-O-C-H-Y@users.noreply.github.com> Date: Tue, 14 Nov 2023 13:47:48 +0100 Subject: [PATCH 7/7] Updated readme for local development --- idf_component_examples/Hello_world/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/idf_component_examples/Hello_world/README.md b/idf_component_examples/Hello_world/README.md index 7d3214e8d99..e4fcc16ff34 100644 --- a/idf_component_examples/Hello_world/README.md +++ b/idf_component_examples/Hello_world/README.md @@ -12,7 +12,9 @@ To create a ESP-IDF project from this example with the latest relase of Arduino- 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` and run command: `idf.py build`. +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 @@ -28,6 +30,7 @@ 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 ``` @@ -54,6 +57,7 @@ Below is structure of the project folder with the Arduino libraries. │   │   ├── ... ├── main │   ├── CMakeLists.txt +│ ├── idf_component.yml │   └── main.cpp └── README.md This is the file you are currently reading ``` \ No newline at end of file