From 2cc73ed608694f617f589b4cc9378690547e2913 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Sat, 9 Nov 2024 00:10:46 +0100 Subject: [PATCH 1/4] added basic sample for CrowPanel ESP32C3 240x240 --- .../crowpanel-receiver/crowpanel-receiver.cpp | 144 ++++++++++++++++++ .../lgfx-esp32c3-crowpanel.h | 52 +++++++ platformio.ini | 12 ++ 3 files changed, 208 insertions(+) create mode 100644 examples/crowpanel-receiver/crowpanel-receiver.cpp create mode 100644 examples/crowpanel-receiver/lgfx-esp32c3-crowpanel.h diff --git a/examples/crowpanel-receiver/crowpanel-receiver.cpp b/examples/crowpanel-receiver/crowpanel-receiver.cpp new file mode 100644 index 0000000..99d4321 --- /dev/null +++ b/examples/crowpanel-receiver/crowpanel-receiver.cpp @@ -0,0 +1,144 @@ +/************************************************** + * ESPNowCam video Receiver + * by @hpsaturn Copyright (C) 2024 + * This file is part ESPNowCam tests project: + * https://github.com/hpsaturn/ESPNowCam +**************************************************/ + +#include +#include +#include +#include "lgfx-esp32c3-crowpanel.h" +#include +#include "Utils.h" + +ESPNowCam radio; +LGFX tft; + +#define I2C_SDA 4 +#define I2C_SCL 5 +#define TP_INT 0 +#define TP_RST -1 +#define LCD_CS 10 +#define LCD_BLK -1 +#define PI4IO_I2C_ADDR 0x43 + +// frame buffer +uint8_t *fb; +// display globals +int32_t dw, dh; + +static uint32_t frame_camera = 0; +static uint_fast64_t time_stamp_camera = 0; + +static void print_FPS(int x, int y, const char *msg, uint32_t &frame, uint_fast64_t &time_stamp, uint32_t len) { + frame++; + if (millis() - time_stamp > 1000) { + time_stamp = millis(); + char output[40]; + sprintf(output, "%s%2d FPS JPG: %05d\r\n",msg, frame, len); + tft.drawString(output, x, y); + frame = 0; + Serial.print(output); + } +} + +void onDataReady(uint32_t lenght) { + tft.drawJpg(fb, lenght , 0, 0, dw, dh); + print_FPS(5, 250, "CAM:", frame_camera, time_stamp_camera, lenght); +} + +//Extended IO function +void init_IO_extender() { + Wire.beginTransmission(PI4IO_I2C_ADDR); + Wire.write(0x01); // test register + Wire.endTransmission(); + Wire.requestFrom(PI4IO_I2C_ADDR, 1); + uint8_t rxdata = Wire.read(); + Serial.print("Device ID: "); + Serial.println(rxdata, HEX); + + Wire.beginTransmission(PI4IO_I2C_ADDR); + Wire.write(0x03); // IO direction register + Wire.write((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4)); // set pins 0, 1, 2 as outputs + Wire.endTransmission(); + + Wire.beginTransmission(PI4IO_I2C_ADDR); + Wire.write(0x07); // Output Hi-Z register + Wire.write(~((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4))); // set pins 0, 1, 2 low + Wire.endTransmission(); +} + +void set_pin_io(uint8_t pin_number, bool value) { + + Wire.beginTransmission(PI4IO_I2C_ADDR); + Wire.write(0x05); // test register + Wire.endTransmission(); + Wire.requestFrom(PI4IO_I2C_ADDR, 1); + uint8_t rxdata = Wire.read(); + Serial.print("Before the change: "); + Serial.println(rxdata, HEX); + + Wire.beginTransmission(PI4IO_I2C_ADDR); + Wire.write(0x05); // Output register + + if (!value) + Wire.write((~(1 << pin_number)) & rxdata); // set pin low + else + Wire.write((1 << pin_number) | rxdata); // set pin high + Wire.endTransmission(); + + Wire.beginTransmission(PI4IO_I2C_ADDR); + Wire.write(0x05); // test register + Wire.endTransmission(); + Wire.requestFrom(PI4IO_I2C_ADDR, 1); + rxdata = Wire.read(); + Serial.print("after the change: "); + Serial.println(rxdata, HEX); +} + + +void setup() { + Serial.begin(115200); + + Wire.begin(4, 5); + init_IO_extender(); + delay(100); + set_pin_io(3, true); + set_pin_io(4, true); + set_pin_io(2, true); + + pinMode(3, OUTPUT); + digitalWrite(3, LOW); + + // ticker.attach(1, tcr1s); + tft.init(); + tft.initDMA(); + tft.startWrite(); + tft.setColor(0, 0, 0); + + tft.fillScreen(TFT_BLACK); + + dw = tft.width(); + dh = tft.height(); + + // if(psramFound()){ + // size_t psram_size = esp_spiram_get_size() / 1048576; + // Serial.printf("PSRAM size: %dMb\r\n", psram_size); + // } + + // BE CAREFUL WITH IT, IF JPG LEVEL CHANGES, INCREASE IT + fb = static_cast(malloc(50000 * sizeof(uint8_t))); + + radio.setRecvBuffer(fb); + radio.setRecvCallback(onDataReady); + + if (radio.init()) { + tft.setTextSize(2); + tft.drawString("ESPNow Init Success", 5, 2); + } + delay(1000); +} + +void loop() { +} diff --git a/examples/crowpanel-receiver/lgfx-esp32c3-crowpanel.h b/examples/crowpanel-receiver/lgfx-esp32c3-crowpanel.h new file mode 100644 index 0000000..f728c7e --- /dev/null +++ b/examples/crowpanel-receiver/lgfx-esp32c3-crowpanel.h @@ -0,0 +1,52 @@ +#define LGFX_USE_V1 + +#include + +class LGFX : public lgfx::LGFX_Device +{ + lgfx::Panel_GC9A01 _panel_instance; + lgfx::Bus_SPI _bus_instance; + public: + LGFX(void) + { + { + auto cfg = _bus_instance.config(); + cfg.spi_host = SPI2_HOST; + cfg.spi_mode = 0; + cfg.freq_write = 80000000; + cfg.freq_read = 20000000; + cfg.spi_3wire = true; + cfg.use_lock = true; + cfg.dma_channel = SPI_DMA_CH_AUTO; + cfg.pin_sclk = 6; + cfg.pin_mosi = 7; + cfg.pin_miso = -1; + cfg.pin_dc = 2; + _bus_instance.config(cfg); + _panel_instance.setBus(&_bus_instance); + } + { + auto cfg = _panel_instance.config(); + cfg.pin_cs = 10; + cfg.pin_rst = -1; + cfg.pin_busy = -1; + cfg.memory_width = 240; + cfg.memory_height = 240; + cfg.panel_width = 240; + cfg.panel_height = 240; + cfg.offset_x = 0; + cfg.offset_y = 0; + cfg.offset_rotation = 0; + cfg.dummy_read_pixel = 8; + cfg.dummy_read_bits = 1; + cfg.readable = false; + cfg.invert = true; + cfg.rgb_order = false; + cfg.dlen_16bit = false; + cfg.bus_shared = false; + _panel_instance.config(cfg); + } + setPanel(&_panel_instance); + } +}; + diff --git a/platformio.ini b/platformio.ini index ce2d4b4..6745499 100644 --- a/platformio.ini +++ b/platformio.ini @@ -150,6 +150,18 @@ lib_deps = ${esp32common.lib_deps} lovyan03/LovyanGFX@^1.1.5 +[env:crowpanel-receiver] +extends = esp32common +board = esp32-c3-devkitm-1 +build_src_filter = -<*> + +monitor_speed = 115200 +board_build.partitions = min_spiffs.csv +monitor_rts = 0 +monitor_dtr = 0 +lib_deps = + ${esp32common.lib_deps} + lovyan03/LovyanGFX@^1.1.16 + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; N:1 EXAMPLES ; Multi camera to one receiver examples. From 8f5e404ae6123252fdc42bc9687c260f86046a6a Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Mon, 25 Nov 2024 17:40:10 +0100 Subject: [PATCH 2/4] decresed unnecessary memory psmalloc allocation for 320x240 demo --- examples/crowpanel-receiver/crowpanel-receiver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/crowpanel-receiver/crowpanel-receiver.cpp b/examples/crowpanel-receiver/crowpanel-receiver.cpp index 99d4321..4904432 100644 --- a/examples/crowpanel-receiver/crowpanel-receiver.cpp +++ b/examples/crowpanel-receiver/crowpanel-receiver.cpp @@ -128,7 +128,7 @@ void setup() { // } // BE CAREFUL WITH IT, IF JPG LEVEL CHANGES, INCREASE IT - fb = static_cast(malloc(50000 * sizeof(uint8_t))); + fb = static_cast(malloc(10000 * sizeof(uint8_t))); radio.setRecvBuffer(fb); radio.setRecvCallback(onDataReady); From a87e262fb720eab0d072ae2106cacc7745bc46f7 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Mon, 25 Nov 2024 23:02:05 +0100 Subject: [PATCH 3/4] examples upgraded to the lastest dependencies --- platformio.ini | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/platformio.ini b/platformio.ini index 6745499..a851d43 100644 --- a/platformio.ini +++ b/platformio.ini @@ -43,7 +43,7 @@ extends = esp32common lib_deps = ${esp32common.lib_deps} m5stack/M5CoreS3@1.0.0 - m5stack/M5Unified@^0.1.17 + m5stack/M5Unified@0.2.0 build_flags = ${env.build_flags} -DESP32S3 @@ -126,7 +126,7 @@ board = esp32dev build_src_filter = -<*> + lib_deps = ${esp32common.lib_deps} - m5stack/M5Unified@^0.1.6 + m5stack/M5Unified@^0.2.0 [env:makerfabs-receiver] extends = esp32common @@ -160,7 +160,7 @@ monitor_rts = 0 monitor_dtr = 0 lib_deps = ${esp32common.lib_deps} - lovyan03/LovyanGFX@^1.1.16 + lovyan03/LovyanGFX@^1.2.0 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; N:1 EXAMPLES @@ -174,7 +174,7 @@ board = esp32dev build_src_filter = -<*> + lib_deps = ${esp32common.lib_deps} - m5stack/M5Unified@^0.1.6 + m5stack/M5Unified@^0.2.0 [env:makerfabs-multi-receiver] extends = esp32common @@ -212,7 +212,7 @@ lib_deps = ${esp32common.lib_deps} madhephaestus/ESP32Servo@3.0.5 hpsaturn/EasyPreferences@^0.1.0 - hpsaturn/ESP32 Wifi CLI @^0.3.2 + hpsaturn/ESP32 Wifi CLI @^0.3.3 [env:m5stickCplus-joystick-tank] extends = esp32common @@ -220,4 +220,4 @@ board = esp32dev build_src_filter = -<*> + + lib_deps = ${esp32common.lib_deps} - m5stack/M5Unified@^0.1.6 \ No newline at end of file + m5stack/M5Unified@^0.2.0 From f0f51ce91973e96e88cd637d93d50ef6fa46bf45 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Mon, 25 Nov 2024 23:03:10 +0100 Subject: [PATCH 4/4] v0.1.16 Elecrow Crowpanel receiver sample and some minors --- examples/README.md | 1 + library.json | 2 +- library.properties | 2 +- src/ESPNowCam.h | 4 ++-- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/examples/README.md b/examples/README.md index c8e8a31..de3950a 100644 --- a/examples/README.md +++ b/examples/README.md @@ -29,6 +29,7 @@ Some video receivers | tft-3.5-basic-receiver | Any TFT display with LGFX [1] | STABLE | | tft-il9485-basic-receiver | M5Core TFT reciver il9481 [1] [2]| STABLE | | ft-rgb-hmi-basic-receiver | ESP32S3_RGB_ESP32-8048S043 [1] [2] | STABLE | +| crowpanel-receiver | Elecrow round panel 320x240 [1] | TESTING | [1] Use with any sender sample [2] Use with freenove HVGA sender sample for example. diff --git a/library.json b/library.json index 2d926a2..cec8923 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "EspNowCam", - "version": "0.1.15", + "version": "0.1.16", "homepage":"https://github.com/hpsaturn/esp32s3-cam", "keywords": [ diff --git a/library.properties b/library.properties index 42359e0..d2021cc 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=EspNowCam -version=0.1.15 +version=0.1.16 author=@hpsaturn maintainer=Antonio Vanegas sentence=ESPNowCam, a straightforward video streamer for popular ESP32Cam models, leveraging the ESPNow protocol. No need for IPs, routers, or credentials—keeping it simple! :D diff --git a/src/ESPNowCam.h b/src/ESPNowCam.h index a64b010..64a9d40 100644 --- a/src/ESPNowCam.h +++ b/src/ESPNowCam.h @@ -13,8 +13,8 @@ extern "C" { typedef void (*RecvCb)(uint32_t lenght); } -#define ENC_VERSION "0.1.15" -#define ENC_REVISION 080 +#define ENC_VERSION "0.1.16" +#define ENC_REVISION 081 class ESPNowCam { private: