hdmi_text_2x.v 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /*
  2. * hdmi_text_2x.v
  3. *
  4. * vim: ts=4 sw=4
  5. *
  6. * HDMI text generator core top level running in 1:2 mode
  7. *
  8. * Copyright (C) 2019 Sylvain Munaut <tnt@246tNt.com>
  9. * All rights reserved.
  10. *
  11. * BSD 3-clause, see LICENSE.bsd
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions are met:
  15. * * Redistributions of source code must retain the above copyright
  16. * notice, this list of conditions and the following disclaimer.
  17. * * Redistributions in binary form must reproduce the above copyright
  18. * notice, this list of conditions and the following disclaimer in the
  19. * documentation and/or other materials provided with the distribution.
  20. * * Neither the name of the <organization> nor the
  21. * names of its contributors may be used to endorse or promote products
  22. * derived from this software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  25. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  26. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  27. * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
  28. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  29. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  30. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  31. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  32. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. `default_nettype none
  36. module hdmi_text_2x #(
  37. parameter integer DW = 4
  38. )(
  39. // HDMI pads
  40. output wire [DW-1:0] hdmi_data,
  41. output wire hdmi_hsync,
  42. output wire hdmi_vsync,
  43. output wire hdmi_de,
  44. output wire hdmi_clk,
  45. // Bus interface
  46. input wire [15:0] bus_addr,
  47. input wire [15:0] bus_din,
  48. output wire [15:0] bus_dout,
  49. input wire bus_cyc,
  50. input wire bus_we,
  51. output wire bus_ack,
  52. // Clock / Reset
  53. input wire clk_1x,
  54. input wire clk_2x,
  55. input wire rst
  56. );
  57. // Signals
  58. // -------
  59. // Timing generator
  60. wire tg_hsync;
  61. wire tg_vsync;
  62. wire tg_active;
  63. wire tg_h_first;
  64. wire tg_h_last;
  65. wire tg_v_first;
  66. wire tg_v_last;
  67. // Text generator pixels
  68. wire [15:0] txt_data0;
  69. wire [15:0] txt_data1;
  70. // Video output
  71. wire vo_hsync;
  72. wire vo_vsync;
  73. wire vo_active;
  74. reg vo_toggle = 1'b0;
  75. reg [ 3:0] vo_data0;
  76. reg [ 3:0] vo_data1;
  77. // Timing generation
  78. // -----------------
  79. vid_tgen tgen_I (
  80. .vid_hsync(tg_hsync),
  81. .vid_vsync(tg_vsync),
  82. .vid_active(tg_active),
  83. .vid_h_first(tg_h_first),
  84. .vid_h_last(tg_h_last),
  85. .vid_v_first(tg_v_first),
  86. .vid_v_last(tg_v_last),
  87. .clk(clk_1x),
  88. .rst(rst)
  89. );
  90. // Video text mode
  91. // ---------------
  92. vid_text text_I (
  93. .vid_active_0(tg_active),
  94. .vid_h_first_0(tg_h_first),
  95. .vid_h_last_0(tg_h_last),
  96. .vid_v_first_0(tg_v_first),
  97. .vid_v_last_0(tg_v_last),
  98. .vid_pix0_11(txt_data0),
  99. .vid_pix1_11(txt_data1),
  100. .bus_addr(bus_addr),
  101. .bus_din(bus_din),
  102. .bus_dout(bus_dout),
  103. .bus_cyc(bus_cyc),
  104. .bus_we(bus_we),
  105. .bus_ack(bus_ack),
  106. .clk(clk_1x),
  107. .rst(rst)
  108. );
  109. // Video output
  110. // ------------
  111. // Align required sync signals
  112. delay_bit #(12) dly_hsync ( .d(tg_hsync), .q(vo_hsync), .clk(clk_1x) );
  113. delay_bit #(12) dly_vsync ( .d(tg_vsync), .q(vo_vsync), .clk(clk_1x) );
  114. delay_bit #(12) dly_active ( .d(tg_active), .q(vo_active), .clk(clk_1x) );
  115. // Pixel color map
  116. always @(posedge clk_1x)
  117. begin
  118. vo_toggle <= ~rst & (vo_toggle ^ (tg_v_first & tg_h_first));
  119. vo_data0 <= vo_toggle ? txt_data0[7:4] : txt_data0[3:0];
  120. vo_data1 <= vo_toggle ? txt_data1[7:4] : txt_data1[3:0];
  121. end
  122. // PHY
  123. // ---
  124. hdmi_phy_2x #(
  125. .DW(DW)
  126. ) phy_I (
  127. .hdmi_data(hdmi_data),
  128. .hdmi_hsync(hdmi_hsync),
  129. .hdmi_vsync(hdmi_vsync),
  130. .hdmi_de(hdmi_de),
  131. .hdmi_clk(hdmi_clk),
  132. .in_data0(vo_data0),
  133. .in_data1(vo_data1),
  134. .in_hsync(vo_hsync),
  135. .in_vsync(vo_vsync),
  136. .in_de(vo_active),
  137. .clk_1x(clk_1x),
  138. .clk_2x(clk_2x)
  139. );
  140. endmodule // hdmi_text_2x