-
Notifications
You must be signed in to change notification settings - Fork 0
/
ili9341_initialiser.v
139 lines (126 loc) · 3.45 KB
/
ili9341_initialiser.v
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
`timescale 1ns / 1ps
module ili9341_initialiser( clk, bl, rst, dc, cs, din, ready );
//, debug_ram_out, debug_ram_out_addr );
input clk;
output bl;
output rst;
output dc;
output cs;
output din;
output ready;
//output [9:0] debug_ram_out;
//output [2:0] debug_ram_out_addr;
reg int_rst = 1'b1;
reg int_dc = 1'bx;
reg int_din = 1'bx;
reg int_cs = 1'b1;
reg system_ready = 1'b0;
// State machines
reg [9:0] ram_addr = 10'b0;
reg [2:0] ram_out_addr = 3'b111;
wire [7:0] ram_out;
localparam DECISION = 2'b00, WRITE = 2'b01, NORM = 2'b10, WAIT = 2'b11;
localparam LS_COMMAND = 2'b00, LS_DATA = 2'b01, LS_IDLE = 2'b10;
reg [1:0] state = DECISION;
reg [1:0] ls = LS_IDLE;
reg [7:0] num_commands = 8'b0;
// ROM loaded with init_commands.coe
dist_mem_gen_0 init_ram (
.a(ram_addr),
.spo(ram_out)
);
reg [19:0] wait_counter = 20'b0;
assign bl = 1'b0;
assign rst = int_rst;
assign dc = int_dc;
assign cs = int_cs;
assign din = int_din;
assign ready = system_ready;
//assign debug_ram_out = ram_out;
//assign debug_ram_out_addr = ram_out_addr;
always @ (negedge clk)
begin
case (state)
DECISION:
begin
int_cs <= 1'b1;
case (ls)
LS_IDLE:
begin
if (ram_addr == 112)
begin
state <= NORM;
int_dc <= 1'b1;
end
else
begin
state <= WRITE;
ls <= LS_COMMAND;
int_dc <= 1'b0;
end
end
LS_COMMAND:
begin
if (ram_out == 8'b10000000)
begin
state <= WAIT;
ls <= LS_IDLE;
ram_addr <= ram_addr + 1;
end
else
begin
state <= WRITE;
ls <= LS_DATA;
num_commands <= ram_out;
ram_addr <= ram_addr + 1;
int_dc <= 1'b1;
end
end
LS_DATA:
begin
if (num_commands > 1)
begin
num_commands <= num_commands - 1;
state <= WRITE;
end
else
begin
state <= DECISION;
ls <= LS_IDLE;
end
end
endcase
end
WRITE:
begin
int_cs <= 1'b0;
if (ram_out_addr == 3'b0)
begin
ram_out_addr <= 3'b111;
ram_addr <= ram_addr + 1;
state <= DECISION;
end
else
ram_out_addr <= ram_out_addr - 1;
int_din <= ram_out[ram_out_addr];
end
WAIT:
begin
int_cs <= 1'b1;
// 150ms wait desired so 900,000 cycles for 6MHz clock
if (wait_counter == 900000)
begin
wait_counter = 20'b0;
state <= DECISION;
end
else
wait_counter <= wait_counter + 1;
end
NORM:
begin
int_cs <= 1'b1;
system_ready <= 1'b1;
end
endcase
end
endmodule