diff --git a/examples/rp/src/bin/usb_serial.rs b/examples/rp/src/bin/usb_serial.rs index 26be705db844c7602c12032b1db0b35213363b1d..f6652dd637a401c7ef23f8fe2a75619851eae028 100644 --- a/examples/rp/src/bin/usb_serial.rs +++ b/examples/rp/src/bin/usb_serial.rs @@ -112,34 +112,37 @@ async fn run<'d, P: Pin>(pin: &mut Flex<'d, P>, syst: &mut SYST) -> Result<(), D loop { const LOOP: usize = 20; + const T: u32 = 10000; let mut dels = [0u32; LOOP]; let mut ups = [0u32; LOOP]; let mut downs = [0u32; LOOP]; critical_section::with(|_cs| { - let mut down = 0; - let mut up = 0; - let mut last_up = 0; - let mut last_down = 0; + let mut up = 0u32; + let mut up_x = 0u32; + let mut down = 0u32; + let mut down_x = 0u32; for i in 0..LOOP { - cortex_m::asm::delay(3*last_up); + cortex_m::asm::delay(down_x); pin.set_pull(Pull::Up); syst.clear_current(); let t1 = SYST::get_current(); while pin.is_low() {} let t2 = SYST::get_current(); - let up = t1 - t2; - last_up = up; + up = t1 - t2; + up_x = up_x + T - down; + up_x = up_x.min(T * 4); - cortex_m::asm::delay(3*last_down); + cortex_m::asm::delay(up_x); pin.set_pull(Pull::Down); syst.clear_current(); let t1 = SYST::get_current(); while pin.is_high() {} let t2 = SYST::get_current(); - let down = t1 - t2; - last_down = down; + down = t1 - t2; + down_x = down_x + T - up; + down_x = down_x.min(T * 4); ups[i] = up; downs[i] = down;