OpenCores
URL https://opencores.org/ocsvn/vga_lcd/vga_lcd/trunk

Subversion Repositories vga_lcd

[/] [vga_lcd/] [trunk/] [rtl/] [vhdl/] [colproc.vhd] - Blame information for rev 62

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 rudi
--
2
-- File colproc.vhd, Color Processor
3
-- Project: VGA
4
-- Author : Richard Herveille. Ideas and thoughts: Sherif Taher Eid
5
-- rev.: 0.1 May     1st, 2001
6
-- rev.: 0.2 June   23rd, 2001. Removed unused "prev_state" references from statemachine. Removed unused "dWB_Di" signal.
7
-- rev.: 1.0 July    6th, 2001. Fixed a bug where the core did not repond correctly to a delayed clut_ack signal in 8bpp_pseudo_color mode.
8
-- rev.: 1.1 August  2nd, 2001. Changed 24bpp section in output-decoder. Smaller/faster synthesis results.
9
 
10
library ieee;
11
use ieee.std_logic_1164.all;
12
use ieee.std_logic_arith.all;
13
 
14
entity colproc is
15
        port(
16
                clk : in std_logic;                            -- master clock
17
                ctrl_Ven : in std_logic;                       -- Video Enable
18
 
19
                pixel_buffer_Di,                               -- Pixel Buffer data input
20
                WB_Di : in std_logic_vector(31 downto 0);      -- WISHBONE data input
21
 
22
                ColorDepth : in std_logic_vector(1 downto 0);  -- color depth (8bpp, 16bpp, 24bpp)
23
                PseudoColor : in std_logic;                    -- pseudo color enabled (only for 8bpp color depth)
24
 
25
                pixel_buffer_empty : in std_logic;
26
                pixel_buffer_rreq : buffer std_logic;          -- pixel buffer read request
27
 
28
                RGB_fifo_full : in std_logic;
29
                RGB_fifo_wreq : out std_logic;
30
                R,G,B : out std_logic_vector(7 downto 0);      -- pixel color (to RGB fifo)
31
 
32
                clut_req : out std_logic;                      -- CLUT access request
33
                clut_offs: out unsigned(7 downto 0);           -- offset into color lookup table
34
                clut_ack : in std_logic                        -- CLUT data acknowledge
35
        );
36
end entity colproc;
37
 
38
architecture structural of colproc is
39
        signal DataBuffer : std_logic_vector(31 downto 0);
40
        signal colcnt : unsigned(1 downto 0);
41
        signal RGBbuf_wreq : std_logic;
42
begin
43
        -- store word from pixelbuffer / wishbone input
44
        process(clk)
45
        begin
46
                if (clk'event and clk = '1') then
47
                        if (pixel_buffer_rreq = '1') then
48
                                DataBuffer <= pixel_buffer_Di;
49
                        end if;
50
                end if;
51
        end process;
52
 
53
        -- extract color information from data buffer
54
        statemachine: block
55
                type states is (idle, fill_buf, bw_8bpp, col_8bpp, col_16bpp_a, col_16bpp_b, col_24bpp);
56
                signal c_state : states;
57
 
58
                signal Ra, Ga, Ba : std_logic_vector(7 downto 0);
59
        begin
60
                gen_nxt_state: process(clk, c_state, pixel_buffer_empty, ColorDepth, PseudoColor, RGB_fifo_full, colcnt, clut_ack)
61
                        variable nxt_state : states;
62
                begin
63
 
64
                        -- initial value
65
                        nxt_state := c_state;
66
 
67
                        case c_state is
68
                                -- idle state
69
                                when idle =>
70
                                        if (pixel_buffer_empty = '0') then
71
                                                nxt_state := fill_buf;
72
                                        end if;
73
 
74
                                when fill_buf =>
75
                                        case ColorDepth is
76
                                                when "00" =>
77
                                                        if (PseudoColor = '1') then
78
                                                                nxt_state := col_8bpp;
79
                                                        else
80
                                                                nxt_state := bw_8bpp;
81
                                                        end if;
82
 
83
                                                when "01" =>
84
                                                        nxt_state := col_16bpp_a;
85
 
86
                                                when others =>
87
                                                        nxt_state := col_24bpp;
88
 
89
                                        end case;
90
 
91
                                --
92
                                -- 8 bits per pixel
93
                                --
94
                                when bw_8bpp =>
95
                                        if ((RGB_fifo_full = '0') and (colcnt = 0)) then
96
                                                nxt_state := idle;
97
                                        end if;
98
 
99
                                when col_8bpp =>
100
                                        if ((RGB_fifo_full = '0') and (colcnt = 0)) then
101
                                                if (clut_ack = '1') then
102
                                                        nxt_state := idle;
103
                                                end if;
104
                                        end if;
105
 
106
                                --
107
                                -- 16 bits per pixel
108
                                --
109
                                when col_16bpp_a =>
110
                                        if (RGB_fifo_full = '0') then
111
                                                nxt_state := col_16bpp_b;
112
                                        end if;
113
 
114
                                when col_16bpp_b =>
115
                                        if (RGB_fifo_full = '0') then
116
                                                nxt_state := idle;
117
                                        end if;
118
 
119
                                --
120
                                -- 24 bits per pixel
121
                                --
122
                                when col_24bpp =>
123
                                        if (RGB_fifo_full = '0') then
124
                                                if (colcnt = 1) then
125
                                                        nxt_state := col_24bpp; -- stay in current state
126
                                                else
127
                                                        nxt_state := idle;
128
                                                end if;
129
                                        end if;
130
                        end case;
131
 
132
                        if (clk'event and clk = '1') then
133
                                if (ctrl_Ven = '0') then
134
                                        c_state <= idle;
135
                                else
136
                                        c_state <= nxt_state;
137
                                end if;
138
                        end if;
139
                end process gen_nxt_state;
140
 
141
                --
142
                -- output decoder
143
                --
144
                gen_odec: process(clk, c_state, pixel_buffer_empty, colcnt, DataBuffer, RGB_fifo_full, clut_ack, WB_Di, Ba, Ga, Ra)
145
                        variable clut_acc : std_logic;
146
                        variable pixelbuf_rreq : std_logic;
147
                        variable iR, iG, iB, iRa, iGa, iBa : std_logic_vector(7 downto 0);
148
                begin
149
                        -- initial values
150
                        pixelbuf_rreq := '0';
151
                        RGBbuf_wreq <= '0';
152
                        clut_acc := '0';
153
 
154
                        iR := (others => '0');
155
                        iG := (others => '0');
156
                        iB := (others => '0');
157
                        iRa := (others => '0');
158
                        iGa := (others => '0');
159
                        iBa := (others => '0');
160
 
161
                        case c_state is
162
                                when idle =>
163
                                        if (pixel_buffer_empty = '0') then
164
                                                pixelbuf_rreq := '1';
165
                                        end if;
166
 
167
                                --              
168
                                -- 8 bits per pixel
169
                                --
170
                                when bw_8bpp =>
171
                                        if (RGB_fifo_full = '0') then
172
                                                RGBbuf_wreq <= '1';
173
                                        end if;
174
 
175
                                        case colcnt is
176
                                                when "11" =>
177
                                                        iR := DataBuffer(31 downto 24);
178
                                                        iG := iR;
179
                                                        iB := iR;
180
 
181
                                                when "10" =>
182
                                                        iR := DataBuffer(23 downto 16);
183
                                                        iG := iR;
184
                                                        iB := iR;
185
 
186
                                                when "01" =>
187
                                                        iR := DataBuffer(15 downto 8);
188
                                                        iG := iR;
189
                                                        iB := iR;
190
 
191
                                                when others =>
192
                                                        iR := DataBuffer(7 downto 0);
193
                                                        iG := iR;
194
                                                        iB := iR;
195
                                        end case;
196
 
197
                                when col_8bpp =>
198
                                        if ((RGB_fifo_full = '0') and (clut_ack = '1')) then
199
                                                RGBbuf_wreq <= '1';
200
                                        end if;
201
 
202
                                        iR := WB_Di(23 downto 16);
203
                                        iG := WB_Di(15 downto  8);
204
                                        iB := WB_Di( 7 downto  0);
205
 
206
                                        clut_acc := not RGB_fifo_full;
207
 
208
                                        if ((colcnt = 0) and (clut_ack = '1')) then
209
                                                clut_acc := '0';
210
                                        end if;
211
 
212
                                --
213
                                -- 16 bits per pixel
214
                                --
215
                                when col_16bpp_a =>
216
                                        if (RGB_fifo_full = '0') then
217
                                                RGBbuf_wreq <= '1';
218
                                        end if;
219
                                        iR(7 downto 3) := DataBuffer(31 downto 27);
220
                                        iG(7 downto 2) := DataBuffer(26 downto 21);
221
                                        iB(7 downto 3) := DataBuffer(20 downto 16);
222
 
223
                                when col_16bpp_b =>
224
                                        if (RGB_fifo_full = '0') then
225
                                                RGBbuf_wreq <= '1';
226
                                        end if;
227
                                        iR(7 downto 3) := DataBuffer(15 downto 11);
228
                                        iG(7 downto 2) := DataBuffer(10 downto  5);
229
                                        iB(7 downto 3) := DataBuffer( 4 downto  0);
230
 
231
                                --
232
                                -- 24 bits per pixel
233
                                --
234
                                when col_24bpp =>
235
                                        if (RGB_fifo_full = '0') then
236
                                                RGBbuf_wreq <= '1';
237
                                        end if;
238
 
239
                                        case colcnt is
240
                                        when "11" =>
241
                                                        iR  := DataBuffer(31 downto 24);
242
                                                        iG  := DataBuffer(23 downto 16);
243
                                                        iB  := DataBuffer(15 downto  8);
244
                                                        iRa := DataBuffer( 7 downto  0);
245
 
246
                                                when "10" =>
247
                                                        iR  := Ra;
248
                                                        iG  := DataBuffer(31 downto 24);
249
                                                        iB  := DataBuffer(23 downto 16);
250
                                                        iRa := DataBuffer(15 downto  8);
251
                                                        iGa := DataBuffer( 7 downto  0);
252
 
253
                                                when "01" =>
254
                                                        iR  := Ra;
255
                                                        iG  := Ga;
256
                                                        iB  := DataBuffer(31 downto 24);
257
                                                        iRa := DataBuffer(23 downto 16);
258
                                                        iGa := DataBuffer(15 downto  8);
259
                                                        iBa := DataBuffer( 7 downto  0);
260
 
261
                                                when others =>
262
                                                        iR := Ra;
263
                                                        iG := Ga;
264
                                                        iB := Ba;
265
                                        end case;
266
 
267
                                when others =>
268
                                        null;
269
 
270
                        end case;
271
 
272
                        if (clk'event and clk = '1') then
273
                                R  <= iR;
274
                                G  <= iG;
275
                                B  <= iB;
276
 
277
                                if (RGBbuf_wreq = '1') then
278
                                        Ra <= iRa;
279
                                        Ba <= iBa;
280
                                        Ga <= iGa;
281
                                end if;
282
 
283
                                if (ctrl_Ven = '0') then
284
                                        pixel_buffer_rreq <= '0';
285
                                        RGB_fifo_wreq <= '0';
286
                                        clut_req <= '0';
287
                                else
288
                                        pixel_buffer_rreq <= pixelbuf_rreq;
289
                                        RGB_fifo_wreq <= RGBbuf_wreq;
290
                                        clut_req <= clut_acc;
291
                                end if;
292
                        end if;
293
                end process gen_odec;
294
 
295
                -- assign clut offset
296
                with colcnt select
297
                        clut_offs <= unsigned(DataBuffer(31 downto 24)) when "11",
298
                                     unsigned(DataBuffer(23 downto 16)) when "10",
299
                                     unsigned(DataBuffer(15 downto  8)) when "01",
300
                                     unsigned(DataBuffer( 7 downto  0)) when others;
301
 
302
        end block statemachine;
303
 
304
 
305
        -- color counter
306
        gen_colcnt: process(clk)
307
        begin
308
                if (clk'event and clk = '1') then
309
                        if (ctrl_Ven = '0') then
310
                                colcnt <= (others => '1');
311
                        elsif (RGBbuf_wreq = '1') then
312
                                colcnt <= colcnt -1;
313
                        end if;
314
                end if;
315
        end process gen_colcnt;
316
 
317
end architecture structural;
318
 
319
 
320
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.