forked from pinballpower/code_dmd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdmd_interface_de_x16_v1.pio
More file actions
66 lines (53 loc) · 2.04 KB
/
dmd_interface_de_x16_v1.pio
File metadata and controls
66 lines (53 loc) · 2.04 KB
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
57
58
59
60
61
62
63
64
65
66
.define DE 7
.define RDATA 6
.define RCLK 5
.define COLLAT 4
.define DOTCLK 3
.define SDATA 2
.define SDATA_X16_PADDING 1
.define SDATA_X16 0
.define FRAME_START_IRQ 5
.program dmd_reader_de_x16_v1
.wrap_target
set y, 31
irq clear FRAME_START_IRQ
wait irq FRAME_START_IRQ
start:
set x, 31
dotloop:
; Because of PIO limitations, we read in 4 bit: px 1 as 000v and px 2 as 0v00 (where v is either 0 or 1 depending on the SDATA state)
; The first bit of px 2 always contains a padding 0, thanks to GPIO 1 because it's pulled low permanently.
; in pins 3 = (px 1 -> v)0(v <- px 2). Here the zero in the middle is the padding bit (GPIO 1), and the 1s on either side are the actual pixel values.
; This lets us create a unique combination which is either lit up (pixval 1) or off (pixval 0)
; possible values here are 0000, 0001 and 0100
wait 1 gpio DOTCLK ; rising edge
in null 3 ; 000 padding for 4bpp
in pins 3 ; read value of px 1(GPIO2), padding 0 (GPIO1) and px 2 (GPIO0) as they're sampled on the same DOTCLK edge
in null 2 ; 00 padding for 4bpp
wait 0 gpio DOTCLK ; falling edge
jmp x-- dotloop
set x, 7 ; loop 32 times
no_lsb_msb_padding:
in null 32
jmp x-- no_lsb_msb_padding
jmp y-- start
.wrap
; Frame detection program runs in parallel to the reader program and signals the start of a new frame using an IRQ.
.program dmd_framedetect_de_x16_v1
.wrap_target
; V1 (TMNT & Checkpoint) Data East 128x16 frame detection
; When RDATA goes high, check if DE is high as well. If this is the case, we are in the middle of a frame.
; Finally, skip 16 rows forward to find the starting row.
detect_loop:
wait 0 gpio RDATA
wait 1 gpio RDATA
jmp pin, prepare_skip_loop ; jmp pin is DE
jmp detect_loop
prepare_skip_loop:
set x, 16 ; 16 rows
skip_loop:
wait 0 gpio DE
wait 1 gpio DE
jmp x-- skip_loop
irq FRAME_START_IRQ
.wrap