From bf2fd957af642b70749e2e0781d2c21e50e2a999 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Mon, 2 Feb 2026 20:42:51 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Adds=20support=20for=20esp32=20P4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/settings.json | 2 +- boards/esp32p4_dev.json | 33 +++++++++++++++ esp32/include/features.h | 1 + esp32/include/global.h | 21 ++++++++++ esp32/include/motion_states/walk_state.h | 1 + esp32/include/peripherals/camera_service.h | 18 ++++++-- esp32/include/peripherals/led_service.h | 5 +++ esp32/include/settings/camera_settings.h | 11 +++-- esp32/include/settings/peripherals_settings.h | 10 +++++ esp32/partition_table/default_32MB.csv | 8 ++++ esp32/src/CMakeLists.txt | 35 ++++++++++------ esp32/src/idf_component.yml | 13 ++++++ esp32/src/main.cpp | 20 +++++++++ esp32/src/peripherals/camera_service.cpp | 25 ++++++++--- esp32/src/system_service.cpp | 6 ++- platformio.ini | 42 +++++++++++++++++++ 16 files changed, 224 insertions(+), 27 deletions(-) create mode 100644 boards/esp32p4_dev.json create mode 100644 esp32/partition_table/default_32MB.csv diff --git a/.vscode/settings.json b/.vscode/settings.json index 2ff8141..36540a8 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -13,7 +13,7 @@ }, "editor.tabSize": 4, "editor.detectIndentation": false, - "cmake.sourceDirectory": "C:/data/repos/Hardware/Spot Micro - Leika/.pio/libdeps/esp32cam/esp32-camera", + "cmake.sourceDirectory": "C:/data/repos/Hardware/Spot_Micro_Leika", "cSpell.words": [ "Adafruit", "IRAM", diff --git a/boards/esp32p4_dev.json b/boards/esp32p4_dev.json new file mode 100644 index 0000000..417467a --- /dev/null +++ b/boards/esp32p4_dev.json @@ -0,0 +1,33 @@ +{ + "build": { + "core": "esp32", + "extra_flags": [ + "-DBOARD_HAS_PSRAM" + ], + "f_cpu": "360000000L", + "f_flash": "80000000L", + "f_psram": "200000000L", + "flash_mode": "qio", + "mcu": "esp32p4", + "variant": "esp32p4" + }, + "connectivity": [ + "wifi" + ], + "debug": { + "openocd_target": "esp32p4.cfg" + }, + "frameworks": [ + "espidf" + ], + "name": "ESP32-P4 Dev Board (32MB PSRAM + 32MB Flash, C6 coprocessor)", + "upload": { + "flash_size": "32MB", + "maximum_ram_size": 786432, + "maximum_size": 33554432, + "require_upload_port": true, + "speed": 1500000 + }, + "url": "https://docs.espressif.com/projects/esp-dev-kits/en/latest/esp32p4/", + "vendor": "Espressif" +} diff --git a/esp32/include/features.h b/esp32/include/features.h index c06103f..04c3659 100644 --- a/esp32/include/features.h +++ b/esp32/include/features.h @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include "platform_shared/message.pb.h" diff --git a/esp32/include/global.h b/esp32/include/global.h index 8494410..e801ea5 100644 --- a/esp32/include/global.h +++ b/esp32/include/global.h @@ -23,16 +23,37 @@ #ifndef ESP_PLATFORM_NAME #define ESP_PLATFORM_NAME "ESP32-S3" #endif +#elif CONFIG_IDF_TARGET_ESP32C6 +#include "esp32c6/rom/rtc.h" +#ifndef ESP_PLATFORM_NAME +#define ESP_PLATFORM_NAME "ESP32-C6" +#endif +#elif CONFIG_IDF_TARGET_ESP32P4 +#include "esp32p4/rom/rtc.h" +#ifndef ESP_PLATFORM_NAME +#define ESP_PLATFORM_NAME "ESP32-P4" +#endif +#define ESP32P4_USES_C6_COPROCESSOR 1 #else #error Target CONFIG_IDF_TARGET is not supported #endif +#if CONFIG_IDF_TARGET_ESP32P4 +#ifndef SDA_PIN +#define SDA_PIN 7 +#endif +#ifndef SCL_PIN +#define SCL_PIN 8 +#endif +#else #ifndef SDA_PIN #define SDA_PIN 21 #endif #ifndef SCL_PIN #define SCL_PIN 22 #endif +#endif + #ifndef I2C_FREQUENCY #define I2C_FREQUENCY 100000UL #endif diff --git a/esp32/include/motion_states/walk_state.h b/esp32/include/motion_states/walk_state.h index 6437f74..cc8ab53 100644 --- a/esp32/include/motion_states/walk_state.h +++ b/esp32/include/motion_states/walk_state.h @@ -2,6 +2,7 @@ #include #include +#include #include #include diff --git a/esp32/include/peripherals/camera_service.h b/esp32/include/peripherals/camera_service.h index a9d97f2..44e4364 100644 --- a/esp32/include/peripherals/camera_service.h +++ b/esp32/include/peripherals/camera_service.h @@ -11,10 +11,16 @@ namespace Camera { +#if USE_CAMERA && !CONFIG_IDF_TARGET_ESP32P4 #include - -#if USE_CAMERA #include +#else +typedef struct { + uint8_t *buf; + size_t len; +} camera_fb_t; +typedef struct { +} sensor_t; #endif #define PART_BOUNDARY "frame" @@ -23,7 +29,11 @@ camera_fb_t *safe_camera_fb_get(); sensor_t *safe_sensor_get(); void safe_sensor_return(); -class CameraService : public StatefulService { +class CameraService +#if USE_CAMERA && !CONFIG_IDF_TARGET_ESP32P4 + : public StatefulService +#endif +{ public: CameraService(); @@ -32,10 +42,12 @@ class CameraService : public StatefulService { esp_err_t cameraStill(httpd_req_t *request); esp_err_t cameraStream(httpd_req_t *request); +#if USE_CAMERA && !CONFIG_IDF_TARGET_ESP32P4 StatefulProtoEndpoint protoEndpoint; private: FSPersistencePB _persistence; void updateCamera(); +#endif }; } // namespace Camera diff --git a/esp32/include/peripherals/led_service.h b/esp32/include/peripherals/led_service.h index 18fd541..b502a45 100644 --- a/esp32/include/peripherals/led_service.h +++ b/esp32/include/peripherals/led_service.h @@ -1,6 +1,7 @@ #ifndef LEDService_h #define LEDService_h +#include #include #include #include @@ -9,8 +10,12 @@ #include #ifndef WS2812_PIN +#if CONFIG_IDF_TARGET_ESP32P4 +#define WS2812_PIN 27 +#else #define WS2812_PIN 12 #endif +#endif #ifndef WS2812_NUM_LEDS #define WS2812_NUM_LEDS 13 diff --git a/esp32/include/settings/camera_settings.h b/esp32/include/settings/camera_settings.h index 76ac494..d5ed451 100644 --- a/esp32/include/settings/camera_settings.h +++ b/esp32/include/settings/camera_settings.h @@ -1,15 +1,20 @@ #pragma once -#include