imxrt-rs / imxrt-hal

Rust for NXP i.MX RT
Apache License 2.0
133 stars 33 forks source link

Implement ADC DMA source and wrapper #107

Closed lkolbly closed 3 years ago

lkolbly commented 3 years ago

This commit makes the ADCs a possible source for DMA operations, and creates a user-friendly wrapper class (StreamingAdc) which can abstract the necessary buffer wrangling.

The StreamingAdc struct may not be a good fit for this crate (after making it, it seems to be a bit niche - supporting only the interrupts-with-256-element-double-buffers case), if so that's perfectly fine and I can pull it out. I might also be able to make it more better using some subset of:

But, it solves my usecase, today at least, and that's the only important one, right? (and I didn't want to spend too much time on it without working toward some specific goal)

Also, this PR is against the maint-v0.4 branch, because that's what I could get teensy4-bsp to work with. If there's a branch of teensy4-bsp which works with the master branch of imxrt-hal, I can try to rebase this.

lkolbly commented 3 years ago

Ah, looks like doctests still compiles no_run things, I can fix that if we want to keep that struct.

lkolbly commented 3 years ago

I agree that, in its current form, StreamingAdc is a bit specific for the HAL. I also see some patterns that might not work, but I'm looking for your insight. If it's not too much work to generalize, I'm happy to support something like StreamingAdc in the HAL. Otherwise, we can merge the foundational work that lets us implement StreamingAdc outside of the HAL.

Awesome, thanks! Tell you what, I'll steal your insights on what direction would make sense to make it better, and then I'll update this PR to be just the AdcSource, and I'll make a new PR for the StreamingAdc once I've cleaned it up a bit. (although, with Circular, maybe it's simple enough to justify just being an example in the docs somewhere, most of what it does now is tracking the two buffers)

I may do that last part contemporaneously with SAI support, that's next on my project todo list and it seems like it may deserve something similar.

mciantyre commented 3 years ago

Sounds great! Thanks again for working though this. Let us know if we can help with any of the ADC, DMA, or SAI work.