Merge remote-tracking branch 'origin/main' into main
This commit is contained in:
commit
7f81e15007
|
@ -62,10 +62,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
|
|||
self->len = 0;
|
||||
save_self = self;
|
||||
|
||||
// Set everything up.
|
||||
rp2pio_statemachine_obj_t state_machine;
|
||||
|
||||
bool ok = rp2pio_statemachine_construct(&state_machine,
|
||||
bool ok = rp2pio_statemachine_construct(&self->state_machine,
|
||||
pulsein_program, sizeof(pulsein_program) / sizeof(pulsein_program[0]),
|
||||
1000000,
|
||||
NULL, 0,
|
||||
|
@ -80,29 +77,26 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
|
|||
false,
|
||||
true, 32, true, // RX auto-push every 32 bits
|
||||
false); // claim pins
|
||||
pio_sm_set_enabled(state_machine.pio,state_machine.state_machine, false);
|
||||
self->state_machine.pio = state_machine.pio;
|
||||
self->state_machine.state_machine = state_machine.state_machine;
|
||||
self->state_machine.sm_config = state_machine.sm_config;
|
||||
self->state_machine.offset = state_machine.offset;
|
||||
|
||||
pio_sm_set_enabled(self->state_machine.pio,self->state_machine.state_machine, false);
|
||||
pio_sm_clear_fifos(self->state_machine.pio,self->state_machine.state_machine);
|
||||
last_level = self->idle_state;
|
||||
level_count = 0;
|
||||
result = 0;
|
||||
buf_index = 0;
|
||||
|
||||
pio_sm_set_in_pins(state_machine.pio,state_machine.state_machine,pin->number);
|
||||
common_hal_rp2pio_statemachine_set_interrupt_handler(&state_machine,&common_hal_pulseio_pulsein_interrupt,NULL,PIO_IRQ0_INTE_SM0_RXNEMPTY_BITS);
|
||||
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);
|
||||
|
||||
// exec a set pindirs to 0 for input
|
||||
pio_sm_exec(state_machine.pio,state_machine.state_machine,0xe080);
|
||||
pio_sm_exec(self->state_machine.pio,self->state_machine.state_machine,0xe080);
|
||||
// exec the appropriate wait for pin
|
||||
if (self->idle_state == true) {
|
||||
pio_sm_exec(self->state_machine.pio,self->state_machine.state_machine,0x2020);
|
||||
} else {
|
||||
pio_sm_exec(self->state_machine.pio,self->state_machine.state_machine,0x20a0);
|
||||
}
|
||||
pio_sm_set_enabled(state_machine.pio, state_machine.state_machine, true);
|
||||
pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, true);
|
||||
}
|
||||
|
||||
bool common_hal_pulseio_pulsein_deinited(pulseio_pulsein_obj_t *self) {
|
||||
|
@ -114,8 +108,9 @@ void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t *self) {
|
|||
return;
|
||||
}
|
||||
pio_sm_set_enabled(self->state_machine.pio, self->state_machine.state_machine, false);
|
||||
pio_sm_unclaim(self->state_machine.pio, self->state_machine.state_machine);
|
||||
common_hal_rp2pio_statemachine_deinit(&self->state_machine);
|
||||
m_free(self->buffer);
|
||||
reset_pin_number(self->pin);
|
||||
self->pin = NO_PIN;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue