Debian Codegraph @

examples/SP.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 [7:0] rom_data;
46 reg [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 [7:0] dout;
57 wire [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 wire [7:0] vmem_start_col;
69 wire [7:0] vmem_start_row;
70 assign vmem_start_col = pixel_count - `START_X;
71 assign vmem_start_row = line_count - `START_Y;
72
73 always @(negedge pixel_clk) begin
74 read_addr = {vmem_start_row[7:2], vmem_start_col[7:2]};
75 end
76
77 wire is_out_x = pixel_count < `START_X || pixel_count >= `STOP_X;
78 wire is_out_y = line_count < `START_Y || line_count >= `STOP_Y;
79
80 assign rw_addr = is_out_x ? write_addr[15:5] : read_addr;
81
82 reg [15:0] color;
83 always @(posedge pixel_clk) begin
84 if (is_out_x || is_out_y) begin
85 color = line_count + pixel_count;
86 end else begin
87 color = {dout[4:0], dout[5:0], dout[4:0]};
88 end
89 end
90
91 always @(posedge write_clk or negedge rst) begin
92 if (!rst) begin
93 write_addr <= 0;
94 end else begin
95 write_addr <= write_addr + 1;
96 end
97 end
98
99 assign LCD_R = LCD_DEN ? color[4:0] >> (4 - `R_MSB) : 0;
100 assign LCD_G = LCD_DEN ? color[10:5] >> (5 - `G_MSB) : 0;
101 assign LCD_B = LCD_DEN ? color[15:11] >> (4 - `B_MSB) : 0;
102
103 endmodule
104