-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHX8357_cont.sv
314 lines (275 loc) · 6.27 KB
/
HX8357_cont.sv
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
module HX8357_cont (
input clk, // Clock
input nres, // Asynchronous reset active low
// inputs to controller
input [15:0] data_in,
// as long as cmd, or data is held high, corresponding element will be send
input cmd,
input data,
// control outputs
output logic transmission_cmpl,
// outputs to display
output logic CSx,
output logic RESx,
output logic DCx,
output logic WRx,
output logic RDx,
output logic [15:0] DATAx
);
enum {IDLE, CS_LOW, D, C, W_PRE_D, W_PRE_C, W_COMMIT_D, W_COMMIT_C} state, next_state;
logic DorC, DorC_next;
// data_sample
logic [15:0] data_sample, data_sample_next;
// assign next state
always_ff @(posedge clk or negedge nres) begin : STATE_CHANGE
if(~nres) begin
state <= IDLE;
DorC <= 0;
data_sample <= 16'h0000;
end else begin
state <= next_state;
DorC <= DorC_next;
data_sample <= data_sample_next;
end
end
// next state logic
always @(state or cmd or data or DorC or data_in or data_sample or nres) begin : NEXT_STATE
if(~nres) begin
next_state = IDLE;
DorC_next = 0;
data_sample_next = 16'h0000;
end else begin
DorC_next = DorC;
data_sample_next = data_sample;
case (state)
IDLE: begin
if(cmd || data) begin
next_state = CS_LOW;
DorC_next = 0;
end else begin
next_state = IDLE;
end
end
CS_LOW: begin
// cmd overrides data if both are set -> should not happen
if(cmd) begin
next_state = C;
end else begin
if(data) begin
next_state = D;
end else begin
next_state = CS_LOW;
end
end
end
D: begin
DorC_next = 1;
next_state = W_PRE_D;
end
C: begin
DorC_next = 0;
next_state = W_PRE_C;
end
/*
W_PRE: begin
next_state = W_COMMIT;
end
*/
W_PRE_D: begin
next_state = W_COMMIT_D;
// sample data for output
data_sample_next = data_in;
end
W_PRE_C: begin
next_state = W_COMMIT_C;
// sample data for output
data_sample_next = data_in;
end
W_COMMIT_D: begin
// cmd overrides data if both are set -> should not happen
if(cmd && !DorC) begin
// previous transmission was also cmd -> NO need to change DCx line
next_state = W_PRE_C;
end else if (cmd && DorC) begin
// previous transmission was data transmission -> need to change DCx line
next_state = C;
end else if (data && DorC) begin
// previous transmission was data -> NO need to change DCx line
next_state = W_PRE_D;
end else if (data && !DorC) begin
// previous transmission was cmd -> need to change DCx line
next_state = D;
end else begin
// (!cmd && !data) -> goto IDLE
next_state = IDLE;
end
end
W_COMMIT_C: begin
// cmd overrides data if both are set -> should not happen
if(cmd && !DorC) begin
// previous transmission was also cmd -> NO need to change DCx line
next_state = W_PRE_C;
end else if (cmd && DorC) begin
// previous transmission was data transmission -> need to change DCx line
next_state = C;
end else if (data && DorC) begin
// previous transmission was data -> NO need to change DCx line
next_state = W_PRE_D;
end else if (data && !DorC) begin
// previous transmission was cmd -> need to change DCx line
next_state = D;
end else begin
// (!cmd && !data) -> goto IDLE
next_state = IDLE;
end
end
/*
W_COMMIT: begin
// cmd overrides data if both are set -> should not happen
if(cmd && !DorC) begin
// previous transmission was also cmd -> NO need to change DCx line
next_state = W_PRE;
end else if (cmd && DorC) begin
// previous transmission was data transmission -> need to change DCx line
next_state = C;
end else if (data && DorC) begin
// previous transmission was data -> NO need to change DCx line
next_state = W_PRE;
end else if (data && !DorC) begin
// previous transmission was cmd -> need to change DCx line
next_state = D;
end else begin
// (!cmd && !data) -> goto IDLE
next_state = IDLE;
end
end
*/
// should not happen
default : next_state = IDLE;
endcase
end
end
logic [15:0] DATAx_sample;
// OUTPUT logic
always @(state or data_sample_next or nres) begin : OUTPUT
if(~nres) begin
// display output
CSx = 1;
RESx = 0;
DCx = 1;
WRx = 1;
RDx = 1;
DATAx = 16'hzzzz;
// controller output
transmission_cmpl = 0;
end else begin
// display output
CSx = 1;
RESx = 1;
DCx = 1;
WRx = 1;
RDx = 1;
DATAx = 16'hzzzz;
// controller output
transmission_cmpl = 0;
case (state)
IDLE: begin
// display output
CSx = 1;
RESx = 1;
DCx = 1;
WRx = 1;
RDx = 1;
DATAx = 16'hzzzz;
// controller output
transmission_cmpl = 0;
end
CS_LOW: begin
CSx = 0;
RESx = 1;
DCx = 1;
WRx = 1;
RDx = 1;
DATAx = 16'hzzzz;
transmission_cmpl = 0;
end
D: begin
CSx = 0;
RESx = 1;
DCx = 1;
WRx = 1;
RDx = 1;
DATAx = 16'hzzzz;
transmission_cmpl = 0;
end
C: begin
CSx = 0;
RESx = 1;
DCx = 0;
WRx = 1;
RDx = 1;
DATAx = 16'hzzzz;
transmission_cmpl = 0;
end
/*
W_PRE: begin
WRx = 0;
DATAx = data_in;
transmission_cmpl = 1;
end
*/
W_PRE_D: begin
CSx = 0;
RESx = 1;
DCx = 1;
WRx = 0;
RDx = 1;
DATAx = data_sample_next;
transmission_cmpl = 1;
end
W_PRE_C: begin
CSx = 0;
RESx = 1;
DCx = 0;
WRx = 0;
RDx = 1;
DATAx = data_sample_next;
transmission_cmpl = 1;
end
/*
W_COMMIT: begin
WRx = 1;
transmission_cmpl = 0;
end
*/
W_COMMIT_D: begin
CSx = 0;
RESx = 1;
DCx = 1;
WRx = 1;
RDx = 1;
DATAx = data_sample_next;
transmission_cmpl = 0;
end
W_COMMIT_C: begin
CSx = 0;
RESx = 1;
DCx = 0;
WRx = 1;
RDx = 1;
DATAx = data_sample_next;
transmission_cmpl = 0;
end
default : begin
CSx = 1;
RESx = 1;
DCx = 1;
WRx = 1;
RDx = 1;
DATAx = 16'hzzzz;
transmission_cmpl = 0;
end
endcase
end
end
endmodule // HX8357_controller