|
| 1 | +`define FORCE_NO_INSTANTIATE_TM1638_BOARD_CONTROLLER_MODULE |
| 2 | +`include "config.svh" |
| 3 | +`include "lab_specific_board_config.svh" |
| 4 | +`include "swap_bits.svh" |
| 5 | + |
| 6 | +`ifdef FORCE_NO_INSTANTIATE_TM1638_BOARD_CONTROLLER_MODULE |
| 7 | + `undef INSTANTIATE_TM1638_BOARD_CONTROLLER_MODULE |
| 8 | +`endif |
| 9 | + |
| 10 | +module board_specific_top |
| 11 | +# ( |
| 12 | + parameter clk_mhz = 25, |
| 13 | + |
| 14 | + w_key = 4, |
| 15 | + w_sw = 16, |
| 16 | + w_led = 16, |
| 17 | + w_digit = 8, |
| 18 | + w_gpio = 20, |
| 19 | + |
| 20 | + screen_width = 800, |
| 21 | + screen_height = 480, |
| 22 | + |
| 23 | + w_red = 5, |
| 24 | + w_green = 6, |
| 25 | + w_blue = 5, |
| 26 | + |
| 27 | + w_x = $clog2 ( screen_width ), |
| 28 | + w_y = $clog2 ( screen_height ), |
| 29 | + |
| 30 | + w_sound = 16 |
| 31 | +) |
| 32 | +( |
| 33 | + input CLK, |
| 34 | + |
| 35 | + input [w_key - 1:0] KEY, |
| 36 | + input [w_sw - 1:0] SW, |
| 37 | + |
| 38 | + input UART_RX, |
| 39 | + output UART_TX, |
| 40 | + |
| 41 | + output [w_led - 1:0] LED, |
| 42 | + |
| 43 | + output [ 7:0] HGFEDCBA, |
| 44 | + output [w_digit - 1:0] DIGIT, |
| 45 | + |
| 46 | + inout [w_gpio - 1:0] GPIO |
| 47 | +); |
| 48 | + |
| 49 | + wire clk = CLK; |
| 50 | + |
| 51 | + //------------------------------------------------------------------------ |
| 52 | + |
| 53 | + localparam w_tm_key = 8, |
| 54 | + w_tm_led = 8, |
| 55 | + w_tm_digit = 8, |
| 56 | + right = 0; |
| 57 | + |
| 58 | + //------------------------------------------------------------------------ |
| 59 | + |
| 60 | + `ifdef INSTANTIATE_TM1638_BOARD_CONTROLLER_MODULE |
| 61 | + |
| 62 | + localparam w_lab_key = w_tm_key, |
| 63 | + w_lab_sw = w_sw, |
| 64 | + w_lab_led = w_tm_led, |
| 65 | + w_lab_digit = w_tm_digit; |
| 66 | + |
| 67 | + `else // TM1638 module is not connected |
| 68 | + |
| 69 | + localparam w_lab_key = w_key, |
| 70 | + w_lab_sw = w_sw, |
| 71 | + w_lab_led = w_led, |
| 72 | + w_lab_digit = w_digit; |
| 73 | + |
| 74 | + `endif |
| 75 | + |
| 76 | + //------------------------------------------------------------------------ |
| 77 | + |
| 78 | + wire [w_tm_key - 1:0] tm_key; |
| 79 | + wire [w_tm_led - 1:0] tm_led; |
| 80 | + wire [w_tm_digit - 1:0] tm_digit; |
| 81 | + |
| 82 | + logic [w_lab_key - 1:0] lab_key; |
| 83 | + wire [w_lab_led - 1:0] lab_led; |
| 84 | + wire [w_lab_digit - 1:0] lab_digit; |
| 85 | + |
| 86 | + wire rst; |
| 87 | + wire [ 7:0] abcdefgh; |
| 88 | + |
| 89 | + wire [w_x - 1:0] x; |
| 90 | + wire [w_y - 1:0] y; |
| 91 | + |
| 92 | + wire [ 23:0] mic; |
| 93 | + wire [w_sound - 1:0] sound; |
| 94 | + |
| 95 | + //------------------------------------------------------------------------ |
| 96 | + |
| 97 | + `ifdef INSTANTIATE_TM1638_BOARD_CONTROLLER_MODULE |
| 98 | + |
| 99 | + assign rst = tm_key [w_tm_key - 1]; |
| 100 | + assign lab_key = tm_key [w_tm_key - 1:0]; |
| 101 | + |
| 102 | + assign tm_led = lab_led; |
| 103 | + assign tm_digit = lab_digit; |
| 104 | + |
| 105 | + assign LED = w_led' (~ lab_led); |
| 106 | + |
| 107 | + `else // TM1638 module is not connected |
| 108 | + |
| 109 | + assign rst = ~ KEY [w_key - 1]; |
| 110 | + assign lab_key = ~ KEY [w_key - 1:0]; |
| 111 | + |
| 112 | + assign LED = lab_led; |
| 113 | + |
| 114 | + `endif |
| 115 | + |
| 116 | + //------------------------------------------------------------------------ |
| 117 | + |
| 118 | + wire slow_clk; |
| 119 | + |
| 120 | + slow_clk_gen # (.fast_clk_mhz (clk_mhz), .slow_clk_hz (1)) |
| 121 | + i_slow_clk_gen (.slow_clk (slow_clk), .*); |
| 122 | + |
| 123 | + //------------------------------------------------------------------------ |
| 124 | + |
| 125 | + wire [w_x - 1:0] mirrored_x = w_x' (screen_width - 1 - x); |
| 126 | + wire [w_y - 1:0] mirrored_y = w_y' (screen_height - 1 - y); |
| 127 | + |
| 128 | + //------------------------------------------------------------------------ |
| 129 | + |
| 130 | + lab_top |
| 131 | + # ( |
| 132 | + .clk_mhz ( clk_mhz ), |
| 133 | + |
| 134 | + .w_key ( w_lab_key ), // The last key is used for a reset |
| 135 | + .w_sw ( w_lab_key ), |
| 136 | + .w_led ( w_lab_led ), |
| 137 | + .w_digit ( w_lab_digit ), |
| 138 | + .w_gpio ( w_gpio ), |
| 139 | + |
| 140 | + .screen_width ( screen_width ), |
| 141 | + .screen_height ( screen_height ), |
| 142 | + |
| 143 | + .w_red ( w_red ), |
| 144 | + .w_green ( w_green ), |
| 145 | + .w_blue ( w_blue ) |
| 146 | + ) |
| 147 | + i_lab_top |
| 148 | + ( |
| 149 | + .clk ( clk ), |
| 150 | + .slow_clk ( slow_clk ), |
| 151 | + .rst ( rst ), |
| 152 | + |
| 153 | + .key ( lab_key ), |
| 154 | + .sw ( lab_sw ), |
| 155 | + |
| 156 | + .led ( lab_led ), |
| 157 | + |
| 158 | + .abcdefgh ( abcdefgh ), |
| 159 | + .digit ( lab_digit ), |
| 160 | + |
| 161 | + .x ( mirrored_x ), |
| 162 | + .y ( mirrored_y ), |
| 163 | + |
| 164 | + .red ( LCD_R ), |
| 165 | + .green ( LCD_G ), |
| 166 | + .blue ( LCD_B ), |
| 167 | + |
| 168 | + .uart_rx ( UART_RX ), |
| 169 | + .uart_tx ( UART_TX ), |
| 170 | + |
| 171 | + .mic ( mic ), |
| 172 | + .sound ( sound ), |
| 173 | + |
| 174 | + .gpio ( ) |
| 175 | + ); |
| 176 | + |
| 177 | + //------------------------------------------------------------------------ |
| 178 | + |
| 179 | + wire [$left (abcdefgh):0] hgfedcba; |
| 180 | + `SWAP_BITS (hgfedcba, abcdefgh); |
| 181 | + |
| 182 | + assign HGFEDCBA = ~ hgfedcba; |
| 183 | + assign DIGIT = lab_digit; |
| 184 | + |
| 185 | + //------------------------------------------------------------------------ |
| 186 | + |
| 187 | + `ifdef INSTANTIATE_TM1638_BOARD_CONTROLLER_MODULE |
| 188 | + |
| 189 | + tm1638_board_controller |
| 190 | + # ( |
| 191 | + .clk_mhz ( clk_mhz ), |
| 192 | + .w_digit ( w_tm_digit ) |
| 193 | + ) |
| 194 | + i_tm1638 |
| 195 | + ( |
| 196 | + .clk ( clk ), |
| 197 | + .rst ( rst ), |
| 198 | + .hgfedcba ( hgfedcba ), |
| 199 | + .digit ( tm_digit ), |
| 200 | + .ledr ( tm_led ), |
| 201 | + .keys ( tm_key ), |
| 202 | + .sio_data ( GPIO[3] ), |
| 203 | + .sio_clk ( GPIO[5] ), |
| 204 | + .sio_stb ( GPIO[7] ) |
| 205 | + ); |
| 206 | + |
| 207 | + `endif |
| 208 | + |
| 209 | + //------------------------------------------------------------------------ |
| 210 | + |
| 211 | + `ifdef INSTANTIATE_MICROPHONE_INTERFACE_MODULE |
| 212 | + |
| 213 | + inmp441_mic_i2s_receiver_alt |
| 214 | + # ( |
| 215 | + .clk_mhz ( clk_mhz ) |
| 216 | + ) |
| 217 | + i_microphone |
| 218 | + ( |
| 219 | + .clk ( clk ), |
| 220 | + .rst ( rst ), |
| 221 | + .right ( right ), |
| 222 | + .lr ( GPIO[13] ), |
| 223 | + .ws ( GPIO[15] ), |
| 224 | + .sck ( GPIO[11] ), |
| 225 | + .sd ( GPIO[9] ), |
| 226 | + .value ( mic ) |
| 227 | + ); |
| 228 | + |
| 229 | + `endif |
| 230 | + |
| 231 | + //------------------------------------------------------------------------ |
| 232 | + |
| 233 | + `ifdef INSTANTIATE_SOUND_OUTPUT_INTERFACE_MODULE |
| 234 | + |
| 235 | + // External DAC PCM5102A, Digilent Pmod AMP3, UDA1334A |
| 236 | + |
| 237 | + i2s_audio_out |
| 238 | + # ( |
| 239 | + .clk_mhz ( clk_mhz ), |
| 240 | + .in_res ( w_sound ), |
| 241 | + .align_right ( 1'b0 ), |
| 242 | + .offset_by_one_cycle ( 1'b1 ) |
| 243 | + ) |
| 244 | + i_ext_audio_out |
| 245 | + ( |
| 246 | + .clk ( clk ), |
| 247 | + .reset ( rst ), |
| 248 | + .data_in ( sound ), |
| 249 | + .mclk ( GPIO[8] ), |
| 250 | + .bclk ( GPIO[10] ), |
| 251 | + .lrclk ( GPIO[14] ), |
| 252 | + .sdata ( GPIO[12] ) |
| 253 | + ); |
| 254 | + |
| 255 | + `endif |
| 256 | + |
| 257 | +endmodule |
0 commit comments