Skip to content

Commit 41fc4a2

Browse files
Move the timing critical stuff together
1 parent d8fc82b commit 41fc4a2

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,21 @@ where
2727
/// Write a single color for ws2812 devices
2828
fn write_color(&mut self, data: Color) {
2929
let mut serial_bits = (data.g as u32) << 16 | (data.r as u32) << 8 | (data.b as u32) << 0;
30-
// Wait until a timer period has gone by, so we have clean timing
31-
block!(self.timer.wait()).ok();
3230
for _ in 0..24 {
33-
self.pin.set_high();
34-
block!(self.timer.wait()).ok();
3531
if (serial_bits & 0x00800000) != 0 {
32+
block!(self.timer.wait()).ok();
3633
self.pin.set_high();
34+
block!(self.timer.wait()).ok();
35+
block!(self.timer.wait()).ok();
36+
self.pin.set_low();
3737
} else {
38+
block!(self.timer.wait()).ok();
39+
self.pin.set_high();
40+
block!(self.timer.wait()).ok();
3841
self.pin.set_low();
42+
block!(self.timer.wait()).ok();
3943
}
40-
block!(self.timer.wait()).ok();
41-
self.pin.set_low();
4244
serial_bits <<= 1;
43-
block!(self.timer.wait()).ok();
4445
}
4546
}
4647
}

0 commit comments

Comments
 (0)