RGB2HDMI.v 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. module RGB2HDMI(
  2. input clkTMDS,
  3. input clkRGB,
  4. input [7:0] rRGB,
  5. input [7:0] gRGB,
  6. input [7:0] bRGB,
  7. input blk,
  8. input hs,
  9. input vs,
  10. output wire rTMDS,
  11. output wire gTMDS,
  12. output wire bTMDS,
  13. output wire cTMDS
  14. );
  15. wire [9:0] encodedRed;
  16. wire [9:0] encodedGreen;
  17. wire [9:0] encodedBlue;
  18. reg [9:0] latchedRed = 10'd0;
  19. reg [9:0] latchedGreen = 10'd0;
  20. reg [9:0] latchedBlue = 10'd0;
  21. reg [9:0] shiftRed = 10'd0;
  22. reg [9:0] shiftGreen = 10'd0;
  23. reg [9:0] shiftBlue = 10'd0;
  24. reg [9:0] shiftClk = 10'b0000011111;
  25. TMDSenc TMDSr(
  26. .clk (clkRGB),
  27. .data(rRGB),
  28. .c (2'd0),
  29. .blk (blk),
  30. .q (encodedRed)
  31. );
  32. TMDSenc TMDSg(
  33. .clk (clkRGB),
  34. .data(gRGB),
  35. .c (2'd0),
  36. .blk (blk),
  37. .q (encodedGreen)
  38. );
  39. TMDSenc TMDSb(
  40. .clk (clkRGB),
  41. .data(bRGB),
  42. .c ({vs, hs}),
  43. .blk (blk),
  44. .q (encodedBlue)
  45. );
  46. // Everything is inverted here because of a LVDS polarity swap on the V3 PCB
  47. ddr ddrR(
  48. .outclock(clkTMDS),
  49. .datain_h(!shiftRed[0]),
  50. .datain_l(!shiftRed[1]),
  51. .dataout (rTMDS)
  52. );
  53. ddr ddrG(
  54. .outclock(clkTMDS),
  55. .datain_h(!shiftGreen[0]),
  56. .datain_l(!shiftGreen[1]),
  57. .dataout (gTMDS)
  58. );
  59. ddr ddrB(
  60. .outclock(clkTMDS),
  61. .datain_h(!shiftBlue[0]),
  62. .datain_l(!shiftBlue[1]),
  63. .dataout (bTMDS)
  64. );
  65. ddr ddrCLK(
  66. .outclock(clkTMDS),
  67. .datain_h(!shiftClk[0]),
  68. .datain_l(!shiftClk[1]),
  69. .dataout (cTMDS)
  70. );
  71. always @(posedge clkRGB)
  72. begin
  73. latchedRed <= encodedRed;
  74. latchedGreen <= encodedGreen;
  75. latchedBlue <= encodedBlue;
  76. end
  77. always @(posedge clkTMDS)
  78. begin
  79. if (shiftClk == 10'b0000011111)
  80. begin
  81. shiftRed <= latchedRed;
  82. shiftGreen <= latchedGreen;
  83. shiftBlue <= latchedBlue;
  84. end
  85. else
  86. begin
  87. shiftRed <= {2'b00, shiftRed[9:2]};
  88. shiftGreen <= {2'b00, shiftGreen[9:2]};
  89. shiftBlue <= {2'b00, shiftBlue[9:2]};
  90. end
  91. shiftClk <= {shiftClk[1:0], shiftClk[9:2]};
  92. end
  93. endmodule