-
Notifications
You must be signed in to change notification settings - Fork 345
Use move based api for I2S #3639
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
base: main
Are you sure you want to change the base?
Conversation
I'm very glad to see someone else getting the DMA move stuff to the finish line. (I was struggling to find the motivation to touch the I2S driver)
There isn't a one size fits all solution for this one. Some peripherals will tell you when this happens, and other won't. There's probably other DMA registers that can be polled to check for this condition but I haven't looked yet. I'm leaning towards leaving this problem to the user, because regardless of whatever solution you choose here, it is still up to the user to restart the I2S/DMA transfer when it stops. |
b1a1e82
to
50ee962
Compare
50ee962
to
de67c31
Compare
06c00ca
to
5737d41
Compare
Think this may be ready. Added the TxStreamBuf that basically works symmetrically with the RxStreamBuf implementation. A few problems I couldn't get my heads around
I'll fix the docs and also changelog once I get a basic review. |
The RX DMA doesn't "complete". It just keep going until something goes wrong.
Yeah DMA RX doesn't stop. What you want is to figure out when the peripheral has stopped, then you can stop the DMA. Which esp device are you unsure of?
You're on the right track. I2S will emit an EOF every
Leaving it as an argument is the right way to go imo. I'll review your PR shortly |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First batch of comments.
Overall looks good, I'm excited to land this
A small downside to this PR is we've lost support of u16, u32, etc. but that can be brought back later. |
Thanks a lot for PR reviewing @Dominaezzz appreciated! |
9cdb79d
to
6e37aa7
Compare
I meant esp32c3 and similar devices in the sense that they don't have the interrupt |
@AstrickHarren this is super close to the finish line, any plans on getting back to it? |
was too busy tho, I'll be working on it soon |
I think we already have DmaLoopBuf if I'm not mistaken. I'll fix the conflicts and add macros like the one for DmaRxStreamBuf |
The goal of the QA test is to figure out a path forward with #4135 . If it's still possible to starve out an I2S transfer (and why wouldn't it be, if we don't drain the data we read?), then the test should be modified to match the old behaviour. |
Regarding the late error: Currently there is no good way to check if an ongoing transfer is late (due to data overflow in rx or underflow in tx). This is because transfers are separated from their underlying DMA streaming buffer implementations. I attempted to add an For others: esp-hal/esp-hal/src/i2s/master.rs Lines 2185 to 2187 in 24478a4
For esp32s2 and esp32, it doesn't work since in_suc_eof will be triggered in the streaming process. esp-hal/esp-hal/src/i2s/master.rs Lines 1761 to 1764 in 24478a4
The other way will be to report a Please let know if there is a third option. @Dominaezzz |
Also, I just saw the test was counting late errors, which confuses me since if a DMA transfer is already late, all subsequent pop to the transfer should also be late right? I could be wrong. |
On the RX side, you can tell if the transfer is late if the DMA buffer has no data and the peripheral is no longer running. On the TX side, there's a few way and you'll need to DMA data structure to look a certain way. |
Actually the same should be doable for TX. If the buffer is full and the peripheral is no longer running. See this for what I mean
Which test is this? (link pls) |
I didn't find a good way to check if I2s is done on chips esp32 and esp32c2. Looks like they don't have such a register? On the other chips, Late can be consistently reported by checking the
esp-hal/qa-test/src/bin/embassy_wifi_i2s.rs Lines 147 to 151 in be30dda
|
I'm reading the trm |
Right, so in the S1 and S2, like you said, the I2S doesn't tell you that it's done, you just have to stop it when you're done receiving or transmitting data. On the RX side, you can check for the IN_DSCR_EMPTY interrupt. On the TX side, we'll need a different buffer implementation (sorry 😅). Let me know if this makes sense. I'm not very good at explaining this sort of thing. |
I could be wrong but I think on the TX side, TotalEof will be the interrupt to listen to? Should it be sufficient to detect a late for dma transfer? @Dominaezzz |
Yes that would work but every descriptor would need to have it's SUC_EOF marked. (which shouldn't be an issue here I suppose) |
work was kicking my but and need summer off. anything i could attempt to assist with here? getting back into the grove of things |
Are you sure about that? I'm reading manual but I didn't find such instructions? Would you mind point me to it?
I think we are left with how to detect the end of an i2s transfer. You can get the idea of it from the previous discussions. |
@Dominaezzz I don't think IN_DESC_EMPTY works for some reason and TOTAL_EOF works fine without manually set each SUC_EOF bit. For some reason, esp-hal/esp-hal/src/dma/mod.rs Lines 2335 to 2363 in a9777d8
In particular, the future above will never be triggered by |
I'm not too sure what's going on there. You can try using check_owner instead I suppose |
This is to fix #3285, as in #3612 @Dominaezzz laid out reasons for a move-based i2s API so I thought I may help a bit about #2269 . Haven't tested or anything, just to put the draft PR here to see if I'm in the right direction. Also I'm very aware of #3219 but it seems to be dormant for a bit. I really need to make i2s working for my little project with mic and speaker so let me know if anyone's already working on this and I'll be glad to close my PR.
DmaTxStreamBuf
similar toDmaRxStreamBuf
, tested on an ESP32-S3 with MAX98357A to output soundGDMA_OUT_TOTAL_EOF_CHn_INT
, so the other ways around maybecheck_owner
and listen to error