diff --git a/examples/tjournal-espnow-sender/tjournal-espnow-sender.cpp b/examples/tjournal-espnow-sender/tjournal-espnow-sender.cpp new file mode 100644 index 0000000..902bbe6 --- /dev/null +++ b/examples/tjournal-espnow-sender/tjournal-espnow-sender.cpp @@ -0,0 +1,46 @@ +/************************************************** + * ESPNowCam video Transmitter + * by @hpsaturn Copyright (C) 2024 + * This file is part ESP32S3 camera tests project: + * https://github.com/hpsaturn/esp32s3-cam +**************************************************/ + +#include +#include +#include +#include + +CamTJournal Camera; +ESPNowCam radio; + +void processFrame() { + if (Camera.get()) { + radio.sendData(Camera.fb->buf, Camera.fb->len); + delay(25); // ==> weird delay for this camera. + printFPS("CAM:"); + Camera.free(); + } +} + +void setup() { + Serial.begin(115200); + + delay(5000); // only for debugging + + if(psramFound()){ + size_t psram_size = esp_spiram_get_size() / 1048576; + Serial.printf("PSRAM size: %dMb\r\n", psram_size); + } + + radio.init(); + if (!Camera.begin()) { + Serial.println("Camera Init Fail"); + delay(1000); + ESP.restart(); + } + delay(500); +} + +void loop() { + processFrame(); +} diff --git a/platformio.ini b/platformio.ini index e813e31..7984f39 100644 --- a/platformio.ini +++ b/platformio.ini @@ -49,6 +49,14 @@ lib_deps = https://github.com/hpsaturn/SerialTerminal.git hpsaturn/ESP32 Wifi CLI @^0.2.1 +[env:tjournal-espnow-sender] +platform = espressif32 @ 4.4.0 +extends = env +board = esp32dev +build_src_filter = -<*> -<*common*> + +build_flags = + -D CORE_DEBUG_LEVEL=0 + [m5cores3_common] extends = esp32common lib_deps = diff --git a/src/drivers/CamTJournal.cpp b/src/drivers/CamTJournal.cpp new file mode 100644 index 0000000..6eda934 --- /dev/null +++ b/src/drivers/CamTJournal.cpp @@ -0,0 +1,55 @@ +#include "CamTJournal.h" + +static camera_config_t camera_config = { + .pin_reset = 15, + .pin_xclk = 27, + .pin_sscb_sda = 25, + .pin_sscb_scl = 23, + .pin_d7 = 19, + .pin_d6 = 36, + .pin_d5 = 18, + .pin_d4 = 39, + .pin_d3 = 5, + .pin_d2 = 34, + .pin_d1 = 35, + .pin_d0 = 17, + .pin_vsync = 22, + .pin_href = 26, + .pin_pclk = 21, + + .xclk_freq_hz = 20000000, + .ledc_timer = LEDC_TIMER_0, + .ledc_channel = LEDC_CHANNEL_0, + + .pixel_format = PIXFORMAT_JPEG, + .frame_size = FRAMESIZE_QVGA, + .jpeg_quality = 12, + .fb_count = 1, + .fb_location = CAMERA_FB_IN_DRAM, + .grab_mode = CAMERA_GRAB_WHEN_EMPTY, +}; + +bool CamTJournal::begin() { + esp_err_t err = esp_camera_init(&camera_config); + if (err != ESP_OK) { + return false; + } + sensor = esp_camera_sensor_get(); + return true; +} + +bool CamTJournal::get() { + fb = esp_camera_fb_get(); + if (!fb) { + return false; + } + return true; +} + +bool CamTJournal::free() { + if (fb) { + esp_camera_fb_return(fb); + return true; + } + return false; +} diff --git a/src/drivers/CamTJournal.h b/src/drivers/CamTJournal.h new file mode 100644 index 0000000..6eee651 --- /dev/null +++ b/src/drivers/CamTJournal.h @@ -0,0 +1,17 @@ +#ifndef CAMTJOURNAL_H +#define CAMTJOURNAL_H + +#include "esp_camera.h" + +class CamTJournal { + private: + public: + camera_fb_t* fb; + sensor_t* sensor; + camera_config_t* config; + bool begin(); + bool get(); + bool free(); +}; + +#endif \ No newline at end of file