16
16
#include "ws2812.pio.h"
17
17
18
18
#define FRAC_BITS 4
19
- #define PIN_TX 0
19
+ #define NUM_PIXELS 64
20
+ #define WS2812_PIN_BASE 2
20
21
21
22
// horrible temporary hack to avoid changing pattern code
22
23
static uint8_t * current_string_out ;
@@ -174,17 +175,15 @@ void dither_values(const value_bits_t *colors, value_bits_t *state, const value_
174
175
}
175
176
}
176
177
177
- #define MAX_LENGTH 100
178
-
179
- // requested colors * 4 to allow for WRGB
180
- static value_bits_t colors [MAX_LENGTH * 4 ];
178
+ // requested colors * 4 to allow for RGBW
179
+ static value_bits_t colors [NUM_PIXELS * 4 ];
181
180
// double buffer the state of the string, since we update next version in parallel with DMAing out old version
182
- static value_bits_t states [2 ][MAX_LENGTH * 4 ];
181
+ static value_bits_t states [2 ][NUM_PIXELS * 4 ];
183
182
184
183
// example - string 0 is RGB only
185
- static uint8_t string0_data [MAX_LENGTH * 3 ];
186
- // example - string 1 is WRGB
187
- static uint8_t string1_data [MAX_LENGTH * 4 ];
184
+ static uint8_t string0_data [NUM_PIXELS * 3 ];
185
+ // example - string 1 is RGBW
186
+ static uint8_t string1_data [NUM_PIXELS * 4 ];
188
187
189
188
string_t string0 = {
190
189
.data = string0_data ,
@@ -213,7 +212,7 @@ string_t *strings[] = {
213
212
#define DMA_CHANNELS_MASK (DMA_CHANNEL_MASK | DMA_CB_CHANNEL_MASK)
214
213
215
214
// start of each value fragment (+1 for NULL terminator)
216
- static uintptr_t fragment_start [MAX_LENGTH * 4 + 1 ];
215
+ static uintptr_t fragment_start [NUM_PIXELS * 4 + 1 ];
217
216
218
217
// posted when it is safe to output a new set of values
219
218
static struct semaphore reset_delay_complete_sem ;
@@ -286,7 +285,7 @@ int main() {
286
285
int sm = 0 ;
287
286
uint offset = pio_add_program (pio , & ws2812_parallel_program );
288
287
289
- ws2812_parallel_program_init (pio , sm , offset , PIN_TX , count_of (strings ), 800000 );
288
+ ws2812_parallel_program_init (pio , sm , offset , WS2812_PIN_BASE , count_of (strings ), 800000 );
290
289
291
290
sem_init (& reset_delay_complete_sem , 1 , 1 ); // initially posted so we don't block first time
292
291
dma_init (pio , sm );
@@ -300,19 +299,17 @@ int main() {
300
299
int brightness = 0 ;
301
300
uint current = 0 ;
302
301
for (int i = 0 ; i < 1000 ; ++ i ) {
303
- int n = 64 ;
304
-
305
302
current_string_out = string0 .data ;
306
303
current_string_4color = false;
307
- pattern_table [pat ].pat (n , t );
304
+ pattern_table [pat ].pat (NUM_PIXELS , t );
308
305
current_string_out = string1 .data ;
309
306
current_string_4color = true;
310
- pattern_table [pat ].pat (n , t );
307
+ pattern_table [pat ].pat (NUM_PIXELS , t );
311
308
312
- transform_strings (strings , count_of (strings ), colors , n * 4 , brightness );
313
- dither_values (colors , states [current ], states [current ^ 1 ], n * 4 );
309
+ transform_strings (strings , count_of (strings ), colors , NUM_PIXELS * 4 , brightness );
310
+ dither_values (colors , states [current ], states [current ^ 1 ], NUM_PIXELS * 4 );
314
311
sem_acquire_blocking (& reset_delay_complete_sem );
315
- output_strings_dma (states [current ], n * 4 );
312
+ output_strings_dma (states [current ], NUM_PIXELS * 4 );
316
313
317
314
current ^= 1 ;
318
315
t += dir ;
0 commit comments