Skip to content

Commit 6a33cbf

Browse files
authored
Initial support for Ws2813 (Makuna#170)
1 parent 073c89d commit 6a33cbf

File tree

6 files changed

+148
-11
lines changed

6 files changed

+148
-11
lines changed

keywords.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,25 @@ NeoBrgFeature KEYWORD1
2020
NeoRbgFeature KEYWORD1
2121
DotStarBgrFeature KEYWORD1
2222
DotStarLbgrFeature KEYWORD1
23+
NeoWs2813Method KEYWORD1
2324
Neo800KbpsMethod KEYWORD1
2425
Neo400KbpsMethod KEYWORD1
26+
NeoAvrWs2813Method KEYWORD1
2527
NeoAvr800KbpsMethod KEYWORD1
2628
NeoAvr400KbpsMethod KEYWORD1
29+
NeoEsp8266DmaWs2813Method KEYWORD1
2730
NeoEsp8266Dma800KbpsMethod KEYWORD1
2831
NeoEsp8266Dma400KbpsMethod KEYWORD1
32+
NeoEsp8266UartWs2813Method KEYWORD1
2933
NeoEsp8266Uart800KbpsMethod KEYWORD1
3034
NeoEsp8266Uart400KbpsMethod KEYWORD1
35+
NeoEsp8266AsyncUartWs2813Method KEYWORD1
3136
NeoEsp8266AsyncUart800KbpsMethod KEYWORD1
3237
NeoEsp8266AsyncUart400KbpsMethod KEYWORD1
38+
NeoEsp8266BitBangWs2813Method KEYWORD1
3339
NeoEsp8266BitBang800KbpsMethod KEYWORD1
3440
NeoEsp8266BitBang400KbpsMethod KEYWORD1
41+
NeoEsp32BitBangWs2813Method KEYWORD1
3542
NeoEsp32BitBang800KbpsMethod KEYWORD1
3643
NeoEsp32BitBang400KbpsMethod KEYWORD1
3744
DotStarMethod KEYWORD1

src/internal/NeoArmMethod.h

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ template<typename T_SPEED> class NeoArmMethodBase
5656
{
5757
uint32_t delta = micros() - _endTime;
5858

59-
return (delta >= 50L);
59+
return (delta >= T_SPEED::ResetTimeUs);
6060
}
6161

6262
void Initialize()
@@ -109,12 +109,22 @@ template<typename T_SPEED> class NeoArmMethodBase
109109

110110
#if defined(__MK20DX128__) || defined(__MK20DX256__) // Teensy 3.0 & 3.1
111111

112+
class NeoArmMk20dxSpeedPropsWs2813
113+
{
114+
public:
115+
static const uint32_t CyclesT0h = (F_CPU / 4000000);
116+
static const uint32_t CyclesT1h = (F_CPU / 1250000);
117+
static const uint32_t Cycles = (F_CPU / 800000);
118+
static const uint32_t ResetTimeUs = 250;
119+
};
120+
112121
class NeoArmMk20dxSpeedProps800Kbps
113122
{
114123
public:
115124
static const uint32_t CyclesT0h = (F_CPU / 4000000);
116125
static const uint32_t CyclesT1h = (F_CPU / 1250000);
117126
static const uint32_t Cycles = (F_CPU / 800000);
127+
static const uint32_t ResetTimeUs = 50;
118128
};
119129

120130
class NeoArmMk20dxSpeedProps400Kbps
@@ -123,11 +133,14 @@ class NeoArmMk20dxSpeedProps400Kbps
123133
static const uint32_t CyclesT0h = (F_CPU / 2000000);
124134
static const uint32_t CyclesT1h = (F_CPU / 833333);
125135
static const uint32_t Cycles = (F_CPU / 400000);
136+
static const uint32_t ResetTimeUs = 50;
126137
};
127138

128139
template<typename T_SPEEDPROPS> class NeoArmMk20dxSpeedBase
129140
{
130141
public:
142+
static const uint32_t ResetTimeUs = T_SPEEDPROPS::ResetTimeUs;
143+
131144
static void send_pixels(uint8_t* pixels, size_t sizePixels, uint8_t pin)
132145
{
133146
uint8_t* p = pixels;
@@ -167,6 +180,7 @@ template<typename T_SPEEDPROPS> class NeoArmMk20dxSpeedBase
167180
}
168181
};
169182

183+
typedef NeoArmMethodBase<NeoArmMk20dxSpeedBase<NeoArmMk20dxSpeedPropsWs2813>> NeoArmWs2813Method;
170184
typedef NeoArmMethodBase<NeoArmMk20dxSpeedBase<NeoArmMk20dxSpeedProps800Kbps>> NeoArm800KbpsMethod;
171185
typedef NeoArmMethodBase<NeoArmMk20dxSpeedBase<NeoArmMk20dxSpeedProps400Kbps>> NeoArm400KbpsMethod;
172186

@@ -176,7 +190,7 @@ typedef NeoArmMethodBase<NeoArmMk20dxSpeedBase<NeoArmMk20dxSpeedProps400Kbps>> N
176190

177191

178192

179-
class NeoArmMk26z64Speed800Kbps
193+
class NeoArmMk26z64Speed800KbpsBase
180194
{
181195
public:
182196
static void send_pixels(uint8_t* pixels, size_t sizePixels, uint8_t pin)
@@ -266,6 +280,19 @@ class NeoArmMk26z64Speed800Kbps
266280
}
267281
};
268282

283+
class NeoArmMk26z64SpeedWs2813 : public NeoArmMk26z64Speed800KbpsBase
284+
{
285+
public:
286+
const static uint32_t ResetTimeUs = 250;
287+
};
288+
289+
class NeoArmMk26z64Speed800Kbps : public NeoArmMk26z64Speed800KbpsBase
290+
{
291+
public:
292+
const static uint32_t ResetTimeUs = 50;
293+
}
294+
295+
typedef NeoArmMethodBase<NeoArmMk26z64SpeedWs2813> NeoArmWs2813Method;
269296
typedef NeoArmMethodBase<NeoArmMk26z64Speed800Kbps> NeoArm800KbpsMethod;
270297

271298
#else
@@ -275,7 +302,7 @@ typedef NeoArmMethodBase<NeoArmMk26z64Speed800Kbps> NeoArm800KbpsMethod;
275302
#elif defined(__SAMD21G18A__) // Arduino Zero
276303

277304

278-
class NeoArmSamd21g18aSpeedProps800Kbps
305+
class NeoArmSamd21g18aSpeedProps800KbpsBase
279306
{
280307
public:
281308
static void BitPreWait()
@@ -300,6 +327,19 @@ class NeoArmSamd21g18aSpeedProps800Kbps
300327
}
301328
};
302329

330+
class NeoArmSamd21g18aSpeedPropsWs2813 : public NeoArmSamd21g18aSpeedProps800KbpsBase
331+
{
332+
public:
333+
static const uint32_t ResetTimeUs = 250;
334+
};
335+
336+
class NeoArmSamd21g18aSpeedProps800Kbps : public NeoArmSamd21g18aSpeedProps800KbpsBase
337+
{
338+
public:
339+
static const uint32_t ResetTimeUs = 50;
340+
};
341+
342+
303343
class NeoArmSamd21g18aSpeedProps400Kbps
304344
{
305345
public:
@@ -325,11 +365,14 @@ class NeoArmSamd21g18aSpeedProps400Kbps
325365
{
326366
asm("nop; nop; nop; nop; nop; nop; nop;");
327367
}
368+
static const uint32_t ResetTimeUs = 50;
328369
};
329370

330371
template<typename T_SPEEDPROPS> class NeoArmSamd21g18aSpeedBase
331372
{
332373
public:
374+
static const uint32_t ResetTimeUs = T_SPEEDPROPS::ResetTimeUs;
375+
333376
static void send_pixels(uint8_t* pixels, size_t sizePixels, uint8_t pin)
334377
{
335378
// Tried this with a timer/counter, couldn't quite get adequate
@@ -376,15 +419,15 @@ template<typename T_SPEEDPROPS> class NeoArmSamd21g18aSpeedBase
376419
}
377420
};
378421

422+
typedef NeoArmMethodBase<NeoArmSamd21g18aSpeedBase<NeoArmSamd21g18aSpeedPropsWs2813>> NeoArmWs2813Method;
379423
typedef NeoArmMethodBase<NeoArmSamd21g18aSpeedBase<NeoArmSamd21g18aSpeedProps800Kbps>> NeoArm800KbpsMethod;
380424
typedef NeoArmMethodBase<NeoArmSamd21g18aSpeedBase<NeoArmSamd21g18aSpeedProps400Kbps>> NeoArm400KbpsMethod;
381425

382426
#elif defined (ARDUINO_STM32_FEATHER) // FEATHER WICED (120MHz)
383427

384-
385-
386-
class NeoArmStm32SpeedProps800Kbps
428+
class NeoArmStm32SpeedProps800KbpsBase
387429
{
430+
public:
388431
static void BitT1hWait()
389432
{
390433
asm("nop; nop; nop; nop; nop; nop; nop; nop;"
@@ -432,9 +475,20 @@ class NeoArmStm32SpeedProps800Kbps
432475
"nop; nop; nop; nop; nop; nop; nop; nop;"
433476
"nop; nop; nop; nop;");
434477
}
478+
};
435479

480+
class NeoArmStm32SpeedProps800Kbps : public NeoArmStm32SpeedProps800KbpsBase
481+
{
482+
public:
483+
static const uint32_t ResetTimeUs = 50;
484+
};
436485

486+
class NeoArmStm32SpeedPropsWs2813 : public NeoArmStm32SpeedProps800KbpsBase
487+
{
488+
public:
489+
static const uint32_t ResetTimeUs = 250;
437490
};
491+
438492
/* TODO - not found in Adafruit library
439493
class NeoArmStm32SpeedProps400Kbps
440494
{
@@ -455,6 +509,9 @@ static void BitT0lWait()
455509

456510
template<typename T_SPEEDPROPS> class NeoArmStm32SpeedBase
457511
{
512+
public:
513+
static const uint32_t ResetTimeUs = T_SPEEDPROPS::ResetTimeUs;
514+
458515
static void send_pixels(uint8_t* pixels, size_t sizePixels, uint8_t pin)
459516
{
460517
// Tried this with a timer/counter, couldn't quite get adequate
@@ -510,6 +567,7 @@ template<typename T_SPEEDPROPS> class NeoArmStm32SpeedBase
510567
}
511568
};
512569

570+
typedef NeoArmMethodBase<NeoArmStm32SpeedBase<NeoArmStm32SpeedPropsWs2813>> NeoArmWs2813Method;
513571
typedef NeoArmMethodBase<NeoArmStm32SpeedBase<NeoArmStm32SpeedProps800Kbps>> NeoArm800KbpsMethod;
514572

515573
#else // Other ARM architecture -- Presumed Arduino Due
@@ -518,12 +576,22 @@ typedef NeoArmMethodBase<NeoArmStm32SpeedBase<NeoArmStm32SpeedProps800Kbps>> Neo
518576
#define ARM_OTHER_SCALE VARIANT_MCK / 2UL / 1000000UL
519577
#define ARM_OTHER_INST (2UL * F_CPU / VARIANT_MCK)
520578

579+
class NeoArmOtherSpeedPropsWs2813
580+
{
581+
public:
582+
static const uint32_t CyclesT0h = ((uint32_t)(0.40 * ARM_OTHER_SCALE + 0.5) - (5 * ARM_OTHER_INST));
583+
static const uint32_t CyclesT1h = ((uint32_t)(0.80 * ARM_OTHER_SCALE + 0.5) - (5 * ARM_OTHER_INST));
584+
static const uint32_t Cycles = ((uint32_t)(1.25 * ARM_OTHER_SCALE + 0.5) - (5 * ARM_OTHER_INST));
585+
static const uint32_t ResetTimeUs = 250;
586+
};
587+
521588
class NeoArmOtherSpeedProps800Kbps
522589
{
523590
public:
524591
static const uint32_t CyclesT0h = ((uint32_t)(0.40 * ARM_OTHER_SCALE + 0.5) - (5 * ARM_OTHER_INST));
525592
static const uint32_t CyclesT1h = ((uint32_t)(0.80 * ARM_OTHER_SCALE + 0.5) - (5 * ARM_OTHER_INST));
526593
static const uint32_t Cycles = ((uint32_t)(1.25 * ARM_OTHER_SCALE + 0.5) - (5 * ARM_OTHER_INST));
594+
static const uint32_t ResetTimeUs = 50;
527595
};
528596

529597
class NeoArmOtherSpeedProps400Kbps
@@ -532,11 +600,14 @@ class NeoArmOtherSpeedProps400Kbps
532600
static const uint32_t CyclesT0h = ((uint32_t)(0.50 * ARM_OTHER_SCALE + 0.5) - (5 * ARM_OTHER_INST));
533601
static const uint32_t CyclesT1h = ((uint32_t)(1.20 * ARM_OTHER_SCALE + 0.5) - (5 * ARM_OTHER_INST));
534602
static const uint32_t Cycles = ((uint32_t)(2.50 * ARM_OTHER_SCALE + 0.5) - (5 * ARM_OTHER_INST));
603+
static const uint32_t ResetTimeUs = 50;
535604
};
536605

537606
template<typename T_SPEEDPROPS> class NeoArmOtherSpeedBase
538607
{
539608
public:
609+
static const uint32_t ResetTimeUs = T_SPEEDPROPS::ResetTimeUs;
610+
540611
static void send_pixels(uint8_t* pixels, size_t sizePixels, uint8_t pin)
541612
{
542613
uint32_t pinMask;
@@ -608,13 +679,15 @@ template<typename T_SPEEDPROPS> class NeoArmOtherSpeedBase
608679
}
609680
};
610681

682+
typedef NeoArmMethodBase<NeoArmOtherSpeedBase<NeoArmOtherSpeedPropsWs2813>> NeoArmWs2813Method;
611683
typedef NeoArmMethodBase<NeoArmOtherSpeedBase<NeoArmOtherSpeedProps800Kbps>> NeoArm800KbpsMethod;
612684
typedef NeoArmMethodBase<NeoArmOtherSpeedBase<NeoArmOtherSpeedProps400Kbps>> NeoArm400KbpsMethod;
613685

614686
#endif
615687

616688

617689
// Arm doesn't have alternatives methods yet, so only one to make the default
690+
typedef NeoArmWs2813Method NeoWs2813Method;
618691
typedef NeoArm800KbpsMethod Neo800KbpsMethod;
619692
#ifdef NeoArm400KbpsMethod // this is needed due to missing 400Kbps for some platforms
620693
typedef NeoArm400KbpsMethod Neo400KbpsMethod;

src/internal/NeoAvrMethod.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ extern "C"
4141
void send_pixels_16mhz_400(uint8_t* pixels, size_t sizePixels, volatile uint8_t* port, uint8_t pinMask);
4242
}
4343

44-
class NeoAvrSpeed800Kbps
44+
class NeoAvrSpeed800KbpsBase
4545
{
4646
public:
4747
static void send_pixels(uint8_t* pixels, size_t sizePixels, volatile uint8_t* port, uint8_t pinMask)
@@ -68,6 +68,19 @@ class NeoAvrSpeed800Kbps
6868
#error "CPU SPEED NOT SUPPORTED"
6969
#endif
7070
}
71+
72+
};
73+
74+
class NeoAvrSpeedWs2813 : public NeoAvrSpeed800KbpsBase
75+
{
76+
public:
77+
static const uint32_t ResetTimeUs = 250;
78+
};
79+
80+
class NeoAvrSpeed800Kbps: public NeoAvrSpeed800KbpsBase
81+
{
82+
public:
83+
static const uint32_t ResetTimeUs = 50;
7184
};
7285

7386
class NeoAvrSpeed400Kbps
@@ -87,6 +100,7 @@ class NeoAvrSpeed400Kbps
87100
#error "CPU SPEED NOT SUPPORTED"
88101
#endif
89102
}
103+
static const uint32_t ResetTimeUs = 50;
90104
};
91105

92106
template<typename T_SPEED> class NeoAvrMethodBase
@@ -118,7 +132,7 @@ template<typename T_SPEED> class NeoAvrMethodBase
118132
{
119133
uint32_t delta = micros() - _endTime;
120134

121-
return (delta >= 50L);
135+
return (delta >= T_SPEED::ResetTimeUs);
122136
}
123137

124138
void Initialize()
@@ -173,10 +187,12 @@ template<typename T_SPEED> class NeoAvrMethodBase
173187
uint8_t _pinMask; // Output PORT bitmask
174188
};
175189

190+
typedef NeoAvrMethodBase<NeoAvrSpeedWs2813> NeoAvrWs2813Method;
176191
typedef NeoAvrMethodBase<NeoAvrSpeed800Kbps> NeoAvr800KbpsMethod;
177192
typedef NeoAvrMethodBase<NeoAvrSpeed400Kbps> NeoAvr400KbpsMethod;
178193

179194
// AVR doesn't have alternatives yet, so there is just the default
195+
typedef NeoAvrWs2813Method NeoWs2813Method;
180196
typedef NeoAvr800KbpsMethod Neo800KbpsMethod;
181197
typedef NeoAvr400KbpsMethod Neo400KbpsMethod;
182198

src/internal/NeoEsp8266DmaMethod.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,28 @@ struct slc_queue_item
6363
uint32 next_link_ptr;
6464
};
6565

66+
class NeoEsp8266DmaSpeedWs2813
67+
{
68+
public:
69+
const static uint32_t I2sClockDivisor = 3;
70+
const static uint32_t I2sBaseClockDivisor = 16;
71+
const static uint32_t ResetTimeUs = 250;
72+
};
6673

6774
class NeoEsp8266DmaSpeed800Kbps
6875
{
6976
public:
7077
const static uint32_t I2sClockDivisor = 3;
7178
const static uint32_t I2sBaseClockDivisor = 16;
79+
const static uint32_t ResetTimeUs = 50;
7280
};
7381

7482
class NeoEsp8266DmaSpeed400Kbps
7583
{
7684
public:
7785
const static uint32_t I2sClockDivisor = 6;
7886
const static uint32_t I2sBaseClockDivisor = 16;
87+
const static uint32_t ResetTimeUs = 50;
7988
};
8089

8190
enum NeoDmaState
@@ -268,7 +277,8 @@ template<typename T_SPEED> class NeoEsp8266DmaMethodBase
268277

269278
// normally 24 bytes creates the minimum 50us latch per spec, but
270279
// with the new logic, this latch is used to space between three states
271-
uint8_t _i2sZeroes[8];
280+
// buffer size = (24 * (speed / 50)) / 3
281+
uint8_t _i2sZeroes[(24L * (T_SPEED::ResetTimeUs / 50L)) / 3L];
272282

273283
slc_queue_item* _i2sBufDesc; // dma block descriptors
274284
uint16_t _i2sBufDescCount; // count of block descriptors in _i2sBufDesc
@@ -360,10 +370,12 @@ template<typename T_SPEED> class NeoEsp8266DmaMethodBase
360370
template<typename T_SPEED>
361371
NeoEsp8266DmaMethodBase<T_SPEED>* NeoEsp8266DmaMethodBase<T_SPEED>::s_this;
362372

373+
typedef NeoEsp8266DmaMethodBase<NeoEsp8266DmaSpeedWs2813> NeoEsp8266DmaWs2813Method;
363374
typedef NeoEsp8266DmaMethodBase<NeoEsp8266DmaSpeed800Kbps> NeoEsp8266Dma800KbpsMethod;
364375
typedef NeoEsp8266DmaMethodBase<NeoEsp8266DmaSpeed400Kbps> NeoEsp8266Dma400KbpsMethod;
365376

366377
// Dma method is the default method for Esp8266
378+
typedef NeoEsp8266DmaWs2813Method NeoWs2813Method;
367379
typedef NeoEsp8266Dma800KbpsMethod Neo800KbpsMethod;
368380
typedef NeoEsp8266Dma400KbpsMethod Neo400KbpsMethod;
369381

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy