ESP_IOT v2.5
IOT ESP Coding
esp_camera.h
Go to the documentation of this file.
1
2#ifdef NOT_HERE
3
4// Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
5//
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17/*
18 * Example Use
19 *
20 static camera_config_t camera_example_config = {
21 .pin_pwdn = PIN_PWDN,
22 .pin_reset = PIN_RESET,
23 .pin_xclk = PIN_XCLK,
24 .pin_sscb_sda = PIN_SIOD,
25 .pin_sscb_scl = PIN_SIOC,
26 .pin_d7 = PIN_D7,
27 .pin_d6 = PIN_D6,
28 .pin_d5 = PIN_D5,
29 .pin_d4 = PIN_D4,
30 .pin_d3 = PIN_D3,
31 .pin_d2 = PIN_D2,
32 .pin_d1 = PIN_D1,
33 .pin_d0 = PIN_D0,
34 .pin_vsync = PIN_VSYNC,
35 .pin_href = PIN_HREF,
36 .pin_pclk = PIN_PCLK,
37
38 .xclk_freq_hz = 20000000,
39 .ledc_timer = LEDC_TIMER_0,
40 .ledc_channel = LEDC_CHANNEL_0,
41 .pixel_format = PIXFORMAT_JPEG,
42 .frame_size = FRAMESIZE_SVGA,
43 .jpeg_quality = 10,
44 .fb_count = 2,
45 .grab_mode = CAMERA_GRAB_WHEN_EMPTY
46 };
47
48 esp_err_t camera_example_init(){
49 return esp_camera_init(&camera_example_config);
50 }
51
52 esp_err_t camera_example_capture(){
53 //capture a frame
54 camera_fb_t * fb = esp_camera_fb_get();
55 if (!fb) {
56 ESP_LOGE(TAG, "Frame buffer could not be acquired");
57 return ESP_FAIL;
58 }
59
60 //replace this with your own function
61 display_image(fb->width, fb->height, fb->pixformat, fb->buf, fb->len);
62
63 //return the frame buffer back to be reused
64 esp_camera_fb_return(fb);
65
66 return ESP_OK;
67 }
68*/
69
70#pragma once
71
72#include "esp_err.h"
73#include "driver/ledc.h"
74#include "sensor.h"
75#include "sys/time.h"
76
77#ifdef __cplusplus
78extern "C" {
79#endif
80
81/**
82 * @brief Configuration structure for camera initialization
83 */
84typedef enum {
85 CAMERA_GRAB_WHEN_EMPTY, /*!< Fills buffers when they are empty. Less resources but first 'fb_count' frames might be old */
86 CAMERA_GRAB_LATEST /*!< Except when 1 frame buffer is used, queue will always contain the last 'fb_count' frames */
87} camera_grab_mode_t;
88
89/**
90 * @brief Camera frame buffer location
91 */
92typedef enum {
93 CAMERA_FB_IN_PSRAM, /*!< Frame buffer is placed in external PSRAM */
94 CAMERA_FB_IN_DRAM /*!< Frame buffer is placed in internal DRAM */
95} camera_fb_location_t;
96
97/**
98 * @brief Configuration structure for camera initialization
99 */
100typedef struct {
101 int pin_pwdn; /*!< GPIO pin for camera power down line */
102 int pin_reset; /*!< GPIO pin for camera reset line */
103 int pin_xclk; /*!< GPIO pin for camera XCLK line */
104 int pin_sscb_sda; /*!< GPIO pin for camera SDA line */
105 int pin_sscb_scl; /*!< GPIO pin for camera SCL line */
106 int pin_d7; /*!< GPIO pin for camera D7 line */
107 int pin_d6; /*!< GPIO pin for camera D6 line */
108 int pin_d5; /*!< GPIO pin for camera D5 line */
109 int pin_d4; /*!< GPIO pin for camera D4 line */
110 int pin_d3; /*!< GPIO pin for camera D3 line */
111 int pin_d2; /*!< GPIO pin for camera D2 line */
112 int pin_d1; /*!< GPIO pin for camera D1 line */
113 int pin_d0; /*!< GPIO pin for camera D0 line */
114 int pin_vsync; /*!< GPIO pin for camera VSYNC line */
115 int pin_href; /*!< GPIO pin for camera HREF line */
116 int pin_pclk; /*!< GPIO pin for camera PCLK line */
117
118 int xclk_freq_hz; /*!< Frequency of XCLK signal, in Hz. EXPERIMENTAL: Set to 16MHz on ESP32-S2 or ESP32-S3 to enable EDMA mode */
119
120 ledc_timer_t ledc_timer; /*!< LEDC timer to be used for generating XCLK */
121 ledc_channel_t ledc_channel; /*!< LEDC channel to be used for generating XCLK */
122
123 pixformat_t pixel_format; /*!< Format of the pixel data: PIXFORMAT_ + YUV422|GRAYSCALE|RGB565|JPEG */
124 framesize_t frame_size; /*!< Size of the output image: FRAMESIZE_ + QVGA|CIF|VGA|SVGA|XGA|SXGA|UXGA */
125
126 int jpeg_quality; /*!< Quality of JPEG output. 0-63 lower means higher quality */
127 size_t fb_count; /*!< Number of frame buffers to be allocated. If more than one, then each frame will be acquired (double speed) */
128 camera_fb_location_t fb_location; /*!< The location where the frame buffer will be allocated */
129 camera_grab_mode_t grab_mode; /*!< When buffers should be filled */
130} camera_config_t;
131
132/**
133 * @brief Data structure of camera frame buffer
134 */
135typedef struct {
136 uint8_t * buf; /*!< Pointer to the pixel data */
137 size_t len; /*!< Length of the buffer in bytes */
138 size_t width; /*!< Width of the buffer in pixels */
139 size_t height; /*!< Height of the buffer in pixels */
140 pixformat_t format; /*!< Format of the pixel data */
141 struct timeval timestamp; /*!< Timestamp since boot of the first DMA buffer of the frame */
142} camera_fb_t;
143
144
145#define ESP_ERR_CAMERA_BASE 0x20000
146#define ESP_ERR_CAMERA_NOT_DETECTED (ESP_ERR_CAMERA_BASE + 1)
147#define ESP_ERR_CAMERA_FAILED_TO_SET_FRAME_SIZE (ESP_ERR_CAMERA_BASE + 2)
148#define ESP_ERR_CAMERA_FAILED_TO_SET_OUT_FORMAT (ESP_ERR_CAMERA_BASE + 3)
149#define ESP_ERR_CAMERA_NOT_SUPPORTED (ESP_ERR_CAMERA_BASE + 4)
150
151/**
152 * @brief Initialize the camera driver
153 *
154 * @note call camera_probe before calling this function
155 *
156 * This function detects and configures camera over I2C interface,
157 * allocates framebuffer and DMA buffers,
158 * initializes parallel I2S input, and sets up DMA descriptors.
159 *
160 * Currently this function can only be called once and there is
161 * no way to de-initialize this module.
162 *
163 * @param config Camera configuration parameters
164 *
165 * @return ESP_OK on success
166 */
167esp_err_t esp_camera_init(const camera_config_t* config);
168
169/**
170 * @brief Deinitialize the camera driver
171 *
172 * @return
173 * - ESP_OK on success
174 * - ESP_ERR_INVALID_STATE if the driver hasn't been initialized yet
175 */
176esp_err_t esp_camera_deinit();
177
178/**
179 * @brief Obtain pointer to a frame buffer.
180 *
181 * @return pointer to the frame buffer
182 */
183camera_fb_t* esp_camera_fb_get();
184
185/**
186 * @brief Return the frame buffer to be reused again.
187 *
188 * @param fb Pointer to the frame buffer
189 */
190void esp_camera_fb_return(camera_fb_t * fb);
191
192/**
193 * @brief Get a pointer to the image sensor control structure
194 *
195 * @return pointer to the sensor
196 */
197sensor_t * esp_camera_sensor_get();
198
199/**
200 * @brief Save camera settings to non-volatile-storage (NVS)
201 *
202 * @param key A unique nvs key name for the camera settings
203 */
204esp_err_t esp_camera_save_to_nvs(const char *key);
205
206/**
207 * @brief Load camera settings from non-volatile-storage (NVS)
208 *
209 * @param key A unique nvs key name for the camera settings
210 */
211esp_err_t esp_camera_load_from_nvs(const char *key);
212
213#ifdef __cplusplus
214}
215#endif
216
217#include "img_converters.h"
218
219#endif