From e247969bca9ff03e4263a778db5eda11817bdaa1 Mon Sep 17 00:00:00 2001 From: Miroslav Pivovarsky Date: Thu, 27 Jun 2024 22:19:31 +0200 Subject: [PATCH] init templates for ESP32-S3-CAM modules --- .../ESP32_PrusaConnectCam.ino | 9 +- ESP32_PrusaConnectCam/camera.cpp | 6 ++ ESP32_PrusaConnectCam/mcu_cfg.h | 3 +- ESP32_PrusaConnectCam/micro_sd.cpp | 2 + .../module_AI_Thinker_ESP32-CAM.h | 6 ++ .../module_ESP32-WROVER-DEV.h | 3 + ESP32_PrusaConnectCam/module_ESP32_S3_CAM.h | 88 +++++++++++++++++++ ESP32_PrusaConnectCam/module_templates.h | 12 ++- ESP32_PrusaConnectCam/system.h | 9 +- 9 files changed, 129 insertions(+), 9 deletions(-) create mode 100644 ESP32_PrusaConnectCam/module_ESP32_S3_CAM.h diff --git a/ESP32_PrusaConnectCam/ESP32_PrusaConnectCam.ino b/ESP32_PrusaConnectCam/ESP32_PrusaConnectCam.ino index 47c70b1..e0da57f 100644 --- a/ESP32_PrusaConnectCam/ESP32_PrusaConnectCam.ino +++ b/ESP32_PrusaConnectCam/ESP32_PrusaConnectCam.ino @@ -108,14 +108,14 @@ void setup() { /* init wdg */ SystemLog.AddEvent(LogLevel_Info, F("Init WDG")); esp_task_wdt_config_t twdt_config; - twdt_config.timeout_ms = 60000; + twdt_config.timeout_ms = WDG_TIMEOUT; twdt_config.idle_core_mask = (1 << portNUM_PROCESSORS) - 1, /* Bitmask of all cores */ twdt_config.trigger_panic = true; + esp_task_wdt_init(&twdt_config); /* enable panic so ESP32 restarts */ esp_task_wdt_reconfigure(&twdt_config); - //ESP_ERROR_CHECK(esp_task_wdt_init(&twdt_config)); /* enable panic so ESP32 restarts */ ESP_ERROR_CHECK(esp_task_wdt_add(NULL)); /* add current thread to WDT watch */ - ESP_ERROR_CHECK(esp_task_wdt_reset()); /* reset wdg */ + esp_task_wdt_reset(); /* reset wdg */ /* init tasks */ SystemLog.AddEvent(LogLevel_Info, F("Start tasks")); @@ -145,7 +145,8 @@ void setup() { void loop() { /* reset wdg */ - ESP_ERROR_CHECK(esp_task_wdt_reset()); + esp_task_wdt_reset(); + delay(1000); } /* EOF */ \ No newline at end of file diff --git a/ESP32_PrusaConnectCam/camera.cpp b/ESP32_PrusaConnectCam/camera.cpp index 113c702..4334e82 100644 --- a/ESP32_PrusaConnectCam/camera.cpp +++ b/ESP32_PrusaConnectCam/camera.cpp @@ -48,9 +48,11 @@ Camera::Camera(Configuration* i_conf, Logs* i_log, uint8_t i_FlashPin) { void Camera::Init() { log->AddEvent(LogLevel_Info, F("Init camera lib")); +#if (true == ENABLE_CAMERA_FLASH) log->AddEvent(LogLevel_Info, F("Init GPIO")); ledcAttach(FLASH_GPIO_NUM, FLASH_PWM_FREQ, FLASH_PWM_RESOLUTION); SetFlashStatus(false); +#endif InitCameraModule(); ApplyCameraCfg(); @@ -65,7 +67,9 @@ void Camera::Init() { void Camera::InitCameraModule() { log->AddEvent(LogLevel_Info, F("Init camera module")); /* Turn-off the 'brownout detector' */ +#if (true == ENABLE_BROWN_OUT_DETECTION) WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); +#endif esp_err_t err; CameraConfig.ledc_channel = LEDC_CHANNEL_0; @@ -211,11 +215,13 @@ void Camera::SetPhotoSending(bool i_data) { @return none */ void Camera::SetFlashStatus(bool i_data) { +#if (true == ENABLE_CAMERA_FLASH) if (true == i_data) { ledcWrite(FLASH_GPIO_NUM, FLASH_ON_STATUS); } else if (false == i_data) { ledcWrite(FLASH_GPIO_NUM, FLASH_OFF_STATUS); } +#endif } /** diff --git a/ESP32_PrusaConnectCam/mcu_cfg.h b/ESP32_PrusaConnectCam/mcu_cfg.h index bc68134..ac0af2c 100644 --- a/ESP32_PrusaConnectCam/mcu_cfg.h +++ b/ESP32_PrusaConnectCam/mcu_cfg.h @@ -16,6 +16,7 @@ /* ----------------- CAMERA TYPE ---------------*/ #define AI_THINKER_ESP32_CAM //#define ESP32_WROVER_DEV +//#define CAMERA_MODEL_ESP32_S3_CAM /* ---------------- BASIC MCU CFG --------------*/ #define SW_VERSION "1.1.0-rc1" ///< SW version @@ -50,7 +51,7 @@ /* --------------- WEB SERVER CFG --------------*/ #define WEB_SERVER_PORT 80 ///< WEB server port #define SERIAL_PORT_SPEED 115200 ///< baud rate -#define WDG_TIMEOUT 40 ///< wdg timeout [second] +#define WDG_TIMEOUT 40000 ///< wdg timeout [second] #define PHOTO_FRAGMENT_SIZE 5120 ///< photo fragmentation size [bytes] #define LOOP_DELAY 100 ///< loop delay [ms] #define WIFI_CLIENT_WAIT_CON false ///< wait for connecting to WiFi network diff --git a/ESP32_PrusaConnectCam/micro_sd.cpp b/ESP32_PrusaConnectCam/micro_sd.cpp index d01edf1..519953c 100644 --- a/ESP32_PrusaConnectCam/micro_sd.cpp +++ b/ESP32_PrusaConnectCam/micro_sd.cpp @@ -115,6 +115,8 @@ void MicroSd::InitSdCard() { /* set SD card to 1-line/1-bit mode. GPIO 4 is used for LED and for microSD card. But communication is slower. */ /* https://github.com/espressif/arduino-esp32/blob/master/libraries/SD_MMC/src/SD_MMC.h */ + SD_MMC.setPins(SD_PIN_CLK, SD_PIN_CMD, SD_PIN_DATA0); + if (!SD_MMC.begin("/sdcard", true)) { Serial.println(F("SD Card Mount Failed")); CardDetected = false; diff --git a/ESP32_PrusaConnectCam/module_AI_Thinker_ESP32-CAM.h b/ESP32_PrusaConnectCam/module_AI_Thinker_ESP32-CAM.h index e7d0df5..ba7d43a 100644 --- a/ESP32_PrusaConnectCam/module_AI_Thinker_ESP32-CAM.h +++ b/ESP32_PrusaConnectCam/module_AI_Thinker_ESP32-CAM.h @@ -45,6 +45,9 @@ #define HREF_GPIO_NUM 23 ///< Line sync pin #define PCLK_GPIO_NUM 22 ///< Pixel clock pin +/* ------------------ MCU CFG ------------------*/ +#define ENABLE_BROWN_OUT_DETECTION true ///< Enable brown out detection + /* --------------- OTA UPDATE CFG --------------*/ #define OTA_UPDATE_FW_FILE PSTR("ESP32_PrusaConnectCam.ino.bin") ///< OTA update firmware file name @@ -59,6 +62,9 @@ /* --------------- SD CARD CFG ---------------*/ #define ENABLE_SD_CARD true ///< Enable SD card function +#define SD_PIN_CLK 14 ///< GPIO pin for SD card clock +#define SD_PIN_CMD 15 ///< GPIO pin for SD card command +#define SD_PIN_DATA0 2 ///< GPIO pin for SD card data 0 /* ---------- RESET CFG CONFIGURATION ----------*/ #define CFG_RESET_PIN 12 ///< GPIO 16 is for reset CFG to default diff --git a/ESP32_PrusaConnectCam/module_ESP32-WROVER-DEV.h b/ESP32_PrusaConnectCam/module_ESP32-WROVER-DEV.h index 64ef39a..e418003 100644 --- a/ESP32_PrusaConnectCam/module_ESP32-WROVER-DEV.h +++ b/ESP32_PrusaConnectCam/module_ESP32-WROVER-DEV.h @@ -45,6 +45,9 @@ #define HREF_GPIO_NUM 23 ///< Line sync pin #define PCLK_GPIO_NUM 22 ///< Pixel clock pin +/* ------------------ MCU CFG ------------------*/ +#define ENABLE_BROWN_OUT_DETECTION true ///< Enable brown out detection + /* --------------- OTA UPDATE CFG --------------*/ #define OTA_UPDATE_FW_FILE PSTR("ESP32_WROVER_DEV_PrusaConnectCam.ino.bin") ///< OTA update firmware file name diff --git a/ESP32_PrusaConnectCam/module_ESP32_S3_CAM.h b/ESP32_PrusaConnectCam/module_ESP32_S3_CAM.h new file mode 100644 index 0000000..1b66444 --- /dev/null +++ b/ESP32_PrusaConnectCam/module_ESP32_S3_CAM.h @@ -0,0 +1,88 @@ +/** + @file module_ESP32-WROVER-DEV.h + + @brief Definition of the ESP32-S3 DEV CAM module + + @author Miroslav Pivovarsky + Contact: miroslav.pivovarsky@gmail.com + + Board configuration in the arduino IDE 2.3.2 + Tools -> Board -> ESP32 Arduino -> ESP32S3 Dev Module + Tools -> USB CDC on BOOT -> Enabled + Tools -> CPU Frequency -> 240MHz (WiFi/BT) + Tools -> Core debug level -> None + Tools -> USB DFU on BOOT -> Disable + Tools -> Events Run On -> Core 1 + Tools -> Flash Mode -> DIO 80MHz + Tools -> Flash Size -> 16MB + Tools -> Jtag Adapter -> Disable + Tools -> Arduino Runs On -> Core 1 + Tools -> USB Firmware MSC On Boot -> Disable + Tools -> Partition scheme -> Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS) + Tools -> PSRAM -> QSPI PSRAM + Tools -> Upload Mode -> UART0 / Hardware CDC + Tools -> Upload Speed -> 921600 + Tools -> USB Mode -> Hardware CDC & JTAG + Tools -> Zigbee mode -> Disable + + Left USB-C connector is for programming and serial monitor + + @bug: Currently SW don't work with this DEV board. WiFi and MicroSD is not working + +*/ + +#pragma once + +#include "mcu_cfg.h" + +#ifdef CAMERA_MODEL_ESP32_S3_CAM + +/* --------------- CAMERA CFG -------------------*/ +#define PWDN_GPIO_NUM -1 ///< Power down control pin +#define RESET_GPIO_NUM -1 ///< Reset control pin +#define XCLK_GPIO_NUM 10 ///< External clock pin +#define SIOD_GPIO_NUM 21 ///< SCCB: SI/O data pin +#define SIOC_GPIO_NUM 14 ///< SCCB: SI/O control pin +#define Y9_GPIO_NUM 11 ///< SCCB: Y9 pin +#define Y8_GPIO_NUM 9 ///< SCCB: Y8 pin +#define Y7_GPIO_NUM 8 ///< SCCB: Y7 pin +#define Y6_GPIO_NUM 6 ///< SCCB: Y6 pin +#define Y5_GPIO_NUM 4 ///< SCCB: Y5 pin +#define Y4_GPIO_NUM 2 ///< SCCB: Y4 pin +#define Y3_GPIO_NUM 3 ///< SCCB: Y3 pin +#define Y2_GPIO_NUM 5 ///< SCCB: Y2 pin +#define VSYNC_GPIO_NUM 13 ///< Vertical sync pin +#define HREF_GPIO_NUM 12 ///< Line sync pin +#define PCLK_GPIO_NUM 7 ///< Pixel clock pin + +/* ------------------ MCU CFG ------------------*/ +#define ENABLE_BROWN_OUT_DETECTION false ///< Enable brown out detection + +/* --------------- OTA UPDATE CFG --------------*/ +#define OTA_UPDATE_FW_FILE PSTR("ESP32_S3_CAM_PrusaConnectCam.ino.bin") ///< OTA update firmware file name + +/* --------------- FLASH LED CFG ---------------*/ +#define ENABLE_CAMERA_FLASH false ///< Enable camera flash function +#define FLASH_GPIO_NUM 4 ///< Flash control pin +#define FLASH_OFF_STATUS 0 ///< PWM intensity LED for OFF. 0-2^FLASH_PWM_RESOLUTION = 0-255 +#define FLASH_ON_STATUS 205 ///< PWM intensity LED for ON. limitation to 80%. 2^FLASH_PWM_RESOLUTION * 0.8% = 204 +#define FLASH_PWM_FREQ 2000 ///< frequency of pwm [240MHz / (100 prescale * pwm cycles)] = frequency +#define FLASH_PWM_CHANNEL 0 ///< channel 0 +#define FLASH_PWM_RESOLUTION 8 ///< range 1-20bit. 8bit = 0-255 range + +/* --------------- SD CARD CFG ---------------*/ +#define ENABLE_SD_CARD true ///< Enable SD card function +#define SD_PIN_CLK 42 ///< GPIO pin for SD card clock +#define SD_PIN_CMD 39 ///< GPIO pin for SD card command +#define SD_PIN_DATA0 41 ///< GPIO pin for SD card data 0 + +/* ---------- RESET CFG CONFIGURATION ----------*/ +#define CFG_RESET_PIN 2 ///< GPIO 16 is for reset CFG to default + +/* -------------- STATUS LED CFG ----------------*/ +#define STATUS_LED_ENABLE true ///< enable/disable status LED +#define STATUS_LED_GPIO_NUM 34 ///< GPIO pin for status LED +#define STATUS_LED_OFF_PIN_LEVEL LOW ///< GPIO pin level for status LED ON + +#endif // ESP32_WROVER_DEV +/* EOF */ \ No newline at end of file diff --git a/ESP32_PrusaConnectCam/module_templates.h b/ESP32_PrusaConnectCam/module_templates.h index 3db5e69..5af0d6d 100644 --- a/ESP32_PrusaConnectCam/module_templates.h +++ b/ESP32_PrusaConnectCam/module_templates.h @@ -14,12 +14,18 @@ #include "mcu_cfg.h" -#ifdef AI_THINKER_ESP32_CAM +#if defined(AI_THINKER_ESP32_CAM) #include "module_AI_Thinker_ESP32-CAM.h" -#endif -#ifdef ESP32_WROVER_DEV +#elif defined(ESP32_WROVER_DEV) #include "module_ESP32-WROVER-DEV.h" + +#elif defined(CAMERA_MODEL_ESP32_S3_CAM) +#include "module_ESP32_S3_CAM.h" + +#else +#error "No module selected" + #endif /* EOF */ \ No newline at end of file diff --git a/ESP32_PrusaConnectCam/system.h b/ESP32_PrusaConnectCam/system.h index 4c0a3a7..f9f079d 100644 --- a/ESP32_PrusaConnectCam/system.h +++ b/ESP32_PrusaConnectCam/system.h @@ -19,9 +19,16 @@ #include #include #include -#include #include +#if defined(CONFIG_IDF_TARGET_ESP32) + #include "esp32/rom/rtc.h" +#elif defined(CONFIG_IDF_TARGET_ESP32S3) + #include "esp32s3/rom/rtc.h" +#else + #error "Unsupported chip target" +#endif + #include "mcu_cfg.h" #include "var.h" #include "cfg.h"