Skip to content

Issue #4945 - handle multiple PulseIns #4975

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

Merged
merged 1 commit into from
Jul 9, 2021
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
8 changes: 2 additions & 6 deletions ports/raspberrypi/common-hal/pulseio/PulseIn.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
#include "bindings/rp2pio/StateMachine.h"
#include "common-hal/pulseio/PulseIn.h"

pulseio_pulsein_obj_t *save_self;

#define NO_PIN 0xff
#define MAX_PULSE 65535
#define MIN_PULSE 10
Expand All @@ -62,7 +60,6 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
self->idle_state = idle_state;
self->start = 0;
self->len = 0;
save_self = self;

bool ok = rp2pio_statemachine_construct(&self->state_machine,
pulsein_program, sizeof(pulsein_program) / sizeof(pulsein_program[0]),
Expand All @@ -88,7 +85,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
buf_index = 0;

pio_sm_set_in_pins(self->state_machine.pio,self->state_machine.state_machine,pin->number);
common_hal_rp2pio_statemachine_set_interrupt_handler(&(self->state_machine),&common_hal_pulseio_pulsein_interrupt,NULL,PIO_IRQ0_INTE_SM0_RXNEMPTY_BITS);
common_hal_rp2pio_statemachine_set_interrupt_handler(&(self->state_machine),&common_hal_pulseio_pulsein_interrupt,self,PIO_IRQ0_INTE_SM0_RXNEMPTY_BITS);

// exec a set pindirs to 0 for input
pio_sm_exec(self->state_machine.pio,self->state_machine.state_machine,0xe080);
Expand Down Expand Up @@ -124,9 +121,8 @@ void common_hal_pulseio_pulsein_pause(pulseio_pulsein_obj_t *self) {
result = 0;
buf_index = 0;
}
void common_hal_pulseio_pulsein_interrupt() {
void common_hal_pulseio_pulsein_interrupt(pulseio_pulsein_obj_t *self) {

pulseio_pulsein_obj_t *self = save_self;
uint32_t rxfifo = 0;

rxfifo = pio_sm_get_blocking(self->state_machine.pio, self->state_machine.state_machine);
Expand Down