From 90a17d6e6fc4cc09d57e5515de186448a4dcb551 Mon Sep 17 00:00:00 2001 From: DaOfficialWizard <45744329+ZanzyTHEbar@users.noreply.github.com> Date: Wed, 19 Apr 2023 22:55:52 +0100 Subject: [PATCH] feat: improve the initial USB implementation, increase the XCLK clock for S3 boards - higher framerate over usb * refactor: begin cleaning up USB impl * refactor: factor out the unneeded header - use USB envs instead of a header - use ifndef for one define * fix: disable Observer on wifi handler * refactor: rename wrovers3 environments - add naming convention for QIO PSRAM * ci(ci-fix): fix gh action environments * Increase XCLK frequency to 24MHz for higher frame rates on ESP32-S3 boards (#49) * feat: increase OV2640 clock freq to yield ~70FPS * fix: cleanup comments --------- Co-authored-by: Sebastian Fitt <9294002+Blu3u@users.noreply.github.com> --- .github/workflows/build_release_bins.yml | 33 +------ ESP.code-workspace | 7 +- ESP/ini/boards.ini | 120 +++++++++++------------ ESP/ini/pinouts.ini | 37 +++++++ ESP/lib/src/etvr_system.hpp | 10 -- ESP/lib/src/io/camera/cameraHandler.cpp | 18 +++- ESP/src/main.cpp | 22 ++--- 7 files changed, 126 insertions(+), 121 deletions(-) delete mode 100644 ESP/lib/src/etvr_system.hpp diff --git a/.github/workflows/build_release_bins.yml b/.github/workflows/build_release_bins.yml index 01cc76f..5508b4e 100644 --- a/.github/workflows/build_release_bins.yml +++ b/.github/workflows/build_release_bins.yml @@ -28,42 +28,13 @@ jobs: fail-fast: false matrix: target_name: - [esp32AIThinker, esp32M5Stack, esp32Cam, esp_eye, wrover, wrovers3] + [esp32AIThinker, esp32M5Stack, esp32Cam, esp_eye, wrover, wrooms3QIO, wrooms3QIOUSB, wrooms3, wrooms3USB] target_build_type: ["", _release] #, _OTA] # OTA is not needed runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 with: fetch-depth: 0 - #- name: Cache pip - # uses: actions/cache@v3 - # with: - # path: ~/.cache/pip - # key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - # restore-keys: ${{ runner.os }}-pip- - #- name: Cache PlatformIO - # uses: actions/cache@v3 - # with: - # path: ~/.platformio - # key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} - # restore-keys: | - # ${{ runner.os }}-pio- - #- name: Setup Python install - # uses: actions/setup-python@v4 - # with: - # python-version: "3.x" - #- name: Install PlatformIO with Pip - # run: | - # - # python -m pip install --upgrade pip - # pip install distro - # pip install --upgrade platformio - # pio upgrade --dev - # pio pkg update --global - #- name: Update build command - # working-directory: ./ESP - # run: | - # sed -i '/\[env\]/p; s/\[env\]/upload_protocol = custom/' platformio.ini - name: Build OpenIris Firmware uses: addnab/docker-run-action@v3 with: @@ -132,7 +103,7 @@ jobs: fail-fast: false matrix: target_name: - [esp32AIThinker, esp32M5Stack, esp32Cam, esp_eye, wrover, wrovers3] + [esp32AIThinker, esp32M5Stack, esp32Cam, esp_eye, wrover, wrooms3QIO, wrooms3QIOUSB, wrooms3, wrooms3USB] target_build_type: ["", _release] name: Cleanup actions needs: diff --git a/ESP.code-workspace b/ESP.code-workspace index 3841b08..f8dfb24 100644 --- a/ESP.code-workspace +++ b/ESP.code-workspace @@ -59,6 +59,11 @@ "cinttypes": "cpp", "typeinfo": "cpp", "iostream": "cpp" - } + }, + "cSpell.words": [ + "ESPS", + "JTAG", + "sccb" + ] } } \ No newline at end of file diff --git a/ESP/ini/boards.ini b/ESP/ini/boards.ini index 345c02c..e559fd9 100644 --- a/ESP/ini/boards.ini +++ b/ESP/ini/boards.ini @@ -16,20 +16,9 @@ build_type = release build_flags = ${env.build_flags} -DDEBUG_MODE=0 ; Set the debug mode -DCORE_DEBUG_LEVEL=1 - -DDEBUG_ESP_OTA ; CAMERA PINOUT DEFINITIONS ${pinoutsAIThinker.build_flags} -; Experimental OTA Environment - do not select unless you know what you are doing -[env:esp32AIThinker_OTA] -extends = env:esp32AIThinker_release -upload_port = ${ota.otaserverip} -upload_protocol = espota -upload_flags = - --port=${ota.otaserverport} - --auth=${ota.otapassword} -build_type = release - [env:esp32M5Stack] board = esp32cam build_type = debug @@ -46,14 +35,6 @@ build_flags = ${env.build_flags} -DCORE_DEBUG_LEVEL=1 ${pinoutsESPCAM_M5STACK.build_flags} -[env:esp32M5Stack_OTA] -extends = env:esp32M5Stack_release -upload_port = ${ota.otaserverip} -upload_protocol = espota -upload_flags = - --port=${ota.otaserverport} - --auth=${ota.otapassword} - [env:esp32Cam] board = esp32cam build_type = debug @@ -69,20 +50,9 @@ build_type = release build_flags = ${env.build_flags} -DDEBUG_MODE=0 ; Set the debug mode -DCORE_DEBUG_LEVEL=1 - -DDEBUG_ESP_OTA ; CAMERA PINOUT DEFINITIONS ${pinoutsESPCam.build_flags} -; Experimental OTA Environment - do not select unless you know what you are doing -[env:esp32Cam_OTA] -extends = env:esp32Cam_release -upload_port = ${ota.otaserverip} -upload_protocol = espota -upload_flags = - --port=${ota.otaserverport} - --auth=${ota.otapassword} -build_type = release - [env:esp_eye] board = esp-wrover-kit ;board_build.f_flash = 80000000L @@ -101,20 +71,9 @@ build_type = release build_flags = ${env.build_flags} -DDEBUG_MODE=0 ; Set the debug mode -DCORE_DEBUG_LEVEL=1 - -DDEBUG_ESP_OTA ; CAMERA PINOUT DEFINITIONS ${pinoutsESP-EYE.build_flags} -; Experimental OTA Environment - do not select unless you know what you are doing -[env:esp_eye_OTA] -extends = env:esp_eye_release -upload_port = ${ota.otaserverip} -upload_protocol = espota -upload_flags = - --port=${ota.otaserverport} - --auth=${ota.otapassword} -build_type = release - [env:wrover] board = esp-wrover-kit board_build.f_flash = 80000000L @@ -134,19 +93,10 @@ build_type = release build_flags = ${env.build_flags} -DDEBUG_MODE=0 ; Set the debug mode -DCORE_DEBUG_LEVEL=1 - -DDEBUG_ESP_OTA ; CAMERA PINOUT DEFINITIONS ${pinoutsESPWROVER.build_flags} -[env:wrover_OTA] -extends = env:wrover_release -upload_port = ${ota.otaserverip} -upload_protocol = espota -upload_flags = - --port=${ota.otaserverport} - --auth=${ota.otapassword} - -[env:wrovers3] +[env:wrooms3QIO] board = esp32-s3-devkitc-1 board_build.arduino.memory_type = qio_opi build_type = debug @@ -154,10 +104,11 @@ build_flags = ${env.build_flags} -DCORE_DEBUG_LEVEL=4 -DDEBUG_MODE=1 -DARDUINO_USB_CDC_ON_BOOT=1 + -DETVR_EYE_TRACKER_USB_API ${pinoutsESPS3WROVER.build_flags} upload_flags = --no-stub -[env:wrovers3_release] +[env:wrooms3QIO_release] board = esp32-s3-devkitc-1 board_build.arduino.memory_type = qio_opi build_type = release @@ -165,14 +116,63 @@ build_flags = ${env.build_flags} -DDEBUG_MODE=0 -DCORE_DEBUG_LEVEL=1 -DARDUINO_USB_CDC_ON_BOOT=1 - -DDEBUG_ESP_OTA ${pinoutsESPS3WROVER.build_flags} upload_flags = --no-stub -[env:wrovers3_OTA] -extends = env:wrovers3_release -upload_port = ${ota.otaserverip} -upload_protocol = espota -upload_flags = - --port=${ota.otaserverport} - --auth=${ota.otapassword} +[env:wrooms3QIOUSB] +board = esp32-s3-devkitc-1 +board_build.arduino.memory_type = qio_opi +build_type = debug +build_flags = ${env.build_flags} + -DCORE_DEBUG_LEVEL=4 + -DDEBUG_MODE=1 + -DARDUINO_USB_CDC_ON_BOOT=1 + -DETVR_EYE_TRACKER_USB_API + ${pinoutsESPS3WROVER.build_flags} + +[env:wrooms3QIOUSB_release] +board = esp32-s3-devkitc-1 +board_build.arduino.memory_type = qio_opi +build_type = release +build_flags = ${env.build_flags} + -DDEBUG_MODE=0 + -DCORE_DEBUG_LEVEL=1 + -DARDUINO_USB_CDC_ON_BOOT=1 + -DETVR_EYE_TRACKER_USB_API + ${pinoutsESPS3WROVER.build_flags} + +[env:wrooms3] +board = esp32-s3-devkitc-1 +build_type = debug +build_flags = ${env.build_flags} + -DCORE_DEBUG_LEVEL=4 + -DDEBUG_MODE=1 + ${pinoutsESPS3WROOM.build_flags} + +[env:wrooms3_release] +board = esp32-s3-devkitc-1 +build_type = release +build_flags = ${env.build_flags} + -DDEBUG_MODE=0 + -DCORE_DEBUG_LEVEL=1 + ${pinoutsESPS3WROOM.build_flags} + +[env:wrooms3USB] +board = esp32-s3-devkitc-1 +build_type = debug +build_flags = ${env.build_flags} + -DCORE_DEBUG_LEVEL=4 + -DDEBUG_MODE=1 + -DETVR_EYE_TRACKER_USB_API + ${pinoutsESPS3WROOM.build_flags} +upload_flags = --no-stub + +[env:wrooms3USB_release] +board = esp32-s3-devkitc-1 +build_type = release +build_flags = ${env.build_flags} + -DDEBUG_MODE=0 + -DCORE_DEBUG_LEVEL=1 + -DETVR_EYE_TRACKER_USB_API + ${pinoutsESPS3WROOM.build_flags} +upload_flags = --no-stub diff --git a/ESP/ini/pinouts.ini b/ESP/ini/pinouts.ini index a054ca9..6ac2ce1 100644 --- a/ESP/ini/pinouts.ini +++ b/ESP/ini/pinouts.ini @@ -221,3 +221,40 @@ build_flags = -DVSYNC_GPIO_NUM=${pinoutsESPS3WROVER.VSYNC_GPIO_NUM} -DHREF_GPIO_NUM=${pinoutsESPS3WROVER.HREF_GPIO_NUM} -DPCLK_GPIO_NUM=${pinoutsESPS3WROVER.PCLK_GPIO_NUM} + +[pinoutsESPS3WROOM] +pwdn_gpio_num = -1 +reset_gpio_num = -1 +xclk_gpio_num = 15 +siod_gpio_num = 4 +sioc_gpio_num = 5 +y9_gpio_num = 16 +y8_gpio_num = 17 +y7_gpio_num = 18 +y6_gpio_num = 12 +y5_gpio_num = 10 +y4_gpio_num = 8 +y3_gpio_num = 9 +y2_gpio_num = 11 +vsync_gpio_num = 6 +href_gpio_num = 7 +pclk_gpio_num = 13 +build_flags = + '-DCAMERA_MODULE_NAME="ESPS3WROOM"' + -DCONFIG_CAMERA_MODULE_ESPS3WROOM=1 + -DPWDN_GPIO_NUM=${pinoutsESPS3WROVER.PWDN_GPIO_NUM} + -DRESET_GPIO_NUM=${pinoutsESPS3WROVER.RESET_GPIO_NUM} + -DXCLK_GPIO_NUM=${pinoutsESPS3WROVER.XCLK_GPIO_NUM} + -DSIOD_GPIO_NUM=${pinoutsESPS3WROVER.SIOD_GPIO_NUM} + -DSIOC_GPIO_NUM=${pinoutsESPS3WROVER.SIOC_GPIO_NUM} + -DY9_GPIO_NUM=${pinoutsESPS3WROVER.Y9_GPIO_NUM} + -DY8_GPIO_NUM=${pinoutsESPS3WROVER.Y8_GPIO_NUM} + -DY7_GPIO_NUM=${pinoutsESPS3WROVER.Y7_GPIO_NUM} + -DY6_GPIO_NUM=${pinoutsESPS3WROVER.Y6_GPIO_NUM} + -DY5_GPIO_NUM=${pinoutsESPS3WROVER.Y5_GPIO_NUM} + -DY4_GPIO_NUM=${pinoutsESPS3WROVER.Y4_GPIO_NUM} + -DY3_GPIO_NUM=${pinoutsESPS3WROVER.Y3_GPIO_NUM} + -DY2_GPIO_NUM=${pinoutsESPS3WROVER.Y2_GPIO_NUM} + -DVSYNC_GPIO_NUM=${pinoutsESPS3WROVER.VSYNC_GPIO_NUM} + -DHREF_GPIO_NUM=${pinoutsESPS3WROVER.HREF_GPIO_NUM} + -DPCLK_GPIO_NUM=${pinoutsESPS3WROVER.PCLK_GPIO_NUM} diff --git a/ESP/lib/src/etvr_system.hpp b/ESP/lib/src/etvr_system.hpp deleted file mode 100644 index e232fda..0000000 --- a/ESP/lib/src/etvr_system.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef INCLUDED_ETVR_SYSTEM_HPP -#define INCLUDED_ETVR_SYSTEM_HPP - -#if CONFIG_CAMERA_MODULE_ESPS3WROVER -#define ETVR_EYE_TRACKER_USB_API -#else -#define ETVR_EYE_TRACKER_WEB_API -#endif - -#endif // INCLUDED_ETVR_SYSTEM_HPP diff --git a/ESP/lib/src/io/camera/cameraHandler.cpp b/ESP/lib/src/io/camera/cameraHandler.cpp index 68249e8..f2edc33 100644 --- a/ESP/lib/src/io/camera/cameraHandler.cpp +++ b/ESP/lib/src/io/camera/cameraHandler.cpp @@ -11,10 +11,17 @@ void CameraHandler::setupCameraPinout() { log_i("Camera module is undefined"); #endif + // camera external clock signal frequencies + // 10000000 stable + // 16500000 optimal freq on ESP32-CAM (default) + // 20000000 max freq on ESP32-CAM + // 24000000 optimal freq on ESP32-S3 + int xclk_freq_hz = 16500000; + #if CONFIG_CAMERA_MODULE_ESP_EYE /* IO13, IO14 is designed for JTAG by default, * to use it as generalized input, - * firstly declair it as pullup input + * firstly declare it as pullup input **/ pinMode(13, INPUT_PULLUP); pinMode(14, INPUT_PULLUP); @@ -22,11 +29,14 @@ void CameraHandler::setupCameraPinout() { #elif CONFIG_CAMERA_MODULE_CAM_BOARD /* IO13, IO14 is designed for JTAG by default, * to use it as generalized input, - * firstly declair it as pullup input + * firstly declare it as pullup input **/ pinMode(13, INPUT_PULLUP); pinMode(14, INPUT_PULLUP); log_i("CAM_BOARD"); +#elif CONFIG_CAMERA_MODULE_ESPS3WROVER + /* ESP32-S3 is capable of using higher freqs */ + xclk_freq_hz = 24000000; #endif config.ledc_channel = LEDC_CHANNEL_0; @@ -48,9 +58,7 @@ void CameraHandler::setupCameraPinout() { config.pin_sccb_scl = SIOC_GPIO_NUM; config.pin_pwdn = PWDN_GPIO_NUM; config.pin_reset = RESET_GPIO_NUM; - config.xclk_freq_hz = 16500000; // 10000000 stable, - // 16500000 optimal, - // 20000000 max fps + config.xclk_freq_hz = xclk_freq_hz; } void CameraHandler::setupBasicResolution() { diff --git a/ESP/src/main.cpp b/ESP/src/main.cpp index 33cc7f1..d444585 100644 --- a/ESP/src/main.cpp +++ b/ESP/src/main.cpp @@ -1,5 +1,3 @@ -#include - #include #include @@ -7,7 +5,7 @@ #include #include -#ifdef ETVR_EYE_TRACKER_WEB_API +#ifndef ETVR_EYE_TRACKER_USB_API #include #include #include @@ -32,7 +30,7 @@ LEDManager ledManager(33); CameraHandler cameraHandler(deviceConfig); #endif // SIM_ENABLED -#ifdef ETVR_EYE_TRACKER_WEB_API +#ifndef ETVR_EYE_TRACKER_USB_API WiFiHandler wifiHandler(deviceConfig, WIFI_SSID, WIFI_PASSWORD, WIFI_CHANNEL); MDNSHandler mdnsHandler(deviceConfig); #ifdef SIM_ENABLED @@ -43,6 +41,8 @@ StreamServer streamServer; #endif // SIM_ENABLED void etvr_eye_tracker_web_init() { + deviceConfig.attach(mdnsHandler); + //deviceConfig.attach(wifiHandler); wifiHandler._enable_adhoc = ENABLE_ADHOC; wifiHandler.begin(); mdnsHandler.startMDNS(); @@ -92,21 +92,15 @@ void setup() { #ifndef SIM_ENABLED deviceConfig.attach(cameraHandler); #endif // SIM_ENABLED - -#ifdef ETVR_EYE_TRACKER_WEB_API - deviceConfig.attach(mdnsHandler); - deviceConfig.attach(wifiHandler); +#ifndef ETVR_EYE_TRACKER_USB_API + etvr_eye_tracker_web_init(); +#else // ETVR_EYE_TRACKER_WEB_API + WiFi.disconnect(true); #endif // ETVR_EYE_TRACKER_WEB_API deviceConfig.initConfig(); deviceConfig.load(); -#ifdef ETVR_EYE_TRACKER_WEB_API - etvr_eye_tracker_web_init(); -#else // ETVR_EYE_TRACKER_WEB_API - WiFi.disconnect(true); -#endif // ETVR_EYE_TRACKER_WEB_API - #ifdef ETVR_EYE_TRACKER_USB_API etvr_eye_tracker_usb_init(); #endif // ETVR_EYE_TRACKER_USB_API