You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.2 KiB

  1. /*
  2. CONNECTION from ESP32 to a composite video TV
  3. A) voltageDivider = false; B) voltageDivider = true
  4. 55 shades 179 shades
  5. ESP32 TV ESP32 TV
  6. -----+ -----+ ____ 100 ohm
  7. G|- G|---|____|+
  8. pin25|--------- Comp pin25|---|____|+--------- Comp
  9. pin26|- pin26|- 220 ohm
  10. | |
  11. | |
  12. -----+ -----+
  13. Connect pin 25 or 26
  14. C) R–2R resistor ladder; D) unequal rungs ladder
  15. 55 shades up to 254 shades?
  16. ESP32 TV ESP32 TV
  17. -----+ -----+ ____
  18. G|-+_____ G|---|____|
  19. pinA0|-| R2R |- Comp pinA0|---|____|+--------- Comp
  20. pinA1|-| | pinA1|---|____|
  21. pinA2|-| | ...|
  22. ...|-|_____| |
  23. -----+ -----+
  24. Connect pins of your choice (A0...A8=any pins).
  25. Custom ladders can be used by tweaking colorMinValue and colorMaxValue
  26. */
  27. #define COMPOSITE_VIDEO_PIN 25 // hardcoded, this pin has a HW DAC
  28. #include <ESP32Lib.h>
  29. #include <Ressources/Font6x8.h>
  30. #include <Ressources/CodePage437_8x8.h>
  31. //#include <Ressources/CodePage437_8x14.h>
  32. //#include <Ressources/CodePage437_8x16.h>
  33. //#include <Ressources/CodePage437_8x19.h>
  34. //#include <Ressources/CodePage437_9x16.h>
  35. #define FONT CodePage437_8x8
  36. //pin configuration for DAC
  37. const int outputPin = COMPOSITE_VIDEO_PIN;
  38. // A) B)
  39. CompositeGrayDAC videodisplay;
  40. // C) D)
  41. //CompositeGrayLadder videodisplay;
  42. class Display {
  43. public:
  44. // view(able) size
  45. int vw = 350;
  46. int vh = 235;
  47. // offsets (to fix overscan, depends on your display)
  48. int ow = 10;
  49. int oh = 26;
  50. // display size
  51. int w = 365; // vw + 2*ow
  52. int h = 275; // vh + 2*oh
  53. int font_w = FONT.charWidth;
  54. int font_h = FONT.charHeight + 1;
  55. int cols = vw / font_w;
  56. int rows = vh / font_h;
  57. void setup()
  58. {
  59. // Composite video init, see options in the header ^^^
  60. // A)
  61. //videodisplay.init(CompMode::MODEPAL288P, 25, false);
  62. // B)
  63. videodisplay.init(CompMode::MODEPAL288P, 25, true);
  64. videodisplay.clear();
  65. videodisplay.xres = w;
  66. videodisplay.yres = h;
  67. videodisplay.setFont(FONT);
  68. /*/ view area test
  69. videodisplay.rect(ow, oh, vw, vh, 50);
  70. /**/
  71. }
  72. void scroll(int d) {
  73. videodisplay.scroll(d, 0);
  74. }
  75. void fill_rect(int x, int y, int w, int h, int color) {
  76. videodisplay.fillRect(x, y, w, h, color);
  77. }
  78. void pixel(int x, int y, int color) {
  79. videodisplay.dotFast(x, y, color);
  80. }
  81. void print_character(int col, int row, int fg_color, int bg_color, char character) {
  82. int x = ow + col*font_w;
  83. int y = oh + row*font_h;
  84. videodisplay.setCursor(x, y);
  85. videodisplay.setTextColor(fg_color, bg_color);
  86. videodisplay.print(character);
  87. }
  88. int get_display_width() { return w; }
  89. int get_display_height() { return h; }
  90. int get_view_width() { return vw; }
  91. int get_view_height() { return vh; }
  92. int get_view_width_offset() { return ow; }
  93. int get_view_height_offset() { return oh; }
  94. };