@@ -628,6 +628,9 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
628628 int mov_status_type ,
629629 int mov_status_n ) {
630630
631+ // Ensure object starts in its deinit state.
632+ common_hal_rp2pio_statemachine_mark_deinit (self );
633+
631634 // First, check that all pins are free OR already in use by any PIO if exclusive_pin_use is false.
632635 pio_pinmask_t pins_we_use = wait_gpio_mask ;
633636 PIO_PINMASK_MERGE (pins_we_use , _check_pins_free (first_out_pin , out_pin_count , exclusive_pin_use ));
@@ -744,7 +747,7 @@ void common_hal_rp2pio_statemachine_construct(rp2pio_statemachine_obj_t *self,
744747 mov_status_type , mov_status_n );
745748 if (!ok ) {
746749 // indicate state machine never inited
747- self -> state_machine = NUM_PIO_STATE_MACHINES ;
750+ common_hal_rp2pio_statemachine_mark_deinit ( self ) ;
748751 mp_raise_RuntimeError (MP_ERROR_TEXT ("All state machines in use" ));
749752 }
750753}
@@ -827,6 +830,10 @@ void common_hal_rp2pio_statemachine_deinit(rp2pio_statemachine_obj_t *self) {
827830 rp2pio_statemachine_deinit (self , false);
828831}
829832
833+ void common_hal_rp2pio_statemachine_mark_deinit (rp2pio_statemachine_obj_t * self ) {
834+ self -> state_machine = NUM_PIO_STATE_MACHINES ;
835+ }
836+
830837void common_hal_rp2pio_statemachine_never_reset (rp2pio_statemachine_obj_t * self ) {
831838 rp2pio_statemachine_never_reset (self -> pio , self -> state_machine );
832839 // TODO: never reset all the pins
0 commit comments