@@ -11,6 +11,8 @@ use core::marker::PhantomData;
11
11
12
12
use smart_leds_trait:: { SmartLedsWrite , RGB8 , RGBW } ;
13
13
14
+ const FLUSH_DATA_LEN : usize = 140 ;
15
+
14
16
/// SPI mode that can be used for this crate
15
17
///
16
18
/// Provided for convenience
@@ -114,18 +116,28 @@ where
114
116
}
115
117
116
118
/// Add a reset sequence (140 zeroes) to the data buffer
119
+ #[ cfg( feature = "reset_single_transaction" ) ]
117
120
fn flush ( & mut self ) -> Result < ( ) , Error < E > > {
118
- const FLUSH_DATA_LEN : usize = 140 ;
119
- const FLUSH_DATA : & [ u8 ] = & [ 0x00 ; FLUSH_DATA_LEN ] ;
121
+ let flush_data = [ ( ) ; FLUSH_DATA_LEN ] . map ( |_| 0 ) ;
120
122
121
123
if self . index + FLUSH_DATA_LEN > self . data . len ( ) {
122
124
return Err ( Error :: OutOfBounds ) ;
123
125
}
124
- self . data [ self . index ..( self . index + FLUSH_DATA_LEN ) ] . copy_from_slice ( FLUSH_DATA ) ;
126
+ self . data [ self . index ..( self . index + FLUSH_DATA_LEN ) ] . copy_from_slice ( & flush_data ) ;
125
127
self . index += FLUSH_DATA_LEN ;
126
128
Ok ( ( ) )
127
129
}
128
130
131
+ /// Send a reset sequence (140 zeroes) on the bus
132
+ #[ cfg( not( feature = "reset_single_transaction" ) ) ]
133
+ fn flush ( & mut self ) -> Result < ( ) , Error < E > > {
134
+ for _ in 0 ..FLUSH_DATA_LEN {
135
+ self . spi . write ( & [ 0 ] ) . map_err ( Error :: Spi ) ?;
136
+ }
137
+
138
+ Ok ( ( ) )
139
+ }
140
+
129
141
fn send_data ( & mut self ) -> Result < ( ) , E > {
130
142
self . spi . write ( & self . data [ ..self . index ] )
131
143
}
@@ -157,7 +169,7 @@ where
157
169
}
158
170
159
171
self . flush ( ) ?;
160
- self . send_data ( ) . map_err ( |e| Error :: Spi ( e ) )
172
+ self . send_data ( ) . map_err ( Error :: Spi )
161
173
}
162
174
}
163
175
@@ -188,6 +200,6 @@ where
188
200
}
189
201
190
202
self . flush ( ) ?;
191
- self . send_data ( ) . map_err ( |e| Error :: Spi ( e ) )
203
+ self . send_data ( ) . map_err ( Error :: Spi )
192
204
}
193
205
}
0 commit comments