-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathboard_specific_top.sv
281 lines (205 loc) · 7.52 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
`include "config.svh"
`include "lab_specific_board_config.svh"
// `define USE_DIGILENT_PMOD_MIC3
`ifdef USE_DIGILENT_PMOD_MIC3
`define USE_SDRAM_PINS_AS_GPIO
`else
`define USE_LCD_AS_GPIO
`endif
`define USE_INTERNALLY_WIDE_COLOR_CHANNELS
//----------------------------------------------------------------------------
module board_specific_top
# (
parameter clk_mhz = 50,
pixel_mhz = 25,
w_key = 4,
w_sw = 4,
w_led = 4,
w_digit = 4,
`ifdef USE_SDRAM_PINS_AS_GPIO
w_gpio = 14,
`elsif USE_LCD_AS_GPIO
w_gpio = 11,
`else
w_gpio = 1,
`endif
screen_width = 640,
screen_height = 480,
`ifdef USE_INTERNALLY_WIDE_COLOR_CHANNELS
w_red = 4,
w_green = 4,
w_blue = 4,
`else
w_red = 1,
w_green = 1,
w_blue = 1,
`endif
w_x = $clog2 ( screen_width ),
w_y = $clog2 ( screen_height )
)
(
input CLK,
input RESET,
input [w_key - 1:0] KEY_SW,
output [w_led - 1:0] LED,
output [ 7:0] SEG,
output [w_digit - 1:0] DIG,
output VGA_HSYNC,
output VGA_VSYNC,
output VGA_R,
output VGA_G,
output VGA_B,
input UART_RXD,
output UART_TXD,
inout [w_gpio - 1:0] PSEUDO_GPIO_USING_SDRAM_PINS,
inout LCD_RS,
inout LCD_RW,
inout LCD_E,
inout [ 7:0] LCD_D
);
//------------------------------------------------------------------------
wire clk = CLK;
wire rst = ~ RESET;
//------------------------------------------------------------------------
wire [w_led - 1:0] lab_led;
// 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 );
assign VGA_G = display_on & ( | green );
assign VGA_B = display_on & ( | blue );
// Sound
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_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 ),
.sw ( ~ KEY_SW ),
.led ( lab_led ),
.abcdefgh ( abcdefgh ),
.digit ( digit ),
.x ( x ),
.y ( y ),
.red ( red ),
.green ( green ),
.blue ( blue ),
.uart_rx ( UART_RXD ),
.uart_tx ( UART_TXD ),
.mic ( mic ),
.sound ( sound ),
`ifdef USE_SDRAM_PINS_AS_GPIO
.gpio ( PSEUDO_GPIO_USING_SDRAM_PINS )
`elsif USE_LCD_AS_GPIO
.gpio ({ LCD_RS, LCD_RW, LCD_E, LCD_D })
`endif
);
//------------------------------------------------------------------------
assign LED = ~ lab_led;
assign SEG = ~ abcdefgh;
assign DIG = ~ digit;
//------------------------------------------------------------------------
`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_HSYNC ),
.vsync ( VGA_VSYNC ),
.display_on ( display_on ),
.hpos ( x10 ),
.vpos ( y10 ),
.pixel_clk ( )
);
`endif
//------------------------------------------------------------------------
`ifdef INSTANTIATE_MICROPHONE_INTERFACE_MODULE
`ifdef USE_DIGILENT_PMOD_MIC3
wire [11:0] mic_12;
digilent_pmod_mic3_spi_receiver i_microphone
(
.clk ( clk ),
.rst ( rst ),
.cs ( PSEUDO_GPIO_USING_SDRAM_PINS [0] ),
.sck ( PSEUDO_GPIO_USING_SDRAM_PINS [6] ),
.sdo ( PSEUDO_GPIO_USING_SDRAM_PINS [4] ),
.value ( mic_12 )
);
assign PSEUDO_GPIO_USING_SDRAM_PINS [ 8] = 1'b0; // GND
assign PSEUDO_GPIO_USING_SDRAM_PINS [10] = 1'b1; // VCC
wire [11:0] mic_12_minus_offset = mic_12 - 12'h800;
assign mic = { { 12 { mic_12_minus_offset [11] } },
mic_12_minus_offset };
//--------------------------------------------------------------------
`else // USE_INMP_441_MIC
inmp441_mic_i2s_receiver
# (
.clk_mhz ( clk_mhz )
)
i_microphone
(
.clk ( clk ),
.rst ( rst ),
.lr ( LCD_D [5] ),
.ws ( LCD_D [3] ),
.sck ( LCD_D [1] ),
.sd ( LCD_D [2] ),
.value ( mic )
);
assign LCD_D [6] = 1'b0; // GND
assign LCD_D [4] = 1'b1; // VCC
`endif // USE_INMP_441_MIC
`endif // INSTANTIATE_MICROPHONE_INTERFACE_MODULE
//------------------------------------------------------------------------
`ifdef INSTANTIATE_SOUND_OUTPUT_INTERFACE_MODULE
i2s_audio_out
# (
.clk_mhz ( clk_mhz )
)
inst_audio_out
(
.clk ( clk ),
.reset ( rst ),
.data_in ( sound ),
.mclk ( LCD_E ), // Pin 143
.bclk ( LCD_RS ), // Pin 141
.lrclk ( LCD_RW ), // Pin 138
.sdata ( LCD_D [0] ) // Pin 142
); // GND and VCC 3.3V (30-45 mA)
`endif
endmodule