go-board-code/vga_tester.v

220 lines
5.5 KiB
Coq
Raw Normal View History

2024-07-06 18:51:29 +00:00
module VGA_Tester(
input i_Clk,
output o_VGA_HSync,
output o_VGA_VSync,
output o_VGA_Red_0,
output o_VGA_Red_1,
output o_VGA_Red_2,
output o_VGA_Grn_0,
output o_VGA_Grn_1,
output o_VGA_Grn_2,
output o_VGA_Blu_0,
output o_VGA_Blu_1,
output o_VGA_Blu_2,
input i_UART_RX,
output o_UART_TX,
output o_Segment1_A,
output o_Segment1_B,
output o_Segment1_C,
output o_Segment1_D,
output o_Segment1_E,
output o_Segment1_F,
output o_Segment1_G,
output o_Segment2_A,
output o_Segment2_B,
output o_Segment2_C,
output o_Segment2_D,
output o_Segment2_E,
output o_Segment2_F,
output o_Segment2_G
);
localparam TOTAL_COLUMNS = 800;
localparam TOTAL_ROWS = 525;
localparam ACTIVE_COLUMNS = 640;
localparam ACTIVE_ROWS = 480;
localparam VIDEO_WIDTH = 3;
// vga
wire w_HSync_Start, w_VSync_Start;
wire w_HSync_FromTestPattern, w_VSync_FromTestPattern;
wire w_HSync_FromPorchSync, w_VSync_FromPorchSync;
wire [VIDEO_WIDTH-1:0] w_Red_FromTestPattern;
wire [VIDEO_WIDTH-1:0] w_Red_FromPorchSync;
wire [VIDEO_WIDTH-1:0] w_Green_FromTestPattern;
wire [VIDEO_WIDTH-1:0] w_Green_FromPorchSync;
wire [VIDEO_WIDTH-1:0] w_Blue_FromTestPattern;
wire [VIDEO_WIDTH-1:0] w_Blue_FromPorchSync;
reg [3:0] r_currentPattern = 6;
// uart
wire w_dataReady;
wire [7:0] w_dataByte;
wire w_transmitActive, w_transmitSerial;
wire w_segment1_A, w_segment2_A;
wire w_segment1_B, w_segment2_B;
wire w_segment1_C, w_segment2_C;
wire w_segment1_D, w_segment2_D;
wire w_segment1_E, w_segment2_E;
wire w_segment1_F, w_segment2_F;
wire w_segment1_G, w_segment2_G;
reg r_resetTransmit = 1;
// accept incoming data
UART_RX #(
.CLOCKS_PER_SECOND(25000000),
.BAUD_RATE(115200)
) MyUART_RX (
.i_Clk(i_Clk),
.i_ReceiveBit(i_UART_RX),
.o_DataReady(w_dataReady),
.o_DataByte(w_dataByte)
);
UART_TX #(
.CLOCKS_PER_SECOND(25000000),
.BAUD_RATE(115200)
) MyUART_TX (
.i_Clk(i_Clk),
.i_Reset_Low(r_resetTransmit),
.i_TransmitReady(w_dataReady),
.i_TransmitByte(w_dataByte),
.o_Active(w_transmitActive),
.o_Output(w_transmitSerial),
.o_Done()
);
assign o_UART_TX = w_transmitActive ? w_transmitSerial : 1;
Binary_to_7_Segment Segment_1 (
.i_Clk(i_Clk),
.i_Number(w_dataByte[7:4]),
.o_SegA(w_segment1_A),
.o_SegB(w_segment1_B),
.o_SegC(w_segment1_C),
.o_SegD(w_segment1_D),
.o_SegE(w_segment1_E),
.o_SegF(w_segment1_F),
.o_SegG(w_segment1_G)
);
assign o_Segment1_A = !w_segment1_A;
assign o_Segment1_B = !w_segment1_B;
assign o_Segment1_C = !w_segment1_C;
assign o_Segment1_D = !w_segment1_D;
assign o_Segment1_E = !w_segment1_E;
assign o_Segment1_F = !w_segment1_F;
assign o_Segment1_G = !w_segment1_G;
Binary_to_7_Segment Segment_2 (
.i_Clk(i_Clk),
.i_Number(w_dataByte[3:0]),
.o_SegA(w_segment2_A),
.o_SegB(w_segment2_B),
.o_SegC(w_segment2_C),
.o_SegD(w_segment2_D),
.o_SegE(w_segment2_E),
.o_SegF(w_segment2_F),
.o_SegG(w_segment2_G)
);
assign o_Segment2_A = !w_segment2_A;
assign o_Segment2_B = !w_segment2_B;
assign o_Segment2_C = !w_segment2_C;
assign o_Segment2_D = !w_segment2_D;
assign o_Segment2_E = !w_segment2_E;
assign o_Segment2_F = !w_segment2_F;
assign o_Segment2_G = !w_segment2_G;
always @(posedge i_Clk) begin
if (w_dataReady) begin
r_currentPattern <= w_dataByte[3:0];
end
end
// show the video
VGA_Sync_Pulse_Generator #(
.TOTAL_COLUMNS(TOTAL_COLUMNS),
.TOTAL_ROWS(TOTAL_ROWS),
.ACTIVE_COLUMNS(ACTIVE_COLUMNS),
.ACTIVE_ROWS(ACTIVE_ROWS)
) SyncGenerator (
.i_Clk(i_Clk),
.o_HSync(w_HSync_Start),
.o_VSync(w_VSync_Start),
.o_rawX(),
.o_rawY()
);
VGA_Pattern_Generator #(
.VIDEO_WIDTH(VIDEO_WIDTH),
.TOTAL_COLUMNS(TOTAL_COLUMNS),
.TOTAL_ROWS(TOTAL_ROWS),
.ACTIVE_COLUMNS(ACTIVE_COLUMNS),
.ACTIVE_ROWS(ACTIVE_ROWS)
) PatternGenerator (
.i_Clk(i_Clk),
.i_Pattern(r_currentPattern),
.i_HSync(w_HSync_Start),
.i_VSync(w_VSync_Start),
.o_HSync(w_HSync_FromTestPattern),
.i_Clk(i_Clk),
.i_Pattern(r_currentPattern),
.i_HSync(w_HSync_Start),
.i_VSync(w_VSync_Start),
.o_HSync(w_HSync_FromTestPattern),
.o_VSync(w_VSync_FromTestPattern),
.o_Red(w_Red_FromTestPattern),
.o_Green(w_Green_FromTestPattern),
.o_Blue(w_Blue_FromTestPattern)
);
VGA_Add_Porches_To_Output #(
.VIDEO_WIDTH(VIDEO_WIDTH),
.TOTAL_COLUMNS(TOTAL_COLUMNS),
.TOTAL_ROWS(TOTAL_ROWS),
.ACTIVE_COLUMNS(ACTIVE_COLUMNS),
.ACTIVE_ROWS(ACTIVE_ROWS)
) PorchBuilder (
.i_Clk(i_Clk),
.i_HSync(w_HSync_FromTestPattern),
.i_VSync(w_VSync_FromTestPattern),
.i_Red(w_Red_FromTestPattern),
.i_Green(w_Green_FromTestPattern),
.i_Blue(w_Blue_FromTestPattern),
.o_HSync(w_HSync_FromPorchSync),
.o_VSync(w_VSync_FromPorchSync),
.o_Red(w_Red_FromPorchSync),
.o_Green(w_Green_FromPorchSync),
.o_Blue(w_Blue_FromPorchSync)
);
assign o_VGA_HSync = w_HSync_FromPorchSync;
assign o_VGA_VSync = w_VSync_FromPorchSync;
assign o_VGA_Red_0 = w_Red_FromPorchSync[0];
assign o_VGA_Red_1 = w_Red_FromPorchSync[1];
assign o_VGA_Red_2 = w_Red_FromPorchSync[2];
assign o_VGA_Grn_0 = w_Green_FromPorchSync[0];
assign o_VGA_Grn_1 = w_Green_FromPorchSync[1];
assign o_VGA_Grn_2 = w_Green_FromPorchSync[2];
assign o_VGA_Blu_0 = w_Blue_FromPorchSync[0];
assign o_VGA_Blu_1 = w_Blue_FromPorchSync[1];
assign o_VGA_Blu_2 = w_Blue_FromPorchSync[2];
endmodule