-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDE0_Nano.v
281 lines (216 loc) · 5.25 KB
/
DE0_Nano.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
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
//=======================================================
// This code is generated by Terasic System Builder
//=======================================================
module DE0_Nano(
//////////// CLOCK //////////
CLOCK_50,
//////////// LED //////////
LED,
//////////// KEY //////////
KEY,
//////////// SW //////////
SW,
//////////// SDRAM //////////
DRAM_ADDR,
DRAM_BA,
DRAM_CAS_N,
DRAM_CKE,
DRAM_CLK,
DRAM_CS_N,
DRAM_DQ,
DRAM_DQM,
DRAM_RAS_N,
DRAM_WE_N,
//////////// EPCS //////////
EPCS_ASDO,
EPCS_DATA0,
EPCS_DCLK,
EPCS_NCSO,
//////////// Accelerometer and EEPROM //////////
G_SENSOR_CS_N,
G_SENSOR_INT,
I2C_SCLK,
I2C_SDAT,
//////////// ADC //////////
ADC_CS_N,
ADC_SADDR,
ADC_SCLK,
ADC_SDAT,
//////////// 2x13 GPIO Header //////////
GPIO_2,
GPIO_2_IN,
//////////// GPIO_0, GPIO_0 connect to GPIO Default //////////
GPIO_0,
GPIO_0_IN,
//////////// GPIO_1, GPIO_1 connect to GPIO Default //////////
GPIO_1,
GPIO_1_IN
);
//=======================================================
// PARAMETER declarations
//=======================================================
//=======================================================
// PORT declarations
//=======================================================
`define CLOCK
`define LED
`define KEY
`define SW
`define SDRAM
`define EPCS
`define AE
`define ADC
`define GPIOH
`define GPIO0
`define GPIO1
//////////// CLOCK //////////
//3.3-V LVTTL//
`ifdef CLOCK
input CLOCK_50;
`endif
//////////// LED //////////
//3.3-V LVTTL//
`ifdef LED
output [7:0] LED;
`endif
//////////// KEY //////////
//3.3-V LVTTL//
`ifdef KEY
input [1:0] KEY;
`endif
//////////// SW //////////
//3.3-V LVTTL//
`ifdef SW
input [3:0] SW;
`endif
//////////// SDRAM //////////
//3.3-V LVTTL//
`ifdef SDRAM
output [12:0] DRAM_ADDR;
output [1:0] DRAM_BA;
output DRAM_CAS_N;
output DRAM_CKE;
output DRAM_CLK;
output DRAM_CS_N;
inout [15:0] DRAM_DQ;
output [1:0] DRAM_DQM;
output DRAM_RAS_N;
output DRAM_WE_N;
`endif
//////////// EPCS //////////
//3.3-V LVTTL//
`ifdef EPCS
output EPCS_ASDO;
input EPCS_DATA0;
output EPCS_DCLK;
output EPCS_NCSO;
`endif
//////////// Accelerometer and EEPROM //////////
//3.3-V LVTTL//
`ifdef AE
output G_SENSOR_CS_N;
input G_SENSOR_INT;
output I2C_SCLK;
inout I2C_SDAT;
`endif
//////////// ADC //////////
//3.3-V LVTTL//
`ifdef ADC
output ADC_CS_N;
output ADC_SADDR;
output ADC_SCLK;
input ADC_SDAT;
`endif
//////////// 2x13 GPIO Header //////////
//3.3-V LVTTL//
`ifdef GPIOH
inout [12:0] GPIO_2;
input [2:0] GPIO_2_IN;
`endif
//////////// GPIO_0, GPIO_0 connect to GPIO Default //////////
//3.3-V LVTTL//
`ifdef GPIO0
inout [33:0] GPIO_0;
input [1:0] GPIO_0_IN;
`endif
//////////// GPIO_1, GPIO_1 connect to GPIO Default //////////
//3.3-V LVTTL//
`ifdef GPIO1
inout [33:0] GPIO_1;
input [1:0] GPIO_1_IN;
`endif
//=======================================================
// REG/WIRE declarations
//=======================================================
wire DISP_I2C_SCL, DISP_I2C_SDA;
wire rst;
wire[7:0] i2c_reg_addr, i2c_tx_data;
wire tx_en, tx_done, i2c_err, full_screen_refreshed;
wire I2C_tx_clk;
wire sda_down;
wire[3:0] fsm_state;
wire[7:0] reg_addr;
wire[7:0] tx_data;
wire[7:0] i2c_reg_addr_static;
wire[7:0] i2c_tx_data_static;
wire[7:0] fb_data;
wire[7:0] fb_addr;
wire[3:0] action_btn;
wire[63:0] fb_write_data;
wire[6:0] fb_write_col_sel;
wire fb_write_en;
//=======================================================
// Structural coding
//=======================================================
assign rst = ~KEY[0];
assign GPIO_0[24] = DISP_I2C_SCL;
assign GPIO_0[28] = ~sda_down;
assign GPIO_0[30] = full_screen_refreshed;
clk_div #(.DIVISION_RATE(32'h00000007)) div_inst(CLOCK_50, I2C_tx_clk); //divide 50M clock for I2C
assign reg_addr = ~disp_init_complete ? i2c_reg_addr_static : fb_addr; //set I2C transmitter register input
assign tx_data = ~disp_init_complete ? i2c_tx_data_static : fb_data; //set I2C transmitter data input
i2c_transmitter transmitter(
.rst(rst),
.fast_clk(I2C_tx_clk),
.scl(DISP_I2C_SCL),
.sda(GPIO_0[26]),
.slave_addr(7'h3f), //addr of ST7567S
.reg_addr(reg_addr),
.tx_data(tx_data),
.tx_en(tx_en),
.tx_done(tx_done),
.err(i2c_err),
.fsm_state(fsm_state),
.sda_down(sda_down)
);
i2c_data_static data_inst(
.clk(I2C_tx_clk),
.rst(rst),
.reg_addr(i2c_reg_addr_static),
.tx_data(i2c_tx_data_static),
.tx_en(tx_en),
.tx_done(tx_done),
.init_complete(disp_init_complete)
);
frame_buffer fb_inst(
.clk(I2C_tx_clk),
.rst(rst),
.fb_start(disp_init_complete),
.tx_done(tx_done),
.fb_data(fb_data),
.fb_addr(fb_addr),
.full_screen_refreshed(full_screen_refreshed),
.fb_col_w_data(fb_write_data),
.fb_col_sel(fb_write_col_sel),
.fb_write(fb_write_en),
);
process game_inst(
.clk(CLOCK_50),
.rst(rst),
.move_paddle_1({GPIO_1[33], GPIO_1[31]}),
.move_paddle_2({GPIO_1[29], GPIO_1[27]}),
.fb_col_w_data(fb_write_data),
.fb_col_sel(fb_write_col_sel),
.fb_write(fb_write_en),
);
endmodule