-
Notifications
You must be signed in to change notification settings - Fork 0
/
ws2812b.pio
56 lines (52 loc) · 1.34 KB
/
ws2812b.pio
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
; According to https://cdn-shop.adafruit.com/datasheets/WS2812B.pdf
;
; zero:
; 1 +----------. |
; | | |
; | T0H=.4us | T0L=.85us |
; | | |
; 0 + '----------------------|
;
; one:
; 1 +--------------------. |
; | | |
; | T1H=.8us | T1L=.45us |
; | | |
; 0 + '------------|
;
; | TH=.4us | TD=.4us | TL=0.45us |
;
; | T=1.25us |
;
;
; T = 1.25us (=800kHz) = 10cycles
;
; TH = 0.4us = 0.32*T = ~3cycles
; TD = 0.4us = 0.32*T = ~3cycles
; TL = 0.45us = 0.36*T = ~4cycles
;
; T0H/T0L/T1H/T1L +- 0.15us (=0.12*T)
;
;
; reset:
; 1 + |
; | |
; | RES>=50us |
; | |
; 0 +-----//-----|
.program ws2812b_pio
.side_set 1
.define TH 3
.define TD 3
.define TL 4
.define public CYCLES_PER_BIT (TH+TD+TL)
.define public RESET_US 50
.wrap_target
loop:
out x 1 side 0 [TL-1] ; Set low then shift in a bit and wait for TL (side-set is executed even on stalls)
jmp !x do_zero side 1 [TH-1] ; Set high then branch if bit is zero and wait for TH
do_one:
jmp loop side 1 [TD-1] ; Keep high for TD then jump back
do_zero:
nop side 0 [TD-1] ; Set low for TD then jump back
.wrap