Merge pull request #6361 from mwisslead/rp2040_pulsein_buffer_fix

Fix buffer issue for rp2040 PulseIn
This commit is contained in:
Dan Halbert 2022-05-08 12:37:17 -04:00 committed by GitHub
commit bb46898572
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -147,9 +147,12 @@ void common_hal_pulseio_pulsein_interrupt(void *self_in) {
}
// return pulses that are not too short
if (result > MIN_PULSE) {
self->buffer[self->buf_index] = (uint16_t)result;
size_t buf_index = (self->start + self->len) % self->maxlen;
self->buffer[buf_index] = (uint16_t)result;
if (self->len < self->maxlen) {
self->len++;
} else {
self->start = (self->start + 1) % self->maxlen;
}
if (self->buf_index < self->maxlen) {
self->buf_index++;
@ -169,7 +172,6 @@ void common_hal_pulseio_pulsein_interrupt(void *self_in) {
pio_sm_restart(self->state_machine.pio,self->state_machine.state_machine);
pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, true);
self->buf_index = 0;
self->start = 0;
}
}
void common_hal_pulseio_pulsein_resume(pulseio_pulsein_obj_t *self,