@@ -103,7 +103,7 @@ struct ColorGrb
103103 uint8_t B;
104104 uint8_t R;
105105 uint8_t G;
106-
106+
107107
108108 ColorGrb (uint8_t gray) :
109109 R (gray), G(gray), B(gray)
@@ -116,7 +116,7 @@ struct ColorGrb
116116};
117117
118118struct ColorGrbw
119- {
119+ {
120120 uint8_t W;
121121 uint8_t B;
122122 uint8_t R;
@@ -134,13 +134,13 @@ struct ColorGrbw
134134 static bool isAlignedTo24 ()
135135 {
136136 return false ;
137- };
137+ };
138138};
139139
140140struct ColorDotstartBgr
141- {
141+ {
142142 uint8_t brightness;
143- uint8_t B;
143+ uint8_t B;
144144 uint8_t G;
145145 uint8_t R;
146146
@@ -155,16 +155,16 @@ struct ColorDotstartBgr
155155};
156156
157157class LedDriver
158- {
158+ {
159159 protected:
160160
161161 int ledsNumber;
162162 int pin;
163163 int clockPin;
164164 int dmaSize;
165165 uint8_t * buffer;
166- uint8_t * dma;
167-
166+ uint8_t * dma;
167+
168168 public:
169169
170170 LedDriver (int _ledsNumber, int _pin, int _dmaSize): LedDriver(_ledsNumber, _pin, 0 , _dmaSize)
@@ -191,7 +191,7 @@ class LedDriver
191191 free (dma);
192192 if (LedDriverDmaReceiver == this )
193193 LedDriverDmaReceiver = nullptr ;
194- }
194+ }
195195
196196 static LedDriver* LedDriverDmaReceiver;
197197};
@@ -213,21 +213,21 @@ class DmaClient
213213 DmaClient ()
214214 {
215215 PICO_DMA_CHANNEL = dma_claim_unused_channel (true );
216- isDmaBusy = false ;
216+ isDmaBusy = false ;
217217 lastRenderTime = 0 ;
218218 };
219219
220220 ~DmaClient ()
221221 {
222222 for (int i = 0 ; i < 10 && isDmaBusy; i++)
223- busy_wait_us (500 );
223+ busy_wait_us (500 );
224224
225225 dma_channel_abort (PICO_DMA_CHANNEL);
226226 dma_channel_set_irq0_enabled (PICO_DMA_CHANNEL, false );
227227 irq_set_enabled (DMA_IRQ_0, false );
228228
229229 dma_channel_unclaim (PICO_DMA_CHANNEL);
230- };
230+ };
231231
232232 void dmaConfigure (PIO _selectedPIO, uint _sm)
233233 {
@@ -270,9 +270,9 @@ class DmaClient
270270 int wait = 200 ;
271271 while (isDmaBusy && wait-- > 0 )
272272 busy_wait_us (50 );
273-
273+
274274 return !isDmaBusy;
275- }
275+ }
276276
277277 bool isReady ()
278278 {
@@ -284,15 +284,15 @@ class DmaClient
284284 if (dma_hw->ints0 & (1u <<DmaClient::PICO_DMA_CHANNEL))
285285 {
286286 dma_hw->ints0 = (1u <<DmaClient::PICO_DMA_CHANNEL);
287-
287+
288288 lastRenderTime = time_us_64 ();
289289 isDmaBusy = false ;
290290 }
291291 }
292292};
293293
294294class Neopixel : public LedDriver , public DmaClient
295- {
295+ {
296296
297297 uint64_t resetTime;
298298
@@ -329,12 +329,12 @@ class Neopixel : public LedDriver, public DmaClient
329329 pio_sm_set_consecutive_pindirs (selectedPIO, stateIndex, _pin, std::max (lanes, 1 ), true );
330330 sm_config_set_out_shift (&smConfig, false , true , (alignTo24) ? 24 : 32 );
331331 sm_config_set_fifo_join (&smConfig, PIO_FIFO_JOIN_TX);
332- float div = clock_get_hz (clk_sys) / (800000 * 12 );
332+ float div = clock_get_hz (clk_sys) / (800000 * 12 );
333333 sm_config_set_clkdiv (&smConfig, div);
334334 pio_sm_init (selectedPIO, stateIndex, programAddress, &smConfig);
335335 pio_sm_set_enabled (selectedPIO, stateIndex, true );
336336
337- initDmaPio (dmaSize / 4 );
337+ initDmaPio (dmaSize / 4 );
338338 }
339339
340340 uint8_t * getBufferMemory ()
@@ -355,29 +355,29 @@ class Neopixel : public LedDriver, public DmaClient
355355 if (currentTime < resetTime + lastRenderTime)
356356 busy_wait_us (std::min (resetTime + lastRenderTime - currentTime, resetTime));
357357
358- memcpy (dma, buffer, dmaSize);
358+ memcpy (dma, buffer, dmaSize);
359359
360360 dma_channel_set_read_addr (PICO_DMA_CHANNEL, dma, true );
361361
362362 if (resetBuffer)
363363 memset (buffer, 0 , dmaSize);
364- }
364+ }
365365};
366366
367367template <int RESET_TIME, typename colorData>
368368class NeopixelType : public Neopixel
369- {
369+ {
370370 public:
371371
372372 NeopixelType (int _ledsNumber, int _pin) : Neopixel(0 , RESET_TIME, _ledsNumber, _pin, _ledsNumber * sizeof (colorData), colorData::isAlignedTo24())
373373 {
374374 }
375-
375+
376376 void SetPixel (int index, colorData color)
377377 {
378378 if (index >= ledsNumber)
379379 return ;
380-
380+
381381 *(reinterpret_cast <colorData*>(buffer)+index) = color;
382382 }
383383
@@ -395,7 +395,7 @@ class NeopixelParallel
395395
396396 protected:
397397 static int maxLeds;
398- const uint8_t myLaneMask;
398+ const uint8_t myLaneMask;
399399 static uint8_t * buffer;
400400
401401 public:
@@ -432,26 +432,26 @@ class NeopixelParallel
432432 bool isReady ()
433433 {
434434 return muxer->isReady ();
435- }
435+ }
436436
437437 void renderAllLanes ()
438438 {
439439 muxer->renderDma (true );
440- }
440+ }
441441};
442442
443443template <int RESET_TIME, typename colorData>
444444class NeopixelParallelType : public NeopixelParallel
445445{
446446 uint32_t lut[16 ];
447447
448- public:
448+ public:
449449
450450 NeopixelParallelType (int _ledsNumber, int _basePinForLanes) : NeopixelParallel(sizeof (colorData), RESET_TIME,
451451 _ledsNumber, _basePinForLanes)
452452 {
453453 for (uint8_t a = 0 ; a < 16 ; a++)
454- {
454+ {
455455 uint8_t * target = reinterpret_cast <uint8_t *>(&(lut[a]));
456456 for (uint8_t b = 0 ; b < 4 ; b++)
457457 *(target++) = (uint8_t ) ((a & (0b00000001 << b)) ? myLaneMask : 0 );
@@ -462,16 +462,16 @@ class NeopixelParallelType : public NeopixelParallel
462462 {
463463 if (index >= maxLeds)
464464 return ;
465-
465+
466466 uint8_t * source = reinterpret_cast <uint8_t *>(&color);
467467 uint32_t * target = reinterpret_cast <uint32_t *>(&(buffer[(index + 1 ) * 8 * sizeof (colorData)]));
468468
469469 for (int i = 0 ; i < sizeof (colorData); i++)
470- {
471- *(--target) |= lut[ *(source) & 0b00001111 ];
470+ {
471+ *(--target) |= lut[ *(source) & 0b00001111 ];
472472 *(--target) |= lut[ *(source++) >> 4 ];
473473 }
474- }
474+ }
475475};
476476
477477class Dotstar : public LedDriver , public DmaClient
@@ -485,7 +485,7 @@ class Dotstar : public LedDriver, public DmaClient
485485 LedDriver (_ledsNumber, _datapin, _clockpin, _dmaSize)
486486 {
487487 dmaConfigure (pio0, 0 );
488- resetTime = _resetTime;
488+ resetTime = _resetTime;
489489
490490 spi_init (spi_default, 10000000 );
491491 gpio_set_function (PICO_DEFAULT_SPI_RX_PIN, GPIO_FUNC_SPI);
@@ -496,7 +496,7 @@ class Dotstar : public LedDriver, public DmaClient
496496 bi_decl (bi_1pin_with_name (PICO_DEFAULT_SPI_CSN_PIN, " SPI CS" ));
497497
498498 initDmaSpi (_dmaSize);
499- }
499+ }
500500
501501 uint8_t * getBufferMemory ()
502502 {
@@ -544,7 +544,7 @@ class DotstarType : public Dotstar
544544 memset (buffer,0 ,4 );
545545 *(reinterpret_cast <colorData*>(buffer)+ledsNumber+1 ) = colorData (0xff );
546546 renderDma ();
547- }
547+ }
548548};
549549
550550Neopixel* NeopixelParallel::muxer = nullptr ;
@@ -562,4 +562,3 @@ typedef NeopixelType<450, ColorGrbw> sk6812;
562562typedef NeopixelParallelType<300 , ColorGrb> ws2812p;
563563typedef NeopixelParallelType<80 , ColorGrbw> sk6812p;
564564typedef DotstarType<100 , ColorDotstartBgr> apa102;
565-
0 commit comments