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

Migrate Camera to a move based API #2242

Merged
merged 6 commits into from
Oct 2, 2024
Merged

Conversation

Dominaezzz
Copy link
Collaborator

@Dominaezzz Dominaezzz commented Sep 27, 2024

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.
  • I have added necessary changes to user code to the Migration Guide.
  • My changes are in accordance to the esp-rs API guidelines

Extra:

Pull Request Details 📖

Description

Similar to #2191, this PR migrates the Camera driver to move based API for the same reasons. Camera now accepts a DmaRxBuffer rather than a plain slice, providing flexibility with DMA.

This PR depends on #2213 and #2191 (I need to refactor it to expose the new View type).

This PR introduces a new DmaRxBuffer implementation called DmaRxStreamBuf. It's effectively the "circular transfer" version of DmaRxBuf but with an important difference, it doesn't create a circle of descriptors, which avoids the problem in #2021. It also provides a zero copy API and exposes EOFs (See #2033). There's more info on how it works in the doc of the struct.

To support this new DmaRxBuffer implementation, I've added an associated type View to DmaRxBuffer (and DmaTxBuffer) to allow limited but safe access to the buffer during the DMA transfer. This is what lets users read from the buffer during the transfer.

Now the choice of "one shot" or "circular" (or any other transfer type) is based on the dma buffer implementation rather than the driver, effectively achieving half of #2035 .

I haven't provided a with_buffer/SpiDmaBus equivalent here because most people using this driver would typically just start one transfer and endlessly read from it for the rest of their application.
Users can easily create a wrapper if they have a more specific use case.

Testing

Ran the modified example on my devkit and it's even more reliable than before.
cc @MabezDev for running the example on your ESP32-S3-EYE. (I don't think anyone else on the team has a ESP32-S3 + OV2640 devkit).

esp-hal/src/dma/mod.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@bugadani bugadani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "circular if you can process it fast enough" approach is interesting.

Let's start moving these buffer types out to submodules, the main dma module is big enough without these as it is.

esp-hal/src/dma/mod.rs Outdated Show resolved Hide resolved
esp-hal/src/dma/mod.rs Outdated Show resolved Hide resolved
esp-hal/src/dma/mod.rs Outdated Show resolved Hide resolved
esp-hal/src/dma/mod.rs Outdated Show resolved Hide resolved
@Dominaezzz
Copy link
Collaborator Author

Let's start moving these buffer types out to submodules, the main dma module is big enough without these as it is.

I'll do this one in a separate PR, I'm scared of merge conflicts from doing it here.

esp-hal/src/dma/mod.rs Outdated Show resolved Hide resolved
esp-hal/src/dma/mod.rs Outdated Show resolved Hide resolved
@Dominaezzz Dominaezzz marked this pull request as ready for review September 27, 2024 12:22
Copy link
Contributor

@bjoernQ bjoernQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks good now. I also have an ESP32S3-EYE now and can confirm the example is still working

Copy link
Contributor

@bugadani bugadani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@bugadani bugadani added this pull request to the merge queue Oct 2, 2024
Merged via the queue into esp-rs:main with commit 30aef58 Oct 2, 2024
28 checks passed
@bugadani bugadani mentioned this pull request Oct 3, 2024
20 tasks
@Dominaezzz Dominaezzz deleted the camera_move_api branch October 16, 2024 21:56
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