rgb_encoder.vhd 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.STD_LOGIC_ARITH.ALL;
  4. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  5. ---- Uncomment the following library declaration if instantiating
  6. ---- any Xilinx primitives in this code.
  7. --library UNISIM;
  8. --use UNISIM.VComponents.all;
  9. entity rgb_encoder is
  10. port(
  11. CLK14M : in std_logic;
  12. CREF : in std_logic;
  13. nSEROUT : in std_logic;
  14. nSYNC : in std_logic;
  15. TEXT : in std_logic;
  16. GR : in std_logic;
  17. RED : out std_logic_vector(1 downto 0);
  18. GREEN : out std_logic_vector(1 downto 0);
  19. BLUE : out std_logic_vector(1 downto 0);
  20. nSYNCOUT : out std_logic
  21. );
  22. end rgb_encoder;
  23. architecture rtl of rgb_encoder is
  24. signal R : std_logic_vector(1 downto 0) := "00";
  25. signal G : std_logic_vector(1 downto 0) := "00";
  26. signal B : std_logic_vector(1 downto 0) := "00";
  27. signal COLCLK : std_logic_vector(3 downto 0) := "1111";
  28. signal COLPAT : std_logic_vector(3 downto 0) := "1111";
  29. begin
  30. RED <= R;
  31. GREEN <= G;
  32. BLUE <= B;
  33. nSYNCOUT <= nSYNC;
  34. process(CLK14M, nSEROUT, CREF, GR)
  35. variable COLPAT2 : std_logic_vector(3 downto 0);
  36. begin
  37. if falling_edge(CLK14M) then
  38. COLCLK <= COLCLK(2 downto 0) & CREF;
  39. COLPAT <= COLPAT(2 downto 0) & nSEROUT;
  40. if GR = '1' then
  41. if COLCLK = "0011" or COLCLK = "1100" then
  42. if COLCLK = "0011" then
  43. COLPAT2 := COLPAT;
  44. else
  45. COLPAT2 := COLPAT(1 downto 0) & COLPAT(3 downto 2);
  46. end if;
  47. case COLPAT2 is
  48. when "1011" => -- 1 - 0x90 17 40
  49. R <= "10";
  50. G <= "00";
  51. B <= "01";
  52. when "1101" => -- 2 - 0x40 2c a5
  53. R <= "01";
  54. G <= "00";
  55. B <= "10";
  56. when "1001" => -- 3 - 0xd0 43 e5
  57. R <= "11";
  58. G <= "01";
  59. B <= "11";
  60. when "1110" => -- 4 - 0x00 69 40
  61. R <= "00";
  62. G <= "01";
  63. B <= "01";
  64. when "1010" => -- 5 - 0x80 80 80
  65. R <= "10";
  66. G <= "10";
  67. B <= "10";
  68. when "1100" => -- 6 - 0x2f 95 e5
  69. R <= "00";
  70. G <= "10";
  71. B <= "11";
  72. when "1000" => -- 7 - 0xbf ab ff
  73. R <= "11";
  74. G <= "10";
  75. B <= "11";
  76. when "0111" => -- 8 - 0x40 54 00
  77. R <= "01";
  78. G <= "01";
  79. B <= "00";
  80. when "0011" => -- 9 - 0xd0 6a 1a
  81. R <= "11";
  82. G <= "01";
  83. B <= "00";
  84. when "0101" => -- 10 - 0x80 80 80
  85. R <= "01";
  86. G <= "01";
  87. B <= "01";
  88. when "0001" => -- 11 - 0xff 96 bf
  89. R <= "11";
  90. G <= "10";
  91. B <= "11";
  92. when "0110" => -- 12 - 0x2f bc 1a
  93. R <= "00";
  94. G <= "11";
  95. B <= "00";
  96. when "0010" => -- 13 - 0xbf d3 5a
  97. R <= "11";
  98. G <= "11";
  99. B <= "01";
  100. when "0100" => -- 14 - 0x6f e8 bf
  101. R <= "01";
  102. G <= "11";
  103. B <= "11";
  104. when "0000" => -- 15 - 0xff ff ff
  105. R <= "11";
  106. G <= "11";
  107. B <= "11";
  108. when others => -- 0 - 0x00 00 00
  109. R <= "00";
  110. G <= "00";
  111. B <= "00";
  112. end case;
  113. end if;
  114. else
  115. if COLPAT(3) = '1' then
  116. R <= "00";
  117. G <= "00";
  118. B <= "00";
  119. else
  120. R <= "11";
  121. G <= "11";
  122. B <= "11";
  123. end if;
  124. end if;
  125. end if;
  126. end process;
  127. end rtl;