espressif: pulseio.PulseIn - Use dma only when necessary #10499
+30
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a second attempt at allowing longer pulse sequences to be recorded using
pulseio.PulseIn
on espressif ports using the DMA backend of the RMT hardware.This is essentially the same code as in the original PR #10397, but the new logic is now only activated in cases where the existing logic didn't work, i.e. if
maxlen > 128
. I believe this fixes all issues raised in #10466 and #10470:maxlen <= 128
, then the old logic works fine on all ports.maxlen > 128
and the DMA backend is available (i.e. the hardware supports it and it is not allocated), then recording longer pulse sequences works.maxlen > 128
and the DMA backend is NOT available (i.e. the hardware doesn't support it or it is already allocated, e.g. due to an existingPulseIn
object), then a"Invalid maxlen"
error is raised. In this case, usingmaxlen <= 128
still works.I tested all of this on a Lolin-S2-mini and a Waveshare-S3-Zero and added a sentence to the documentation regarding this.
Notes:
This is a breaking change to anyone previously using
maxlen > 128
on a variant that did not support it. Previously this silently just returned shorter sequences, now this raises an error.I think it might be possible to get
maxlen > 128
to work also on variants without DMA hardware because the documentation says:But this might introduce more limitations regarding use of multiple
PulseIn
andPulseOut
, which is a can-of-worms I did not want to open in this PR.Strictly speaking the value of 128 above should be replaced by
2*SOC_RMT_MEM_WORDS_PER_CHANNEL
. But since this was previously hard-coded to a maximum of 128 pulses (with only worked due to Note 2), and changing this would be another breaking change, I left this at 128.Maybe @jbrelwof and @bill88t want to try this out before it gets merged.