@@ -117,9 +117,13 @@ void common_hal_pulseio_pulsein_deinit(pulseio_pulsein_obj_t *self) {
117
117
}
118
118
119
119
void common_hal_pulseio_pulsein_pause (pulseio_pulsein_obj_t * self ) {
120
+ pio_sm_restart (self -> state_machine .pio , self -> state_machine .state_machine );
120
121
pio_sm_set_enabled (self -> state_machine .pio , self -> state_machine .state_machine , false);
122
+ last_level = self -> idle_state ;
123
+ level_count = 0 ;
124
+ result = 0 ;
125
+ buf_index = 0 ;
121
126
}
122
-
123
127
void common_hal_pulseio_pulsein_interrupt () {
124
128
125
129
pulseio_pulsein_obj_t * self = save_self ;
@@ -134,13 +138,13 @@ void common_hal_pulseio_pulsein_interrupt() {
134
138
} else {
135
139
result = level_count ;
136
140
last_level = level ;
137
- level_count = 1 ;
138
- // Pulses that are londger than MAX_PULSE will return MAX_PULSE
141
+ level_count = 0 ;
142
+ // Pulses that are longer than MAX_PULSE will return MAX_PULSE
139
143
if (result > MAX_PULSE ) {
140
144
result = MAX_PULSE ;
141
145
}
142
- // ignore pulses that are too short
143
- if (result <= MAX_PULSE && result > MIN_PULSE ) {
146
+ // return pulses that are not too short
147
+ if (result > MIN_PULSE ) {
144
148
self -> buffer [buf_index ] = (uint16_t )result ;
145
149
if (self -> len < self -> maxlen ) {
146
150
self -> len ++ ;
@@ -165,24 +169,24 @@ void common_hal_pulseio_pulsein_interrupt() {
165
169
}
166
170
void common_hal_pulseio_pulsein_resume (pulseio_pulsein_obj_t * self ,
167
171
uint16_t trigger_duration ) {
168
- // exec a wait for the selected pin to change state
169
- if (self -> idle_state == true) {
170
- pio_sm_exec (self -> state_machine .pio ,self -> state_machine .state_machine ,0x2020 );
171
- } else {
172
- pio_sm_exec (self -> state_machine .pio ,self -> state_machine .state_machine ,0x20a0 );
173
- }
174
172
// Send the trigger pulse.
175
173
if (trigger_duration > 0 ) {
176
174
gpio_set_function (self -> pin ,GPIO_FUNC_SIO );
177
175
gpio_set_dir (self -> pin ,true);
178
176
gpio_put (self -> pin , !self -> idle_state );
179
177
common_hal_mcu_delay_us ((uint32_t )trigger_duration );
180
178
gpio_set_function (self -> pin ,GPIO_FUNC_PIO0 );
181
- common_hal_mcu_delay_us (225 );
179
+ common_hal_mcu_delay_us (125 );
182
180
}
183
181
184
182
// Reconfigure the pin for PIO
185
183
gpio_set_function (self -> pin , GPIO_FUNC_PIO0 );
184
+ // exec a wait for the selected pin to change state
185
+ if (self -> idle_state == true) {
186
+ pio_sm_exec (self -> state_machine .pio ,self -> state_machine .state_machine ,0x2020 );
187
+ } else {
188
+ pio_sm_exec (self -> state_machine .pio ,self -> state_machine .state_machine ,0x20a0 );
189
+ }
186
190
pio_sm_set_enabled (self -> state_machine .pio , self -> state_machine .state_machine , true);
187
191
}
188
192
0 commit comments