From 3cb7fc1a5795c5e5fa49adb18d05ac1092e9c07f Mon Sep 17 00:00:00 2001 From: Tangent Wantwight Date: Mon, 5 Jul 2021 01:22:59 -0400 Subject: [PATCH] Fix timings for solid output --- itsybitsy_m0_lights/src/lib.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/itsybitsy_m0_lights/src/lib.rs b/itsybitsy_m0_lights/src/lib.rs index e8ffef8..66b3b6c 100644 --- a/itsybitsy_m0_lights/src/lib.rs +++ b/itsybitsy_m0_lights/src/lib.rs @@ -39,19 +39,13 @@ pub fn boot() -> NeopixelLights< } } -// WS2815 lighting times +// WS2815 ideal lighting times // approx. 20ns per clock cycle; // const ZERO_HIGH_CYCLES: u32 = 11; // about 220ns // const ONE_HIGH_CYCLES: u32 = 29; // about 580ns // const ZERO_LOW_CYCLES: u32 = 29; // about 580ns // const ONE_LOW_CYCLES: u32 = 11; // about 220ns -// experimentally, there is some unknown overhead -// but these timings appear to work for me: -const ZERO_HIGH_CYCLES: u32 = 2; -const ONE_HIGH_CYCLES: u32 = 9; -const ZERO_LOW_CYCLES: u32 = 10; -const ONE_LOW_CYCLES: u32 = 10; const LATCH_CYCLES: u32 = 15000; // about 300us pub struct NeopixelLights { @@ -72,11 +66,13 @@ where // go high self.high_out.set_high().unwrap(); + // experimentally, there is some unknown overhead + // but these timings appear to work for me unsafe { compiler_fence(Ordering::SeqCst); asm!( - // ? nops - "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", + // 8 nops + "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", ); compiler_fence(Ordering::SeqCst); } @@ -85,7 +81,7 @@ where unsafe { compiler_fence(Ordering::SeqCst); asm!( - // 7 nops + // 14 nops "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", ); @@ -99,7 +95,7 @@ where unsafe { compiler_fence(Ordering::SeqCst); asm!( - // 2 nops + // 15 nops "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", );