71
71
/// You may need to look at the datasheet and your own hal to verify this.
72
72
///
73
73
/// 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
75
75
///
76
76
/// Please ensure that the mcu is pretty fast, otherwise weird timing
77
77
/// issues will occur
@@ -105,21 +105,25 @@ where
105
105
}
106
106
}
107
107
108
- fn flush ( & mut self ) {
109
- for _ in 0 ..20 {
110
- self . data [ self . index ] = 0 ;
111
- self . index += 1 ;
112
- }
113
- }
114
108
fn send_data ( & mut self ) -> Result < ( ) , E > {
115
109
// We introduce an offset in the fifo here, so there's always one byte in transit
116
110
// Some MCUs (like the stm32f1) only a one byte fifo, which would result
117
111
// in overrun error if two bytes need to be stored
118
112
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
+ }
119
119
for b in self . data [ ..self . index ] . iter ( ) {
120
120
block ! ( self . spi. send( * b) ) ?;
121
121
block ! ( self . spi. read( ) ) ?;
122
122
}
123
+ for _ in 0 ..140 {
124
+ block ! ( self . spi. send( 0 ) ) ?;
125
+ block ! ( self . spi. read( ) ) ?;
126
+ }
123
127
// Now, resolve the offset we introduced at the beginning
124
128
block ! ( self . spi. read( ) ) ?;
125
129
Ok ( ( ) )
@@ -139,17 +143,13 @@ where
139
143
I : Into < Self :: Color > ,
140
144
{
141
145
self . index = 0 ;
142
- if cfg ! ( feature = "mosi_idle_high" ) {
143
- self . flush ( ) ;
144
- }
145
146
146
147
for item in iterator {
147
148
let item = item. into ( ) ;
148
149
self . write_byte ( item. g ) ;
149
150
self . write_byte ( item. r ) ;
150
151
self . write_byte ( item. b ) ;
151
152
}
152
- self . flush ( ) ;
153
153
self . send_data ( )
154
154
}
155
155
}
@@ -167,9 +167,6 @@ where
167
167
I : Into < Self :: Color > ,
168
168
{
169
169
self . index = 0 ;
170
- if cfg ! ( feature = "mosi_idle_high" ) {
171
- self . flush ( ) ;
172
- }
173
170
174
171
for item in iterator {
175
172
let item = item. into ( ) ;
@@ -178,7 +175,6 @@ where
178
175
self . write_byte ( item. b ) ;
179
176
self . write_byte ( item. a . 0 ) ;
180
177
}
181
- self . flush ( ) ;
182
178
self . send_data ( )
183
179
}
184
180
}
0 commit comments