diff --git a/.github/workflows/test-all-builds.yml b/.github/workflows/test-all-builds.yml index 480db642..ed968668 100644 --- a/.github/workflows/test-all-builds.yml +++ b/.github/workflows/test-all-builds.yml @@ -15,8 +15,8 @@ jobs: matrix: # *_v3: ESP32-P4 chip revision v3.x (sdkconfig.rev3); IDF cannot # build one image for both v1.x and v3.x silicon. - board: [wave_4b, wave_35, wave_5, wave_43, crowpanel, wave_7b, - wave_4b_v3, wave_35_v3, wave_5_v3, wave_43_v3, crowpanel_v3, wave_7b_v3] + board: [wave_4b, wave_35, wave_5, wave_43, crowpanel, wave_7b, p4_pico, + wave_4b_v3, wave_35_v3, wave_5_v3, wave_43_v3, crowpanel_v3, wave_7b_v3, p4_pico_v3] name: build (${{ matrix.board }}) steps: - name: Checkout repo diff --git a/.gitignore b/.gitignore index 734f2b2f..a93246e9 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ build_wave_43/ build_wave_5/ build_wave_7b/ build_crowpanel/ +build_p4_pico/ build_*_v3/ build_wave_7b/ sdkconfig diff --git a/.justfile b/.justfile index c141d188..d3de5a93 100644 --- a/.justfile +++ b/.justfile @@ -1,14 +1,14 @@ export IDF_PATH := env_var_or_default("IDF_PATH", env_var("HOME") + "/esp/esp-idf") export IDF_PATH_FORCE := "1" -# Board parameter: "wave_4b" (default), "wave_35", "wave_5", "wave_43", "crowpanel", or "wave_7b" +# Board parameter: "wave_4b" (default), "wave_35", "wave_5", "wave_43", "crowpanel", "wave_7b", or "p4_pico" # Usage: just build wave_35, just flash wave_4b, just build wave_5, just build wave_7b # Each board builds into its own build_/ directory, so switching # boards is instant (no clean required) and per-board builds stay incremental. # Append _v3 to a board (just build wave_43_v3) for ESP32-P4 chip revision # v3.x: IDF cannot build one image for both v1.x and v3.x silicon. -boards := "wave_4b wave_35 wave_5 wave_43 crowpanel wave_7b" +boards := "wave_4b wave_35 wave_5 wave_43 crowpanel wave_7b p4_pico" _check_board board: #!/usr/bin/env sh @@ -56,7 +56,7 @@ test: ./scripts/test.sh clean: - rm -fRd build build_wave_4b build_wave_35 build_wave_5 build_wave_43 build_crowpanel build_wave_7b + rm -fRd build build_wave_4b build_wave_35 build_wave_5 build_wave_43 build_crowpanel build_wave_7b build_p4_pico rm -fRd build_*_v3 rm -fRd build_pbkdf2_* rm -fRd build_scanprof_* @@ -98,14 +98,14 @@ site port="8000": python3 -m http.server {{port}} -d site # Simulator board resolution mapping -# wave_4b: 720x720, wave_35: 320x480, wave_5: 720x1280, wave_43: 480x800, crowpanel: 1024x600, wave_7b: 1024x600 +# wave_4b: 720x720, wave_35: 320x480, wave_5: 720x1280, wave_43: 480x800, crowpanel: 1024x600, wave_7b: 1024x600, p4_pico: 720x1280 _sim_h_res board: #!/usr/bin/env sh - case "{{board}}" in wave_35) echo 320;; wave_5) echo 720;; wave_43) echo 480;; crowpanel) echo 1024;; wave_7b) echo 1024;; *) echo 720;; esac + case "{{board}}" in wave_35) echo 320;; wave_5) echo 720;; wave_43) echo 480;; crowpanel) echo 1024;; wave_7b) echo 1024;; p4_pico) echo 720;; *) echo 720;; esac _sim_v_res board: #!/usr/bin/env sh - case "{{board}}" in wave_35) echo 480;; wave_5) echo 1280;; wave_43) echo 800;; crowpanel) echo 600;; wave_7b) echo 600;; *) echo 720;; esac + case "{{board}}" in wave_35) echo 480;; wave_5) echo 1280;; wave_43) echo 800;; crowpanel) echo 600;; wave_7b) echo 600;; p4_pico) echo 1280;; *) echo 720;; esac # Build the desktop simulator sim-build board="wave_4b": (_check_board board) diff --git a/CHANGELOG.md b/CHANGELOG.md index 30dbddf2..9bd357e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [Unreleased] + +### Added +- Board target for the Waveshare ESP32-P4-Pico (`p4_pico`), a display-less module with Raspberry Pi style DSI and CSI connectors and no radio chip, paired with Waveshare's 5-DSI-TOUCH-A (720x1280). The display is the HX8394 panel of the ESP32-P4-WiFi6-Touch-LCD-5, so it shares that board's panel driver, now its own component; its MCU at I2C 0x45 drives the backlight, and the GT911 touch controller is probed at 0x5D and 0x14. Untested on hardware + ## [0.0.20] - 2026-09-23 ### Added diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c3a7117b..cf808f1f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -38,7 +38,7 @@ Do not introduce UI dependencies into core modules. If a core function needs use The project uses two static analysis tools to catch bugs early. Both are available after sourcing ESP-IDF (`source ~/esp/esp-idf/export.sh`), except `cppcheck` which is installed separately. -Both tools cover `main/` and first-party components (`bbqr`, `cUR`, `k_quirc`, `sd_card`, `video`, `wave_4b`, `wave_35`, `wave_43`, `crowpanel`, `wave_7b`). `libwally-core` and `wave_5` are excluded (third-party upstream code: libwally-core is the original; wave_5 ships a vendored ST-style HX8394 driver). +Both tools cover `main/` and first-party components (`bbqr`, `cUR`, `k_quirc`, `sd_card`, `video`, `wave_4b`, `wave_35`, `wave_5`, `wave_43`, `crowpanel`, `wave_7b`, `p4_pico`). `libwally-core` and `esp_lcd_hx8394` are excluded (third-party upstream code: libwally-core is the original; esp_lcd_hx8394 is a vendored ST-style HX8394 driver). **clang-tidy** (recommended, catches real bugs): ```bash @@ -51,8 +51,8 @@ clang-tidy -p build/compile_commands.json main/core/wallet.c # Run on all project source files (excluding libwally-core) find main components/bbqr components/cUR components/k_quirc \ components/sd_card components/video \ - components/wave_4b components/wave_35 components/wave_43 components/crowpanel \ - components/wave_7b \ + components/wave_4b components/wave_35 components/wave_5 components/wave_43 components/crowpanel \ + components/wave_7b components/p4_pico \ -name '*.c' -not -path '*/build/*' 2>/dev/null | \ xargs -P$(nproc) -I{} clang-tidy -p build/compile_commands.json {} ``` @@ -66,8 +66,8 @@ The project `.clang-tidy` config enables bug-finding and security checks tuned f # Run on project source directories cppcheck main/ components/bbqr components/cUR components/k_quirc \ components/sd_card components/video \ - components/wave_4b components/wave_35 components/wave_43 components/crowpanel \ - components/wave_7b \ + components/wave_4b components/wave_35 components/wave_5 components/wave_43 components/crowpanel \ + components/wave_7b components/p4_pico \ --enable=warning,style,performance \ --suppress=missingIncludeSystem \ --suppress=missingInclude \ diff --git a/README.md b/README.md index a12249b7..c343397c 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ It signs PSBTs for single-sig, multisig and miniscript policies on both native s ## Hardware -Kern supports five Waveshare ESP32-P4 boards and one Elecrow CrowPanel board: +Kern supports five Waveshare ESP32-P4 boards, one Elecrow CrowPanel board, and the display-less Waveshare ESP32-P4-Pico paired with a Waveshare DSI display: | Board | Display | Touch | Camera | |-------|---------|-------|--------| @@ -29,8 +29,9 @@ Kern supports five Waveshare ESP32-P4 boards and one Elecrow CrowPanel board: | [ESP32-P4-WiFi6-Touch-LCD-4.3](https://www.waveshare.com/esp32-p4-wifi6-touch-lcd-4.3.htm) (`wave_43`) | 480x800 MIPI DSI | GT911 | OV5647, included | | [ESP32-P4-WiFi6-Touch-LCD-7B](https://www.waveshare.com/esp32-p4-wifi6-touch-lcd-7b.htm) (`wave_7b`) | 1024x600 MIPI DSI | GT911 | OV5647, sold separately | | [CrowPanel Advanced 10.1" ESP32-P4](https://github.com/Elecrow-RD/CrowPanel-Advanced-10.1inch-ESP32-P4-HMI-AI-Display-1024x600-IPS-Touch-Screen) and 7" siblings (`crowpanel`) | 1024x600 MIPI DSI | GT911 | SC2336, included | +| [ESP32-P4-Pico](https://www.waveshare.com/esp32-p4-pico.htm) (`p4_pico`) with a [5-DSI-TOUCH-A](https://www.waveshare.com/wiki/5-DSI-TOUCH-A) | 720x1280 MIPI DSI, sold separately | GT911, on the display | sold separately, OV5647 | -ESP32-P4 does not contain radio (WiFi, BLE), but these boards have a radio in a secondary chip (ESP32-C6 mini). Exploring radio-less, simpler and cheaper ESP32-P4-only boards is part of the project's hardware research. +ESP32-P4 does not contain radio (WiFi, BLE), but the Touch-LCD and CrowPanel boards have a radio in a secondary chip (ESP32-C6 mini). The ESP32-P4-Pico has no radio chip at all; it is the first radio-less target. It drives Waveshare's 5-DSI-TOUCH-A, the same HX8394 panel as the ESP32-P4-WiFi6-Touch-LCD-5, over the 22-pin cable included with the display; the display also needs 5 V from the Pico's header. A MIPI CSI camera module is required for all boards. Kern ships drivers for the OV5647 and SC2336 sensors and probes for whichever one is attached at boot, so @@ -80,13 +81,14 @@ git submodule update --init --recursive ### Building the Project -Build with [just](https://github.com/casey/just) (recommended) or `idf.py` directly. All `just` commands accept a board parameter, one of `wave_4b` (default), `wave_35`, `wave_5`, `wave_43`, `crowpanel`, or `wave_7b`: +Build with [just](https://github.com/casey/just) (recommended) or `idf.py` directly. All `just` commands accept a board parameter, one of `wave_4b` (default), `wave_35`, `wave_5`, `wave_43`, `crowpanel`, `wave_7b`, or `p4_pico`: ```bash just build # Build for wave_4b (default) just build wave_35 # Build for wave_35 just build wave_5 # Build for wave_5 just build wave_43 # Build for wave_43 +just build p4_pico # Build for the ESP32-P4-Pico + 5-DSI-TOUCH-A just build crowpanel # Build for CrowPanel 7" / 10.1" just build wave_7b # Build for wave_7b just flash wave_5 # Flash for wave_5 @@ -111,6 +113,9 @@ idf.py -D 'SDKCONFIG_DEFAULTS=sdkconfig.defaults;sdkconfig.defaults.wave_5' buil # wave_43 idf.py -D 'SDKCONFIG_DEFAULTS=sdkconfig.defaults;sdkconfig.defaults.wave_43' build +# p4_pico +idf.py -D 'SDKCONFIG_DEFAULTS=sdkconfig.defaults;sdkconfig.defaults.p4_pico' build + # crowpanel (7" / 10.1") idf.py -D 'SDKCONFIG_DEFAULTS=sdkconfig.defaults;sdkconfig.defaults.crowpanel' build @@ -131,6 +136,7 @@ just sim # Run simulator as wave_4b (720x720) with webcam (V4L2) just sim wave_35 # Run simulator as wave_35 (320x480) just sim wave_5 # Run simulator as wave_5 (720x1280) just sim wave_43 # Run simulator as wave_43 (480x800) +just sim p4_pico # Run simulator as p4_pico (720x1280) just sim crowpanel # Run simulator as crowpanel (1024x600) just sim wave_7b # Run simulator as wave_7b (1024x600) just sim-build wave_35 # Build only @@ -241,6 +247,7 @@ Pre-release firmware is provided **for research and testing purposes only**. Any | `wave_43` | Waveshare ESP32-P4-WiFi6-Touch-LCD-4.3 | 480x800 MIPI DSI | | `crowpanel` | CrowPanel Advanced 7" / 10.1" ESP32-P4 | 1024x600 MIPI DSI | | `wave_7b` | Waveshare ESP32-P4-WiFi6-Touch-LCD-7B | 1024x600 MIPI DSI | +| `p4_pico` | Waveshare ESP32-P4-Pico + 5-DSI-TOUCH-A | 720x1280 MIPI DSI | ### Requirements diff --git a/components/esp_lcd_hx8394/CMakeLists.txt b/components/esp_lcd_hx8394/CMakeLists.txt new file mode 100644 index 00000000..bad126ad --- /dev/null +++ b/components/esp_lcd_hx8394/CMakeLists.txt @@ -0,0 +1,13 @@ +if(CONFIG_KERN_BOARD_WAVE_5 OR CONFIG_KERN_BOARD_P4_PICO) + idf_component_register( + SRCS "esp_lcd_hx8394.c" + INCLUDE_DIRS "include" + REQUIRES esp_lcd + PRIV_REQUIRES driver + ) +else() + idf_component_register( + REQUIRES esp_lcd + PRIV_REQUIRES driver + ) +endif() diff --git a/components/wave_5/esp_lcd_hx8394.c b/components/esp_lcd_hx8394/esp_lcd_hx8394.c similarity index 97% rename from components/wave_5/esp_lcd_hx8394.c rename to components/esp_lcd_hx8394/esp_lcd_hx8394.c index e851d6c8..7f354b7b 100644 --- a/components/wave_5/esp_lcd_hx8394.c +++ b/components/esp_lcd_hx8394/esp_lcd_hx8394.c @@ -1,11 +1,11 @@ /* - * HX8394 MIPI-DSI panel driver for wave_5 BSP. + * HX8394 MIPI-DSI panel driver for the Waveshare 720x1280 5" panel. * * Adapted from waveshare/esp_lcd_hx8394 v1.0.3: * - renamed `color_space` field to `rgb_ele_order` for ESP-IDF >= 6.0 - * - removed private legacy-API I2C bus creation (the TPS65132 power-rail - * chip is initialised separately in wave_5.c before this driver runs, - * using the same i2c_master bus as the rest of the board). + * - removed private legacy-API I2C bus creation (any power-rail chip is + * initialised by the BSP before this driver runs, using the same + * i2c_master bus as the rest of the board). */ #include "soc/soc_caps.h" diff --git a/components/wave_5/include/esp_lcd_hx8394.h b/components/esp_lcd_hx8394/include/esp_lcd_hx8394.h similarity index 100% rename from components/wave_5/include/esp_lcd_hx8394.h rename to components/esp_lcd_hx8394/include/esp_lcd_hx8394.h diff --git a/components/p4_pico/CMakeLists.txt b/components/p4_pico/CMakeLists.txt new file mode 100644 index 00000000..f9878834 --- /dev/null +++ b/components/p4_pico/CMakeLists.txt @@ -0,0 +1,13 @@ +if(CONFIG_KERN_BOARD_P4_PICO) + idf_component_register( + SRCS "p4_pico.c" + INCLUDE_DIRS "include" + REQUIRES driver esp_lcd bsp_common + PRIV_REQUIRES esp_lcd_touch_gt911 esp_lcd_hx8394 + ) +else() + idf_component_register( + REQUIRES driver esp_lcd bsp_common + PRIV_REQUIRES esp_lcd_hx8394 + ) +endif() diff --git a/components/p4_pico/idf_component.yml b/components/p4_pico/idf_component.yml new file mode 100644 index 00000000..8c81d7d1 --- /dev/null +++ b/components/p4_pico/idf_component.yml @@ -0,0 +1,13 @@ +dependencies: + idf: + version: '>=5.4' + esp_lcd_touch_gt911: ^1 + espressif/esp_lvgl_adapter: + version: '>=0.5.1' + public: true + lvgl/lvgl: '>=8,<10' + +description: Minimal BSP for Waveshare ESP32-P4-Pico with a Waveshare 5-DSI-TOUCH-A display (720x1280, HX8394, GT911) +targets: +- esp32p4 +version: 1.0.0 diff --git a/components/p4_pico/include/bsp/display.h b/components/p4_pico/include/bsp/display.h new file mode 100644 index 00000000..0bc2db98 --- /dev/null +++ b/components/p4_pico/include/bsp/display.h @@ -0,0 +1,50 @@ +#pragma once +#include "esp_lcd_mipi_dsi.h" +#include "esp_lcd_types.h" +#include "sdkconfig.h" + +/* LCD color formats */ +#define ESP_LCD_COLOR_FORMAT_RGB565 (1) +#define ESP_LCD_COLOR_FORMAT_RGB888 (2) + +/* LCD display color format */ +#if CONFIG_BSP_LCD_COLOR_FORMAT_RGB888 +#define BSP_LCD_COLOR_FORMAT (ESP_LCD_COLOR_FORMAT_RGB888) +#else +#define BSP_LCD_COLOR_FORMAT (ESP_LCD_COLOR_FORMAT_RGB565) +#endif +/* LCD display color bytes endianess */ +#define BSP_LCD_BIGENDIAN (0) +/* LCD display color bits */ +#define BSP_LCD_BITS_PER_PIXEL (16) +/* LCD display color space */ +#define BSP_LCD_COLOR_SPACE (LCD_RGB_ELEMENT_ORDER_RGB) + +#define BSP_LCD_H_RES (720) +#define BSP_LCD_V_RES (1280) +#define BSP_LCD_MIPI_DSI_LANE_BITRATE_MBPS (700) + +#define BSP_LCD_MIPI_DSI_LANE_NUM (2) +#define BSP_MIPI_DSI_PHY_PWR_LDO_CHAN (3) +#define BSP_MIPI_DSI_PHY_PWR_LDO_VOLTAGE_MV (2500) + +typedef struct { + int dummy; +} bsp_display_config_t; + +typedef struct { + esp_lcd_dsi_bus_handle_t mipi_dsi_bus; + esp_lcd_panel_io_handle_t io; + esp_lcd_panel_handle_t panel; + esp_lcd_panel_handle_t control; +} bsp_lcd_handles_t; + +esp_err_t bsp_display_new(const bsp_display_config_t *config, + esp_lcd_panel_handle_t *ret_panel, + esp_lcd_panel_io_handle_t *ret_io); +esp_err_t bsp_display_new_with_handles(const bsp_display_config_t *config, + bsp_lcd_handles_t *ret_handles); +esp_err_t bsp_display_brightness_init(void); +esp_err_t bsp_display_brightness_set(int brightness_percent); +esp_err_t bsp_display_backlight_on(void); +esp_err_t bsp_display_backlight_off(void); diff --git a/components/p4_pico/include/bsp/esp-bsp.h b/components/p4_pico/include/bsp/esp-bsp.h new file mode 100644 index 00000000..7c143bba --- /dev/null +++ b/components/p4_pico/include/bsp/esp-bsp.h @@ -0,0 +1,2 @@ +#pragma once +#include "bsp/esp32_p4_pico.h" diff --git a/components/p4_pico/include/bsp/esp32_p4_pico.h b/components/p4_pico/include/bsp/esp32_p4_pico.h new file mode 100644 index 00000000..503bceae --- /dev/null +++ b/components/p4_pico/include/bsp/esp32_p4_pico.h @@ -0,0 +1,97 @@ +#pragma once + +#include "bsp/config.h" +#include "bsp/display.h" +#include "driver/gpio.h" +#include "driver/i2c_master.h" +#include "sdkconfig.h" + +#if (BSP_CONFIG_NO_GRAPHIC_LIB == 0) +#include "esp_lv_adapter.h" +#include "lvgl.h" +#endif + +/************************************************************************************************** + * BSP Capabilities + **************************************************************************************************/ + +#define BSP_CAPS_DISPLAY 1 +#define BSP_CAPS_TOUCH 1 +#define BSP_CAPS_BUTTONS 0 +#define BSP_CAPS_AUDIO 0 +#define BSP_CAPS_AUDIO_SPEAKER 0 +#define BSP_CAPS_AUDIO_MIC 0 +#define BSP_CAPS_SDCARD 0 +#define BSP_CAPS_IMU 0 + +/************************************************************************************************** + * Pinout + **************************************************************************************************/ +/* I2C: the same pair is routed to the DISPLAY and CAMERA connectors and to the + * header, so the display MCU, touch controller and camera SCCB all share it. */ +#define BSP_I2C_SCL (GPIO_NUM_8) +#define BSP_I2C_SDA (GPIO_NUM_7) + +/* A Raspberry Pi style DSI cable carries no reset or backlight line: the panel + * takes a DCS soft reset and the MCU on the display drives the backlight. */ +#define BSP_LCD_BACKLIGHT (GPIO_NUM_NC) +#define BSP_LCD_RST (GPIO_NUM_NC) +#define BSP_LCD_TOUCH_RST (GPIO_NUM_NC) +#define BSP_LCD_TOUCH_INT (GPIO_NUM_NC) + +/* I2C address of the display's backlight MCU */ +#define BSP_LCD_MCU_I2C_ADDR (0x45) + +/* Camera I2C (shares main I2C bus on this board) */ +#define BSP_CAM_I2C_SCL BSP_I2C_SCL +#define BSP_CAM_I2C_SDA BSP_I2C_SDA +#define BSP_CAM_HAS_MOTOR 0 + +/************************************************************************************************** + * + * I2C interface + * + **************************************************************************************************/ +#define BSP_I2C_NUM CONFIG_BSP_I2C_NUM + +esp_err_t bsp_i2c_init(void); +esp_err_t bsp_i2c_deinit(void); +i2c_master_bus_handle_t bsp_i2c_get_handle(void); + +/************************************************************************************************** + * + * Wireless co-processor + * + **************************************************************************************************/ + +/** + * @brief The Pico carries no wireless co-processor; this exists so the shared + * boot path can call it unconditionally. Always returns ESP_OK. + */ +esp_err_t bsp_wifi_coproc_disable(void); + +/************************************************************************************************** + * + * LCD interface + * + **************************************************************************************************/ + +#if (BSP_CONFIG_NO_GRAPHIC_LIB == 0) + +lv_display_t *bsp_display_start(void); + +/** + * @brief Take LVGL mutex + * + * @param[in] timeout_ms Timeout in [ms]. 0 will block indefinitely. + * @return true Mutex was taken + * @return false Mutex was NOT taken + */ +bool bsp_display_lock(uint32_t timeout_ms); + +/** + * @brief Give LVGL mutex + */ +void bsp_display_unlock(void); + +#endif diff --git a/components/p4_pico/p4_pico.c b/components/p4_pico/p4_pico.c new file mode 100644 index 00000000..b68f9f36 --- /dev/null +++ b/components/p4_pico/p4_pico.c @@ -0,0 +1,365 @@ +#include "bsp/display.h" +#include "bsp/display_security.h" +#include "bsp/esp32_p4_pico.h" +#include "bsp/touch.h" +#include "bsp_err_check.h" +#include "driver/i2c_master.h" +#include "esp_check.h" +#include "esp_err.h" +#include "esp_lcd_hx8394.h" +#include "esp_lcd_mipi_dsi.h" +#include "esp_lcd_panel_ops.h" +#include "esp_lcd_touch_gt911.h" +#include "esp_ldo_regulator.h" +#include "esp_log.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "sdkconfig.h" +#include + +static const char *TAG = "p4_pico"; + +static bool i2c_initialized = false; +static i2c_master_bus_handle_t i2c_handle = NULL; +static i2c_master_dev_handle_t lcd_mcu = NULL; + +esp_err_t bsp_wifi_coproc_disable(void) { + ESP_LOGI(TAG, "No wireless co-processor on this board"); + return ESP_OK; +} + +esp_err_t bsp_i2c_init(void) { + if (i2c_initialized) { + return ESP_OK; + } + + i2c_master_bus_config_t i2c_bus_conf = { + .clk_source = I2C_CLK_SRC_DEFAULT, + .sda_io_num = BSP_I2C_SDA, + .scl_io_num = BSP_I2C_SCL, + .i2c_port = BSP_I2C_NUM, + .flags.enable_internal_pullup = true, + }; + BSP_ERROR_CHECK_RETURN_ERR(i2c_new_master_bus(&i2c_bus_conf, &i2c_handle)); + + i2c_initialized = true; + + return ESP_OK; +} + +esp_err_t bsp_i2c_deinit(void) { + if (lcd_mcu) { + i2c_master_bus_rm_device(lcd_mcu); + lcd_mcu = NULL; + } + BSP_ERROR_CHECK_RETURN_ERR(i2c_del_master_bus(i2c_handle)); + i2c_initialized = false; + return ESP_OK; +} + +i2c_master_bus_handle_t bsp_i2c_get_handle(void) { return i2c_handle; } + +static esp_err_t bsp_i2c_device_probe(uint8_t addr) { + return i2c_master_probe(i2c_handle, addr, 100); +} + +esp_err_t bsp_display_brightness_init(void) { + if (lcd_mcu) { + return ESP_OK; + } + BSP_ERROR_CHECK_RETURN_ERR(bsp_i2c_init()); + if (bsp_i2c_device_probe(BSP_LCD_MCU_I2C_ADDR) != ESP_OK) { + ESP_LOGE(TAG, "No display MCU at 0x%02X: is the display attached?", + BSP_LCD_MCU_I2C_ADDR); + return ESP_ERR_NOT_FOUND; + } + const i2c_device_config_t dev_cfg = { + .dev_addr_length = I2C_ADDR_BIT_LEN_7, + .device_address = BSP_LCD_MCU_I2C_ADDR, + .scl_speed_hz = 100000, + }; + BSP_ERROR_CHECK_RETURN_ERR( + i2c_master_bus_add_device(i2c_handle, &dev_cfg, &lcd_mcu)); + + /* Panel power-up, as wave_5 sends it to the same display MCU: wave_5 + firmware brings this panel up on a Pico, only its GPIO backlight fails. */ + const uint8_t power[][2] = {{0x95, 0x11}, {0x95, 0x17}}; + for (size_t i = 0; i < sizeof(power) / sizeof(power[0]); i++) { + BSP_ERROR_CHECK_RETURN_ERR( + i2c_master_transmit(lcd_mcu, power[i], sizeof(power[i]), 50)); + } + vTaskDelay(pdMS_TO_TICKS(100)); + return ESP_OK; +} + +esp_err_t bsp_display_brightness_set(int brightness_percent) { + if (brightness_percent > 100) { + brightness_percent = 100; + } else if (brightness_percent < 0) { + brightness_percent = 0; + } + + ESP_LOGI(TAG, "Setting LCD backlight: %d%%", brightness_percent); + BSP_ERROR_CHECK_RETURN_ERR(bsp_display_brightness_init()); + + /* Register 0x96 of the display MCU: 0x00 off to 0xFF full */ + const uint8_t buf[2] = {0x96, (uint8_t)(255 * brightness_percent / 100)}; + return i2c_master_transmit(lcd_mcu, buf, sizeof(buf), 50); +} + +esp_err_t bsp_display_backlight_off(void) { + return bsp_display_brightness_set(0); +} + +esp_err_t bsp_display_backlight_on(void) { + return bsp_display_brightness_set(100); +} + +static esp_err_t bsp_enable_dsi_phy_power(void) { +#if BSP_MIPI_DSI_PHY_PWR_LDO_CHAN > 0 + static esp_ldo_channel_handle_t phy_pwr_chan = NULL; + esp_ldo_channel_config_t ldo_cfg = { + .chan_id = BSP_MIPI_DSI_PHY_PWR_LDO_CHAN, + .voltage_mv = BSP_MIPI_DSI_PHY_PWR_LDO_VOLTAGE_MV, + }; + ESP_RETURN_ON_ERROR(esp_ldo_acquire_channel(&ldo_cfg, &phy_pwr_chan), TAG, + "Acquire LDO channel for DPHY failed"); + ESP_LOGI(TAG, "MIPI DSI PHY Powered on"); +#endif + + return ESP_OK; +} + +esp_err_t bsp_display_new(const bsp_display_config_t *config, + esp_lcd_panel_handle_t *ret_panel, + esp_lcd_panel_io_handle_t *ret_io) { + bsp_lcd_handles_t handles = {0}; + esp_err_t ret = bsp_display_new_with_handles(config, &handles); + + *ret_panel = handles.panel; + *ret_io = handles.io; + + return ret; +} + +esp_err_t bsp_display_new_with_handles(const bsp_display_config_t *config, + bsp_lcd_handles_t *ret_handles) { + esp_err_t ret = ESP_OK; + + ESP_RETURN_ON_ERROR(bsp_display_brightness_init(), TAG, + "Brightness init failed"); + ESP_RETURN_ON_ERROR(bsp_enable_dsi_phy_power(), TAG, "DSI PHY power failed"); + + esp_lcd_dsi_bus_handle_t mipi_dsi_bus = NULL; + esp_lcd_dsi_bus_config_t bus_config = { + .bus_id = 0, + .num_data_lanes = BSP_LCD_MIPI_DSI_LANE_NUM, + .lane_bit_rate_mbps = BSP_LCD_MIPI_DSI_LANE_BITRATE_MBPS, + }; + ESP_RETURN_ON_ERROR(esp_lcd_new_dsi_bus(&bus_config, &mipi_dsi_bus), TAG, + "New DSI bus init failed"); + + ESP_LOGI(TAG, "Install MIPI DSI LCD control panel"); + esp_lcd_panel_io_handle_t io = NULL; + esp_lcd_dbi_io_config_t dbi_config = { + .virtual_channel = 0, + .lcd_cmd_bits = 8, + .lcd_param_bits = 8, + }; + esp_lcd_panel_handle_t disp_panel = NULL; + ESP_GOTO_ON_ERROR(esp_lcd_new_panel_io_dbi(mipi_dsi_bus, &dbi_config, &io), + err, TAG, "New panel IO failed"); + + ESP_LOGI(TAG, "Install HX8394 LCD control panel"); + esp_lcd_dpi_panel_config_t dpi_config = { + .dpi_clk_src = MIPI_DSI_DPI_CLK_SRC_DEFAULT, + .dpi_clock_freq_mhz = 58, + .virtual_channel = 0, +#if CONFIG_BSP_LCD_COLOR_FORMAT_RGB888 + .in_color_format = LCD_COLOR_FMT_RGB888, +#else + .in_color_format = LCD_COLOR_FMT_RGB565, +#endif + .num_fbs = CONFIG_BSP_LCD_DPI_BUFFER_NUMS, + .video_timing = + { + .h_size = 720, + .v_size = 1280, + .hsync_back_porch = 20, + .hsync_pulse_width = 20, + .hsync_front_porch = 40, + .vsync_back_porch = 10, + .vsync_pulse_width = 4, + .vsync_front_porch = 24, + }, + }; + + hx8394_vendor_config_t vendor_config = { + .mipi_config = + { + .dsi_bus = mipi_dsi_bus, + .dpi_config = &dpi_config, + .lane_num = BSP_LCD_MIPI_DSI_LANE_NUM, + }, + }; + esp_lcd_panel_dev_config_t lcd_dev_config = { +#if CONFIG_BSP_LCD_COLOR_FORMAT_RGB888 + .bits_per_pixel = 24, +#else + .bits_per_pixel = 16, +#endif + .rgb_ele_order = BSP_LCD_COLOR_SPACE, + .reset_gpio_num = BSP_LCD_RST, + .vendor_config = &vendor_config, + }; + ESP_GOTO_ON_ERROR(esp_lcd_new_panel_hx8394(io, &lcd_dev_config, &disp_panel), + err, TAG, "New LCD panel failed"); + ESP_GOTO_ON_ERROR(esp_lcd_dpi_panel_enable_dma2d(disp_panel), err, TAG, + "Enable DMA2D failed"); + ESP_GOTO_ON_ERROR(esp_lcd_panel_reset(disp_panel), err, TAG, + "LCD panel reset failed"); + ESP_GOTO_ON_ERROR(esp_lcd_panel_init(disp_panel), err, TAG, + "LCD panel init failed"); + + ret_handles->io = io; + ret_handles->mipi_dsi_bus = mipi_dsi_bus; + ret_handles->panel = disp_panel; + ret_handles->control = NULL; + + ESP_LOGI(TAG, "Display initialized"); + + return ret; + +err: + if (disp_panel) { + esp_lcd_panel_del(disp_panel); + } + if (io) { + esp_lcd_panel_io_del(io); + } + if (mipi_dsi_bus) { + esp_lcd_del_dsi_bus(mipi_dsi_bus); + } + return ret; +} + +esp_err_t bsp_touch_new(const bsp_touch_config_t *config, + esp_lcd_touch_handle_t *ret_touch) { + BSP_ERROR_CHECK_RETURN_ERR(bsp_i2c_init()); + + /* With no INT or RST line to strap it, the GT911 may come up at either + 0x5D (primary) or 0x14 (backup); probe both. */ + const esp_lcd_touch_config_t tp_cfg = { + .x_max = BSP_LCD_H_RES, + .y_max = BSP_LCD_V_RES, + .rst_gpio_num = BSP_LCD_TOUCH_RST, + .int_gpio_num = BSP_LCD_TOUCH_INT, + .levels = + { + .reset = 0, + .interrupt = 0, + }, + .flags = + { + .swap_xy = 0, + .mirror_x = 0, + .mirror_y = 0, + }, + }; + + esp_lcd_panel_io_i2c_config_t tp_io_config; + if (bsp_i2c_device_probe(ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS) == ESP_OK) { + ESP_LOGI(TAG, "GT911 found at 0x%02X", ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS); + esp_lcd_panel_io_i2c_config_t cfg = ESP_LCD_TOUCH_IO_I2C_GT911_CONFIG(); + memcpy(&tp_io_config, &cfg, sizeof(cfg)); + } else if (bsp_i2c_device_probe(ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS_BACKUP) == + ESP_OK) { + ESP_LOGI(TAG, "GT911 found at 0x%02X", + ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS_BACKUP); + esp_lcd_panel_io_i2c_config_t cfg = ESP_LCD_TOUCH_IO_I2C_GT911_CONFIG(); + cfg.dev_addr = ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS_BACKUP; + memcpy(&tp_io_config, &cfg, sizeof(cfg)); + } else { + ESP_LOGE(TAG, "GT911 not found at either I2C address"); + return ESP_ERR_NOT_FOUND; + } + tp_io_config.scl_speed_hz = CONFIG_BSP_I2C_CLK_SPEED_HZ; + + esp_lcd_panel_io_handle_t tp_io_handle = NULL; + ESP_RETURN_ON_ERROR( + esp_lcd_new_panel_io_i2c(i2c_handle, &tp_io_config, &tp_io_handle), TAG, + ""); + + return esp_lcd_touch_new_i2c_gt911(tp_io_handle, &tp_cfg, ret_touch); +} + +#if (BSP_CONFIG_NO_GRAPHIC_LIB == 0) +static lv_display_t *bsp_display_lcd_init(void) { + bsp_lcd_handles_t lcd_panels; + BSP_ERROR_CHECK_RETURN_NULL(bsp_display_new_with_handles(NULL, &lcd_panels)); + bsp_display_register_sensitive_buffers( + lcd_panels.panel, CONFIG_BSP_LCD_DPI_BUFFER_NUMS, + (size_t)BSP_LCD_H_RES * BSP_LCD_V_RES * BSP_LCD_BITS_PER_PIXEL / 8); + + ESP_LOGD(TAG, "Add LCD screen"); + esp_lv_adapter_display_config_t disp_cfg = { + .panel = lcd_panels.panel, + .panel_io = lcd_panels.io, + .profile = + { + .interface = ESP_LV_ADAPTER_PANEL_IF_MIPI_DSI, + .rotation = ESP_LV_ADAPTER_ROTATE_0, + .hor_res = BSP_LCD_H_RES, + .ver_res = BSP_LCD_V_RES, + .buffer_height = 50, + .use_psram = false, + .enable_ppa_accel = false, + .require_double_buffer = false, + }, + .tear_avoid_mode = ESP_LV_ADAPTER_TEAR_AVOID_MODE_NONE, + .te_sync = ESP_LV_ADAPTER_TE_SYNC_DISABLED(), + }; + + return esp_lv_adapter_register_display(&disp_cfg); +} + +static lv_indev_t *bsp_display_indev_init(lv_display_t *disp) { + esp_lcd_touch_handle_t tp; + BSP_ERROR_CHECK_RETURN_NULL(bsp_touch_new(NULL, &tp)); + assert(tp); + + const esp_lv_adapter_touch_config_t touch_cfg = + ESP_LV_ADAPTER_TOUCH_DEFAULT_CONFIG(disp, tp); + + return esp_lv_adapter_register_touch(&touch_cfg); +} + +lv_display_t *bsp_display_start(void) { + esp_lv_adapter_config_t adapter_cfg = ESP_LV_ADAPTER_DEFAULT_CONFIG(); + // Larger task stack: libwally descriptor parsing has deep call chains + adapter_cfg.task_stack_size = 16384; + adapter_cfg.stack_in_psram = false; + BSP_ERROR_CHECK_RETURN_NULL(esp_lv_adapter_init(&adapter_cfg)); + + BSP_ERROR_CHECK_RETURN_NULL(bsp_display_brightness_init()); + + lv_display_t *disp; + BSP_NULL_CHECK(disp = bsp_display_lcd_init(), NULL); + BSP_NULL_CHECK(bsp_display_indev_init(disp), NULL); + + ESP_ERROR_CHECK(esp_lv_adapter_start()); + + return disp; +} + +bool bsp_display_lock(uint32_t timeout_ms) { + // esp_lv_adapter_lock treats 0 as "try once, fail immediately", + // but callers use 0 to mean "block forever" (matching esp_lvgl_port + // convention). Translate 0 → -1 (portMAX_DELAY). + int32_t ms = (timeout_ms == 0) ? -1 : (int32_t)timeout_ms; + return esp_lv_adapter_lock(ms) == ESP_OK; +} + +void bsp_display_unlock(void) { esp_lv_adapter_unlock(); } + +#endif diff --git a/components/video/CMakeLists.txt b/components/video/CMakeLists.txt index 7974e532..66f16aa7 100644 --- a/components/video/CMakeLists.txt +++ b/components/video/CMakeLists.txt @@ -1,5 +1,5 @@ idf_component_register( SRCS "video.c" INCLUDE_DIRS "." - REQUIRES esp_cam_sensor esp_video esp_sccb_intf wave_4b wave_35 wave_5 wave_43 crowpanel wave_7b secure_memory + REQUIRES esp_cam_sensor esp_video esp_sccb_intf wave_4b wave_35 wave_5 wave_43 crowpanel wave_7b p4_pico secure_memory ) diff --git a/components/wave_5/CMakeLists.txt b/components/wave_5/CMakeLists.txt index ce755ba6..22b83a9c 100644 --- a/components/wave_5/CMakeLists.txt +++ b/components/wave_5/CMakeLists.txt @@ -1,12 +1,13 @@ if(CONFIG_KERN_BOARD_WAVE_5) idf_component_register( - SRCS "wave_5.c" "esp_lcd_hx8394.c" + SRCS "wave_5.c" INCLUDE_DIRS "include" REQUIRES driver esp_lcd esp_driver_ledc bsp_common - PRIV_REQUIRES esp_lcd_touch_gt911 + PRIV_REQUIRES esp_lcd_touch_gt911 esp_lcd_hx8394 ) else() idf_component_register( REQUIRES driver esp_lcd esp_driver_ledc bsp_common + PRIV_REQUIRES esp_lcd_hx8394 ) endif() diff --git a/dependencies.lock b/dependencies.lock index 3a35d40f..76d87539 100644 --- a/dependencies.lock +++ b/dependencies.lock @@ -479,6 +479,6 @@ direct_dependencies: - espressif/zlib - idf - lvgl/lvgl -manifest_hash: a2ce878214ee5baf39853e69d7efc73c3b9c4e339ae1e753ff6d5bcd4e2f25a8 +manifest_hash: 120480420ff2d4d96df9360b613fd5014a8c351b3222c6a0156683cec63768b5 target: esp32p4 version: 3.0.0 diff --git a/docs/design-guidelines.md b/docs/design-guidelines.md index 6f375fff..7161038d 100644 --- a/docs/design-guidelines.md +++ b/docs/design-guidelines.md @@ -50,6 +50,7 @@ Font sizes are **derived, not hand-picked**. `tools/derive_font_sizes.py` holds | crowpanel | 24 / 34 | | wave_7b | 24 / 34 | | wave_5 | 28 / 40 | +| p4_pico | 28 / 40 | To retune: edit the targets/specs in `derive_font_sizes.py`, run `python3 tools/derive_font_sizes.py --apply`, then `scripts/bake_icons.sh`, then rebuild. diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 21e22090..25d6b5b5 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -27,13 +27,17 @@ elseif(CONFIG_KERN_BOARD_WAVE_7B) set(TOUCH_DRIVER esp_lcd_touch_gt911) set(FONT_POLICY_WIDTH 1024) set(FONT_POLICY_HEIGHT 600) +elseif(CONFIG_KERN_BOARD_P4_PICO) + set(TOUCH_DRIVER esp_lcd_touch_gt911) + set(FONT_POLICY_WIDTH 720) + set(FONT_POLICY_HEIGHT 1280) endif() idf_component_register( SRCS ${SOURCES} INCLUDE_DIRS . PRIV_REQUIRES lvgl ${TOUCH_DRIVER} k_quirc esp_timer wave_4b wave_35 wave_5 wave_43 - crowpanel wave_7b libwally-core cUR sd_card bbqr deflate_codec video spiffs + crowpanel wave_7b p4_pico libwally-core cUR sd_card bbqr deflate_codec video spiffs nvs_flash efuse esp_hw_support esp_app_format mbedtls bip138 esp_driver_ppa app_update bootloader_support secure_memory bsp_common bus_timeout diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild index 1dbbba9f..040fb062 100644 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -23,6 +23,9 @@ menu "Kern Configuration" config KERN_BOARD_WAVE_7B bool "Waveshare ESP32-P4-WiFi6-Touch-LCD-7B (1024x600 MIPI DSI)" + + config KERN_BOARD_P4_PICO + bool "Waveshare ESP32-P4-Pico + 5-DSI-TOUCH-A (720x1280 MIPI DSI)" endchoice config KERN_PBKDF2_HW_SHA diff --git a/scripts/format.sh b/scripts/format.sh index a42a929a..6deb1b43 100755 --- a/scripts/format.sh +++ b/scripts/format.sh @@ -52,8 +52,10 @@ DIRS=( "$REPO_ROOT/components/wave_35" "$REPO_ROOT/components/wave_43" "$REPO_ROOT/components/wave_5" + "$REPO_ROOT/components/esp_lcd_hx8394" "$REPO_ROOT/components/crowpanel" "$REPO_ROOT/components/wave_7b" + "$REPO_ROOT/components/p4_pico" ) if $CHECK_MODE; then diff --git a/scripts/release.sh b/scripts/release.sh index f4f27fbe..3cc6081e 100755 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -3,7 +3,7 @@ set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" -BOARDS="wave_4b wave_35 wave_5 wave_43 crowpanel wave_7b" +BOARDS="wave_4b wave_35 wave_5 wave_43 crowpanel wave_7b p4_pico" # Each board twice: ESP32-P4 chip revision v1.x, then v3.x (_v3) DEVICES="$BOARDS $(printf '%s_v3 ' $BOARDS)" VERSION=$(tr -d '[:space:]' < "$REPO_ROOT/version.txt") diff --git a/sdkconfig.defaults.p4_pico b/sdkconfig.defaults.p4_pico new file mode 100644 index 00000000..997c14e4 --- /dev/null +++ b/sdkconfig.defaults.p4_pico @@ -0,0 +1,5 @@ +# Board: Waveshare ESP32-P4-Pico + 5-DSI-TOUCH-A (720x1280 MIPI DSI) +CONFIG_KERN_BOARD_P4_PICO=y +CONFIG_LV_FONT_MONTSERRAT_28=y +CONFIG_LV_FONT_MONTSERRAT_40=y +CONFIG_ESPTOOLPY_FLASHMODE_QIO=y diff --git a/simulator/CMakeLists.txt b/simulator/CMakeLists.txt index 7847a208..0e9d18b2 100644 --- a/simulator/CMakeLists.txt +++ b/simulator/CMakeLists.txt @@ -436,6 +436,7 @@ target_compile_definitions(kern_simulator PRIVATE $<$:CONFIG_KERN_BOARD_WAVE_43=1> $<$:CONFIG_KERN_BOARD_CROWPANEL=1> $<$:CONFIG_KERN_BOARD_WAVE_7B=1> + $<$:CONFIG_KERN_BOARD_P4_PICO=1> ) target_compile_options(kern_simulator PRIVATE diff --git a/site/flash/index.html b/site/flash/index.html index 358d68ef..ecd287a5 100644 --- a/site/flash/index.html +++ b/site/flash/index.html @@ -181,6 +181,7 @@

Web Flasher

+
diff --git a/site/index.html b/site/index.html index 6253ebc9..f170f64e 100644 --- a/site/index.html +++ b/site/index.html @@ -293,6 +293,10 @@

Supported hardware

CrowPanel Advanced 7″ / 10.1″ crowpanel1024×600 MIPI DSISC2336, included + + Waveshare ESP32-P4-Pico + 5-DSI-TOUCH-A + p4_pico720×1280 MIPI DSI, sold separatelyOV5647, sold separately + diff --git a/tools/derive_font_sizes.py b/tools/derive_font_sizes.py index d3844dd9..92169210 100644 --- a/tools/derive_font_sizes.py +++ b/tools/derive_font_sizes.py @@ -38,6 +38,7 @@ {"name": "crowpanel", "sdkconfig": "sdkconfig.defaults.crowpanel", "w": 1024, "h": 600, "diag_in": 7.0}, {"name": "wave_7b", "sdkconfig": "sdkconfig.defaults.wave_7b", "w": 1024, "h": 600, "diag_in": 7.0}, {"name": "wave_5", "sdkconfig": "sdkconfig.defaults.wave_5", "w": 720, "h": 1280, "diag_in": 5.0}, + {"name": "p4_pico", "sdkconfig": "sdkconfig.defaults.p4_pico", "w": 720, "h": 1280, "diag_in": 5.0}, ] # --- Curve knobs (adjust these) ----------------------------------------------