Skip to content
Snippets Groups Projects
Commit 0f3d95f2 authored by Matt Johnston's avatar Matt Johnston
Browse files

jagged

up_x = if down < T {
    up_x * 2
} else {
    up_x.saturating_sub(down/2)
}.max(1);
parent 2d965c45
Branches
No related merge requests found
...@@ -110,18 +110,21 @@ async fn run<'d, P: Pin>(pin: &mut Flex<'d, P>, syst: &mut SYST) -> Result<(), D ...@@ -110,18 +110,21 @@ async fn run<'d, P: Pin>(pin: &mut Flex<'d, P>, syst: &mut SYST) -> Result<(), D
while pin.is_high() {} while pin.is_high() {}
}); });
let mut up_x = 0u32;
let mut down_x = 0u32;
let mut up = 0u32;
let mut down = 0u32;
loop { loop {
const LOOP: usize = 20; const LOOP: usize = 20;
const T: u32 = 10000; const T: u32 = 8192;
let mut dels = [0u32; LOOP]; let mut dels = [0u32; LOOP];
let mut ups = [0u32; LOOP]; let mut ups = [0u32; LOOP];
let mut downs = [0u32; LOOP]; let mut downs = [0u32; LOOP];
critical_section::with(|_cs| { let mut upx = [0u32; LOOP];
let mut downx = [0u32; LOOP];
let mut up = 0u32; critical_section::with(|_cs| {
let mut up_x = 0u32;
let mut down = 0u32;
let mut down_x = 0u32;
for i in 0..LOOP { for i in 0..LOOP {
cortex_m::asm::delay(down_x); cortex_m::asm::delay(down_x);
...@@ -131,8 +134,12 @@ async fn run<'d, P: Pin>(pin: &mut Flex<'d, P>, syst: &mut SYST) -> Result<(), D ...@@ -131,8 +134,12 @@ async fn run<'d, P: Pin>(pin: &mut Flex<'d, P>, syst: &mut SYST) -> Result<(), D
while pin.is_low() {} while pin.is_low() {}
let t2 = SYST::get_current(); let t2 = SYST::get_current();
up = t1 - t2; up = t1 - t2;
up_x = up_x + T - down;
up_x = up_x.min(T * 4); up_x = if down < T {
up_x * 2
} else {
up_x.saturating_sub(down/2)
}.max(1);
cortex_m::asm::delay(up_x); cortex_m::asm::delay(up_x);
pin.set_pull(Pull::Down); pin.set_pull(Pull::Down);
...@@ -141,18 +148,24 @@ async fn run<'d, P: Pin>(pin: &mut Flex<'d, P>, syst: &mut SYST) -> Result<(), D ...@@ -141,18 +148,24 @@ async fn run<'d, P: Pin>(pin: &mut Flex<'d, P>, syst: &mut SYST) -> Result<(), D
while pin.is_high() {} while pin.is_high() {}
let t2 = SYST::get_current(); let t2 = SYST::get_current();
down = t1 - t2; down = t1 - t2;
down_x = down_x + T - up;
down_x = down_x.min(T * 4); down_x = if up < T {
down_x * 2
} else {
down_x.saturating_sub(up/2)
}.max(1);
ups[i] = up; ups[i] = up;
upx[i] = up_x;
downs[i] = down; downs[i] = down;
downx[i] = down_x;
dels[i] = up + down; dels[i] = up + down;
} }
pin.set_pull(Pull::None); pin.set_pull(Pull::None);
}); });
for i in 0..LOOP { for i in 0..LOOP {
info!("{} U {} D {}", dels[i], ups[i], downs[i]); info!("{} U {} x {} D {} x {}", dels[i], ups[i], upx[i], downs[i], downx[i]);
} }
info!("==="); info!("===");
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment