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

De-duplicate DMA transfer implementations #1550

Merged
merged 6 commits into from
May 15, 2024

Conversation

bjoernQ
Copy link
Contributor

@bjoernQ bjoernQ commented May 10, 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).
  • My changes were added to the CHANGELOG.md in the proper section.

Extra:

Pull Request Details 📖

Description

Previously each DMA capable peripheral had its own implementation of DMA transaction. This creates common implementations in the DMA module and the peripherals now use the shared implementation.

Testing

All DMA-related examples should work as before.

I cannot test lcd_cam examples (lacking hardware) - the i8080 example still outputs "something" on the pins at least

@bjoernQ bjoernQ force-pushed the dma-transaction branch from bdb900f to e74750e Compare May 10, 2024 12:47
Copy link
Collaborator

@Dominaezzz Dominaezzz left a comment

Choose a reason for hiding this comment

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

Looks great! I'm excited for this PR to land.

Unfortunately I'm abroad and don't have my I8080 hardware to test the example.

/// Wait until the transfer is done.
/// Depending on the peripheral this might include checking the DMA
/// channel.
fn peripheral_wait_dma(&mut self, is_tx: bool, is_rx: bool);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this just wait for the DMA to empty it's data into the peripheral's FIFO? Or also wait for the peripheral to empty it's FIFO as well?

Copy link
Member

Choose a reason for hiding this comment

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

This is impl specific I think, for SPI the peripheral FIFO is checked, for others its DMA & peripheral registers. I guess it doesn't matter what the impl does, as long as it does the expected thing which is returns when all bytes are sent/recv'd by the peripheral.

esp-hal/src/dma/mod.rs Outdated Show resolved Hide resolved
where
I: dma_private::DmaSupportTx,
{
instance: &'a mut I,
Copy link
Collaborator

Choose a reason for hiding this comment

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

In a future PR, it might be interesting to use BorrowMut/DerefMut here instead of a plain mut ref to solve the #1512.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have ideas how to avoid duplicating everything when introducing a Move-API but would need to explore that in more detail - feel free to do the same on top of this (I'm not yet too happy with my own ideas)

I: dma_private::DmaSupportTx,
{
fn drop(&mut self) {
self.instance.peripheral_wait_dma(true, false);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some peripherals like LCD_CAM support cancellation, where you can just stop the transfer on the spot. There should probably be a cancel_and_wait method with a default that just waits like this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Though, since this shouldn't be introducing new behavior, maybe this can be saved for a different PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense! As you said probably not in this PR

@bjoernQ bjoernQ force-pushed the dma-transaction branch from cc6906f to 2573822 Compare May 14, 2024 10:35
Copy link
Contributor

@JurajSadel JurajSadel left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! I tested related examples (including i8080, @Dominaezzz ) and they work fine for me.

Copy link
Member

@MabezDev MabezDev left a comment

Choose a reason for hiding this comment

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

Overall looks good to me! I think @Dominaezzz brought up some good points which we should think about before merging.

@bjoernQ bjoernQ force-pushed the dma-transaction branch from 2573822 to b1d1f41 Compare May 15, 2024 09:39
@bjoernQ
Copy link
Contributor Author

bjoernQ commented May 15, 2024

Overall looks good to me! I think @Dominaezzz brought up some good points which we should think about before merging.

Agreed we definitely shouldn't forget about those points. My original idea for this PR was to have one place for the implementation and explore the next steps in another PR. (and keep this PR a "naive" refactoring)

@MabezDev MabezDev added this pull request to the merge queue May 15, 2024
Merged via the queue into esp-rs:main with commit 9edd098 May 15, 2024
22 checks passed
@bjoernQ bjoernQ deleted the dma-transaction branch November 26, 2024 08:43
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.

4 participants