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

Simplify DMA impl removing most macros #162

Open
wants to merge 2 commits into
base: staged-pac
Choose a base branch
from

Conversation

usbalbin
Copy link
Contributor

@usbalbin usbalbin commented Jan 7, 2025

Simplify DMA impl by not using macros now that the pac has been improved using the same pac types across the two DMAs

@usbalbin
Copy link
Contributor Author

usbalbin commented Jan 12, 2025

@AdinAck do you have any thoughts on this or further DMA-related things? I have quite limited experiance with DMA, but I get the feeling the DMA story of this crate is less than ideal as is. :)

@AdinAck
Copy link
Contributor

AdinAck commented Jan 12, 2025

Just by coincidence a few days ago I used it for the first time and I was very frustrated very quickly, so suffice it to say I am happy for any improvements, and am interested in helping with that effort.

I need to think a lot harder before I propose any significant design changes, this is something I have actively skipped thinking about in my HAL design journey. But I think soon it will be time.

In general I do believe traitifying everything as much as possible is the correct direction. For example, when designing abstract structures intended for reuse, if I want let's say to stream some bytes out over UART via DMA, I of course will hold something of type Transfer<{lot's of generics}>.

This is bad because then my abstraction needs to hold many generics related to lower implementation details.

I don't care what generics the Transfer has, I just want any kind of Transfer.

Embassy's solution is to simply erase this type information. They went with that approach because tasks cannot accept generics, so the full type signature would need to be elaborated, defeating the purpose of lifting methods into a trait. I don't like this approach because type-erasure forbids compile-time evaluation and opens the door for incurred runtime costs.

My idea for a good solution would be if Transfer<...> implemented a trait let's call TransferAgent (horrible name, doesn't matter) which houses all of the transfer methods, i.e. start, peek_buffer, pause, etc. That way abstractions simply hold an impl TransferAgent. Additionally, since the types and their respective generics are all still resolved at compile-time, no runtime cost is incurred for differing implementations.

If lower-level specification is really necessary, the generics could be concretely specified via associated types of the trait: impl TransferAgent<Stream = hal::dma::streams::Stream5>.

I believe many HAL components would benefit from this design. I'm just spitballing here though, I have not tested this approach quite yet, although I intend to do so soon.

I don't know if this is too much for what you were asking.

@usbalbin
Copy link
Contributor Author

Thanks for the answer :)

I am happy for any improvements, and am interested in helping with that effort.

Great:)

I don't care what generics the Transfer has, I just want any kind of Transfer.

Makes sense

There is also #112

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.

2 participants