From cad870295dfb741d5c24c25016c5bba878bc37e5 Mon Sep 17 00:00:00 2001 From: Alejandro Soto Date: Sun, 13 Nov 2022 22:37:10 -0600 Subject: Implement VGA controller --- platform.qsys | 18 ++--- rtl/vga.sv | 182 +++++++++++++++++++++++++++++++++++++++++++++----- vga_controller_hw.tcl | 7 +- 3 files changed, 179 insertions(+), 28 deletions(-) diff --git a/platform.qsys b/platform.qsys index 51c1d54..9ccd6ed 100644 --- a/platform.qsys +++ b/platform.qsys @@ -875,7 +875,7 @@ - + @@ -887,9 +887,9 @@ - - - + + + @@ -924,7 +924,7 @@ - + @@ -947,7 +947,7 @@ - + @@ -959,7 +959,7 @@ Automatic Switchover - + @@ -990,7 +990,7 @@ - + @@ -1097,7 +1097,7 @@ = H_BPORCH && next_x < H_FPORCH_AT + && next_y >= V_BPORCH && next_y < V_FPORCH_AT; + + always_comb begin + unique case(reading) + A: current = read_a; + B: current = read_b; + endcase + + if(x != H_TOTAL - 1) begin + next_x = x + 1; + next_y = y; + end else begin + next_x = 0; + next_y = y != V_TOTAL - 1 ? y + 1 : 0; + end + end + + always @(posedge clk or negedge rst_n) + if(!rst_n) begin + x <= H_TOTAL - 1; + y <= V_TOTAL - 1; + reading <= A; + write_idx <= 0; + pending_read <= 0; + pending_data <= 0; + fill_start_reading <= A; + + read_a <= 0; + read_b <= 0; + + addr <= 0; + avl_read <= 0; + + vga_hsync <= 0; + vga_vsync <= 0; + end else begin + if(next_active) + unique case(next_reading) + A: read_a <= scanline_a[read_idx]; + B: read_b <= scanline_b[read_idx]; + endcase + + if(avl_readdatavalid) begin + unique case(fill_start_reading) + A: scanline_b[write_idx] <= avl_readdata; + B: scanline_a[write_idx] <= avl_readdata; + endcase + + write_idx <= write_idx + 1; + pending_data <= pending_data - 1; + end + + if(!avl_read || !avl_waitrequest) begin + avl_read <= 0; + + if(pending_read != 0) begin + addr <= addr + 1; + avl_read <= 1; + pending_read <= pending_read - 1; + end + end + + if(pending_read == 0 && pending_data == 0 && next_reading != reading) begin + if(y >= V_BPORCH - 2 && y < V_FPORCH_AT - 2) begin + write_idx <= 0; + pending_read <= H_ACTIVE; + pending_data <= H_ACTIVE; + fill_start_reading <= next_reading; + end else + addr <= {$bits(addr){1'b1}}; + end + + x <= next_x; + y <= next_y; + reading <= next_reading; + + vga_hsync <= next_x < H_SYNC_AT; + vga_vsync <= next_y < V_SYNC_AT; + end endmodule diff --git a/vga_controller_hw.tcl b/vga_controller_hw.tcl index 2816d9c..bf95f0a 100644 --- a/vga_controller_hw.tcl +++ b/vga_controller_hw.tcl @@ -1,11 +1,11 @@ # TCL File Generated by Component Editor 20.1 -# Thu Nov 03 11:42:18 CST 2022 +# Mon Nov 14 02:57:50 GMT 2022 # DO NOT MODIFY # # vga_controller "vga_controller" v1.0 -# Alejandro Soto 2022.11.03.11:42:18 +# Alejandro Soto 2022.11.14.02:57:50 # # @@ -110,8 +110,9 @@ set_interface_property avalon_master SVD_ADDRESS_GROUP "" add_interface_port avalon_master avl_address address Output 26 add_interface_port avalon_master avl_read read Output 1 -add_interface_port avalon_master avl_readdata readdata Input 32 +add_interface_port avalon_master avl_readdata readdata Input 16 add_interface_port avalon_master avl_waitrequest waitrequest Input 1 +add_interface_port avalon_master avl_readdatavalid readdatavalid Input 1 # -- cgit v1.2.3