#include "camera.h" static void ov_camera_pw_gpio_init(void); static void ov_camera_pw_on(void); static void ov_camera_pw_off(void); static const char *TAG = "camera"; camera_fb_t *pic; static camera_config_t camera_config = { .pin_pwdn = -1, .pin_reset = CAM_RST_PIN, .pin_xclk = CAM_XCLK_PIN, .pin_sscb_sda = CAM_SDA_PIN, .pin_sscb_scl = CAM_SCL_PIN, .pin_d7 = CAM_D7_PIN, .pin_d6 = CAM_D6_PIN, .pin_d5 = CAM_D5_PIN, .pin_d4 = CAM_D4_PIN, .pin_d3 = CAM_D3_PIN, .pin_d2 = CAM_D2_PIN, .pin_d1 = CAM_D1_PIN, .pin_d0 = CAM_D0_PIN, .pin_vsync = CAM_VSYNC_PIN, .pin_href = CAM_HREF_PIN, .pin_pclk = CAM_PCLK_PIN, //XCLK 20MHz or 10MHz for OV2640 double FPS (Experimental) .xclk_freq_hz = CONFIG_CAM_XCLK_FREQ, .pixel_format = PIXFORMAT_JPEG, //YUV422,GRAYSCALE,RGB565,JPEG .frame_size = FRAMESIZE_SVGA, //QQVGA-UXGA Do not use sizes above QVGA when not JPEG .jpeg_quality = JPG_QUALITY, //0-63 lower number means higher quality .fb_count = 1, //if more than one, i2s runs in continuous mode. Use only with JPEG .grab_mode = CAMERA_GRAB_WHEN_EMPTY, }; static void camera_task(void) { while (1) { ESP_LOGI(TAG, "Taking picture..."); camera_fb_t *pic = esp_camera_fb_get(); // use pic->buf to access the image ESP_LOGI(TAG, "Picture taken! Its size was: %zu bytes", pic->len); esp_camera_fb_return(pic); vTaskDelay(5000 / portTICK_RATE_MS); } } esp_err_t camera_run(void) { ESP_LOGD(TAG, "Taking picture..."); pic = esp_camera_fb_get(); if(pic == NULL) { return ESP_FAIL; } // use pic->buf to access the image ESP_LOGD(TAG, "Picture taken! Its size was: %zu bytes", pic->len); return ESP_OK; } void camera_stop(void) { esp_camera_fb_return(pic); } uint8_t * camera_get_fb(void) { return pic->buf; } size_t camera_get_data_size(void) { return pic->len; } esp_err_t init_camera(void) { ov_camera_pw_gpio_init(); ov_camera_pw_on(); //initialize the camera esp_err_t err = esp_camera_init(&camera_config); if (err != ESP_OK) { ESP_LOGE(TAG, "Camera Init Failed"); return err; } return ESP_OK; } static void ov_camera_pw_gpio_init(void) { #ifdef CONFIG_OV2640_SUPPORT uint64_t ov2640_output_gpio = ((1ULL<