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

Allow users to easily name DMA channels #1771

Merged
merged 7 commits into from
Jul 16, 2024
Merged

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

Fixes part of #1767.

With this PR users can now consistently name the dma channel in use in a driver.

let i8080: I8080<_, GdmaCh<0>, _>;
let cam: Camera<_, GdmaCh<2>, _>;
let spi: Spi<_, GdmaCh<4>, _>;
let spi: Spi<_, Spi2DmaCh, _>;

This PR introduces a public trait called DmaChannel which describes the RX and TX parts of a channel in associated types.

The existing ChannelTypes trait which is really similar just didn't cut it (maybe a skill issue). With this PR at least, the "private but public for technical reasons" traits Tx, TxPrivate, Rx and RxPrivate can be removed and ChannelTx and ChannelRx can just have pub(crate) methods on it.

There will be a follow up PR to simplify the InstanceDma trait (based on this) in the SPI driver, which was my main motive for making this PR.

Testing

No actual code changes, I just shuffled the generics about so CI should be fine.

@bugadani
Copy link
Contributor

bugadani commented Jul 8, 2024

This is totally bike-shedding, but to be honest, I'm not sure how, as a user, I would react seeing a type like GdmaCh. I would probably prefer not renaming Channel<N>, but instead renaming the other, shadowing Channel. That being said, the ChannelN type aliasses are probably better - if they were instead newtypes, they would show up in rustdoc and it would be obvious how many channels users may choose from.

@Dominaezzz
Copy link
Collaborator Author

I added Gdma to the name because Channel is a common type in the repo and it make imports a little more tedious in the IDE. Thought this is something that can be fixed with an import alias.
I also wasn't sure what I would rename the shadowing Channel type to if I went that direction instead. Adding "Gdma" felt straightforward.

The type aliases kinda suck for discoverability like you said. The DmaChannel implementations are meant to be the new types at least.

Having said that, I don't care about the names (someone else can decide), I just want the solution to not use type aliases, it should be consistent across drivers and it shouldn't get in the way of splitting a channel into an Rx half and tx half.

@bjoernQ
Copy link
Contributor

bjoernQ commented Jul 15, 2024

I also think names like GdmaCh are not ideal (but I see why just Channel is a bit too generic). Maybe something like DmaChannel as the user-facing name?

Maybe having DmaChannelN new-types in addition would make sense since I agree that it would make it easier to know how many channels are available

@Dominaezzz
Copy link
Collaborator Author

Alright I'll replace the const generic with a simple type.
GdmaCh<0> -> DmaChannel0.

Spi1DmaCh, Spi2DmaCh, I2S1DmaCh stay the same?

@bjoernQ
Copy link
Contributor

bjoernQ commented Jul 15, 2024

Spi1DmaCh, Spi2DmaCh, I2S1DmaCh stay the same?

Probably naming them like Spi1DmaChannel, Spi2DmaChannel etc. looks more consistent since those are the ones which are actually used in user code - but would be probably good to hear another opinion on this

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.

LGTM - Thanks!

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!

@JurajSadel JurajSadel added this pull request to the merge queue Jul 16, 2024
Merged via the queue into esp-rs:main with commit 6fd9443 Jul 16, 2024
31 checks passed
@Dominaezzz Dominaezzz deleted the dma_name branch July 16, 2024 23:30
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