Skip to content

Commit

Permalink
Merge pull request #6361 from mwisslead/rp2040_pulsein_buffer_fix
Browse files Browse the repository at this point in the history
Fix buffer issue for rp2040 PulseIn
  • Loading branch information
dhalbert authored May 8, 2022
2 parents 5f4f667 + b7882ed commit bb46898
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ports/raspberrypi/common-hal/pulseio/PulseIn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand All @@ -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,
Expand Down

0 comments on commit bb46898

Please sign in to comment.