@@ -62,10 +62,7 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
62
62
self -> len = 0 ;
63
63
save_self = self ;
64
64
65
- // Set everything up.
66
- rp2pio_statemachine_obj_t state_machine ;
67
-
68
- bool ok = rp2pio_statemachine_construct (& state_machine ,
65
+ bool ok = rp2pio_statemachine_construct (& self -> state_machine ,
69
66
pulsein_program , sizeof (pulsein_program ) / sizeof (pulsein_program [0 ]),
70
67
1000000 ,
71
68
NULL , 0 ,
@@ -80,29 +77,26 @@ void common_hal_pulseio_pulsein_construct(pulseio_pulsein_obj_t *self,
80
77
false,
81
78
true, 32 , true, // RX auto-push every 32 bits
82
79
false); // claim pins
83
- pio_sm_set_enabled (state_machine .pio ,state_machine .state_machine , false);
84
- self -> state_machine .pio = state_machine .pio ;
85
- self -> state_machine .state_machine = state_machine .state_machine ;
86
- self -> state_machine .sm_config = state_machine .sm_config ;
87
- self -> state_machine .offset = state_machine .offset ;
80
+
81
+ pio_sm_set_enabled (self -> state_machine .pio ,self -> state_machine .state_machine , false);
88
82
pio_sm_clear_fifos (self -> state_machine .pio ,self -> state_machine .state_machine );
89
83
last_level = self -> idle_state ;
90
84
level_count = 0 ;
91
85
result = 0 ;
92
86
buf_index = 0 ;
93
87
94
- pio_sm_set_in_pins (state_machine .pio ,state_machine .state_machine ,pin -> number );
95
- common_hal_rp2pio_statemachine_set_interrupt_handler (& state_machine ,& common_hal_pulseio_pulsein_interrupt ,NULL ,PIO_IRQ0_INTE_SM0_RXNEMPTY_BITS );
88
+ pio_sm_set_in_pins (self -> state_machine .pio ,self -> state_machine .state_machine ,pin -> number );
89
+ common_hal_rp2pio_statemachine_set_interrupt_handler (& ( self -> state_machine ) ,& common_hal_pulseio_pulsein_interrupt ,NULL ,PIO_IRQ0_INTE_SM0_RXNEMPTY_BITS );
96
90
97
91
// exec a set pindirs to 0 for input
98
- pio_sm_exec (state_machine .pio ,state_machine .state_machine ,0xe080 );
92
+ pio_sm_exec (self -> state_machine .pio ,self -> state_machine .state_machine ,0xe080 );
99
93
// exec the appropriate wait for pin
100
94
if (self -> idle_state == true) {
101
95
pio_sm_exec (self -> state_machine .pio ,self -> state_machine .state_machine ,0x2020 );
102
96
} else {
103
97
pio_sm_exec (self -> state_machine .pio ,self -> state_machine .state_machine ,0x20a0 );
104
98
}
105
- pio_sm_set_enabled (state_machine .pio , state_machine .state_machine , true);
99
+ pio_sm_set_enabled (self -> state_machine .pio , self -> state_machine .state_machine , true);
106
100
}
107
101
108
102
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) {
114
108
return ;
115
109
}
116
110
pio_sm_set_enabled (self -> state_machine .pio , self -> state_machine .state_machine , false);
117
- pio_sm_unclaim ( self -> state_machine . pio , self -> state_machine . state_machine );
111
+ common_hal_rp2pio_statemachine_deinit ( & self -> state_machine );
118
112
m_free (self -> buffer );
113
+ reset_pin_number (self -> pin );
119
114
self -> pin = NO_PIN ;
120
115
}
121
116
0 commit comments