forked from yuri-panchul/basics-graphics-music
-
Notifications
You must be signed in to change notification settings - Fork 0
/
board_specific_top.sv
286 lines (212 loc) · 8.03 KB
/
board_specific_top.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
`include "config.svh"
`include "lab_specific_board_config.svh"
module board_specific_top
# (
parameter clk_mhz = 50,
pixel_mhz = 25,
w_key = 4,
w_sw = 10, // One onboard SW is used as a reset
w_led = 8,
w_digit = 4,
w_gpio = 72, // GPIO_1[5:0] reserved for mic
// gpio 0..5 are reserved for INMP 441 I2S microphone.
// Odd gpio .. are reserved I2S audio.
screen_width = 640,
screen_height = 480,
w_red = 4,
w_green = 4,
w_blue = 4,
w_x = $clog2 ( screen_width ),
w_y = $clog2 ( screen_height )
)
(
input CLOCK_50,
input [ w_key - 1:0] KEY,
input [ w_sw - 1:0] SW,
output logic [ 9:0] LEDR,
output logic [ 7:0] LEDG,
output logic [ 6:0] HEX0, // HEX[7] aka dp are not connected to FPGA at DE1 board
output logic [ 6:0] HEX1,
output logic [ 6:0] HEX2,
output logic [ 6:0] HEX3,
output VGA_HS,
output VGA_VS,
output [ w_red - 1:0] VGA_R,
output [ w_green - 1:0] VGA_G,
output [ w_blue - 1:0] VGA_B,
input UART_RXD,
output UART_TXD,
inout [ w_gpio / 2 - 1:0] GPIO_0,
inout [ w_gpio / 2 - 1:0] GPIO_1
);
//------------------------------------------------------------------------
localparam w_lab_sw = w_sw - 1; // One sw is used as a reset
//------------------------------------------------------------------------
wire clk = CLOCK_50;
wire rst = SW [w_lab_sw];
// Keys, switches, LEDs
wire [ w_lab_sw - 1:0] lab_sw = SW [w_lab_sw - 1:0];
// A dynamic seven-segment display
wire [ 7:0] abcdefgh;
wire [ w_digit - 1:0] digit;
// Graphics
wire display_on;
wire [ w_x - 1:0] x;
wire [ w_y - 1:0] y;
wire [ w_red - 1:0] red;
wire [ w_green - 1:0] green;
wire [ w_blue - 1:0] blue;
assign VGA_R = display_on ? red : '0;
assign VGA_G = display_on ? green : '0;
assign VGA_B = display_on ? blue : '0;
// Microphone, sound output and UART
wire [ 23:0] mic;
wire [ 15:0] sound;
//------------------------------------------------------------------------
wire slow_clk;
slow_clk_gen # (.fast_clk_mhz (clk_mhz), .slow_clk_hz (1))
i_slow_clk_gen (.slow_clk (slow_clk), .*);
//------------------------------------------------------------------------
lab_top
# (
.clk_mhz ( clk_mhz ),
.w_key ( w_key ),
.w_sw ( w_lab_sw ),
.w_led ( w_led ),
.w_digit ( w_digit ),
.w_gpio ( w_gpio ),
.screen_width ( screen_width ),
.screen_height ( screen_height ),
.w_red ( w_red ),
.w_green ( w_green ),
.w_blue ( w_blue )
)
i_lab_top
(
.clk ( clk ),
.slow_clk ( slow_clk ),
.rst ( rst ),
.key ( ~ KEY ),
.sw ( lab_sw ),
.led ( LEDG ),
.abcdefgh ( abcdefgh ),
.digit ( digit ),
.x ( x ),
.y ( y ),
.red ( red ),
.green ( green ),
.blue ( blue ),
.mic ( mic ),
.sound ( sound ),
.uart_rx ( UART_RXD ),
.uart_tx ( UART_TXD ),
.gpio ( { GPIO_0, GPIO_1 } )
);
//------------------------------------------------------------------------
wire [$left (abcdefgh):0] hgfedcba;
generate
genvar i;
for (i = 0; i < $bits (abcdefgh); i ++)
begin : abc
assign hgfedcba [i] = abcdefgh [$left (abcdefgh) - i];
end
endgenerate
//------------------------------------------------------------------------
`ifdef EMULATE_DYNAMIC_7SEG_ON_STATIC_WITHOUT_STICKY_FLOPS
// Pro: This implementation is necessary for the lab 7segment_word
// to properly demonstrate the idea of dynamic 7-segment display
// on a static 7-segment display.
//
// Con: This implementation makes the 7-segment LEDs dim
// on most boards with the static 7-sigment display.
// inverted logic
assign HEX0 = digit [0] ? ~ hgfedcba [$left (HEX0):0] : '1;
assign HEX1 = digit [1] ? ~ hgfedcba [$left (HEX1):0] : '1;
assign HEX2 = digit [2] ? ~ hgfedcba [$left (HEX2):0] : '1;
assign HEX3 = digit [3] ? ~ hgfedcba [$left (HEX3):0] : '1;
// positive logic
always_comb
begin
LEDR = '0;
for (int i = 0; i < w_digit; i ++)
LEDR [$bits (LEDR) - w_digit + i]
= digit [i] ? hgfedcba [$left (HEX0) + 1] : '0;
end
`else
always_ff @ (posedge clk or posedge rst)
begin
if (rst)
begin
{ HEX0, HEX1, HEX2, HEX3 } <= '1;
LEDR <= '0;
end
else
begin
if (digit [0]) HEX0 <= ~ hgfedcba [$left (HEX0):0];
if (digit [1]) HEX1 <= ~ hgfedcba [$left (HEX1):0];
if (digit [2]) HEX2 <= ~ hgfedcba [$left (HEX2):0];
if (digit [3]) HEX3 <= ~ hgfedcba [$left (HEX3):0];
for (int i = 0; i < w_digit; i ++)
if (digit [i])
LEDR [$bits (LEDR) - w_digit + i] <= hgfedcba [$left (HEX0) + 1];
end
end
`endif
//------------------------------------------------------------------------
`ifdef INSTANTIATE_GRAPHICS_INTERFACE_MODULE
wire [9:0] x10; assign x = x10;
wire [9:0] y10; assign y = y10;
vga
# (
.CLK_MHZ ( clk_mhz ),
.PIXEL_MHZ ( pixel_mhz )
)
i_vga
(
.clk ( clk ),
.rst ( rst ),
.hsync ( VGA_HS ),
.vsync ( VGA_VS ),
.display_on ( display_on ),
.hpos ( x10 ),
.vpos ( y10 ),
.pixel_clk ( )
);
`endif
//------------------------------------------------------------------------
`ifdef INSTANTIATE_MICROPHONE_INTERFACE_MODULE
inmp441_mic_i2s_receiver
# (
.clk_mhz ( clk_mhz )
)
i_microphone
(
.clk ( clk ),
.rst ( rst ),
.lr ( GPIO_1 [0] ),
.ws ( GPIO_1 [2] ),
.sck ( GPIO_1 [4] ),
.sd ( GPIO_1 [5] ),
.value ( mic )
);
assign GPIO_1 [1] = 1'b0; // GND
assign GPIO_1 [3] = 1'b1; // VCC
`endif
//------------------------------------------------------------------------
`ifdef INSTANTIATE_SOUND_OUTPUT_INTERFACE_MODULE
i2s_audio_out
# (
.clk_mhz ( clk_mhz )
)
inst_audio_out
(
.clk ( clk ),
.reset ( rst ),
.data_in ( sound ),
.mclk ( GPIO_1 [33] ),
.bclk ( GPIO_1 [31] ),
.lrclk ( GPIO_1 [27] ),
.sdata ( GPIO_1 [29] )
);
`endif
endmodule