diff --git a/.github/workflows/build-firmware.yml b/.github/workflows/build-firmware.yml index 82179b4e..b8f03375 100644 --- a/.github/workflows/build-firmware.yml +++ b/.github/workflows/build-firmware.yml @@ -153,3 +153,12 @@ jobs: with: board_id: unphone arch: esp32s3 + waveshare-s3-touch-43: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: "Build" + uses: ./.github/actions/build-firmware + with: + board_id: waveshare-s3-touch-43 + arch: esp32s3 \ No newline at end of file diff --git a/App/CMakeLists.txt b/App/CMakeLists.txt index d583047c..8dc09a0d 100644 --- a/App/CMakeLists.txt +++ b/App/CMakeLists.txt @@ -26,6 +26,7 @@ if (DEFINED ENV{ESP_IDF_VERSION}) LilygoTdeck M5stackCoreS3 UnPhone + WaveshareS3Touch43 ) endif() diff --git a/App/Kconfig b/App/Kconfig index de67493d..302912a1 100644 --- a/App/Kconfig +++ b/App/Kconfig @@ -43,6 +43,8 @@ menu "Tactility App" bool "M5Stack CoreS3" config TT_BOARD_UNPHONE bool "unPhone" + config TT_BOARD_WAVESHARE_S3_TOUCH_43 + bool "Waveshare ESP32 S3 Touch LCD 4.3" help Select a board/hardware configuration. Use TT_BOARD_CUSTOM if you will manually configure the board in your project. diff --git a/App/Source/Boards.h b/App/Source/Boards.h index bb29cff2..a9c021b5 100644 --- a/App/Source/Boards.h +++ b/App/Source/Boards.h @@ -52,6 +52,9 @@ #elif defined(CONFIG_TT_BOARD_CYD_4848S040C) #include "CYD4848S040C.h" #define TT_BOARD_HARDWARE &cyd_4848s040c_config +#elif defined(CONFIG_TT_BOARD_WAVESHARE_S3_TOUCH_43) +#include "WaveshareS3Touch43.h" +#define TT_BOARD_HARDWARE &waveshare_s3_touch_43 #else #define TT_BOARD_HARDWARE NULL #error Replace TT_BOARD_HARDWARE in main.c with your own. Or copy one of the ./sdkconfig.board.* files into ./sdkconfig. diff --git a/Boards/WaveshareS3Touch43/CMakeLists.txt b/Boards/WaveshareS3Touch43/CMakeLists.txt new file mode 100644 index 00000000..b3db19c7 --- /dev/null +++ b/Boards/WaveshareS3Touch43/CMakeLists.txt @@ -0,0 +1,7 @@ +file(GLOB_RECURSE SOURCE_FILES Source/*.c*) + +idf_component_register( + SRCS ${SOURCE_FILES} + INCLUDE_DIRS "Source" + REQUIRES Tactility esp_lvgl_port RgbDisplay GT911 driver +) diff --git a/Boards/WaveshareS3Touch43/Source/WaveshareS3Touch43.cpp b/Boards/WaveshareS3Touch43/Source/WaveshareS3Touch43.cpp new file mode 100644 index 00000000..b6906ff1 --- /dev/null +++ b/Boards/WaveshareS3Touch43/Source/WaveshareS3Touch43.cpp @@ -0,0 +1,85 @@ +#include "hal/WaveshareDisplay.h" +#include "hal/WaveshareSdCard.h" + +#include + +using namespace tt::hal; + +extern const Configuration waveshare_s3_touch_43 = { + .createDisplay = createDisplay, + .sdcard = createSdCard(), + .i2c = { + // There is only 1 (internal for touch, and also serves as "I2C-OUT" port) + // Note: You could repurpose 1 or more UART interfaces as I2C interfaces + i2c::Configuration { + .name = "Main", + .port = I2C_NUM_0, + .initMode = i2c::InitMode::ByTactility, + .isMutable = false, + .config = (i2c_config_t) { + .mode = I2C_MODE_MASTER, + .sda_io_num = GPIO_NUM_8, + .scl_io_num = GPIO_NUM_9, + .sda_pullup_en = true, + .scl_pullup_en = true, + .master = { + .clk_speed = 400000 + }, + .clk_flags = 0 + } + } + }, + .spi { + // SD card + spi::Configuration { + .device = SPI2_HOST, + .dma = SPI_DMA_CH_AUTO, + .config = { + .mosi_io_num = GPIO_NUM_11, + .miso_io_num = GPIO_NUM_13, + .sclk_io_num = GPIO_NUM_12, + .quadwp_io_num = GPIO_NUM_NC, + .quadhd_io_num = GPIO_NUM_NC, + .data4_io_num = GPIO_NUM_NC, + .data5_io_num = GPIO_NUM_NC, + .data6_io_num = GPIO_NUM_NC, + .data7_io_num = GPIO_NUM_NC, + .data_io_default_level = false, + .max_transfer_sz = 8192, + .flags = 0, + .isr_cpu_id = ESP_INTR_CPU_AFFINITY_AUTO, + .intr_flags = 0 + }, + .initMode = spi::InitMode::ByTactility, + .isMutable = false, + .lock = nullptr + } + }, + .uart { + // "UART1" + uart::Configuration { + .name = "UART1", + .port = UART_NUM_1, + .rxPin = GPIO_NUM_44, + .txPin = GPIO_NUM_43, + .rtsPin = GPIO_NUM_NC, + .ctsPin = GPIO_NUM_NC, + .rxBufferSize = 1024, + .txBufferSize = 1024, + .config = { + .baud_rate = 115200, + .data_bits = UART_DATA_8_BITS, + .parity = UART_PARITY_DISABLE, + .stop_bits = UART_STOP_BITS_1, + .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, + .rx_flow_ctrl_thresh = 0, + .source_clk = UART_SCLK_DEFAULT, + .flags = { + .allow_pd = 0, + .backup_before_sleep = 0, + } + } + } + }, + .gps = {} +}; diff --git a/Boards/WaveshareS3Touch43/Source/WaveshareS3Touch43.h b/Boards/WaveshareS3Touch43/Source/WaveshareS3Touch43.h new file mode 100644 index 00000000..29ca9e59 --- /dev/null +++ b/Boards/WaveshareS3Touch43/Source/WaveshareS3Touch43.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +extern const tt::hal::Configuration waveshare_s3_touch_43; diff --git a/Boards/WaveshareS3Touch43/Source/hal/WaveshareDisplay.cpp b/Boards/WaveshareS3Touch43/Source/hal/WaveshareDisplay.cpp new file mode 100644 index 00000000..2e5ef1b1 --- /dev/null +++ b/Boards/WaveshareS3Touch43/Source/hal/WaveshareDisplay.cpp @@ -0,0 +1,102 @@ +#include "WaveshareDisplay.h" + +#include +#include + +std::shared_ptr _Nullable createTouch() { + // Note for future changes: Reset pin is 38 and interrupt pin is 18 + // or INT = NC, schematic and other info floating around is kinda conflicting... + auto configuration = std::make_unique( + I2C_NUM_0, + 800, + 480 + ); + + return std::make_shared(std::move(configuration)); +} + +std::shared_ptr createDisplay() { + auto touch = createTouch(); + + constexpr uint32_t bufferPixels = 800 * 10; + + esp_lcd_rgb_panel_config_t rgb_panel_config = { + .clk_src = LCD_CLK_SRC_DEFAULT, + .timings = { + .pclk_hz = 12'000'000, // NOTE: original was 14MHz, but we had to slow it down with PSRAM frame buffer, + .h_res = 800, + .v_res = 480, + .hsync_pulse_width = 10, + .hsync_back_porch = 10, + .hsync_front_porch = 20, + .vsync_pulse_width = 10, + .vsync_back_porch = 10, + .vsync_front_porch = 10, + .flags = { + .hsync_idle_low = false, + .vsync_idle_low = false, + .de_idle_high = false, + .pclk_active_neg = true, + .pclk_idle_high = false + } + }, + .data_width = 16, + .bits_per_pixel = 0, + .num_fbs = 2, + .bounce_buffer_size_px = bufferPixels, + .sram_trans_align = 8, + .psram_trans_align = 64, + .hsync_gpio_num = GPIO_NUM_46, + .vsync_gpio_num = GPIO_NUM_3, + .de_gpio_num = GPIO_NUM_5, + .pclk_gpio_num = GPIO_NUM_7, + .disp_gpio_num = GPIO_NUM_NC, + .data_gpio_nums = { + GPIO_NUM_14, // B3 + GPIO_NUM_38, // B4 + GPIO_NUM_18, // B5 + GPIO_NUM_17, // B6 + GPIO_NUM_10, // B7 + GPIO_NUM_39, // G2 + GPIO_NUM_0, // G3 + GPIO_NUM_45, // G4 + GPIO_NUM_48, // G5 + GPIO_NUM_47, // G6 + GPIO_NUM_21, // G7 + GPIO_NUM_1, // R3 + GPIO_NUM_2, // R4 + GPIO_NUM_42, // R5 + GPIO_NUM_41, // R6 + GPIO_NUM_40, // R7 + }, + .flags = { + .disp_active_low = false, + .refresh_on_demand = false, + .fb_in_psram = true, + .double_fb = true, + .no_fb = false, + .bb_invalidate_cache = false + } + }; + + RgbDisplay::BufferConfiguration buffer_config = { + .size = (800 * 480), + .useSpi = true, + .doubleBuffer = true, + .bounceBufferMode = true, + .avoidTearing = false + }; + + auto configuration = std::make_unique( + rgb_panel_config, + buffer_config, + touch, + LV_COLOR_FORMAT_RGB565, + false, + false, + false, + false + ); + + return std::make_shared(std::move(configuration)); +} diff --git a/Boards/WaveshareS3Touch43/Source/hal/WaveshareDisplay.h b/Boards/WaveshareS3Touch43/Source/hal/WaveshareDisplay.h new file mode 100644 index 00000000..5a0d81b3 --- /dev/null +++ b/Boards/WaveshareS3Touch43/Source/hal/WaveshareDisplay.h @@ -0,0 +1,5 @@ +#pragma once + +#include "Tactility/hal/display/DisplayDevice.h" + +std::shared_ptr createDisplay(); diff --git a/Boards/WaveshareS3Touch43/Source/hal/WaveshareSdCard.cpp b/Boards/WaveshareS3Touch43/Source/hal/WaveshareSdCard.cpp new file mode 100644 index 00000000..c0446d5b --- /dev/null +++ b/Boards/WaveshareS3Touch43/Source/hal/WaveshareSdCard.cpp @@ -0,0 +1,21 @@ +#include "WaveshareSdCard.h" + +#include + +using tt::hal::sdcard::SpiSdCardDevice; + +std::shared_ptr createSdCard() { + auto* configuration = new SpiSdCardDevice::Config( + GPIO_NUM_10, + GPIO_NUM_NC, + GPIO_NUM_NC, + GPIO_NUM_NC, + SdCardDevice::MountBehaviour::AtBoot + ); + + auto* sdcard = (SdCardDevice*) new SpiSdCardDevice( + std::unique_ptr(configuration) + ); + + return std::shared_ptr(sdcard); +} diff --git a/Boards/WaveshareS3Touch43/Source/hal/WaveshareSdCard.h b/Boards/WaveshareS3Touch43/Source/hal/WaveshareSdCard.h new file mode 100644 index 00000000..5cb65a73 --- /dev/null +++ b/Boards/WaveshareS3Touch43/Source/hal/WaveshareSdCard.h @@ -0,0 +1,7 @@ +#pragma once + +#include "Tactility/hal/sdcard/SdCardDevice.h" + +using tt::hal::sdcard::SdCardDevice; + +std::shared_ptr createSdCard(); diff --git a/Buildscripts/build-and-release-all.sh b/Buildscripts/build-and-release-all.sh index bece3b4a..db6229d3 100755 --- a/Buildscripts/build-and-release-all.sh +++ b/Buildscripts/build-and-release-all.sh @@ -60,6 +60,9 @@ release m5stack-core2 build m5stack-cores3 release m5stack-cores3 +build waveshare-s3-touch-43 +release waveshare-s3-touch-43 + duration=$SECONDS echo "Finished in $((duration / 60)) minutes and $((duration % 60)) seconds." \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 3508833a..b98ef5b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,7 @@ if (DEFINED ENV{ESP_IDF_VERSION}) set(EXCLUDE_COMPONENTS "ElecrowCrowpanelBasic50") set(EXCLUDE_COMPONENTS "LilygoTdeck") set(EXCLUDE_COMPONENTS "M5stackCoreS3") + set(EXCLUDE_COMPONENTS "WaveshareEsp32S3TouchLcd43") set(EXCLUDE_COMPONENTS "UnPhone") endif() diff --git a/sdkconfig.board.waveshare-s3-touch-43 b/sdkconfig.board.waveshare-s3-touch-43 new file mode 100644 index 00000000..8a26a789 --- /dev/null +++ b/sdkconfig.board.waveshare-s3-touch-43 @@ -0,0 +1,54 @@ +# Software defaults +# Increase stack size for WiFi (fixes crash after scan) +CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=3072 +CONFIG_LV_FONT_MONTSERRAT_14=y +CONFIG_LV_FONT_MONTSERRAT_18=y +CONFIG_LV_USE_USER_DATA=y +CONFIG_LV_USE_FS_STDIO=y +CONFIG_LV_FS_STDIO_LETTER=65 +CONFIG_LV_FS_STDIO_PATH="" +CONFIG_LV_FS_STDIO_CACHE_SIZE=4096 +CONFIG_LV_USE_LODEPNG=y +CONFIG_LV_USE_BUILTIN_MALLOC=n +CONFIG_LV_USE_CLIB_MALLOC=y +CONFIG_LV_USE_MSGBOX=n +CONFIG_LV_USE_SPINNER=n +CONFIG_LV_USE_WIN=n +CONFIG_LV_USE_SNAPSHOT=y +CONFIG_FREERTOS_HZ=1000 +CONFIG_FREERTOS_TASK_NOTIFICATION_ARRAY_ENTRIES=2 +CONFIG_FREERTOS_SMP=n +CONFIG_FREERTOS_UNICORE=n +CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH=4096 +CONFIG_FREERTOS_USE_TRACE_FACILITY=y +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv" +CONFIG_PARTITION_TABLE_FILENAME="partitions.csv" +CONFIG_FATFS_LFN_HEAP=y +CONFIG_FATFS_VOLUME_COUNT=3 + +# Hardware: Main +CONFIG_TT_BOARD_WAVESHARE_S3_TOUCH_43=y +CONFIG_TT_BOARD_NAME="Waveshare ESP32 S3 Touch LCD 4.3" +CONFIG_TT_BOARD_ID="waveshare-s3-touch-43" +CONFIG_IDF_EXPERIMENTAL_FEATURES=y +CONFIG_IDF_TARGET="esp32s3" +CONFIG_ESP_DEFAULT_CPU_FREQ_MHZ_240=y +CONFIG_ESP32_DEFAULT_CPU_FREQ_240=y +CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +CONFIG_FLASHMODE_QIO=y +# Hardware: SPI RAM +CONFIG_ESP32S3_SPIRAM_SUPPORT=y +CONFIG_SPIRAM_MODE_OCT=y +CONFIG_SPIRAM_SPEED_120M=y +CONFIG_SPIRAM_USE_MALLOC=y +CONFIG_SPIRAM_TRY_ALLOCATE_WIFI_LWIP=y +# SPI Flash (can set back to 80MHz after ESP-IDF bug is resolved) +CONFIG_ESPTOOLPY_FLASHFREQ_120M=y +# LVGL +# TODO: Update DPI +CONFIG_LV_DPI_DEF=143 +CONFIG_LV_DISP_DEF_REFR_PERIOD=10 +# USB +CONFIG_TINYUSB_MSC_ENABLED=y +CONFIG_TINYUSB_MSC_MOUNT_PATH="/sdcard"