Skip to content

Commit

Permalink
complete refactor of internal Camera drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
hpsaturn committed May 4, 2024
1 parent 25cff32 commit e0f71b0
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 262 deletions.
4 changes: 4 additions & 0 deletions examples/xiao-fpv-sender/xiao-fpv-sender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ void setup() {
}

radio.init();

// You are able to change the Camera config E.g:
// Camera.config.frame_size = FRAMESIZE_QQVGA;

if (!Camera.begin()) {
Serial.println("Camera Init Fail");
delay(1000);
Expand Down
58 changes: 0 additions & 58 deletions src/drivers/CamFreenove.cpp

This file was deleted.

43 changes: 34 additions & 9 deletions src/drivers/CamFreenove.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
#ifndef CAMFREENOVE_H
#define CAMFREENOVE_H

#include "CameraBase.hpp"
#include "esp_camera.h"

class CamFreenove {
private:
public:
camera_fb_t* fb;
sensor_t* sensor;
camera_config_t* config;
bool begin();
bool get();
bool free();
class CamFreenove : public CameraBase {
public:
using CameraBase::begin;
using CameraBase::free;
using CameraBase::get;

CamFreenove() {
config.pin_pwdn = -1;
config.pin_reset = -1;
config.pin_xclk = 15;
config.pin_sscb_sda = 4;
config.pin_sscb_scl = 5;
config.pin_d7 = 16;
config.pin_d6 = 17;
config.pin_d5 = 18;
config.pin_d4 = 12;
config.pin_d3 = 10;
config.pin_d2 = 8;
config.pin_d1 = 9;
config.pin_d0 = 11;
config.pin_vsync = 6;
config.pin_href = 7;
config.pin_pclk = 13;
config.xclk_freq_hz = 20000000;
config.ledc_timer = LEDC_TIMER_0;
config.ledc_channel = LEDC_CHANNEL_0;
config.pixel_format = PIXFORMAT_RGB565;
config.frame_size = FRAMESIZE_QVGA;
config.jpeg_quality = 0;
config.fb_count = 2;
config.fb_location = CAMERA_FB_IN_PSRAM;
config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
}
};

#endif
55 changes: 0 additions & 55 deletions src/drivers/CamTJournal.cpp

This file was deleted.

42 changes: 33 additions & 9 deletions src/drivers/CamTJournal.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
#ifndef CAMTJOURNAL_H
#define CAMTJOURNAL_H

#include "CameraBase.hpp"
#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();
class CamTJournal : public CameraBase {
public:
using CameraBase::begin;
using CameraBase::free;
using CameraBase::get;

CamTJournal(){
config.pin_reset = 15;
config.pin_xclk = 27;
config.pin_sscb_sda = 25;
config.pin_sscb_scl = 23;
config.pin_d7 = 19;
config.pin_d6 = 36;
config.pin_d5 = 18;
config.pin_d4 = 39;
config.pin_d3 = 5;
config.pin_d2 = 34;
config.pin_d1 = 35;
config.pin_d0 = 17;
config.pin_vsync = 22;
config.pin_href = 26;
config.pin_pclk = 21;
config.xclk_freq_hz = 20000000;
config.ledc_timer = LEDC_TIMER_0;
config.ledc_channel = LEDC_CHANNEL_0;
config.pixel_format = PIXFORMAT_JPEG;
config.frame_size = FRAMESIZE_QVGA;
config.jpeg_quality = 12;
config.fb_count = 1;
config.fb_location = CAMERA_FB_IN_DRAM;
config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
}
};

#endif
58 changes: 0 additions & 58 deletions src/drivers/CamXiao.cpp

This file was deleted.

43 changes: 34 additions & 9 deletions src/drivers/CamXiao.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,43 @@
#ifndef CAMXIAO_H
#define CAMXIAO_H

#include "CameraBase.hpp"
#include "esp_camera.h"
#include "xiao_pins.h"

class CamXiao {
private:
public:
camera_fb_t* fb;
sensor_t* sensor;
camera_config_t* config;
bool begin();
bool get();
bool free();
class CamXiao : public CameraBase {
public:
using CameraBase::begin;
using CameraBase::free;
using CameraBase::get;

CamXiao() {
config.pin_pwdn = PWDN_GPIO_NUM;
config.pin_reset = RESET_GPIO_NUM;
config.pin_xclk = XCLK_GPIO_NUM;
config.pin_sscb_sda = SIOD_GPIO_NUM;
config.pin_sscb_scl = SIOC_GPIO_NUM;
config.pin_d7 = Y9_GPIO_NUM;
config.pin_d6 = Y8_GPIO_NUM;
config.pin_d5 = Y7_GPIO_NUM;
config.pin_d4 = Y6_GPIO_NUM;
config.pin_d3 = Y5_GPIO_NUM;
config.pin_d2 = Y4_GPIO_NUM;
config.pin_d1 = Y3_GPIO_NUM;
config.pin_d0 = Y2_GPIO_NUM;
config.pin_vsync = VSYNC_GPIO_NUM;
config.pin_href = HREF_GPIO_NUM;
config.pin_pclk = PCLK_GPIO_NUM;
config.xclk_freq_hz = 20000000;
config.ledc_timer = LEDC_TIMER_0;
config.ledc_channel = LEDC_CHANNEL_0;
config.pixel_format = PIXFORMAT_RGB565;
config.frame_size = FRAMESIZE_QVGA;
config.jpeg_quality = 12;
config.fb_count = 2;
config.fb_location = CAMERA_FB_IN_PSRAM;
config.grab_mode = CAMERA_GRAB_WHEN_EMPTY;
}
};

#endif
34 changes: 34 additions & 0 deletions src/drivers/CameraBase.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "esp_camera.h"

class CameraBase {
private:
public:
camera_fb_t* fb;
sensor_t* sensor;
camera_config_t config;

bool begin() {
esp_err_t err = esp_camera_init(&config);
if (err != ESP_OK) {
return false;
}
sensor = esp_camera_sensor_get();
return true;
}

bool get() {
fb = esp_camera_fb_get();
if (!fb) {
return false;
}
return true;
}

bool free() {
if (fb) {
esp_camera_fb_return(fb);
return true;
}
return false;
}
};
Loading

0 comments on commit e0f71b0

Please sign in to comment.