Debian Codegraph @

examples/SPX9.v

raw
1 `default_nettype none
2 (* top *)
3 module top
4 (
5 input wire rst_i,
6 input wire clk,
7
8 output wire LCD_CLK,
9 output wire LCD_HYNC,
10 output wire LCD_SYNC,
11 output wire LCD_DEN,
12 output wire [`R_MSB:0] LCD_R,
13 output wire [`G_MSB:0] LCD_G,
14 output wire [`B_MSB:0] LCD_B
15 );
16
17 wire rst = rst_i ^ `INV_BTN;
18 wire pixel_clk;
19 wire write_clk;
20
21 wire gnd;
22 assign gnd = 1'b0;
23
24 clock_pll clock_pll(
25 .clk(clk),
26 .rst(rst),
27 .write_clk(write_clk),
28 .pixel_clk(pixel_clk));
29
30 assign LCD_CLK = pixel_clk;
31
32 reg [15:0] pixel_count;
33 reg [15:0] line_count;
34
35 display display(
36 .pixel_clk(pixel_clk),
37 .rst(rst),
38 .x(pixel_count),
39 .y(line_count),
40 .LCD_HYNC(LCD_HYNC),
41 .LCD_SYNC(LCD_SYNC),
42 .LCD_DEN(LCD_DEN)
43 );
44
45 wire [8:0] rom_data;
46 wire [10:0] read_addr;
47 reg [16:0] write_addr;
48
49 image_rom image(
50 .clk(pixel_clk),
51 .reset(!rst),
52 .ad(write_addr[16:5]),
53 .data(rom_data)
54 );
55
56 wire [8:0] dout;
57 reg [10:0] rw_addr;
58
59 video_ram vmem(
60 .clk(pixel_clk),
61 .reset(!rst),
62 .wre(!LCD_DEN),
63 .ad(rw_addr),
64 .read_data(dout),
65 .write_data(rom_data)
66 );
67
68
69 wire [7:0] vmem_start_col;
70 wire [7:0] vmem_start_row;
71 assign vmem_start_col = pixel_count - `START_X;
72 assign vmem_start_row = line_count - `START_Y;
73
74 assign read_addr = {vmem_start_row[7:2], vmem_start_col[7:2]};
75
76 wire is_out_x = pixel_count < `START_X || pixel_count >= `STOP_X;
77 wire is_out_y = line_count < `START_Y || line_count >= `STOP_Y;
78
79 always @(negedge pixel_clk) begin
80 if (is_out_x) begin
81 rw_addr <= write_addr[15:5];
82 end else begin
83 rw_addr <= read_addr;
84 end
85 end
86
87 reg [15:0] color;
88 always @(posedge pixel_clk) begin
89 if (is_out_x || is_out_y) begin
90 color = line_count + pixel_count;
91 end else begin
92 color = {dout[8:4], dout[8:3], dout[8:4]};
93 end
94 end
95
96 always @(posedge write_clk or negedge rst) begin
97 if (!rst) begin
98 write_addr <= 0;
99 end else begin
100 write_addr <= write_addr + 1;
101 end
102 end
103
104 assign LCD_R = LCD_DEN ? color[4:0] >> (4 - `R_MSB) : 0;
105 assign LCD_G = LCD_DEN ? color[10:5] >> (5 - `G_MSB) : 0;
106 assign LCD_B = LCD_DEN ? color[15:11] >> (4 - `B_MSB) : 0;
107
108 endmodule
109