345 Commits

Author SHA1 Message Date
b5fd891abc Merge pull request #791 from tore-espressif/fix/idf_dependency
fix: Define IDF >=5.1 requirement
v2.1.2
2025-08-07 13:48:38 +03:00
91f9c993fb fix: Define IDF >=5.1 requirement
esp32-camera now depends on esp_mm which was introduced in IDF 5.1.
2025-08-07 10:12:35 +02:00
89e8d4d565 Merge pull request #785 from RubenKelevra/fix/EOI_expand_checks_search_view
cam_hal: PSRAM: forward-scan last dma node to find JPEG EOI reliably
v2.1.1
2025-08-05 21:50:26 +03:00
38bb948445 cam_hal: PSRAM: forward-scan last half-buffer to find JPEG EOI reliably
When `psram_mode` is active, `cam_take()` used to copy only 32 bytes
from PSRAM and scan backward for the JPEG EOI (FF D9). Because DMA
copies in dma_node_buffer_size length, the true EOI often
falls earlier and was missed, leading to repeated "NO-EOI" resets.

This change:
- Drops the 32-byte SRAM copy; scan directly in PSRAM after cache
  invalidation.
- Searches the last dma_node_buffer_size **plus 1 byte** (marker_len-1),
  starting 1 byte before the final block to catch split EOIs.
- Scans **forward** so we pick the earliest EOI in the current tail and
  avoid stale markers from a larger previous frame.
- Uses a fast byte-hunt for 0xFF with a 2-byte verification for "FF D9".

SRAM DMA mode keeps the simple backward check (we only accept EOI at
offset 0 there), so no extra complexity or perf work is added.

Net effect: robust EOI detection without garbage tails and fewer
spurious "NO-EOI" resets in PSRAM captures.
2025-08-05 14:55:44 +02:00
a60c6502d3 Merge pull request #788 from RubenKelevra/increase_stack_size
increase camera task stack size
2025-08-05 12:30:30 +03:00
f015004121 Merge pull request #787 from RubenKelevra/feat/reduce_stack_usage_of_log_messages
replace Log message handler with a more lightweight version
2025-08-05 12:29:32 +03:00
1077c47966 Merge branch 'master' into increase_stack_size 2025-08-05 12:27:25 +03:00
0305aca11b Merge branch 'master' into feat/reduce_stack_usage_of_log_messages 2025-08-05 12:26:57 +03:00
307bcc000d Merge pull request #781 from RubenKelevra/buffer_overflow_check_rework_for_psram_mode
rework psram_mode frame buffer overflow check
2025-08-05 12:25:01 +03:00
1e1eb15576 Merge branch 'master' into buffer_overflow_check_rework_for_psram_mode 2025-08-05 12:21:21 +03:00
877e5e93eb Merge pull request #778 from RubenKelevra/bugfix/ensure_cache_coherency_before_returning_image_in_psram-mode
cam_hal: drop caches for psram_mode frames before hand-off to application
2025-08-05 12:20:19 +03:00
d0a8751c7f Merge branch 'master' into bugfix/ensure_cache_coherency_before_returning_image_in_psram-mode 2025-08-05 12:16:56 +03:00
9f66ed2e51 Merge pull request #777 from RubenKelevra/bugfix/implement_jpeg_eoi_check_for_psram_dma
fix jpeg eoi check for psram_mode (DMA)
2025-08-05 12:16:23 +03:00
7b9e4f738d Merge branch 'master' into bugfix/implement_jpeg_eoi_check_for_psram_dma 2025-08-05 12:13:23 +03:00
e6378d2532 Merge pull request #776 from RubenKelevra/bugfix/implement_jpeg_soi_check_for_psram_dma
fix jpeg soi check for psram_mode (DMA)
2025-08-05 12:12:27 +03:00
62b16fc2f3 Merge pull request #789 from espzav/fix/gpio_requires
fix: Fixed GPIO implicit declaration
2025-08-05 11:43:32 +03:00
61a7e37b92 fix: Fixed GPIO implicit declaration 2025-08-05 10:34:46 +02:00
181004ceb3 increase camera task stack size 2025-08-04 19:50:37 +02:00
c1c0da435e replace Log message handler with a more lightweight version
in an effort to reduce stack usage
2025-08-04 19:42:06 +02:00
5bb9bfe5e4 rework psram_mode frame buffer overflow check
- Do this check only in psram_mode
- Improve code comment, to make clear that it will stop early on copy operations
- Increase fb size by one dma_half_buffer_size in psram_mode

Rationale:

In psram_mode we will be called after each memory copy operation is completed, by
the CAM_IN_SUC_EOF event. Since we cannot predict at this point, if the camera
will copy another dma_half_buffer_size into the fb, we need to abort here,
if there's not enough size in the fb for the next copy operation.

This assumption means, we will abort even if this is indeed the last
copy operation the camera did, and the next event will be a CAM_VSYNC,
notifying us, that the copy operation is completed.

Since we cannot predict this, we need one dma_half_buffer_size more
space in the fb in psram_mode to allow images of the same size in
psram_mode as in the regular mode.
2025-08-04 19:36:09 +02:00
bea12e7556 cam_hal: drop caches for psram_mode frames before hand-off to application
Invalidate data-cache lines for the image captured via dma (in psram_mode)
before the buffer is handed off to the application. This ensures the the
CPU will read the correct data from the PSRAM instead of cached segments
from the previous image stored in this buffer.

Other work:

- The cache invalidation was refactored into `cam_drop_psram_cache()`

Performance consideration:

On an ESP32-S3 @ 240 MHz with 32-byte cache lines:

|------------------------------------------------|
| Image size | Lines flushed | Cycles | Time     |
|------------|---------------|--------|----------|
|    100 KiB |         3 200 | 16 000 |  66.7 µs |
|    300 KiB |         9 600 | 48 000 | 200   µs |
|________________________________________________|
2025-07-23 18:56:17 +02:00
cf96213968 fix jpeg eoi check for psram_mode (DMA)
- Added a configurable probe length for PSRAM JPEG validation via CAM_EOI_PROBE_BYTES
- For PSRAM mode, CAM_EOI_PROBE_BYTES is copied from the first DMA block into a
  stack buffer and validated by cam_verify_jpeg_eoi() to verify that it's a valid
  jpeg image.
- Reading from PSRAM directly with cam_verify_jpeg_eoi() is here avoided due to
  latency of small operations done by cam_verify_jpeg_eoi().
2025-07-22 21:22:06 +02:00
1c0f7bd611 fix jpeg soi check for psram_mode (DMA)
- Added a configurable probe length for PSRAM JPEG validation via CAM_SOI_PROBE_BYTES
- For PSRAM mode, CAM_SOI_PROBE_BYTES is copied from the first DMA block into a
  stack buffer and validated by cam_verify_jpeg_soi() to verify that it's a valid
  jpeg image before continuing the capture.
- Reading from PSRAM directly with cam_verify_jpeg_soi() is here avoided due to
  latency of small operations done by cam_verify_jpeg_soi().
2025-07-21 22:56:38 +02:00
2368d94f11 Merge pull request #774 from RubenKelevra/feat/introduce_flag_to_enable_psram_dma
feat: add PSRAM-DMA flag + runtime API for ESP32-S2/S3; remove 16MHz heuristic
2025-07-21 12:05:28 +03:00
eedf03a7a7 Merge pull request #772 from RubenKelevra/bugfix/camtask_dma_overflow_detection
cam_hal: add guard in cam_task() so DMA transfers cannot exceed image slot size
2025-07-21 12:01:43 +03:00
309999afba cam_hal: add guard in cam_task() so DMA transfers cannot exceed image slot size
Previously there is no limit how much data would be transferred
via DMA from the camera.

Added a DMA overflow detection block in cam_task() so the
driver stops if the number of frame copies exceeds the
is reaching the maximum amount of storage allocated in
PSRAM.
2025-07-19 01:25:13 +02:00
1484db7dba feat: add PSRAM-DMA flag + runtime API for ESP32-S2/S3; remove 16MHz heuristic
Add a Kconfig switch (CONFIG_CAMERA_PSRAM_DMA) to enable camera to PSRAM
DMA copy on ESP32-S2 and ESP32-S3 targets, in favor of removing the
undocumented "set XCLK=16MHz to enable PSRAM DMA" heuristic.

cam_hal.c:
- Select psram_mode = true when CONFIG_CAMERA_PSRAM_DMA && target is S2/S3.
- Otherwise psram_mode = false.
- Log whether PSRAM DMA mode is enabled.

Kconfig:
- New bool CAMERA_PSRAM_DMA (default n) under Camera configuration.

Runtime control:
- New public API:
  - esp_camera_set_psram_mode(bool enable)
  - esp_camera_get_psram_mode(void)
  - esp_camera_reconfigure(const camera_config_t *cfg)

README/test:
- Remove stale 16MHz XCLK comments.
- Add short note describing CONFIG_CAMERA_PSRAM_DMA.
2025-07-19 01:17:45 +02:00
3ca876a5a9 Merge pull request #773 from RubenKelevra/docs/fix-jpg-stream-example-buffer-and-size-handling
docs(readme): harden jpg_stream_httpd_handler example & fix bugs
2025-07-18 10:52:45 +03:00
7e08a0a561 Merge pull request #770 from RubenKelevra/bugfix/hm1055_set_brightness_return_handling
hm1055: fix set_brightness error handling & logging
2025-07-18 10:47:44 +03:00
7673d3ee22 docs(readme): harden jpg_stream_httpd_handler example & fix bugs
Changes:
* Use `%zu` in _STREAM_PART for size_t-safe Content-Length formatting.
* Fix `part_buf` type: `char part_buf[64]` (was array of char pointers).
* initialize local JPEG buffer vars: `jpg_buf_len`/`jpg_buf`
  * drop leading underscores on them for consistency with other locals
* Bound `snprintf()` by `sizeof(part_buf)`; capture `int hlen`.
* Detect and log header truncation with required/available sizes; fail gracefully.
* Break out of loop on JPEG compression failure to avoid invalid buffer use.
* Send header chunk only when formatting succeeds.
* Guard FPS calculation against divide-by-zero; compute once as `fps`.
* Remove unsafe/needless pointer cast.
* Minor style cleanups for readability.
2025-07-17 19:56:21 +02:00
f0814e695a Merge pull request #771 from RubenKelevra/bugfix/sccb-max-devices-oob
sccb-ng: fix off-by-one device capacity check to prevent overflow
2025-07-17 17:02:07 +03:00
05decdbce7 sccb-ng: fix off-by-one device capacity check to prevent overflow
SCCB_Install_Device() rejected new devices only when device_count > MAX_DEVICES.
When device_count == MAX_DEVICES the function still proceeded to install the
device and wrote to devices[device_count], i.e. devices[MAX_DEVICES], which is
one element past the end of the devices[] array (valid indices 0..MAX_DEVICES-1).

This off-by-one results in a buffer overflow / write outside the designated
memory area and then increments device_count to MAX_DEVICES+1.

Change the guard to `device_count >= MAX_DEVICES` so we refuse installation once
the array is full and prevent the out-of-bounds write/read chain.
2025-07-17 14:32:35 +02:00
7ffdae8c47 hm1055: fix set_brightness error handling & logging
The old code always wrote BRIGHT even if enabling ISPCTRL5 failed,
while also overwriting the first error code. It also used
`if (ret != 0)` to log/update status, so we reported success when
the write actually failed.

Guard the BRIGHT write behind a successful ISPCTRL5 write and only log /
update `sensor->status.brightness` when both writes succeed. This keeps
the original error, and prevents false success reports.
2025-07-17 07:39:51 +02:00
69737c5e84 Merge pull request #767 from RubenKelevra/bugfix/hm0360_missing_error_handling_possible_PLL_register_corruption
hm0360: harden _set_pll() against read-failures & bad widths, silence unused-param warnings
v2.1.0
2025-07-15 10:18:09 +03:00
c1a8d48fbd Merge pull request #766 from RubenKelevra/bugfix/memory_leak_to_bmp_jpg2bmp
jpg2bmp: fix memory leak on error
2025-07-15 10:16:44 +03:00
c12517e467 hm0360: _set_pll(): guard against wide reads and silence unused-param warnings
* Mark all currently unused PLL parameters with (void) to remove
  -Wunused-parameter noise.
* After a successful read_reg(), reject any value > 0xFF and return
  -ERANGE.  Ensures only 8-bit data is written to PLL1CFG.
2025-07-15 06:34:13 +02:00
be37adc2da hm0360: _set_pll(): detect read_reg failure before writing PLL1CFG
The old code stored the raw return value of read_reg() in an 8-bit
variable and wrote it straight back to PLL1CFG.  A negative I²C/SCCB
error therefore became 0xFF (or similar), silently corrupting the
sensor’s clock tree while still returning “success”.

* Read PLL1CFG into an int (`ret`) and return immediately if `ret < 0`.
* Cast to uint8_t only after the error check, then proceed with the
  masked write.

This propagates read failures to the caller and guarantees we never
write garbage to the PLL register under fault conditions.
2025-07-15 06:26:40 +02:00
0c72514363 jpg2bmp: unified rework error handling
Consolidated all error handling in jpg2bmp into a single fail path so memory is freed reliably
2025-07-15 06:23:39 +02:00
225a4db4d6 jpg2bmp: fix memory leak on error
in case the jpeg decode did fail we would never return the memory we
allocated for the output buffer and thus create a memory leak.
2025-07-14 19:40:22 +02:00
ed74d59d1b Merge pull request #756 from rjoly-getraline/fix_camera_probe
Fix camera probe detecting non-camera peripheral
2025-07-14 19:17:22 +03:00
3e251052ec Merge pull request #765 from RubenKelevra/throttle-cam-hal-isr-logging
cam_hal: shrink ISR stack, silence spam, strip logs at low levels
2025-07-14 15:25:58 +03:00
f8fad50da5 cam_hal: shrink ISR stack, silence spam, strip logs at low levels
* Replace ESP_LOGx in ISRs/tight loops with CAM_WARN_THROTTLE(counter,msg)
  → uses ROM-resident ets_printf(); ~300 B less stack per hit.

* At CONFIG_LOG_DEFAULT_LEVEL < 2 the macro compiles to a no-op,
  so *all* warning code is dropped from the binary.

* First miss logs immediately, then every 100th; counter wraps at 10 000
  (reset to 1 to skip the “first miss” banner after wrap).

* New static uint16_t counters per call-site keep totals without globals.

* Kconfig switch CAM_LOG_SPAM_EVERY_FRAME (=0) restores old per-frame debug.

No functional change to capture path—just less stack, fewer cycles,
smaller image, and a much quieter UART.
2025-07-14 14:22:19 +02:00
a42fe2961a Merge pull request #759 from RubenKelevra/fix_jpeg-eoi-underflow
fix(cam_hal): guard cam_verify_jpeg_eoi() against buffer-underflow
2025-07-14 14:57:49 +03:00
ee92090425 fix(cam_hal): guard cam_verify_jpeg_eoi() against buffer-underflow
If DMA returns a frame shorter than two bytes, the previous code
did:

    dptr = inbuf + length - 2;

which under-flows the pointer and produces undefined behaviour.

Behaviour for valid frames (length ≥ 2) is unchanged; damaged or
empty buffers are now discarded safely.
2025-07-14 13:21:17 +02:00
cbed97ce6d Merge pull request #760 from RubenKelevra/fix_jpeg-soi-overread
fix(cam_hal): prevent SOI scan from (1) running on length<3 and (2) over-reading the last 2 bytes
2025-07-14 14:15:15 +03:00
3e50b59f3d fix(cam_hal): prevent SOI scan from (1) running on length<3
and (2) over-reading the last 2 bytes

Changes:
* Store SOI as a 3-byte array (0xFF D8 FF)
* Early-exit when length < 3 to avoid over-reading
* calculate end index correctly, to avoid over-reading
2025-07-14 12:55:21 +02:00
a66af8dab0 Merge pull request #758 from RubenKelevra/fix_cam-task_stack-overflow
fix(cam_hal): replace recursive cam_take() with bounded loop prevents stack-overflow in cam_task
2025-07-14 13:11:04 +03:00
d52b4a3ca4 Merge branch 'master' into fix_cam-task_stack-overflow 2025-07-14 13:02:19 +03:00
8b602050ac Merge branch 'master' into fix_camera_probe 2025-07-07 09:40:48 +02:00
fca7fddea2 Merge pull request #762 from ALToast/fix/remove_unused_kconfig_option
fix: Remove unused Kconfig option
2025-07-03 10:00:38 +03:00