This commit is contained in:
2026-02-12 21:00:02 -08:00
parent 77f8236347
commit 8bdbf227ca
1141 changed files with 1010880 additions and 2 deletions

View File

@@ -0,0 +1,89 @@
#pragma once
#include <memory>
#include "esp_camera.h"
class Camera;
/**
* @brief A simple Arduino C++ API over the ESP32 camera functionality.
* @author Phil Schatzmann
*/
class Camera {
// esp_camera_fb_return
struct Deleter {
void operator()(camera_fb_t *ptr) const {
if (ptr) {
esp_camera_fb_return(ptr);
}
}
};
public:
Camera() = default;
/**
* @brief Initialize the camera driver
*
* @note call camera_probe before calling this function
*
* This function detects and configures camera over I2C interface,
* allocates framebuffer and DMA buffers,
* initializes parallel I2S input, and sets up DMA descriptors.
*
* Currently this function can only be called once and there is
* no way to de-initialize this module.
*
* @param config Camera configuration parameters
*
* @return RESULT_OK on success
*/
bool begin(const camera_config_t &config) {
return esp_camera_init(&config) == ESP_OK;
}
/**
* @brief Deinitialize the camera driver
*
* @return
* - RESULT_OK on success
* - ERR_INVALID_STATE if the driver hasn't been initialized yet
*/
bool end(void) { return esp_camera_deinit() == ESP_OK; }
/**
* @brief Obtain unique_ptr to a frame buffer.
*
* @return pointer to the frame buffer
*/
auto frameBuffer(void) {
return std::unique_ptr<camera_fb_t, Deleter>(esp_camera_fb_get());
}
/**
* @brief Save camera settings to non-volatile-storage (NVS)
*
* @param key A unique nvs key name for the camera settings
*/
bool settingsSave(const char *key) {
return esp_camera_save_to_nvs(key) == ESP_OK;
}
/**
* @brief Load camera settings from non-volatile-storage (NVS)
*
* @param key A unique nvs key name for the camera settings
*/
bool settingsLoad(const char *key) {
return esp_camera_load_from_nvs(key) == ESP_OK;
}
/**
* @brief Return the frame buffer to be reused again.
*
* @param fb Pointer to the frame buffer
*/
void returnFrameBuffer(camera_fb_t &fb) { return esp_camera_fb_return(&fb); }
};

View File

@@ -0,0 +1,68 @@
// important settings:
// - USB CDC on Boot: Enabled (to see the Serial.print)
// - PSRAM: QSPI PSRAM (to have enough memory for the framebuffer)
#include "Camera.h"
#define XCLK_GPIO_NUM 10
#define SIOD_GPIO_NUM 21
#define SIOC_GPIO_NUM 14
#define Y9_GPIO_NUM 11
#define Y8_GPIO_NUM 9
#define Y7_GPIO_NUM 8
#define Y6_GPIO_NUM 6
#define Y5_GPIO_NUM 4
#define Y4_GPIO_NUM 2
#define Y3_GPIO_NUM 3
#define Y2_GPIO_NUM 5
#define VSYNC_GPIO_NUM 13
#define HREF_GPIO_NUM 12
#define PCLK_GPIO_NUM 7
#define LED_GPIO_NUM 34
Camera camera;
camera_config_t config;
void setup() {
Serial.begin(115200);
while(!Serial);
config.ledc_timer = LEDC_TIMER_0;
config.pin_d0 = Y2_GPIO_NUM;
config.pin_d1 = Y3_GPIO_NUM;
config.pin_d2 = Y4_GPIO_NUM;
config.pin_d3 = Y5_GPIO_NUM;
config.pin_d4 = Y6_GPIO_NUM;
config.pin_d5 = Y7_GPIO_NUM;
config.pin_d6 = Y8_GPIO_NUM;
config.pin_d7 = Y9_GPIO_NUM;
config.pin_xclk = XCLK_GPIO_NUM;
config.pin_pclk = PCLK_GPIO_NUM;
config.pin_vsync = VSYNC_GPIO_NUM;
config.pin_href = HREF_GPIO_NUM;
config.pin_sccb_sda = SIOD_GPIO_NUM;
config.pin_sccb_scl = SIOC_GPIO_NUM;
config.xclk_freq_hz = 20000000;
config.pixel_format = PIXFORMAT_JPEG; // YUV422,GRAYSCALE,RGB565,JPEG
config.frame_size = FRAMESIZE_HD; //
config.jpeg_quality = 16;
config.fb_count = 2; // 8
config.fb_location = CAMERA_FB_IN_PSRAM; /*!< The location where the frame
buffer will be allocated */
config.grab_mode = CAMERA_GRAB_LATEST; /*!< When buffers should be filled */
if (!camera.begin(config)){
Serial.println("Camera failed");
while(true);
}
Serial.print("Recording...");
}
void loop() {
auto fb = camera.frameBuffer();
Serial.println(fb->len);
}