Initial commit

This commit is contained in:
2022-07-26 04:39:32 +02:00
commit 0750693641
26 changed files with 1783 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
build
main/build
sdkconfig.old
*.bak
*.old
.vscode

45
.gitmodules vendored Normal file
View File

@ -0,0 +1,45 @@
[submodule "esp-idf"]
path = esp-idf
url = https://github.com/espressif/esp-idf.git
[submodule "components/bus-i2c"]
path = components/bus-i2c
url = https://github.com/Nicolai-Electronics/esp32-component-bus-i2c.git
[submodule "components/i2c-bno055"]
path = components/i2c-bno055
url = https://github.com/Nicolai-Electronics/esp32-component-i2c-bno055.git
[submodule "components/spi-ili9341"]
path = components/spi-ili9341
url = https://github.com/Nicolai-Electronics/esp32-component-spi-ili9341.git
[submodule "components/spi-ice40"]
path = components/spi-ice40
url = https://github.com/Nicolai-Electronics/esp32-component-spi-ice40.git
[submodule "components/sdcard"]
path = components/sdcard
url = https://github.com/Nicolai-Electronics/esp32-component-sdcard.git
[submodule "components/pax-graphics"]
path = components/pax-graphics
url = https://github.com/robotman2412/pax-graphics.git
[submodule "components/mch2022-rp2040"]
path = components/mch2022-rp2040
url = https://github.com/badgeteam/esp32-component-mch2022-rp2040.git
[submodule "components/esp32-component-appfs"]
path = components/appfs
url = https://github.com/badgeteam/esp32-component-appfs.git
[submodule "components/ws2812"]
path = components/ws2812
url = https://github.com/badgeteam/esp32-component-ws2812.git
[submodule "components/mch2022-bsp"]
path = components/mch2022-bsp
url = https://github.com/badgeteam/esp32-component-mch2022-bsp.git
[submodule "components/pax-codecs"]
path = components/pax-codecs
url = https://github.com/robotman2412/pax-codecs.git
[submodule "main/pax-keyboard"]
path = components/pax-keyboard
url = https://github.com/robotman2412/pax-keyboard
[submodule "components/i2c-bme680"]
path = components/i2c-bme680
url = https://github.com/badgeteam/esp32-component-bme680.git
[submodule "tools"]
path = tools
url = https://github.com/badgeteam/mch2022-tools

8
CMakeLists.txt Normal file
View File

@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
set(PROJECT_NAME "MCH2022 launcher")
set(PROJECT_VER "0.1")
project(main)

28
Makefile Normal file
View File

@ -0,0 +1,28 @@
PORT ?= /dev/ttyACM0
BUILDDIR ?= build
IDF_PATH ?= $(shell pwd)/esp-idf
IDF_EXPORT_QUIET ?= 0
SHELL := /usr/bin/env bash
.PHONY: prepare clean build flash monitor menuconfig
all: prepare build install
prepare:
git submodule update --init --recursive
cd esp-idf; bash install.sh
clean:
rm -rf "$(BUILDDIR)"
build:
source "$(IDF_PATH)/export.sh" && idf.py build
install: build
python3 tools/webusb_push.py "Template App" build/main.bin --run
monitor:
source "$(IDF_PATH)/export.sh" && idf.py monitor -p $(PORT)
menuconfig:
source "$(IDF_PATH)/export.sh" && idf.py menuconfig

65
README.md Normal file
View File

@ -0,0 +1,65 @@
# MCH2022 template app
This repository contains a template app for the MCH2022 badge.
It is intended to be used as the basis for developing your own native ESP32
apps. See [Getting Started](https://badge.team/docs/badges/mch2022/software-development/esp-idf/esp_idf_getting_started/)
## License
The source code contained in the main folder of this example is public domain / CC0 licensed, use it as you please.
Source code included as submodules is licensed separately, please check the
following table for details.
| Submodule | License | Author |
|-----------------------------|-----------------------------------|--------------------------------------------------------|
| esp-idf | Apache License 2.0 | Espressif Systems (Shanghai) CO LTD |
| components/appfs | THE BEER-WARE LICENSE Revision 42 | Jeroen Domburg <jeroen@spritesmods.com> |
| components/bus-i2c | MIT | Nicolai Electronics |
| components/i2c-bno055 | MIT | Nicolai Electronics |
| components/mch2022-rp2040 | MIT | Renze Nicolai |
| components/pax-graphics | MIT | Julian Scheffers |
| components/pax-keyboard | MIT | Julian Scheffers |
| components/sdcard | MIT | Nicolai Electronics |
| components/spi-ice40 | MIT | Nicolai Electronics |
| components/spi-ili9341 | MIT | Nicolai Electronics |
| components/ws2812 | Unlicense / Public domain | None |
Source the `update_components.sh` to update all the submodules to their
corresponding tips.
## How to make
```sh
git clone --recursive https://github.com/badgeteam/mch2022-template-app
cd mch2022-template-app
make
```
The default target of the Makefile (the one executed if you just run `make`) installs the proper ESP-IDF version and all other dependencies, then builds the project and tries to install it on an attached Badge. Because this process checks all the dependencies for updates, this can become tedious during development, so you'll probably want to execute specific targets:
- prepare : this is (one of) the targets executed in the default task and the one that, technically, only needs to run once to install dependencies
- clean : clean the build environment. This does NOT clean up installed dependencies.
- build : well ... build. Compiles you sources and assembles a binary to install.
- install : This install the binary that was build, you can only call `install`, it depends on `build`. *Note* installation is not and SHOULD NOT be performed with the typical `idf.py flash` call, see the note below for details.
- monitor : start the serial monitor to examine log output
- menuconfig : The IDF build system has a fairly elaborate configuration system that can be accessed via `menuconfig`. You'll know if you need it. Or try it out to explore.
### Note: Why not to use `idf.py flash` to install my native app.
If you have previously used the IDF, you may have noticed that we dont use
`idf.py flash` to install the app on the Badge. (And if you havent, you can
safely skip this section. :)
The `idf.py flash` command assumes that the binary to flash is the main (and
only) application for the device. This is not the case for the Badge, though.
The main application is the launcher app, i.e. the app with the menu that
starts by default. The `make install` target of the Makefile copies our newly
created app into the
[appfs](https://github.com/badgeteam/esp32-component-appfThe Makefile cs)
instead of overwriting the launcher. Once copied to the appfs, the launcher can
find your app and it should appear in the apps menu.
Obviously you _can_ use idf.py flash but youll delete the launcher app and would
need to reinstall it later.

1
components/appfs Submodule

Submodule components/appfs added at b20b1d8f4d

1
components/bus-i2c Submodule

Submodule components/bus-i2c added at f775f174c3

1
components/i2c-bme680 Submodule

Submodule components/i2c-bme680 added at 97cd2137cb

1
components/i2c-bno055 Submodule

Submodule components/i2c-bno055 added at e7c1f4eb8c

1
components/pax-codecs Submodule

Submodule components/pax-codecs added at d8a9ad7253

1
components/sdcard Submodule

Submodule components/sdcard added at 2b6630e85e

1
components/spi-ice40 Submodule

Submodule components/spi-ice40 added at 7e2bdc0f1d

1
components/ws2812 Submodule

Submodule components/ws2812 added at 4236aa600d

1
esp-idf Submodule

Submodule esp-idf added at 1329b19fe4

11
main/CMakeLists.txt Normal file
View File

@ -0,0 +1,11 @@
# This example code is in the Public Domain (or CC0 licensed, at your option.)
# Unless required by applicable law or agreed to in writing, this
# software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied.
idf_component_register(
SRCS
"main.c"
INCLUDE_DIRS
"." "include"
)

36
main/include/main.h Normal file
View File

@ -0,0 +1,36 @@
/*
* This example code is in the Public Domain (or CC0 licensed, at your option.)
* Unless required by applicable law or agreed to in writing, this
* software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied.
*/
#pragma once
// For pin mappings.
#include "hardware.h"
// For graphics.
#include "pax_gfx.h"
// For PNG images.
#include "pax_codecs.h"
// The screen driver.
#include "ili9341.h"
// For all system settings and alike.
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "esp_system.h"
#include "nvs.h"
#include "nvs_flash.h"
// For WiFi connectivity.
#include "wifi_connect.h"
#include "wifi_connection.h"
// For exiting to the launcher.
#include "soc/rtc.h"
#include "soc/rtc_cntl_reg.h"
// Updates the screen with the last drawing.
void disp_flush();
// Exits the app, returning to the launcher.
void exit_to_launcher();

101
main/main.c Normal file
View File

@ -0,0 +1,101 @@
/*
* This example code is in the Public Domain (or CC0 licensed, at your option.)
* Unless required by applicable law or agreed to in writing, this
* software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied.
*/
// This file contains a simple Hello World app which you can base you own
// native Badge apps on.
#include "main.h"
static pax_buf_t buf;
xQueueHandle buttonQueue;
#include <esp_log.h>
static const char *TAG = "mch2022-demo-app";
// Updates the screen with the latest buffer.
void disp_flush() {
ili9341_write(get_ili9341(), buf.buf);
}
// Exits the app, returning to the launcher.
void exit_to_launcher() {
REG_WRITE(RTC_CNTL_STORE0_REG, 0);
esp_restart();
}
void app_main() {
ESP_LOGI(TAG, "Welcome to the template app!");
// Initialize the screen, the I2C and the SPI busses.
bsp_init();
// Initialize the RP2040 (responsible for buttons, etc).
bsp_rp2040_init();
// This queue is used to receive button presses.
buttonQueue = get_rp2040()->queue;
// Initialize graphics for the screen.
pax_buf_init(&buf, NULL, 320, 240, PAX_BUF_16_565RGB);
// Initialize NVS.
nvs_flash_init();
// Initialize WiFi. This doesn't connect to Wifi yet.
wifi_init();
while (1) {
// Pick a random background color.
int hue = esp_random() & 255;
pax_col_t col = pax_col_hsv(hue, 255 /*saturation*/, 255 /*brighness*/);
// Greet the World in front of a random background color!
// Fill the background with the random color.
pax_background(&buf, col);
// This text is shown on screen.
char *text = "Hello, MCH2022!";
// Pick the font (Saira is the only one that looks nice in this size).
const pax_font_t *font = pax_font_saira_condensed;
// Determine how the text dimensions so we can display it centered on
// screen.
pax_vec1_t dims = pax_text_size(font, font->default_size, text);
// Draw the centered text.
pax_draw_text(
&buf, // Buffer to draw to.
0xff000000, // color
font, font->default_size, // Font and size to use.
// Position (top left corner) of the app.
(buf.width - dims.x) / 2.0,
(buf.height - dims.y) / 2.0,
// The text to be rendered.
text
);
// Draws the entire graphics buffer to the screen.
disp_flush();
// Wait for button presses and do another cycle.
// Structure used to receive data.
rp2040_input_message_t message;
// Wait forever for a button press (because of portMAX_DELAY)
xQueueReceive(buttonQueue, &message, portMAX_DELAY);
// Which button is currently pressed?
if (message.input == RP2040_INPUT_BUTTON_HOME && message.state) {
// If home is pressed, exit to launcher.
exit_to_launcher();
}
}
}

4
partitions.csv Normal file
View File

@ -0,0 +1,4 @@
nvs, data, nvs, 0x9000, 16K,
phy_init, data, phy, 0xF000, 4K,
factory, app, factory, , 5M,
locfd, data, fat, , 10M,
1 nvs data nvs 0x9000 16K
2 phy_init data phy 0xF000 4K
3 factory app factory 5M
4 locfd data fat 10M

1444
sdkconfig Normal file

File diff suppressed because it is too large Load Diff

1
tools Submodule

Submodule tools added at bef7edfe70

20
update_components.sh Normal file
View File

@ -0,0 +1,20 @@
BASE=`pwd`
for component in appfs bus-i2c i2c-bno055 mch2022-bsp mch2022-rp2040 sdcard spi-ice40 spi-ili9341 ws2812; do
cd $BASE/components/$component
git checkout master
git pull
cd $BASE
done
for component in i2c-bme680 pax-codecs pax-graphics pax-keyboard; do
cd $BASE/components/$component
git checkout main
git pull
cd $BASE
done
cd $BASE/tools
git checkout master
git pull
cd $BASE