Skip to content

Commit 68d98bf

Browse files
Unify flush vs. reset to reset, as used in the ws2812 data sheet
1 parent 99f7ee8 commit 68d98bf

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ where
104104
Ok(())
105105
}
106106

107-
fn flush(&mut self) -> Result<(), E> {
107+
fn reset(&mut self) -> Result<(), E> {
108108
// Should be > 300μs, so for an SPI Freq. of 3.8MHz, we have to send at least 1140 low bits or 140 low bytes
109109
for _ in 0..140 {
110110
self.spi.write(from_ref(&0))?;
@@ -126,7 +126,7 @@ where
126126
I: Into<Self::Color>,
127127
{
128128
if cfg!(feature = "mosi_idle_high") {
129-
self.flush()?;
129+
self.reset()?;
130130
}
131131

132132
for item in iterator {
@@ -135,7 +135,7 @@ where
135135
self.write_byte(item.r)?;
136136
self.write_byte(item.b)?;
137137
}
138-
self.flush()?;
138+
self.reset()?;
139139
Ok(())
140140
}
141141
}
@@ -153,7 +153,7 @@ where
153153
I: Into<Self::Color>,
154154
{
155155
if cfg!(feature = "mosi_idle_high") {
156-
self.flush()?;
156+
self.reset()?;
157157
}
158158

159159
for item in iterator {
@@ -163,7 +163,7 @@ where
163163
self.write_byte(item.b)?;
164164
self.write_byte(item.a.0)?;
165165
}
166-
self.flush()?;
166+
self.reset()?;
167167
Ok(())
168168
}
169169
}

src/prerendered.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use core::marker::PhantomData;
1111

1212
use smart_leds_trait::{SmartLedsWrite, RGB8, RGBW};
1313

14-
const FLUSH_DATA_LEN: usize = 140;
14+
const RESET_DATA_LEN: usize = 140;
1515

1616
/// SPI mode that can be used for this crate
1717
///
@@ -124,10 +124,10 @@ where
124124
/// Add a reset sequence (140 zeroes) to the data buffer
125125
// Is always used for `mosi_idle_high`, as otherwise the time required to fill the buffer can lead to idle cycles on the SPI bus
126126
fn write_reset(&mut self) -> Result<(), Error<E>> {
127-
if self.index + FLUSH_DATA_LEN > self.data.len() {
127+
if self.index + RESET_DATA_LEN > self.data.len() {
128128
return Err(Error::OutOfBounds);
129129
}
130-
for _ in 0..FLUSH_DATA_LEN {
130+
for _ in 0..RESET_DATA_LEN {
131131
self.data[self.index] = 0;
132132
self.index += 1;
133133
}
@@ -136,7 +136,7 @@ where
136136

137137
/// Send a reset sequence (140 zeroes) on the bus
138138
fn send_reset(&mut self) -> Result<(), Error<E>> {
139-
for _ in 0..FLUSH_DATA_LEN {
139+
for _ in 0..RESET_DATA_LEN {
140140
self.spi.write(&[0]).map_err(Error::Spi)?;
141141
}
142142

0 commit comments

Comments
 (0)