Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add I2S Camera mode driver #1646

Closed
wants to merge 4 commits into from
Closed

Conversation

Dominaezzz
Copy link
Collaborator

Thank you for your contribution!

We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:

Submission Checklist 📝

  • I have updated existing examples or added new ones (if applicable).
  • I have used cargo xtask fmt-packages command to ensure that all changed code is formatted correctly.
  • My changes were added to the CHANGELOG.md in the proper section.
  • My changes are in accordance to the esp-rs API guidelines

Extra:

Pull Request Details 📖

Description

Adds a driver for I2S Camera mode on the ESP32 only. (ESP32-S2 to come in a future PR)

Testing

Ran the example on a MaTouch_ESP32 3.2" TFT Touch with Camera.

@Dominaezzz
Copy link
Collaborator Author

Part of #1475

@Dominaezzz Dominaezzz force-pushed the i2s_cam branch 2 times, most recently from 8032725 to fe47795 Compare June 14, 2024 21:50
@Dominaezzz Dominaezzz marked this pull request as ready for review June 14, 2024 21:54
@Dominaezzz
Copy link
Collaborator Author

Anyone using this driver will almost certainly want to setup a separate clock signal with the LEDC driver. Should this be included in the example in the doc of the driver?

@MabezDev are you able to run the example?

@MabezDev
Copy link
Member

@Dominaezzz Thanks for the PR! I'm trying to run the example on the TTGO-Camera board I have here, but without success so far. I've changed the required pins for this board, and I can communicate with camera, but the read back data is garbage.

Probe successful!
Found PID of 0x26, and was expecting 0x26
Failed to find JPEG terminator
// followed by a stream of useless bytes

Any suggestions on debugging this?

@Dominaezzz
Copy link
Collaborator Author

What are the first 10 bytes that come out? I'm hoping the stream at least starts as a valid JPEG.
If it's truly garbage, is there any consistency at least?

Any suggestions on debugging this?

Sadly I don't have a good answer (besides pulling out a logic analyser).

In my experience with I2S camera mode, it tends to return garbage for the first image (or sometimes it's several images).
I haven't been able to prove whether this is from the camera, the peripheral or the firmware. I do know that esp32-camera have similar issues but they hide it by using framebuffers (if a framebuffer isn't a valid jpeg, it is discarded but this sacrifices latency).

I will just change the example to skip the first 10 images. i.e. Wait for the vsync pin to toggle 10 times.
Might try using the PCNT peripheral for this if the borrow checker lets me.

@Dominaezzz
Copy link
Collaborator Author

@MabezDev I've updated the example to skip the first 10 images. You should be able to reliably get an image every time you run the example now.

Also I've use the experimental coroutines feature for the example, I hope this is okay.

Side note: read_dma_circular now works properly after rebasing on the recent DMA pop() fixes!

@wuwbobo2021
Copy link

I don't know why this PR failed. I need to capture raw data via I2S camera mode of ESP32-S2, and now I have to do it in ESP-IDF. However, this code helps me understand how to drive it (ESP32-S2 I2S registers differ from that of ESP32, though), because I'm not using any camera supported by esp32-camera component in IDF.

@Dominaezzz
Copy link
Collaborator Author

I don't know why this PR failed.

Was tired of rebasing at the time, I was juggling 4 to 5 PRs at a time and closed this to reduce my workload.

I also wasn't 100% happy with how the API came out tbh. Wasn't a big fan of the "different mode in a separate driver" idea here.

Feel free to resurrect the PR with my commits if you like, I currently don't have the motivation not personal need to drive this to the finish line. The DMA APIs themselves need a bit of improving before this driver can shine imo and that's where I'm at.

Btw I strongly recommend using the ESP32-S3 for cameras. Much better hardware than the S2 and base ESP32.

via I2S camera mode of ESP32-S2

Are you actually using Rust? And what devkit are you playing around with?

@wuwbobo2021
Copy link

I had considered using Rust, but I encountered a problem of not having enough internal SRAM (#1084, #2001). Maybe memory management (including esp-alloc crate) needs to be improved. Now I just use ESP-IDF.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants