Skip to content

Commit 846f871

Browse files
authored
Initial commit
0 parents  commit 846f871

File tree

9 files changed

+204
-0
lines changed

9 files changed

+204
-0
lines changed

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Prerequisites
2+
*.d
3+
4+
# Compiled Object files
5+
*.slo
6+
*.lo
7+
*.o
8+
*.obj
9+
10+
# Precompiled Headers
11+
*.gch
12+
*.pch
13+
14+
# Compiled Dynamic libraries
15+
*.so
16+
*.dylib
17+
*.dll
18+
19+
# Fortran module files
20+
*.mod
21+
*.smod
22+
23+
# Compiled Static libraries
24+
*.lai
25+
*.la
26+
*.a
27+
*.lib
28+
29+
# Executables
30+
*.exe
31+
*.out
32+
*.app
33+
build/
34+
sdkconfig
35+
sdkconfig.old

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "components/espp"]
2+
path = components/espp
3+
url = git@github.com:esp-cpp/espp

CMakeLists.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# The following lines of boilerplate have to be in your project's CMakeLists
2+
# in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.5)
4+
5+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
6+
7+
# add the component directories that we want to use
8+
set(EXTRA_COMPONENT_DIRS
9+
"components/"
10+
"components/espp/components/"
11+
)
12+
13+
set(
14+
COMPONENTS
15+
# TODO: add additional esp-idf and espp components you want to use to the line below:
16+
"main esptool_py logger task"
17+
CACHE STRING
18+
"List of components to include"
19+
)
20+
21+
# TODO: update this with your project's name
22+
project(template)
23+
24+
set(CMAKE_CXX_STANDARD 20)

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 esp-cpp
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# ESP++ Template
2+
3+
Template repository for building an ESP app with ESP++ (espp) components and
4+
ESP-IDF components.
5+
6+
## Development
7+
8+
This repository is designed to be used as a template repository - so you can
9+
sepcify this as the template repository type when creating a new repository on
10+
GitHub.
11+
12+
After setting this as the template, make sure to update the following:
13+
- [This README](./README.md) to contain the relevant description and images of your project
14+
- The [./CMakeLists.txt](./CMakeLists.txt) file to have the components that you
15+
want to use (and any you may have added to the [components
16+
folder](./components)) as well as to update the project name
17+
- The [./main/main.cpp](./main/main.cpp) To run the main code for your app. The
18+
[main folder](./main) is also where you can put additional header and source
19+
files that you don't think belong in their own components but help keep the
20+
main code clean.
21+
22+
## Cloning
23+
24+
Since this repo contains a submodule, you need to make sure you clone it
25+
recursively, e.g. with:
26+
27+
``` sh
28+
git clone --recurse-submodules <your repo name>
29+
```
30+
31+
Alternatively, you can always ensure the submodules are up to date after cloning
32+
(or if you forgot to clone recursively) by running:
33+
34+
``` sh
35+
git submodule update --init --recursive
36+
```
37+
38+
## Build and Flash
39+
40+
Build the project and flash it to the board, then run monitor tool to view serial output:
41+
42+
```
43+
idf.py -p PORT flash monitor
44+
```
45+
46+
(Replace PORT with the name of the serial port to use.)
47+
48+
(To exit the serial monitor, type ``Ctrl-]``.)
49+
50+
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
51+
52+
## Output
53+
54+
Example screenshot of the console output from this app:
55+
56+
![CleanShot 2023-07-12 at 14 01 21](https://github.com/esp-cpp/template/assets/213467/7f8abeae-121b-4679-86d8-7214a76f1b75)

components/espp

Submodule espp added at c9b6fc7

main/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
idf_component_register(SRC_DIRS "."
2+
INCLUDE_DIRS ".")

main/main.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <chrono>
2+
#include <thread>
3+
4+
#include "logger.hpp"
5+
#include "task.hpp"
6+
7+
using namespace std::chrono_literals;
8+
9+
extern "C" void app_main(void) {
10+
static auto start = std::chrono::high_resolution_clock::now();
11+
static auto elapsed = [&]() {
12+
auto now = std::chrono::high_resolution_clock::now();
13+
return std::chrono::duration<float>(now - start).count();
14+
};
15+
16+
espp::Logger logger({.tag = "Template", .level = espp::Logger::Verbosity::DEBUG});
17+
18+
logger.info("Bootup");
19+
20+
// make a simple task that prints "Hello World!" every second
21+
espp::Task task({
22+
.name = "Hello World",
23+
.callback = [&](auto &m, auto &cv) -> bool {
24+
logger.debug("[{:.3f}] Hello from the task!", elapsed());
25+
std::unique_lock<std::mutex> lock(m);
26+
cv.wait_for(lock, 1s);
27+
// we don't want to stop the task, so return false
28+
return false;
29+
},
30+
.stack_size_bytes = 4096,
31+
});
32+
task.start();
33+
34+
// also print in the main thread
35+
while (true) {
36+
logger.debug("[{:.3f}] Hello World!", elapsed());
37+
std::this_thread::sleep_for(1s);
38+
}
39+
}

sdkconfig.defaults

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# TODO: uncomment one of these if you want to support a specifc target by default
2+
# CONFIG_IDF_TARGET="esp32"
3+
# CONFIG_IDF_TARGET="esp32s2"
4+
# CONFIG_IDF_TARGET="esp32s3"
5+
# CONFIG_IDF_TARGET="esp32c3"
6+
7+
# TODO: uncomment if you want freertos to run at 1 khz instead of the default 100 hz
8+
# CONFIG_FREERTOS_HZ=1000
9+
10+
# TODO: uncomment if you want to run the esp at max clock speed (240 mhz)
11+
# ESP32-specific
12+
#
13+
# CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y
14+
# CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ=240
15+
16+
# TODO: uncomment if you want to update the event and main task stask sizes
17+
# Common ESP-related
18+
#
19+
# CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=4096
20+
# CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192
21+
22+
# TODO: uncomment if you want to enable exceptions (which may be needed by certain components such as cli)
23+
# CONFIG_COMPILER_CXX_EXCEPTIONS=y

0 commit comments

Comments
 (0)