Skip to content
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

Fix buffer issue for rp2040 PulseIn #6361

Merged
merged 1 commit into from
May 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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