From ffe4fcf2184938e6837b92952b38cdc00655989b Mon Sep 17 00:00:00 2001 From: William Emfinger Date: Sat, 6 Jul 2024 15:46:06 -0500 Subject: [PATCH] feat: Update to use esp-box and t-deck components * Update to remove lcd and box/t-deck headers in favor of reusing the code from the `espp::EspBox` and `espp::TDeck` classes * Update actions to use latest versions * Update submodules to latest * Add a few things to defaults --- .github/workflows/build.yml | 4 +- .github/workflows/package_main.yml | 8 +- .github/workflows/static_analysis.yml | 2 +- CMakeLists.txt | 2 +- components/esp-protocols | 2 +- components/espp | 2 +- main/Kconfig.projbuild | 4 +- main/box.hpp | 75 --------- main/box_3.hpp | 75 --------- main/lcd.cpp | 210 -------------------------- main/lcd.hpp | 8 - main/main.cpp | 49 ++++-- main/tdeck.hpp | 83 ---------- sdkconfig.defaults | 4 + 14 files changed, 48 insertions(+), 480 deletions(-) delete mode 100644 main/box.hpp delete mode 100644 main/box_3.hpp delete mode 100644 main/lcd.cpp delete mode 100644 main/lcd.hpp delete mode 100644 main/tdeck.hpp diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 99fd921..56d68bf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,13 +9,13 @@ jobs: steps: - name: Checkout repo - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: submodules: 'recursive' - name: Build Examples uses: espressif/esp-idf-ci-action@v1 with: - esp_idf_version: release-v5.2 + esp_idf_version: v5.2.2 target: esp32s3 path: '.' diff --git a/.github/workflows/package_main.yml b/.github/workflows/package_main.yml index 04683d9..6ad826b 100644 --- a/.github/workflows/package_main.yml +++ b/.github/workflows/package_main.yml @@ -14,20 +14,20 @@ jobs: steps: - name: Checkout repo - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: submodules: 'recursive' - name: Build Main Code uses: espressif/esp-idf-ci-action@v1 with: - esp_idf_version: release-v5.2 + esp_idf_version: v5.2.2 target: esp32s3 path: '.' command: 'idf.py build' - name: Upload Build Outputs - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: build-artifacts path: | @@ -37,7 +37,7 @@ jobs: build/flash_args - name: Attach files to release - uses: softprops/action-gh-release@v1 + uses: softprops/action-gh-release@v2 if: ${{ github.event.release && github.event.action == 'published' }} with: files: | diff --git a/.github/workflows/static_analysis.yml b/.github/workflows/static_analysis.yml index 1fec262..8820fa2 100644 --- a/.github/workflows/static_analysis.yml +++ b/.github/workflows/static_analysis.yml @@ -8,7 +8,7 @@ jobs: steps: - name: Checkout repo - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: submodules: 'recursive' diff --git a/CMakeLists.txt b/CMakeLists.txt index 9bb4c39..1657c45 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ add_compile_definitions(BOARD_HAS_PSRAM) set( COMPONENTS - "main esptool_py esp_psram jpegdec task format monitor i2c display_drivers input_drivers gt911 tt21100 wifi socket rtsp mdns" + "main esptool_py esp_psram jpegdec task format nvs esp-box t-deck monitor wifi socket rtsp mdns" CACHE STRING "List of components to include" ) diff --git a/components/esp-protocols b/components/esp-protocols index 38a3631..25d8423 160000 --- a/components/esp-protocols +++ b/components/esp-protocols @@ -1 +1 @@ -Subproject commit 38a3631a27f71f25109f1d6e28d3c2ba309f292d +Subproject commit 25d8423e6dd9031d4bd5a3afe815810137d4532b diff --git a/components/espp b/components/espp index 761b524..691753d 160000 --- a/components/espp +++ b/components/espp @@ -1 +1 @@ -Subproject commit 761b52412c903319f06e66f66696e5ac29ded285 +Subproject commit 691753decb2a990a306ebb997f949710eb34dbe2 diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild index df8c8e2..ee62ad8 100644 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -6,9 +6,7 @@ menu "Camera Display Configuration" help Select the dev-kit / hardware you're using. config HARDWARE_BOX - bool "ESP BOX" - config HARDWARE_BOX_3 - bool "ESP BOX 3" + bool "ESP BOX (ESP32-S3-BOX or ESP32-S3-BOX-3)" config HARDWARE_TDECK bool "LILYGO T DECK" endchoice diff --git a/main/box.hpp b/main/box.hpp deleted file mode 100644 index 8963e6d..0000000 --- a/main/box.hpp +++ /dev/null @@ -1,75 +0,0 @@ -#pragma once - -#include "driver/gpio.h" -#include "driver/i2s_std.h" -#include "driver/spi_master.h" -#include "hal/spi_types.h" - -#include "i2c.hpp" -#include "st7789.hpp" -#include "touchpad_input.hpp" -#include "tt21100.hpp" - -namespace hal { - -static constexpr std::string_view dev_kit = "ESP32-S3-BOX"; - -// internal i2c (touchscreen, audio codec) -static constexpr auto internal_i2c_port = I2C_NUM_0; -static constexpr auto internal_i2c_clock_speed = 400 * 1000; -static constexpr gpio_num_t internal_i2c_sda = GPIO_NUM_8; -static constexpr gpio_num_t internal_i2c_scl = GPIO_NUM_18; - -// external I2c (peripherals) -static constexpr auto external_i2c_port = I2C_NUM_1; -static constexpr auto external_i2c_clock_speed = 400 * 1000; -static constexpr gpio_num_t external_i2c_sda = GPIO_NUM_41; -static constexpr gpio_num_t external_i2c_scl = GPIO_NUM_40; - -// LCD -static constexpr int lcd_clock_speed = 60 * 1000 * 1000; -static constexpr auto lcd_spi_num = SPI2_HOST; -static constexpr gpio_num_t lcd_cs = GPIO_NUM_5; -static constexpr gpio_num_t lcd_mosi = GPIO_NUM_6; -static constexpr gpio_num_t lcd_sclk = GPIO_NUM_7; -static constexpr gpio_num_t lcd_reset = GPIO_NUM_48; -static constexpr gpio_num_t lcd_dc = GPIO_NUM_4; -static constexpr gpio_num_t backlight = GPIO_NUM_45; -static constexpr size_t display_width = 320; -static constexpr size_t display_height = 240; -static constexpr bool backlight_value = true; -static constexpr bool reset_value = false; -static constexpr bool invert_colors = true; -static constexpr auto rotation = espp::Display::Rotation::LANDSCAPE; -static constexpr bool mirror_x = true; -static constexpr bool mirror_y = true; -using DisplayDriver = espp::St7789; - -// touch -static constexpr bool touch_swap_xy = false; -static constexpr bool touch_invert_x = true; -static constexpr bool touch_invert_y = false; -static constexpr gpio_num_t touch_interrupt = GPIO_NUM_3; -using TouchDriver = espp::Tt21100; -#define TOUCH_DRIVER_USE_WRITE 0 -#define TOUCH_DRIVER_USE_READ 1 -#define TOUCH_DRIVER_USE_WRITE_READ 0 - -// sound -static constexpr gpio_num_t sound_power_pin = GPIO_NUM_46; -static constexpr auto i2s_port = I2S_NUM_0; -static constexpr gpio_num_t i2s_mck_io = GPIO_NUM_2; -static constexpr gpio_num_t i2s_bck_io = GPIO_NUM_17; -static constexpr gpio_num_t i2s_ws_io = GPIO_NUM_47; -static constexpr gpio_num_t i2s_do_io = GPIO_NUM_15; -static constexpr gpio_num_t i2s_di_io = GPIO_NUM_16; -static constexpr gpio_num_t mute_pin = GPIO_NUM_1; - -// uSD card -static constexpr gpio_num_t sdcard_cs = GPIO_NUM_10; -static constexpr gpio_num_t sdcard_mosi = GPIO_NUM_11; -static constexpr gpio_num_t sdcard_miso = GPIO_NUM_13; -static constexpr gpio_num_t sdcard_sclk = GPIO_NUM_12; -static constexpr auto sdcard_spi_num = SPI3_HOST; - -} // namespace hal diff --git a/main/box_3.hpp b/main/box_3.hpp deleted file mode 100644 index 7aafafa..0000000 --- a/main/box_3.hpp +++ /dev/null @@ -1,75 +0,0 @@ -#pragma once - -#include "driver/gpio.h" -#include "driver/i2s_std.h" -#include "driver/spi_master.h" -#include "hal/spi_types.h" - -#include "gt911.hpp" -#include "i2c.hpp" -#include "st7789.hpp" -#include "touchpad_input.hpp" - -namespace hal { - -static constexpr std::string_view dev_kit = "ESP32-S3-BOX-3"; - -// internal i2c (touchscreen, audio codec) -static constexpr auto internal_i2c_port = I2C_NUM_0; -static constexpr auto internal_i2c_clock_speed = 400 * 1000; -static constexpr gpio_num_t internal_i2c_sda = GPIO_NUM_8; -static constexpr gpio_num_t internal_i2c_scl = GPIO_NUM_18; - -// external I2c (peripherals) -static constexpr auto external_i2c_port = I2C_NUM_1; -static constexpr auto external_i2c_clock_speed = 400 * 1000; -static constexpr gpio_num_t external_i2c_sda = GPIO_NUM_41; -static constexpr gpio_num_t external_i2c_scl = GPIO_NUM_40; - -// LCD -static constexpr int lcd_clock_speed = 60 * 1000 * 1000; -static constexpr auto lcd_spi_num = SPI2_HOST; -static constexpr gpio_num_t lcd_cs = GPIO_NUM_5; -static constexpr gpio_num_t lcd_mosi = GPIO_NUM_6; -static constexpr gpio_num_t lcd_sclk = GPIO_NUM_7; -static constexpr gpio_num_t lcd_reset = GPIO_NUM_48; -static constexpr gpio_num_t lcd_dc = GPIO_NUM_4; -static constexpr gpio_num_t backlight = GPIO_NUM_47; // was 45 on ESP32-S3-BOX -static constexpr size_t display_width = 320; -static constexpr size_t display_height = 240; -static constexpr bool backlight_value = true; -static constexpr bool reset_value = true; // was false on ESP32-S3-BOX -static constexpr bool invert_colors = true; -static constexpr auto rotation = espp::Display::Rotation::LANDSCAPE; -static constexpr bool mirror_x = false; -static constexpr bool mirror_y = true; -using DisplayDriver = espp::St7789; - -// touch -static constexpr bool touch_swap_xy = false; -static constexpr bool touch_invert_x = false; -static constexpr bool touch_invert_y = false; -static constexpr gpio_num_t touch_interrupt = GPIO_NUM_3; -using TouchDriver = espp::Gt911; -#define TOUCH_DRIVER_USE_WRITE 1 -#define TOUCH_DRIVER_USE_READ 0 -#define TOUCH_DRIVER_USE_WRITE_READ 1 - -// sound -static constexpr gpio_num_t sound_power_pin = GPIO_NUM_46; -static constexpr auto i2s_port = I2S_NUM_0; -static constexpr gpio_num_t i2s_mck_io = GPIO_NUM_2; -static constexpr gpio_num_t i2s_bck_io = GPIO_NUM_17; -static constexpr gpio_num_t i2s_ws_io = GPIO_NUM_45; // was 47 on ESP32-S3-BOX -static constexpr gpio_num_t i2s_do_io = GPIO_NUM_15; -static constexpr gpio_num_t i2s_di_io = GPIO_NUM_16; -static constexpr gpio_num_t mute_pin = GPIO_NUM_1; - -// uSD card -static constexpr gpio_num_t sdcard_cs = GPIO_NUM_10; -static constexpr gpio_num_t sdcard_mosi = GPIO_NUM_11; -static constexpr gpio_num_t sdcard_miso = GPIO_NUM_13; -static constexpr gpio_num_t sdcard_sclk = GPIO_NUM_12; -static constexpr auto sdcard_spi_num = SPI3_HOST; - -} // namespace hal diff --git a/main/lcd.cpp b/main/lcd.cpp deleted file mode 100644 index 42d3294..0000000 --- a/main/lcd.cpp +++ /dev/null @@ -1,210 +0,0 @@ -#include "lcd.hpp" - -#include "driver/spi_master.h" -#include "hal/spi_types.h" - -#include "display.hpp" - -#if CONFIG_HARDWARE_BOX -#include "box.hpp" -#elif CONFIG_HARDWARE_BOX_3 -#include "box_3.hpp" -#elif CONFIG_HARDWARE_TDECK -#include "tdeck.hpp" -#else -#error "Invalid hardware configuration selected!" -#endif - -using namespace hal; - -static spi_device_handle_t spi; - -static constexpr size_t NUM_ROWS_IN_FRAME_BUFFER = 50; -static constexpr size_t pixel_buffer_size = display_width * NUM_ROWS_IN_FRAME_BUFFER; -std::shared_ptr display; - -static const int spi_queue_size = 6; -static spi_transaction_t ts_[spi_queue_size]; -static size_t num_queued_trans = 0; - -// the user flag for the callbacks does two things: -// 1. Provides the GPIO level for the data/command pin, and -// 2. Sets some bits for other signaling (such as LVGL FLUSH) -static constexpr int FLUSH_BIT = (1 << (int)espp::display_drivers::Flags::FLUSH_BIT); -static constexpr int DC_LEVEL_BIT = (1 << (int)espp::display_drivers::Flags::DC_LEVEL_BIT); - -// This function is called (in irq context!) just before a transmission starts. -// It will set the D/C line to the value indicated in the user field -// (DC_LEVEL_BIT). -static void lcd_spi_pre_transfer_callback(spi_transaction_t *t) { - uint32_t user_flags = (uint32_t)(t->user); - bool dc_level = user_flags & DC_LEVEL_BIT; - gpio_set_level(lcd_dc, dc_level); -} - -// This function is called (in irq context!) just after a transmission ends. It -// will indicate to lvgl that the next flush is ready to be done if the -// FLUSH_BIT is set. -static void lcd_spi_post_transfer_callback(spi_transaction_t *t) { - uint16_t user_flags = (uint32_t)(t->user); - bool should_flush = user_flags & FLUSH_BIT; - if (should_flush) { - lv_disp_t *disp = _lv_refr_get_disp_refreshing(); - lv_disp_flush_ready(disp->driver); - } -} - -extern "C" void lcd_write(const uint8_t *data, size_t length, uint32_t user_data) { - if (length == 0) { - return; - } - esp_err_t ret; - static spi_transaction_t t; - memset(&t, 0, sizeof(t)); - t.length = length * 8; - t.tx_buffer = data; - t.user = (void *)user_data; - ret = spi_device_polling_transmit(spi, &t); -} - -static void lcd_wait_lines() { - spi_transaction_t *rtrans; - esp_err_t ret; - // Wait for all transactions to be done and get back the results. - while (num_queued_trans) { - // fmt::print("Waiting for {} lines\n", num_queued_trans); - ret = spi_device_get_trans_result(spi, &rtrans, portMAX_DELAY); - if (ret != ESP_OK) { - fmt::print("Could not get trans result: {} '{}'\n", ret, esp_err_to_name(ret)); - } - num_queued_trans--; - // We could inspect rtrans now if we received any info back. The LCD is treated as write-only, - // though. - } -} - -void IRAM_ATTR lcd_send_lines(int xs, int ys, int xe, int ye, const uint8_t *data, - uint32_t user_data) { - // if we haven't waited by now, wait here... - lcd_wait_lines(); - esp_err_t ret; - // Transaction descriptors. Declared static so they're not allocated on the stack; we need this - // memory even when this function is finished because the SPI driver needs access to it even while - // we're already calculating the next line. - static spi_transaction_t trans[6]; - // In theory, it's better to initialize trans and data only once and hang on to the initialized - // variables. We allocate them on the stack, so we need to re-init them each call. - for (int i = 0; i < 6; i++) { - memset(&trans[i], 0, sizeof(spi_transaction_t)); - if ((i & 1) == 0) { - // Even transfers are commands - trans[i].length = 8; - trans[i].user = (void *)0; - } else { - // Odd transfers are data - trans[i].length = 8 * 4; - trans[i].user = (void *)DC_LEVEL_BIT; - } - trans[i].flags = SPI_TRANS_USE_TXDATA; - } - size_t length = (xe - xs + 1) * (ye - ys + 1) * 2; - trans[0].tx_data[0] = (uint8_t)DisplayDriver::Command::caset; - trans[1].tx_data[0] = (xs) >> 8; - trans[1].tx_data[1] = (xs)&0xff; - trans[1].tx_data[2] = (xe) >> 8; - trans[1].tx_data[3] = (xe)&0xff; - trans[2].tx_data[0] = (uint8_t)DisplayDriver::Command::raset; - trans[3].tx_data[0] = (ys) >> 8; - trans[3].tx_data[1] = (ys)&0xff; - trans[3].tx_data[2] = (ye) >> 8; - trans[3].tx_data[3] = (ye)&0xff; - trans[4].tx_data[0] = (uint8_t)DisplayDriver::Command::ramwr; - trans[5].tx_buffer = data; - trans[5].length = length * 8; - // undo SPI_TRANS_USE_TXDATA flag - trans[5].flags = 0; - // we need to keep the dc bit set, but also add our flags - trans[5].user = (void *)(DC_LEVEL_BIT | user_data); - // Queue all transactions. - for (int i = 0; i < 6; i++) { - ret = spi_device_queue_trans(spi, &trans[i], portMAX_DELAY); - if (ret != ESP_OK) { - fmt::print("Couldn't queue trans: {} '{}'\n", ret, esp_err_to_name(ret)); - } else { - num_queued_trans++; - } - } - // When we are here, the SPI driver is busy (in the background) getting the - // transactions sent. That happens mostly using DMA, so the CPU doesn't have - // much to do here. We're not going to wait for the transaction to finish - // because we may as well spend the time calculating the next line. When that - // is done, we can call send_line_finish, which will wait for the transfers - // to be done and check their status. -} - -uint16_t *get_vram0() { return display->vram0(); } - -uint16_t *get_vram1() { return display->vram1(); } - -void lcd_init() { - static bool initialized = false; - if (initialized) { - return; - } - esp_err_t ret; - - spi_bus_config_t buscfg; - memset(&buscfg, 0, sizeof(buscfg)); - buscfg.mosi_io_num = lcd_mosi; - buscfg.miso_io_num = -1; - buscfg.sclk_io_num = lcd_sclk; - buscfg.quadwp_io_num = -1; - buscfg.quadhd_io_num = -1; - buscfg.max_transfer_sz = display_width * display_height * 2 + 8; - - spi_device_interface_config_t devcfg; - memset(&devcfg, 0, sizeof(devcfg)); - devcfg.mode = 0; - devcfg.clock_speed_hz = lcd_clock_speed; - devcfg.input_delay_ns = 0; - devcfg.spics_io_num = lcd_cs; - devcfg.queue_size = spi_queue_size; - devcfg.pre_cb = lcd_spi_pre_transfer_callback; - devcfg.post_cb = lcd_spi_post_transfer_callback; - - // Initialize the SPI bus - ret = spi_bus_initialize(lcd_spi_num, &buscfg, SPI_DMA_CH_AUTO); - ESP_ERROR_CHECK(ret); - // Attach the LCD to the SPI bus - ret = spi_bus_add_device(lcd_spi_num, &devcfg, &spi); - ESP_ERROR_CHECK(ret); - // initialize the controller - DisplayDriver::initialize(espp::display_drivers::Config{ - .lcd_write = lcd_write, - .lcd_send_lines = lcd_send_lines, - .reset_pin = lcd_reset, - .data_command_pin = lcd_dc, - .reset_value = reset_value, - .invert_colors = invert_colors, - .mirror_x = mirror_x, - .mirror_y = mirror_y, - }); - // initialize the display / lvgl - using namespace std::chrono_literals; - display = std::make_shared(espp::Display::AllocatingConfig{ - .width = display_width, - .height = display_height, - .pixel_buffer_size = pixel_buffer_size, - .flush_callback = DisplayDriver::flush, - .backlight_pin = backlight, - .backlight_on_value = backlight_value, - .update_period = 5ms, - .double_buffered = true, - .allocation_flags = MALLOC_CAP_8BIT | MALLOC_CAP_DMA, - .rotation = rotation, - .software_rotation_enabled = true, - }); - // clear the display - DisplayDriver::clear(0, 0, display_width, display_height); - initialized = true; -} diff --git a/main/lcd.hpp b/main/lcd.hpp deleted file mode 100644 index c2423fa..0000000 --- a/main/lcd.hpp +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include "display.hpp" - -void lcd_init(); -uint16_t *get_vram0(); -uint16_t *get_vram1(); -void lcd_send_lines(int xs, int ys, int xe, int ye, const uint8_t *data, uint32_t user_data); diff --git a/main/main.cpp b/main/main.cpp index 6cd68de..f0dcb61 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -7,13 +7,12 @@ #include "freertos/FreeRTOS.h" #include "freertos/task.h" -#include "driver/gpio.h" #include "mdns.h" -#include "nvs_flash.h" #include "JPEGDEC.h" #include "format.hpp" +#include "nvs.hpp" #include "rtsp_client.hpp" #include "task.hpp" #include "task_monitor.hpp" @@ -21,7 +20,15 @@ #include "udp_socket.hpp" #include "wifi_sta.hpp" -#include "lcd.hpp" +#if CONFIG_HARDWARE_BOX +#include "esp-box.hpp" +using hal = espp::EspBox; +#elif CONFIG_HARDWARE_TDECK +#include "t-deck.hpp" +using hal = espp::TDeck; +#else +#error "No hardware defined" +#endif using namespace std::chrono_literals; @@ -38,11 +45,11 @@ int drawMCUs(JPEGDRAW *pDraw) { auto ye = pDraw->y + pDraw->iHeight - 1; static size_t frame_buffer_index = 0; - uint8_t *out_img_buf = (uint8_t *)(frame_buffer_index ? get_vram1() : get_vram0()); + uint8_t *out_img_buf = (uint8_t *)(frame_buffer_index ? hal::get().vram1() : hal::get().vram0()); frame_buffer_index = frame_buffer_index ? 0 : 1; memcpy(out_img_buf, pDraw->pPixels, iCount * 2); - lcd_send_lines(xs, ys, xe, ye, out_img_buf, 0); + hal::get().write_lcd_lines(xs, ys, xe, ye, out_img_buf, 0); // returning true (1) tells JPEGDEC to continue decoding. Returning false // (0) would quit decoding immediately. return 1; @@ -52,17 +59,29 @@ extern "C" void app_main(void) { espp::Logger logger({.tag = "Camera Display", .level = espp::Logger::Verbosity::INFO}); logger.info("Bootup"); - // initialize the lcd for the image display - lcd_init(); + // initialize the hardware + auto &hw = hal::get(); + if (!hw.initialize_lcd()) { + logger.error("Could not initialize LCD"); + return; + } + static constexpr size_t pixel_buffer_size = hal::lcd_width() * 50; + if (!hw.initialize_display(pixel_buffer_size)) { + logger.error("Could not initialize display"); + return; + } + if (!hw.initialize_touch()) { + logger.error("Could not initialize touch"); + return; + } + std::error_code ec; + +#if CONFIG_ESP32_WIFI_NVS_ENABLED // initialize NVS, needed for WiFi - esp_err_t ret = nvs_flash_init(); - if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { - logger.warn("Erasing NVS flash..."); - ESP_ERROR_CHECK(nvs_flash_erase()); - ret = nvs_flash_init(); - } - ESP_ERROR_CHECK(ret); + espp::Nvs nvs; + nvs.init(ec); +#endif // initialize WiFi logger.info("Initializing WiFi"); @@ -189,8 +208,6 @@ extern "C" void app_main(void) { .log_level = espp::Logger::Verbosity::ERROR, }); - std::error_code ec; - do { // clear the error code ec.clear(); diff --git a/main/tdeck.hpp b/main/tdeck.hpp deleted file mode 100644 index 9032ff8..0000000 --- a/main/tdeck.hpp +++ /dev/null @@ -1,83 +0,0 @@ -#pragma once - -#include "driver/gpio.h" -#include "driver/i2s_std.h" -#include "driver/spi_master.h" -#include "hal/spi_types.h" - -#include "gt911.hpp" -#include "i2c.hpp" -#include "st7789.hpp" -#include "touchpad_input.hpp" - -namespace hal { - -static constexpr std::string_view dev_kit = "LILYGO T-DECK"; - -// internal i2c (touchscreen, audio codec) -static constexpr auto internal_i2c_port = I2C_NUM_0; -static constexpr auto internal_i2c_clock_speed = 400 * 1000; -static constexpr gpio_num_t internal_i2c_sda = GPIO_NUM_18; -static constexpr gpio_num_t internal_i2c_scl = GPIO_NUM_8; - -#if 0 -// TODO: figure out what these are for T-DECK: -// external I2c (peripherals) -static constexpr auto external_i2c_port = I2C_NUM_1; -static constexpr auto external_i2c_clock_speed = 400 * 1000; -static constexpr gpio_num_t external_i2c_sda = GPIO_NUM_41; -static constexpr gpio_num_t external_i2c_scl = GPIO_NUM_40; -#endif - -// LCD -static constexpr int lcd_clock_speed = 60 * 1000 * 1000; -static constexpr auto lcd_spi_num = SPI2_HOST; -static constexpr gpio_num_t lcd_cs = GPIO_NUM_12; -static constexpr gpio_num_t lcd_mosi = GPIO_NUM_41; -static constexpr gpio_num_t lcd_sclk = GPIO_NUM_40; -static constexpr gpio_num_t lcd_reset = GPIO_NUM_NC; -static constexpr gpio_num_t lcd_dc = GPIO_NUM_11; -static constexpr gpio_num_t backlight = GPIO_NUM_42; -static constexpr size_t display_width = 320; -static constexpr size_t display_height = 240; -static constexpr bool backlight_value = true; -static constexpr bool reset_value = false; -static constexpr bool invert_colors = false; -static constexpr auto rotation = espp::Display::Rotation::LANDSCAPE; -static constexpr bool mirror_x = false; -static constexpr bool mirror_y = true; -using DisplayDriver = espp::St7789; - -// touch -static constexpr bool touch_swap_xy = true; -static constexpr bool touch_invert_x = true; -static constexpr bool touch_invert_y = false; -#if 0 -// TODO: figure out what these are for T-DECK: -static constexpr gpio_num_t touch_interrupt = GPIO_NUM_3; -#endif -using TouchDriver = espp::Gt911; -#define TOUCH_DRIVER_USE_WRITE 1 -#define TOUCH_DRIVER_USE_READ 0 -#define TOUCH_DRIVER_USE_WRITE_READ 1 - -#if 0 -// TODO: figure out what these are for T-DECK: -// sound -static constexpr gpio_num_t sound_power_pin = GPIO_NUM_46; -static constexpr auto i2s_port = I2S_NUM_0; -static constexpr gpio_num_t i2s_mck_io = GPIO_NUM_2; -static constexpr gpio_num_t i2s_bck_io = GPIO_NUM_17; -static constexpr gpio_num_t i2s_ws_io = GPIO_NUM_45; // was 47 on ESP32-S3-BOX -static constexpr gpio_num_t i2s_do_io = GPIO_NUM_15; -static constexpr gpio_num_t i2s_di_io = GPIO_NUM_16; -static constexpr gpio_num_t mute_pin = GPIO_NUM_1; - -// uSD card -static constexpr gpio_num_t sdcard_cs = GPIO_NUM_10; -static constexpr gpio_num_t sdcard_mosi = GPIO_NUM_11; -static constexpr gpio_num_t sdcard_miso = GPIO_NUM_13; -static constexpr gpio_num_t sdcard_sclk = GPIO_NUM_12; -static constexpr auto sdcard_spi_num = SPI3_HOST; -#endif -} // namespace hal diff --git a/sdkconfig.defaults b/sdkconfig.defaults index 668f00c..7e51ada 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -9,6 +9,7 @@ CONFIG_ESP_TASK_WDT_EN=n CONFIG_ESPTOOLPY_FLASHSIZE_16MB=y CONFIG_ESPTOOLPY_FLASHSIZE="16MB" +CONFIG_ESPTOOLPY_FLASHMODE_QIO=y # over twice as fast as DIO CONFIG_FREERTOS_HZ=1000 @@ -19,6 +20,9 @@ CONFIG_FREERTOS_HZ=1000 CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=4096 CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192 +# set the functions into IRAM +CONFIG_SPI_MASTER_IN_IRAM=y + # SPIRAM Configuration CONFIG_SPIRAM=y CONFIG_SPIRAM_USE=y