Skip to content

Commit d22bc98

Browse files
Increase reset time for the prerendered variant
Also moves `flush` into the send function, otherwise the buffer will get to big. We also save 20-40 bytes of RAM. Yay!
1 parent 10ab8eb commit d22bc98

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

src/prerendered.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ where
7171
/// You may need to look at the datasheet and your own hal to verify this.
7272
///
7373
/// You need to provide a buffer `data`, whoose length is at least 12 * the
74-
/// length of the led strip + 20 byes (or 40, if using the `mosi_idle_high` feature)
74+
/// length of the led strip
7575
///
7676
/// Please ensure that the mcu is pretty fast, otherwise weird timing
7777
/// issues will occur
@@ -105,21 +105,25 @@ where
105105
}
106106
}
107107

108-
fn flush(&mut self) {
109-
for _ in 0..20 {
110-
self.data[self.index] = 0;
111-
self.index += 1;
112-
}
113-
}
114108
fn send_data(&mut self) -> Result<(), E> {
115109
// We introduce an offset in the fifo here, so there's always one byte in transit
116110
// Some MCUs (like the stm32f1) only a one byte fifo, which would result
117111
// in overrun error if two bytes need to be stored
118112
block!(self.spi.send(0))?;
113+
if cfg!(feature = "mosi_idle_high") {
114+
for _ in 0..140 {
115+
block!(self.spi.send(0))?;
116+
block!(self.spi.read())?;
117+
}
118+
}
119119
for b in self.data[..self.index].iter() {
120120
block!(self.spi.send(*b))?;
121121
block!(self.spi.read())?;
122122
}
123+
for _ in 0..140 {
124+
block!(self.spi.send(0))?;
125+
block!(self.spi.read())?;
126+
}
123127
// Now, resolve the offset we introduced at the beginning
124128
block!(self.spi.read())?;
125129
Ok(())
@@ -139,17 +143,13 @@ where
139143
I: Into<Self::Color>,
140144
{
141145
self.index = 0;
142-
if cfg!(feature = "mosi_idle_high") {
143-
self.flush();
144-
}
145146

146147
for item in iterator {
147148
let item = item.into();
148149
self.write_byte(item.g);
149150
self.write_byte(item.r);
150151
self.write_byte(item.b);
151152
}
152-
self.flush();
153153
self.send_data()
154154
}
155155
}
@@ -167,9 +167,6 @@ where
167167
I: Into<Self::Color>,
168168
{
169169
self.index = 0;
170-
if cfg!(feature = "mosi_idle_high") {
171-
self.flush();
172-
}
173170

174171
for item in iterator {
175172
let item = item.into();
@@ -178,7 +175,6 @@ where
178175
self.write_byte(item.b);
179176
self.write_byte(item.a.0);
180177
}
181-
self.flush();
182178
self.send_data()
183179
}
184180
}

0 commit comments

Comments
 (0)