Skip to content

Commit d7864ac

Browse files
authored
Merge branch 'espressif:master' into err_pixformat
2 parents 7472fc7 + b817e9b commit d7864ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+3794
-1736
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
idf_ver: ["release-v5.0", "release-v5.1", "release-v5.2", "release-v5.3", "latest"]
14+
idf_ver: ["release-v5.1", "release-v5.2", "release-v5.3", "release-v5.4", "release-v5.5", "latest"]
1515
idf_target: ["esp32", "esp32s2", "esp32s3", "esp32c2", "esp32c3"]
1616
container: espressif/idf:${{ matrix.idf_ver }}
1717
steps:

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
**/build
44
**/sdkconfig
55
**/sdkconfig.old
6-
**/dependencies.lock
6+
**/dependencies.lock
7+
**/managed_components/**

CMakeLists.txt

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# get IDF version for comparison
22
set(idf_version "${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}")
33

4+
set(priv_requires "")
5+
46
# set conversion sources
57
set(srcs
68
conversions/yuv.c
79
conversions/to_jpg.cpp
810
conversions/to_bmp.c
911
conversions/jpge.cpp
10-
conversions/esp_jpg_decode.c
1112
)
1213

1314
set(priv_include_dirs
@@ -19,8 +20,6 @@ set(include_dirs
1920
conversions/include
2021
)
2122

22-
set(COMPONENT_REQUIRES driver)
23-
2423
# set driver sources only for supported platforms
2524
if(IDF_TARGET STREQUAL "esp32" OR IDF_TARGET STREQUAL "esp32s2" OR IDF_TARGET STREQUAL "esp32s3")
2625
list(APPEND srcs
@@ -42,6 +41,8 @@ if(IDF_TARGET STREQUAL "esp32" OR IDF_TARGET STREQUAL "esp32s2" OR IDF_TARGET ST
4241
sensors/sc030iot.c
4342
sensors/sc031gs.c
4443
sensors/mega_ccm.c
44+
sensors/hm1055.c
45+
sensors/hm0360.c
4546
)
4647

4748
list(APPEND priv_include_dirs
@@ -61,7 +62,6 @@ if(IDF_TARGET STREQUAL "esp32" OR IDF_TARGET STREQUAL "esp32s2" OR IDF_TARGET ST
6162
list(APPEND srcs
6263
target/xclk.c
6364
target/esp32s2/ll_cam.c
64-
target/tjpgd.c
6565
)
6666

6767
list(APPEND priv_include_dirs
@@ -75,39 +75,34 @@ if(IDF_TARGET STREQUAL "esp32" OR IDF_TARGET STREQUAL "esp32s2" OR IDF_TARGET ST
7575
)
7676
endif()
7777

78-
set(priv_requires freertos nvs_flash)
78+
list(APPEND priv_requires freertos nvs_flash esp_mm)
7979

8080
set(min_version_for_esp_timer "4.2")
8181
if (idf_version VERSION_GREATER_EQUAL min_version_for_esp_timer)
8282
list(APPEND priv_requires esp_timer)
8383
endif()
8484

8585
# include the SCCB I2C driver
86-
# this uses either the legacy I2C API or the newwer version from IDF v5.4
86+
# this uses either the legacy I2C API or the newer version from IDF v5.4
8787
# as this features a method to obtain the I2C driver from a port number
88-
if (idf_version VERSION_GREATER_EQUAL "5.4")
88+
if (idf_version VERSION_GREATER_EQUAL "5.4" AND NOT CONFIG_SCCB_HARDWARE_I2C_DRIVER_LEGACY)
8989
list(APPEND srcs driver/sccb-ng.c)
9090
else()
9191
list(APPEND srcs driver/sccb.c)
9292
endif()
9393

9494
endif()
9595

96-
# CONFIG_ESP_ROM_HAS_JPEG_DECODE is available from IDF v4.4 but
97-
# previous IDF supported chips already support JPEG decoder, hence okay to use this
98-
if(idf_version VERSION_GREATER_EQUAL "4.4" AND NOT CONFIG_ESP_ROM_HAS_JPEG_DECODE)
99-
list(APPEND srcs
100-
target/tjpgd.c
101-
)
102-
list(APPEND priv_include_dirs
103-
target/jpeg_include/
104-
)
96+
set(req driver)
97+
if (idf_version VERSION_GREATER_EQUAL "6.0")
98+
list(APPEND priv_requires esp_driver_gpio esp_driver_spi esp_driver_i2c)
99+
list(APPEND req esp_driver_ledc)
105100
endif()
106101

107102
idf_component_register(
108103
SRCS ${srcs}
109104
INCLUDE_DIRS ${include_dirs}
110105
PRIV_INCLUDE_DIRS ${priv_include_dirs}
111-
REQUIRES driver # due to include of driver/gpio.h in esp_camera.h
106+
REQUIRES ${req}
112107
PRIV_REQUIRES ${priv_requires}
113108
)

Kconfig

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,20 @@ menu "Camera configuration"
116116
SC031GS is a global shutter CMOS sensor with high frame rate and single-frame HDR.
117117
Enable this option if you want to use the SC031GS.
118118
Disable this option to save memory.
119+
120+
config HM1055_SUPPORT
121+
bool "Support HM1055 VGA"
122+
default y
123+
help
124+
Enable this option if you want to use the HM1055.
125+
Disable this option to save memory.
126+
127+
config HM0360_SUPPORT
128+
bool "Support HM0360 VGA"
129+
default y
130+
help
131+
Enable this option if you want to use the HM0360.
132+
Disable this option to save memory.
119133

120134
config MEGA_CCM_SUPPORT
121135
bool "Support MEGA CCM 5MP"
@@ -124,6 +138,20 @@ menu "Camera configuration"
124138
Enable this option if you want to use the MEGA CCM.
125139
Disable this option to save memory.
126140

141+
choice SCCB_HARDWARE_I2C_DRIVER_SELECTION
142+
prompt "I2C driver selection for SCCB"
143+
default SCCB_HARDWARE_I2C_DRIVER_NEW
144+
help
145+
Select the I2C driver to use for SCCB communication.
146+
NOTE: new driver is only supported for ESP-IDF >= 5.4.
147+
148+
config SCCB_HARDWARE_I2C_DRIVER_LEGACY
149+
bool "Legacy I2C driver"
150+
config SCCB_HARDWARE_I2C_DRIVER_NEW
151+
bool "New I2C driver"
152+
153+
endchoice
154+
127155
choice SCCB_HARDWARE_I2C_PORT
128156
bool "I2C peripheral to use for SCCB"
129157
default SCCB_HARDWARE_I2C_PORT1
@@ -159,7 +187,7 @@ menu "Camera configuration"
159187

160188
config CAMERA_TASK_STACK_SIZE
161189
int "CAM task stack size"
162-
default 2048
190+
default 4096
163191
help
164192
Camera task stack size
165193

@@ -186,6 +214,14 @@ menu "Camera configuration"
186214
Maximum value of DMA buffer
187215
Larger values may fail to allocate due to insufficient contiguous memory blocks, and smaller value may cause DMA interrupt to be too frequent.
188216

217+
config CAMERA_PSRAM_DMA
218+
bool "Enable PSRAM DMA mode by default"
219+
depends on IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3
220+
default n
221+
help
222+
Enable DMA transfers directly from PSRAM on supported targets
223+
(ESP32-S2 and ESP32-S3) by default.
224+
189225
choice CAMERA_JPEG_MODE_FRAME_SIZE_OPTION
190226
prompt "JPEG mode frame size option"
191227
default CAMERA_JPEG_MODE_FRAME_SIZE_AUTO

README.md

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,17 @@ This repository hosts ESP32 series Soc compatible driver for image sensors. Addi
2929
| SC101IOT| 1280 x 720 | color | YUV/YCbCr422<br/>Raw RGB | 1/4.2" |
3030
| SC030IOT| 640 x 480 | color | YUV/YCbCr422<br/>RAW Bayer | 1/6.5" |
3131
| SC031GS | 640 x 480 | monochrome | RAW MONO<br/>Grayscale | 1/6" |
32+
| HM0360 | 656 x 496 | monochrome | RAW MONO<br/>Grayscale | 1/6" |
33+
| HM1055 | 1280 x 720 | color | 8/10-bit Raw<br/>YUV/YCbCr422<br/>RGB565/555/444 | 1/6" |
3234

3335
## Important to Remember
3436

3537
- Except when using CIF or lower resolution with JPEG, the driver requires PSRAM to be installed and activated.
3638
- Using YUV or RGB puts a lot of strain on the chip because writing to PSRAM is not particularly fast. The result is that image data might be missing. This is particularly true if WiFi is enabled. If you need RGB data, it is recommended that JPEG is captured and then turned into RGB using `fmt2rgb888` or `fmt2bmp`/`frame2bmp`.
3739
- When 1 frame buffer is used, the driver will wait for the current frame to finish (VSYNC) and start I2S DMA. After the frame is acquired, I2S will be stopped and the frame buffer returned to the application. This approach gives more control over the system, but results in longer time to get the frame.
3840
- When 2 or more frame bufers are used, I2S is running in continuous mode and each frame is pushed to a queue that the application can access. This approach puts more strain on the CPU/Memory, but allows for double the frame rate. Please use only with JPEG.
41+
- The Kconfig option `CONFIG_CAMERA_PSRAM_DMA` enables PSRAM DMA mode on ESP32-S2 and ESP32-S3 devices. This flag defaults to false.
42+
- You can switch PSRAM DMA mode at runtime using `esp_camera_set_psram_mode()`.
3943

4044
## Installation Instructions
4145

@@ -133,7 +137,7 @@ static camera_config_t camera_config = {
133137
.pin_href = CAM_PIN_HREF,
134138
.pin_pclk = CAM_PIN_PCLK,
135139

136-
.xclk_freq_hz = 20000000,//EXPERIMENTAL: Set to 16MHz on ESP32-S2 or ESP32-S3 to enable EDMA mode
140+
.xclk_freq_hz = 20000000,
137141
.ledc_timer = LEDC_TIMER_0,
138142
.ledc_channel = LEDC_CHANNEL_0,
139143

@@ -247,14 +251,14 @@ esp_err_t jpg_httpd_handler(httpd_req_t *req){
247251
#define PART_BOUNDARY "123456789000000000000987654321"
248252
static const char* _STREAM_CONTENT_TYPE = "multipart/x-mixed-replace;boundary=" PART_BOUNDARY;
249253
static const char* _STREAM_BOUNDARY = "\r\n--" PART_BOUNDARY "\r\n";
250-
static const char* _STREAM_PART = "Content-Type: image/jpeg\r\nContent-Length: %u\r\n\r\n";
254+
static const char* _STREAM_PART = "Content-Type: image/jpeg\r\nContent-Length: %zu\r\n\r\n";
251255
252256
esp_err_t jpg_stream_httpd_handler(httpd_req_t *req){
253257
camera_fb_t * fb = NULL;
254258
esp_err_t res = ESP_OK;
255-
size_t _jpg_buf_len;
256-
uint8_t * _jpg_buf;
257-
char * part_buf[64];
259+
size_t jpg_buf_len = 0;
260+
uint8_t * jpg_buf = NULL;
261+
char part_buf[64];
258262
static int64_t last_frame = 0;
259263
if(!last_frame) {
260264
last_frame = esp_timer_get_time();
@@ -273,30 +277,36 @@ esp_err_t jpg_stream_httpd_handler(httpd_req_t *req){
273277
break;
274278
}
275279
if(fb->format != PIXFORMAT_JPEG){
276-
bool jpeg_converted = frame2jpg(fb, 80, &_jpg_buf, &_jpg_buf_len);
280+
bool jpeg_converted = frame2jpg(fb, 80, &jpg_buf, &jpg_buf_len);
277281
if(!jpeg_converted){
278282
ESP_LOGE(TAG, "JPEG compression failed");
279283
esp_camera_fb_return(fb);
280284
res = ESP_FAIL;
285+
break;
281286
}
282287
} else {
283-
_jpg_buf_len = fb->len;
284-
_jpg_buf = fb->buf;
288+
jpg_buf_len = fb->len;
289+
jpg_buf = fb->buf;
285290
}
286291
287292
if(res == ESP_OK){
288293
res = httpd_resp_send_chunk(req, _STREAM_BOUNDARY, strlen(_STREAM_BOUNDARY));
289294
}
290295
if(res == ESP_OK){
291-
size_t hlen = snprintf((char *)part_buf, 64, _STREAM_PART, _jpg_buf_len);
292-
293-
res = httpd_resp_send_chunk(req, (const char *)part_buf, hlen);
296+
int hlen = snprintf(part_buf, sizeof(part_buf), _STREAM_PART, jpg_buf_len);
297+
if(hlen < 0 || hlen >= sizeof(part_buf)){
298+
ESP_LOGE(TAG, "Header truncated (%d bytes needed >= %zu buffer)",
299+
hlen, sizeof(part_buf));
300+
res = ESP_FAIL;
301+
} else {
302+
res = httpd_resp_send_chunk(req, part_buf, (size_t)hlen);
303+
}
294304
}
295305
if(res == ESP_OK){
296-
res = httpd_resp_send_chunk(req, (const char *)_jpg_buf, _jpg_buf_len);
306+
res = httpd_resp_send_chunk(req, (const char *)jpg_buf, jpg_buf_len);
297307
}
298308
if(fb->format != PIXFORMAT_JPEG){
299-
free(_jpg_buf);
309+
free(jpg_buf);
300310
}
301311
esp_camera_fb_return(fb);
302312
if(res != ESP_OK){
@@ -306,9 +316,10 @@ esp_err_t jpg_stream_httpd_handler(httpd_req_t *req){
306316
int64_t frame_time = fr_end - last_frame;
307317
last_frame = fr_end;
308318
frame_time /= 1000;
319+
float fps = frame_time > 0 ? 1000.0f / (float)frame_time : 0.0f;
309320
ESP_LOGI(TAG, "MJPG: %uKB %ums (%.1ffps)",
310-
(uint32_t)(_jpg_buf_len/1024),
311-
(uint32_t)frame_time, 1000.0 / (uint32_t)frame_time);
321+
(uint32_t)(jpg_buf_len/1024),
322+
(uint32_t)frame_time, fps);
312323
}
313324
314325
last_frame = 0;

0 commit comments

Comments
 (0)