attempt to deglitch lights. dubious.

This commit is contained in:
Tangent Wantwight 2024-10-02 21:10:58 -04:00
parent e745c55b51
commit ca70b50e49

View file

@ -63,43 +63,85 @@ where
{ {
#[inline] #[inline]
pub fn write(&mut self, bit: bool) { pub fn write(&mut self, bit: bool) {
// 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!(
// 8 nops
"nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;",
);
compiler_fence(Ordering::SeqCst);
}
if bit { if bit {
unsafe { unsafe {
compiler_fence(Ordering::SeqCst);
self.high_out.set_high().unwrap();
compiler_fence(Ordering::SeqCst); compiler_fence(Ordering::SeqCst);
asm!( asm!(
// 14 nops // 15 nops
"nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;",
"nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;",
);
compiler_fence(Ordering::SeqCst);
self.high_out.set_low().unwrap();
compiler_fence(Ordering::SeqCst);
asm!(
// 8 nops
"nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;",
);
compiler_fence(Ordering::SeqCst);
}
} else {
unsafe {
compiler_fence(Ordering::SeqCst);
self.high_out.set_high().unwrap();
compiler_fence(Ordering::SeqCst);
asm!(
// 8 nops
"nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;",
);
compiler_fence(Ordering::SeqCst);
self.high_out.set_low().unwrap();
compiler_fence(Ordering::SeqCst);
asm!(
// 15 nops
"nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;",
"nop;", "nop;", "nop;", "nop;", "nop;",
); );
compiler_fence(Ordering::SeqCst); compiler_fence(Ordering::SeqCst);
} }
} }
// go low if false {
self.high_out.set_low().unwrap(); // go high
self.high_out.set_high().unwrap();
unsafe { // experimentally, there is some unknown overhead
compiler_fence(Ordering::SeqCst); // but these timings appear to work for me
asm!( unsafe {
// 15 nops compiler_fence(Ordering::SeqCst);
"nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", asm!(
"nop;", "nop;", "nop;", "nop;", "nop;", // 8 nops
); "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;",
compiler_fence(Ordering::SeqCst); );
compiler_fence(Ordering::SeqCst);
}
if bit {
unsafe {
compiler_fence(Ordering::SeqCst);
asm!(
// 14 nops
"nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;",
"nop;", "nop;", "nop;", "nop;", "nop;",
);
compiler_fence(Ordering::SeqCst);
}
}
// go low
self.high_out.set_low().unwrap();
unsafe {
compiler_fence(Ordering::SeqCst);
asm!(
// 15 nops
"nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;", "nop;",
"nop;", "nop;", "nop;", "nop;", "nop;",
);
compiler_fence(Ordering::SeqCst);
}
} }
} }