Skip to content

Commit 02f6726

Browse files
committed
further NeoPixel tuning, but needs testing
1 parent 640dede commit 02f6726

File tree

1 file changed

+28
-5
lines changed
  • ports/atmel-samd/common-hal/neopixel_write

1 file changed

+28
-5
lines changed

ports/atmel-samd/common-hal/neopixel_write/__init__.c

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,29 @@ __attribute__((naked,noinline,aligned(16)))
4646
static void neopixel_send_buffer_core(volatile uint32_t *clraddr, uint32_t pinMask,
4747
const uint8_t *ptr, int numBytes);
4848

49+
// From the SK6812 datasheet:
50+
// T0H 0 code, high level time 0.3µs ±0.15µs
51+
// T1H 1 code, high level time 0.6µs ±0.15µs
52+
// T0L 0 code, low level time 0.9µs ±0.15µs
53+
// T1L 1 code, low level time 0.6µs ±0.15µs
54+
// Trst Reset code,low level time 80µs
55+
56+
// From the WS2812 datasheet:
57+
// T0H 0 code, high voltage time 0.35us ±150ns
58+
// T1H 1 code, high voltage time 0.7us ±150ns
59+
// T0L 0 code, low voltage time 0.8us ±150ns
60+
// T1L 1 code, low voltage time 0.6us ±150ns
61+
// RES low voltage time Above 50µs
62+
63+
// From the WS28212B datasheet:
64+
// T0H 0 code, high voltage time 0.4us ±150ns
65+
// T1H 1 code, high voltage time 0.8us ±150ns
66+
// T0L 0 code, low voltage time 0.85us ±150ns
67+
// T1L 1 code, low voltage time 0.45us ±150ns
68+
// RES low voltage time Above 50µs
69+
70+
// The SAMDx5x timings do not correspond to the SAMD21 timings. The SAMDx5x were determined
71+
// by looking at the output of an SK6812, and trying to match what it sent.
4972
static void neopixel_send_buffer_core(volatile uint32_t *clraddr, uint32_t pinMask,
5073
const uint8_t *ptr, int numBytes) {
5174
asm volatile (" push {r4, r5, r6, lr};"
@@ -60,17 +83,17 @@ static void neopixel_send_buffer_core(volatile uint32_t *clraddr, uint32_t pinMa
6083
" movs r6, #3; d2: sub r6, #1; bne d2;" // delay 3
6184
#endif
6285
#ifdef SAM_D5X_E5X
63-
" movs r6, #15; d2: subs r6, #1; bne d2;" // short low or high
86+
" movs r6, #11; d2: subs r6, #1; bne d2;" // 302 ns high (entire T0H or start T1H)
6487
#endif
6588
" tst r4, r5;" // mask&r5
6689
" bne skipclr;"
6790
" str r1, [r0, #0];" // clr
6891
"skipclr:"
6992
#ifdef SAMD21
70-
" movs r6, #6; d0: sub r6, #1; bne d0;" // long low or high
93+
" movs r6, #6; d0: sub r6, #1; bne d0;" // delay 6
7194
#endif
7295
#ifdef SAM_D5X_E5X
73-
" movs r6, #17; d0: subs r6, #1; bne d0;" // 834 ns
96+
" movs r6, #11; d0: subs r6, #1; bne d0;" // 302 ns low or high (start T0L or end T1H)
7497
#endif
7598
" str r1, [r0, #0];" // clr (possibly again, doesn't matter)
7699
#ifdef SAMD21
@@ -85,12 +108,12 @@ static void neopixel_send_buffer_core(volatile uint32_t *clraddr, uint32_t pinMa
85108
" movs r6, #2; d1: sub r6, #1; bne d1;" // delay 2
86109
#endif
87110
#ifdef SAM_D5X_E5X
88-
" movs r6, #14; d1: subs r6, #1; bne d1;" // finish low
111+
" movs r6, #22; d1: subs r6, #1; bne d1;" // 606 ns (end TOL or entire T1L)
89112
#endif
90113
" b loopBit;"
91114
"nextbyte:"
92115
#ifdef SAM_D5X_E5X
93-
" movs r6, #14; d3: subs r6, #1; bne d3;" // finish low
116+
" movs r6, #6; d3: subs r6, #1; bne d3;" // byte delay FIGURE THIS OUT
94117
#endif
95118
" cmp r2, r3;"
96119
" bcs neopixel_stop;"

0 commit comments

Comments
 (0)