File tree Expand file tree Collapse file tree 2 files changed +26
-6
lines changed Expand file tree Collapse file tree 2 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -132,7 +132,29 @@ impl swj::Dependencies<Swd, Jtag> for Context {
132
132
}
133
133
}
134
134
135
- self . delay . delay_ticks ( self . cycles_per_us * wait_us) ;
135
+ // Delay until desired output state or timeout.
136
+ let mut last = self . delay . get_current ( ) ;
137
+ for _ in 0 ..wait_us {
138
+ last = self . delay . delay_ticks_from_last ( self . cycles_per_us , last) ;
139
+
140
+ // If a pin is selected, make sure its output equals the desired output state, or else
141
+ // continue waiting.
142
+ let swclk_not_in_desired_state = mask. contains ( swj:: Pins :: SWCLK )
143
+ && output. contains ( swj:: Pins :: SWCLK ) != self . swclk . is_high ( ) ;
144
+ let swdio_not_in_desired_state = mask. contains ( swj:: Pins :: SWDIO )
145
+ && output. contains ( swj:: Pins :: SWDIO ) != self . swdio . is_high ( ) ;
146
+ let nreset_not_in_desired_state = mask. contains ( swj:: Pins :: NRESET )
147
+ && output. contains ( swj:: Pins :: NRESET ) != self . nreset . is_high ( ) ;
148
+
149
+ if swclk_not_in_desired_state
150
+ || swdio_not_in_desired_state
151
+ || nreset_not_in_desired_state
152
+ {
153
+ continue ;
154
+ }
155
+
156
+ break ;
157
+ }
136
158
137
159
let mut ret = swj:: Pins :: empty ( ) ;
138
160
ret. set ( swj:: Pins :: SWCLK , self . swclk . is_high ( ) ) ;
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ use crate::systick_delay::Delay;
4
4
use crate :: { dap, usb:: ProbeUsb } ;
5
5
use core:: mem:: MaybeUninit ;
6
6
use dap_rs:: usb_device:: class_prelude:: UsbBusAllocator ;
7
- use embedded_hal:: digital:: { InputPin , OutputPin } ;
7
+ use embedded_hal:: digital:: { InputPin , OutputPin , StatefulOutputPin } ;
8
8
use embedded_hal:: pwm:: SetDutyCycle ;
9
9
use embedded_hal_02:: adc:: OneShot ;
10
10
use replace_with:: replace_with_or_abort_unchecked;
@@ -303,13 +303,11 @@ where
303
303
}
304
304
}
305
305
306
- /// Note: This function panics if the pin is in the wrong mode .
306
+ /// Note: If the pin is an output this will only reflect the set state, NOT electrical state .
307
307
pub fn is_high ( & mut self ) -> bool {
308
308
match self {
309
309
DynPin :: Input ( i) => i. is_high ( ) == Ok ( true ) ,
310
- DynPin :: Output ( _) => {
311
- defmt:: panic!( "Input operation on output pin" ) ;
312
- }
310
+ DynPin :: Output ( o) => o. is_set_high ( ) == Ok ( true ) ,
313
311
}
314
312
}
315
313
}
You can’t perform that action at this time.
0 commit comments