PicoCamera 0.2.0
Camera library for RP2040 with an esp32-camera compatible API
GitHub
Loading...
Searching...
No Matches
pico_camera.h
Go to the documentation of this file.
1/*
2 * This file is part of the PicoCamera project.
3 * https://github.com/umeiko/PicoCamera
4 *
5 * Author: umeko <umeko@stu.xmu.edu.cn>
6 * License: MIT
7 */
8
38#pragma once
39
40#include <stddef.h>
41#include <stdint.h>
42#include <stdbool.h>
43#include <sys/time.h>
44
45#include "sensor.h"
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51typedef int pico_camera_err_t;
52
53#define PICO_CAMERA_OK 0
54#define PICO_CAMERA_FAIL -1
55#define PICO_CAMERA_ERR_NO_MEM -2
56#define PICO_CAMERA_ERR_INVALID_ARG -3
57#define PICO_CAMERA_ERR_INVALID_STATE -4
58#define PICO_CAMERA_ERR_NOT_SUPPORTED -5
59#define PICO_CAMERA_ERR_TIMEOUT -6
60#define PICO_CAMERA_ERR_BASE (-100)
61#define PICO_CAMERA_ERR_NOT_DETECTED (PICO_CAMERA_ERR_BASE - 1)
62#define PICO_CAMERA_ERR_FAILED_TO_SET_FRAME_SIZE (PICO_CAMERA_ERR_BASE - 2)
63#define PICO_CAMERA_ERR_FAILED_TO_SET_OUT_FORMAT (PICO_CAMERA_ERR_BASE - 3)
64
70static inline const char *pico_camera_err_str(pico_camera_err_t err) {
71 switch (err) {
72 case PICO_CAMERA_OK: return "OK";
73 case PICO_CAMERA_FAIL: return "generic failure";
74 case PICO_CAMERA_ERR_NO_MEM: return "out of memory (frame buffer allocation failed)";
75 case PICO_CAMERA_ERR_INVALID_ARG: return "invalid argument (check pins, pixel_format, frame_size)";
76 case PICO_CAMERA_ERR_INVALID_STATE: return "invalid state (camera already initialized)";
77 case PICO_CAMERA_ERR_NOT_SUPPORTED: return "not supported (e.g. JPEG on a sensor without a JPEG encoder)";
78 case PICO_CAMERA_ERR_TIMEOUT: return "timeout";
79 case PICO_CAMERA_ERR_NOT_DETECTED: return "no sensor detected on the SCCB bus (check wiring/power)";
80 case PICO_CAMERA_ERR_FAILED_TO_SET_FRAME_SIZE: return "failed to set frame size";
81 case PICO_CAMERA_ERR_FAILED_TO_SET_OUT_FORMAT: return "failed to set output format";
82 default: return "unknown error";
83 }
84}
85
86/* Library version, kept in sync with library.properties / library.json.
87 * When a copy installed from the Library Manager overrides a (possibly older)
88 * copy bundled with the Arduino core, these macros describe the copy the
89 * sketch actually compiled against. */
90#define PICO_CAMERA_VERSION_MAJOR 0
91#define PICO_CAMERA_VERSION_MINOR 4
92#define PICO_CAMERA_VERSION_PATCH 2
93#define PICO_CAMERA_VERSION_HEX ((PICO_CAMERA_VERSION_MAJOR << 16) | \
94 (PICO_CAMERA_VERSION_MINOR << 8) | \
95 PICO_CAMERA_VERSION_PATCH)
96#define PICO_CAMERA_VERSION_STRING "0.4.2"
97
107typedef enum {
108 PICO_CAMERA_FB_AUTO = 0, //< PSRAM when available, SRAM otherwise (default)
109 PICO_CAMERA_FB_IN_PSRAM, //< PSRAM only; init fails if unavailable (esp32-camera parity)
110 PICO_CAMERA_FB_IN_SRAM //< On-chip SRAM only
112
122typedef struct {
123 int pin_pwdn; //< GPIO for camera power down line (-1 if unused)
124 int pin_reset; //< GPIO for camera reset line (-1 if unused)
125 int pin_xclk; //< GPIO for XCLK output
126 int pin_sccb_sda; //< GPIO for SCCB SDA. Hard-muxed: SDA must be an even
127 //< GPIO, SCL the matching odd one, both routing to I2C(sccb_i2c_port) —
128 //< i.e. (pin / 2) % 2 == sccb_i2c_port (e.g. port 0: SDA on 0/4/8/.../28,
129 //< SCL on 1/5/9/.../29). If -1, use the already configured I2C bus by
130 //< number (sccb_i2c_port); esp32-camera parity. The bus must be
131 //< initialized beforehand (Wire.begin() / Wire1.begin() under Arduino,
132 //< i2c_init() under the bare Pico SDK).
133 int pin_sccb_scl; //< GPIO for SCCB SCL (ignored when pin_sccb_sda is -1)
134 int pin_d0; //< GPIO for data line 0 (lowest of 8 consecutive pins)
135 int pin_d1;
136 int pin_d2;
137 int pin_d3;
138 int pin_d4;
139 int pin_d5;
140 int pin_d6;
141 int pin_d7;
142 int pin_vsync; //< GPIO for VSYNC line
143 int pin_href; //< GPIO for HREF line
144 int pin_pclk; //< GPIO for PCLK line
145
146 int xclk_freq_hz; //< XCLK frequency in Hz (0 = default 10 MHz)
147
148 int sccb_i2c_port; //< I2C peripheral: 0 or 1. In shared bus mode
149 //< (pin_sccb_sda == -1) this selects which
150 //< already-initialized bus to reuse
151
152 pixformat_t pixel_format; //< PIXFORMAT_RGB565, PIXFORMAT_YUV422 or PIXFORMAT_JPEG
153 framesize_t frame_size; //< FRAMESIZE_*
154
155 int jpeg_quality; //< 0-63, lower means higher quality (JPEG only)
156 size_t fb_count; //< Number of frame buffers to allocate
157 camera_fb_location_t fb_location; //< Where frame buffers live; PICO_CAMERA_FB_AUTO (0)
158 //< keeps old zero-initialized configs working
160
164typedef struct {
165 uint8_t *buf; //< Pointer to the pixel data
166 size_t len; //< Length of the used data in bytes
167 size_t width; //< Width in pixels
168 size_t height; //< Height in pixels
169 pixformat_t format; //< Format of the pixel data
170 struct timeval timestamp; //< Timestamp since boot of the captured frame
172
186pico_camera_err_t pico_camera_init(const camera_config_t *config);
187
191pico_camera_err_t pico_camera_deinit(void);
192
199camera_fb_t *pico_camera_fb_get(void);
200
204void pico_camera_fb_return(camera_fb_t *fb);
205
211sensor_t *pico_camera_sensor_get(void);
212
218const camera_sensor_info_t *pico_camera_sensor_info_get(void);
219
220#ifdef __cplusplus
221}
222#endif
camera_fb_location_t
Frame buffer location.
Definition pico_camera.h:107
Common camera sensor types, aligned with esp32-camera's sensor.h (subset).
Configuration structure for camera initialization.
Definition pico_camera.h:122
Data structure of camera frame buffer.
Definition pico_camera.h:164
Definition sensor.h:108
中文文档