Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CrowPanel ESP32C3 240x240 #47

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
144 changes: 144 additions & 0 deletions examples/crowpanel-receiver/crowpanel-receiver.cpp
Original file line number Diff line number Diff line change
@@ -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 <Arduino.h>
#include <Wire.h>
#include <ESPNowCam.h>
#include "lgfx-esp32c3-crowpanel.h"
#include <LGFX_TFT_eSPI.hpp>
#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<uint8_t*>(malloc(10000 * 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() {
}
52 changes: 52 additions & 0 deletions examples/crowpanel-receiver/lgfx-esp32c3-crowpanel.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#define LGFX_USE_V1

#include <LovyanGFX.hpp>

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);
}
};

2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "EspNowCam",
"version": "0.1.15",
"version": "0.1.16",
"homepage":"https://github.com/hpsaturn/esp32s3-cam",
"keywords":
[
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=EspNowCam
version=0.1.15
version=0.1.16
author=@hpsaturn
maintainer=Antonio Vanegas <[email protected]>
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
Expand Down
22 changes: 17 additions & 5 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ extends = esp32common
lib_deps =
${esp32common.lib_deps}
m5stack/[email protected]
m5stack/M5Unified@^0.1.17
m5stack/M5Unified@0.2.0
build_flags =
${env.build_flags}
-DESP32S3
Expand Down Expand Up @@ -126,7 +126,7 @@ board = esp32dev
build_src_filter = -<*> +<m5core2-espnow-receiver/>
lib_deps =
${esp32common.lib_deps}
m5stack/M5Unified@^0.1.6
m5stack/M5Unified@^0.2.0

[env:makerfabs-receiver]
extends = esp32common
Expand All @@ -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 = -<*> +<crowpanel-receiver/crowpanel-receiver.cpp>
monitor_speed = 115200
board_build.partitions = min_spiffs.csv
monitor_rts = 0
monitor_dtr = 0
lib_deps =
${esp32common.lib_deps}
lovyan03/LovyanGFX@^1.2.0

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; N:1 EXAMPLES
; Multi camera to one receiver examples.
Expand All @@ -162,7 +174,7 @@ board = esp32dev
build_src_filter = -<*> +<multi-camera-one-receiver/m5core2-multi-receiver.cpp>
lib_deps =
${esp32common.lib_deps}
m5stack/M5Unified@^0.1.6
m5stack/M5Unified@^0.2.0

[env:makerfabs-multi-receiver]
extends = esp32common
Expand Down Expand Up @@ -200,12 +212,12 @@ lib_deps =
${esp32common.lib_deps}
madhephaestus/[email protected]
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
board = esp32dev
build_src_filter = -<*> +<common/> +<m5stickCplus-joystick-tank/>
lib_deps =
${esp32common.lib_deps}
m5stack/M5Unified@^0.1.6
m5stack/M5Unified@^0.2.0
4 changes: 2 additions & 2 deletions src/ESPNowCam.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down