From a18221db08332f33fb8dd826c9b5068abfc73a05 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sat, 14 Dec 2024 21:50:02 +0100 Subject: [PATCH] Tactility SDK and release build scripting (#122) * Implement release scripting and SDK building process * Fix for CYD display colors * Various improvements and fixes * Made build scripts more modular --- .gitignore | 2 + .../YellowBoard/Source/hal/YellowDisplay.cpp | 4 +- Buildscripts/CMake/CMakeLists.txt | 17 ++++++ Buildscripts/CMake/TactilitySDK.cmake | 19 +++++++ Buildscripts/Flashing/flash.ps1 | 20 +++++++ Buildscripts/Flashing/flash.sh | 41 ++++++++++++++ Buildscripts/build-and-release-all.sh | 35 ++++++++++++ Buildscripts/build.sh | 38 +++++++++++++ clean.sh => Buildscripts/clean.sh | 3 +- Buildscripts/release-sdk-current.sh | 9 +++ Buildscripts/release-sdk.sh | 52 ++++++++++++++++++ Buildscripts/release.sh | 55 +++++++++++++++++++ runtests.sh => Buildscripts/runtests.sh | 2 + CMakeLists.txt | 3 +- ExternalApps/HelloWorld/CMakeLists.txt | 21 ++++--- ExternalApps/HelloWorld/main/CMakeLists.txt | 12 +--- ExternalApps/HelloWorld/sdkconfig.override | 1 + README.md | 16 ++++-- .../Source/service/statusbar/Statusbar.cpp | 6 +- build.sh | 8 --- run.sh | 12 ---- version.txt | 1 + 22 files changed, 324 insertions(+), 53 deletions(-) create mode 100644 Buildscripts/CMake/CMakeLists.txt create mode 100644 Buildscripts/CMake/TactilitySDK.cmake create mode 100644 Buildscripts/Flashing/flash.ps1 create mode 100755 Buildscripts/Flashing/flash.sh create mode 100755 Buildscripts/build-and-release-all.sh create mode 100755 Buildscripts/build.sh rename clean.sh => Buildscripts/clean.sh (79%) create mode 100755 Buildscripts/release-sdk-current.sh create mode 100755 Buildscripts/release-sdk.sh create mode 100755 Buildscripts/release.sh rename runtests.sh => Buildscripts/runtests.sh (91%) delete mode 100755 build.sh delete mode 100755 run.sh create mode 100644 version.txt diff --git a/.gitignore b/.gitignore index d37e9ba4..5bbe365c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ cmake-build-*/ CMakeCache.txt *.cbp +release/ + sdkconfig sdkconfig.old diff --git a/Boards/YellowBoard/Source/hal/YellowDisplay.cpp b/Boards/YellowBoard/Source/hal/YellowDisplay.cpp index 17705773..da346750 100644 --- a/Boards/YellowBoard/Source/hal/YellowDisplay.cpp +++ b/Boards/YellowBoard/Source/hal/YellowDisplay.cpp @@ -72,7 +72,7 @@ bool YellowDisplay::start() { const esp_lcd_panel_dev_config_t panel_config = { .reset_gpio_num = GPIO_NUM_NC, - .rgb_ele_order = LCD_RGB_ELEMENT_ORDER_RGB, + .rgb_ele_order = LCD_RGB_ELEMENT_ORDER_BGR, .data_endian = LCD_RGB_DATA_ENDIAN_LITTLE, .bits_per_pixel = TWODOTFOUR_LCD_BITS_PER_PIXEL, .flags = { @@ -123,7 +123,7 @@ bool YellowDisplay::start() { .buff_dma = true, .buff_spiram = false, .sw_rotate = false, - .swap_bytes = false + .swap_bytes = true } }; diff --git a/Buildscripts/CMake/CMakeLists.txt b/Buildscripts/CMake/CMakeLists.txt new file mode 100644 index 00000000..e2e5a18c --- /dev/null +++ b/Buildscripts/CMake/CMakeLists.txt @@ -0,0 +1,17 @@ +idf_component_register( + INCLUDE_DIRS "Libraries/Tactility/Include" "Libraries/lvgl/Include" +) + +add_prebuilt_library(Tactility Libraries/Tactility/Binary/libTactility.a) +add_prebuilt_library(TactilityC Libraries/Tactility/Binary/libTactilityC.a) +add_prebuilt_library(TactilityCore Libraries/Tactility/Binary/libTactilityCore.a) +add_prebuilt_library(TactilityHeadless Libraries/Tactility/Binary/libTactilityHeadless.a) +add_prebuilt_library(elf_loader Libraries/elf_loader/Binary/libelf_loader.a) +add_prebuilt_library(lvgl Libraries/lvgl/Binary/liblvgl.a) + +target_link_libraries(${COMPONENT_LIB} INTERFACE TactilityC) +target_link_libraries(${COMPONENT_LIB} INTERFACE Tactility) +target_link_libraries(${COMPONENT_LIB} INTERFACE TactilityHeadless) +target_link_libraries(${COMPONENT_LIB} INTERFACE TactilityCore) +target_link_libraries(${COMPONENT_LIB} INTERFACE lvgl) +target_link_libraries(${COMPONENT_LIB} INTERFACE elf_loader) diff --git a/Buildscripts/CMake/TactilitySDK.cmake b/Buildscripts/CMake/TactilitySDK.cmake new file mode 100644 index 00000000..346d50cf --- /dev/null +++ b/Buildscripts/CMake/TactilitySDK.cmake @@ -0,0 +1,19 @@ +function(tactility_project) +endfunction() + +function(_tactility_project) +endfunction() + +macro(tactility_project project_name) + set(TACTILITY_SKIP_SPIFFS 1) + add_definitions(-DESP_TARGET) + add_compile_definitions(ESP_TARGET) + + include("${TACTILITY_SDK_PATH}/Libraries/elf_loader/elf_loader.cmake") + project_elf($project_name) + + file(READ ${TACTILITY_SDK_PATH}/idf-version.txt TACTILITY_SDK_IDF_VERSION) + if (NOT "$ENV{ESP_IDF_VERSION}" STREQUAL "${TACTILITY_SDK_IDF_VERSION}") + message(FATAL_ERROR "ESP-IDF version of Tactility SDK (${TACTILITY_SDK_IDF_VERSION}) does not match current ESP-IDF version ($ENV{ESP_IDF_VERSION})") + endif() +endmacro() diff --git a/Buildscripts/Flashing/flash.ps1 b/Buildscripts/Flashing/flash.ps1 new file mode 100644 index 00000000..8bbccd72 --- /dev/null +++ b/Buildscripts/Flashing/flash.ps1 @@ -0,0 +1,20 @@ +param( + $port +) + +if ((Get-Command "esptool.py" -ErrorAction SilentlyContinue) -eq $null) +{ + Write-Host "Unable to find esptool.py in your path. Make sure you have Python installed and on your path. Then run `pip install esptool`." +} + + +# Create flash command based on partitions +$json = Get-Content .\build\flasher_args.json -Raw | ConvertFrom-Json +$jsonClean = $json.flash_files -replace '[\{\}\@\;]', '' +$jsonClean = $jsonClean -replace '[\=]', ' ' + +cd Binaries +$command = "esptool.py --connect-attemps 10 --port $port -b 460800 write_flash $jsonClean" +Invoke-Expression $command +cd .. + diff --git a/Buildscripts/Flashing/flash.sh b/Buildscripts/Flashing/flash.sh new file mode 100755 index 00000000..33919268 --- /dev/null +++ b/Buildscripts/Flashing/flash.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# Usage: +# flash.sh [port] +# +# Arguments: +# port - the port of the device (e.g. /dev/ttyUSB0, ...) +# +# Requirements: +# jq - run 'pip install jq' +# esptool.py - run 'pip install esptool' +# +# Documentation: +# https://docs.espressif.com/projects/esptool/en/latest/esp32/ +# + +# Source: https://stackoverflow.com/a/53798785 +function is_bin_in_path { + builtin type -P "$1" &> /dev/null +} + +function require_bin { + program=$1 + tip=$2 + if ! is_bin_in_path $program; then + echo -e "\e[31m⚠️ $program not found!\n\t$tip\e[0m" + fi +} + +require_bin esptool.py "install esptool from your package manager or install python and run 'pip install esptool'" +require_bin jq "install jq from your package manager or install python and run 'pip install jq'" + +if [[ $1 -eq 0 ]]; then + echo -e "\e[31m⚠️ Must Specify port as argument. For example:\n\tflash.sh /dev/ttyACM0\n\tflash.sh /dev/ttyUSB0\e[0m" + exit -1 +fi + +cd Binaries +# Create flash command based on partitions +KEY_VALUES=`jq -r '.flash_files | keys[] as $k | "\($k) \(.[$k])"' flasher_args.json | tr "\n" " "` +esptool.py --port $1 --connect-attempts 10 -b 460800 write_flash $KEY_VALUES diff --git a/Buildscripts/build-and-release-all.sh b/Buildscripts/build-and-release-all.sh new file mode 100755 index 00000000..878139b0 --- /dev/null +++ b/Buildscripts/build-and-release-all.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +function build() { + Buildscripts/build.sh $1 +} + +function release() { + Buildscripts/release.sh $1 +} + +function releaseSdk() { + Buildscripts/release-sdk.sh $1 +} + +SECONDS=0 + +build lilygo_tdeck +release lilygo_tdeck + +releaseSdk release/Tactility-ESP32S3-SDK/TactilitySDK + +build yellow_board +release yellow_board + +releaseSdk release/Tactility-ESP32-SDK/TactilitySDK + +build m5stack_core2 +release m5stack_core2 + +build m5stack_cores3 +release m5stack_cores3 + +duration=$SECONDS + +echo "Finished in $((duration / 60)) minutes and $((duration % 60)) seconds." \ No newline at end of file diff --git a/Buildscripts/build.sh b/Buildscripts/build.sh new file mode 100755 index 00000000..b8d42da5 --- /dev/null +++ b/Buildscripts/build.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# +# Usage: build.sh [boardname] +# Example: build.sh lilygo_tdeck +# Description: Makes a clean build for the specified board. +# + +echoNewPhase() { + echo -e "⏳ \e[36m${1}\e[0m" +} + +fatalError() { + echo -e "⚠️ \e[31m${1}\e[0m" + exit 0 +} + +sdkconfig_file="sdkconfig.board.${1}" + +if [ $# -lt 1 ]; then + fatalError "Must pass board name as first argument. (e.g. lilygo_tdeck)" +fi + +if [ ! -f $sdkconfig_file ]; then + fatalError "Board not found: ${sdkconfig_file}" +fi + +echoNewPhase "Cleaning build folder" + +rm -rf build + +echoNewPhase "Building $sdkconfig_file" + +cp $sdkconfig_file sdkconfig +if not idf.py build; then + fatalError "Failed to build esp32s3 SDK" +fi + diff --git a/clean.sh b/Buildscripts/clean.sh similarity index 79% rename from clean.sh rename to Buildscripts/clean.sh index db2e54d0..02e7eae3 100755 --- a/clean.sh +++ b/Buildscripts/clean.sh @@ -1,4 +1,5 @@ -#!/bin/sh +#!/bin/sh + rm -rf build rm -rf build-sim rm -rf cmake-* diff --git a/Buildscripts/release-sdk-current.sh b/Buildscripts/release-sdk-current.sh new file mode 100755 index 00000000..6d27c001 --- /dev/null +++ b/Buildscripts/release-sdk-current.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# +# Description: Releases the current build files as an SDK in the specified folder. +# This deployment is used when compiling apps in ./ExternalApps +# + +./Buildscripts/release-sdk.sh release/TactilitySDK + diff --git a/Buildscripts/release-sdk.sh b/Buildscripts/release-sdk.sh new file mode 100755 index 00000000..7887218b --- /dev/null +++ b/Buildscripts/release-sdk.sh @@ -0,0 +1,52 @@ +#!/usr/bin/bash + +# +# Usage: release-sdk.sh [target_path] +# Example: release.sh release/TactilitySDK +# Description: Releases the current build files as an SDK in the specified folder. +# + +target_path=$1 + +mkdir -p $target_path + +build_dir=`pwd` +library_path=$target_path/Libraries + +cp version.txt $target_path + +# Tactility +tactility_library_path=$library_path/Tactility +mkdir -p $tactility_library_path/Binary +cp build/esp-idf/Tactility/libTactility.a $tactility_library_path/Binary/ +cp build/esp-idf/TactilityCore/libTactilityCore.a $tactility_library_path/Binary/ +cp build/esp-idf/TactilityHeadless/libTactilityHeadless.a $tactility_library_path/Binary/ +cp build/esp-idf/TactilityC/libTactilityC.a $tactility_library_path/Binary/ +mkdir -p $tactility_library_path/Include +find_target_dir=$build_dir/$tactility_library_path/Include/ +cd TactilityC/Source +echo To $find_target_dir +find -name '*.h' | cpio -pdm $find_target_dir +cd - + +# lvgl +lvgl_library_path=$library_path/lvgl +mkdir -p $lvgl_library_path/Binary +mkdir -p $lvgl_library_path/Include +cp build/esp-idf/lvgl/liblvgl.a $lvgl_library_path/Binary/ +find_target_dir=$build_dir/$lvgl_library_path/Include/ +cd Libraries/lvgl +find src/ -name '*.h' | cpio -pdm $find_target_dir +cd - +cp Libraries/lvgl/lvgl.h $find_target_dir +cp Libraries/lvgl_conf/lv_conf_kconfig.h $lvgl_library_path/Include/lv_conf.h + +# elf_loader +elf_loader_library_path=$library_path/elf_loader +mkdir -p $elf_loader_library_path/Binary +cp -r Libraries/elf_loader/elf_loader.cmake $elf_loader_library_path +cp -r build/esp-idf/elf_loader/libelf_loader.a $elf_loader_library_path/Binary + +cp Buildscripts/CMake/TactilitySDK.cmake $target_path/ +cp Buildscripts/CMake/CMakeLists.txt $target_path/ +echo -n $ESP_IDF_VERSION >> $target_path/idf-version.txt diff --git a/Buildscripts/release.sh b/Buildscripts/release.sh new file mode 100755 index 00000000..b0a5a581 --- /dev/null +++ b/Buildscripts/release.sh @@ -0,0 +1,55 @@ +#!/bin/bash + +# +# Usage: release.sh [boardname] +# Example: release.sh lilygo_tdeck +# Description: Releases the current build labeled as a release for the specified board name. +# + +echoNewPhase() { + echo -e "⏳ \e[36m${1}\e[0m" +} + +fatalError() { + echo -e "⚠️ \e[31m${1}\e[0m" + exit 0 +} + +releaseSymbols() { + target_path=$1 + echoNewPhase "Making symbols release at '$target_path'" + mkdir $target_path + cp build/*.elf $target_path/ +} + +release() { + target_path=$1 + echoNewPhase "Making release at '$target_path'" + + bin_path=$target_path/Binaries + mkdir -p $bin_path + mkdir -p $bin_path/partition_table + mkdir -p $bin_path/bootloader + cp build/*.bin $bin_path/ + cp build/bootloader/*.bin $bin_path/bootloader/ + cp build/partition_table/*.bin $bin_path/partition_table/ + cp build/flash_args $bin_path/ + cp build/flasher_args.json $bin_path/ + + cp Buildscripts/Flashing/* $target_path +} + +board=$1 +board_clean=${board/_/-} +release_path=release + +if [ $# -lt 1 ]; then + fatalError "Must pass board name as first argument. (e.g. lilygo_tdeck)" +fi + +if [ ! -f $sdkconfig_file ]; then + fatalError "Board not found: ${sdkconfig_file}" +fi + +release "${release_path}/Tactility-${board_clean}" +releaseSymbols "${release_path}/Tactility-${board_clean}-symbols" diff --git a/runtests.sh b/Buildscripts/runtests.sh similarity index 91% rename from runtests.sh rename to Buildscripts/runtests.sh index 2e3caac9..8c544c58 100755 --- a/runtests.sh +++ b/Buildscripts/runtests.sh @@ -1,3 +1,5 @@ +#!/bin/bash + cmake -S ./ -B build-sim cmake --build build-sim --target build-tests -j 14 build-sim/Tests/TactilityCore/TactilityCoreTests --exit diff --git a/CMakeLists.txt b/CMakeLists.txt index 4cb725c3..0485f478 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,8 @@ if (DEFINED ENV{ESP_IDF_VERSION}) add_compile_definitions(LV_CONF_PATH=${LVGL_CONFIG_FULL_PATH}/lv_conf_kconfig.h) idf_build_set_property(LINK_OPTIONS "-Wl,--wrap=esp_panic_handler" APPEND) - add_compile_definitions(TT_VERSION="alpha1") + file(READ version.txt TACTILITY_VERSION) + add_compile_definitions(TT_VERSION="$TACTILITY_VERSION") else() message("Building for sim target") endif() diff --git a/ExternalApps/HelloWorld/CMakeLists.txt b/ExternalApps/HelloWorld/CMakeLists.txt index d52c5f14..5ce61018 100644 --- a/ExternalApps/HelloWorld/CMakeLists.txt +++ b/ExternalApps/HelloWorld/CMakeLists.txt @@ -1,17 +1,16 @@ cmake_minimum_required(VERSION 3.20) -set(TACTILITY_SKIP_SPIFFS 1) -add_definitions(-DESP_TARGET) -add_compile_definitions(ESP_TARGET) - -add_definitions(-DLV_CONF_PATH=../../../Boards/Simulator/Source/lv_conf.h) - include($ENV{IDF_PATH}/tools/cmake/project.cmake) -set(EXTRA_COMPONENT_DIRS "../../Libraries/elf_loader") +if (DEFINED ENV{TACTILITY_SDK_PATH}) + set(TACTILITY_SDK_PATH $ENV{TACTILITY_SDK_PATH}) +else() + set(TACTILITY_SDK_PATH "../../release/TactilitySDK") + message(WARNING "⚠️ TACTILITY_SDK_PATH environment variable is not set, defaulting to ${TACTILITY_PATH}") +endif() + +include("${TACTILITY_SDK_PATH}/TactilitySDK.cmake") +set(EXTRA_COMPONENT_DIRS ${TACTILITY_SDK_PATH}) project(HelloWorld) - -include(elf_loader) -project_elf(HelloWorld) - +tactility_project(HelloWorld) diff --git a/ExternalApps/HelloWorld/main/CMakeLists.txt b/ExternalApps/HelloWorld/main/CMakeLists.txt index d4c2270b..db2068e9 100644 --- a/ExternalApps/HelloWorld/main/CMakeLists.txt +++ b/ExternalApps/HelloWorld/main/CMakeLists.txt @@ -2,15 +2,5 @@ file(GLOB_RECURSE SOURCE_FILES Source/*.c) idf_component_register( SRCS ${SOURCE_FILES} + REQUIRES TactilitySDK ) - -add_prebuilt_library(Tactility ../../../build/esp-idf/Tactility/libTactility.a) -add_prebuilt_library(TactilityC ../../../build/esp-idf/TactilityC/libTactilityC.a) -add_prebuilt_library(TactilityCore ../../../build/esp-idf/TactilityCore/libTactilityCore.a) -add_prebuilt_library(TactilityHeadless ../../../build/esp-idf/TactilityHeadless/libTactilityHeadless.a) -add_prebuilt_library(lvgl ../../../build/esp-idf/lvgl/liblvgl.a) - -include_directories("../../../TactilityC/Source") -include_directories("../../../Libraries/lvgl/src") - -target_link_libraries(${COMPONENT_LIB} PRIVATE TactilityC Tactility TactilityCore TactilityHeadless lvgl) diff --git a/ExternalApps/HelloWorld/sdkconfig.override b/ExternalApps/HelloWorld/sdkconfig.override index 7ec27ef3..b02eb18b 100644 --- a/ExternalApps/HelloWorld/sdkconfig.override +++ b/ExternalApps/HelloWorld/sdkconfig.override @@ -1 +1,2 @@ CONFIG_PARTITION_TABLE_SINGLE_APP=y +CONFIG_ESP_SYSTEM_MEMPROT_FEATURE_LOCK=n diff --git a/README.md b/README.md index 5c394b06..683e8794 100644 --- a/README.md +++ b/README.md @@ -105,13 +105,19 @@ Copy the `sdkconfig.board.YOUR_BOARD` into `sdkconfig`. Use `sdkconfig.defaults` ### Building firmware -You can run `idf.py flash monitor`, but there are some helpers available too: +Building for ESP32(\*) or PC: -`./build.sh` - build the ESP-IDF or the PC version of Tactility (*) -`./build.sh -p /dev/ttyACM0` - optional: you can pass on extra parameters for esp-idf builds -`./run.sh` - Does `flash` and `monitor` for ESP-IDF and simply builds and starts it for PC +```bash +idf.py build +``` -The build scripts will detect if ESP-IDF is available. They will adapter if you ran `${IDF_PATH}/export.sh`. +Flashing ESP32: + +```bash +idf.py flash monitor +``` + +(\*) The build scripts will detect if ESP-IDF is available. They will adapt if you ran `${IDF_PATH}/export.sh` ### Development diff --git a/Tactility/Source/service/statusbar/Statusbar.cpp b/Tactility/Source/service/statusbar/Statusbar.cpp index 6ef25467..510f3482 100644 --- a/Tactility/Source/service/statusbar/Statusbar.cpp +++ b/Tactility/Source/service/statusbar/Statusbar.cpp @@ -118,11 +118,13 @@ static void update_sdcard_icon(std::shared_ptr data) { // region power static _Nullable const char* power_get_status_icon() { - const std::shared_ptr power = getConfiguration()->hardware->power(); - if (power == nullptr) { + auto get_power = getConfiguration()->hardware->power; + if (get_power == nullptr) { return nullptr; } + auto power = get_power(); + hal::Power::MetricData charge_level; if (!power->getMetric(hal::Power::MetricType::CHARGE_LEVEL, charge_level)) { return nullptr; diff --git a/build.sh b/build.sh deleted file mode 100755 index 39fbae5d..00000000 --- a/build.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -if [[ -v ESP_IDF_VERSION ]]; then - idf.py build -else - cmake -S ./ -B build-sim - cmake --build build-sim -j 12 -fi - diff --git a/run.sh b/run.sh deleted file mode 100755 index bc1d54bd..00000000 --- a/run.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -if [[ -v ESP_IDF_VERSION ]]; then - idf.py flash monitor $@ -else - set -e - cmake -S ./ -B build-sim - cmake --build build-sim -j 12 - cd Data - ../build-sim/App/AppSim - cd - -fi - diff --git a/version.txt b/version.txt new file mode 100644 index 00000000..6c6aa7cb --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +0.1.0 \ No newline at end of file