My Marlin configs for Fabrikator Mini and CTC i3 Pro B
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.

tft_io.cpp 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "tft_io.h"
  23. #if HAS_SPI_TFT || HAS_FSMC_TFT
  24. #include "st7735.h"
  25. #include "st7789v.h"
  26. #include "st7796s.h"
  27. #include "r65105.h"
  28. #include "ili9328.h"
  29. #include "ili9341.h"
  30. #include "ili9488.h"
  31. #include "ssd1963.h"
  32. #define DEBUG_OUT ENABLED(DEBUG_GRAPHICAL_TFT)
  33. #include "../../core/debug_out.h"
  34. TFT_IO_DRIVER TFT_IO::io;
  35. uint32_t TFT_IO::lcd_id = 0xFFFFFFFF;
  36. void TFT_IO::InitTFT() {
  37. if (lcd_id != 0xFFFFFFFF) return;
  38. #if PIN_EXISTS(TFT_BACKLIGHT)
  39. OUT_WRITE(TFT_BACKLIGHT_PIN, LOW);
  40. #endif
  41. #if PIN_EXISTS(TFT_RESET)
  42. OUT_WRITE(TFT_RESET_PIN, HIGH);
  43. delay(10);
  44. OUT_WRITE(TFT_RESET_PIN, LOW);
  45. delay(10);
  46. OUT_WRITE(TFT_RESET_PIN, HIGH);
  47. #endif
  48. #if PIN_EXISTS(TFT_BACKLIGHT)
  49. OUT_WRITE(TFT_BACKLIGHT_PIN, DISABLED(DELAYED_BACKLIGHT_INIT));
  50. #endif
  51. // io.Init();
  52. delay(100);
  53. #if TFT_DRIVER != AUTO
  54. lcd_id = TFT_DRIVER;
  55. #endif
  56. #if TFT_DRIVER == ST7735
  57. write_esc_sequence(st7735_init);
  58. #elif TFT_DRIVER == SSD1963
  59. write_esc_sequence(ssd1963_init);
  60. #elif TFT_DRIVER == ST7789
  61. write_esc_sequence(st7789v_init);
  62. #elif TFT_DRIVER == ST7796
  63. write_esc_sequence(st7796s_init);
  64. #elif TFT_DRIVER == R61505
  65. write_esc_sequence(r61505_init);
  66. #elif TFT_DRIVER == ILI9328
  67. write_esc_sequence(ili9328_init);
  68. #elif TFT_DRIVER == ILI9341
  69. write_esc_sequence(ili9341_init);
  70. #elif TFT_DRIVER == ILI9488
  71. write_esc_sequence(ili9488_init);
  72. #elif TFT_DRIVER == LERDGE_ST7796
  73. lcd_id = ST7796;
  74. write_esc_sequence(lerdge_st7796s_init);
  75. #elif TFT_DRIVER == AUTO // autodetect
  76. lcd_id = io.GetID() & 0xFFFF;
  77. switch (lcd_id) {
  78. case ST7796: // ST7796S 480x320
  79. DEBUG_ECHO_MSG(" ST7796S");
  80. write_esc_sequence(st7796s_init);
  81. break;
  82. case ST7789: // ST7789V 320x240
  83. DEBUG_ECHO_MSG(" ST7789V");
  84. write_esc_sequence(st7789v_init);
  85. break;
  86. case SSD1963: // SSD1963
  87. DEBUG_ECHO_MSG(" SSD1963");
  88. write_esc_sequence(ssd1963_init);
  89. break;
  90. case ST7735: // ST7735 160x128
  91. DEBUG_ECHO_MSG(" ST7735");
  92. write_esc_sequence(st7735_init);
  93. break;
  94. case R61505: // R61505U 320x240
  95. DEBUG_ECHO_MSG(" R61505U");
  96. write_esc_sequence(r61505_init);
  97. break;
  98. case ILI9328: // ILI9328 320x240
  99. DEBUG_ECHO_MSG(" ILI9328");
  100. write_esc_sequence(ili9328_init);
  101. break;
  102. case ILI9341: // ILI9341 320x240
  103. DEBUG_ECHO_MSG(" ILI9341");
  104. write_esc_sequence(ili9341_init);
  105. break;
  106. case ILI9488: // ILI9488 480x320
  107. case ILI9488_ID1: // 0x8066 ILI9488 480x320
  108. DEBUG_ECHO_MSG(" ILI9488");
  109. write_esc_sequence(ili9488_init);
  110. break;
  111. default:
  112. lcd_id = 0;
  113. }
  114. #else
  115. #error Unsupported TFT driver
  116. #endif
  117. #if PIN_EXISTS(TFT_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT)
  118. OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH);
  119. #endif
  120. }
  121. void TFT_IO::set_window(uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) {
  122. #ifdef OFFSET_X
  123. Xmin += OFFSET_X; Xmax += OFFSET_X;
  124. #endif
  125. #ifdef OFFSET_Y
  126. Ymin += OFFSET_Y; Ymax += OFFSET_Y;
  127. #endif
  128. switch (lcd_id) {
  129. case ST7735: // ST7735 160x128
  130. case ST7789: // ST7789V 320x240
  131. case ST7796: // ST7796 480x320
  132. case ILI9341: // ILI9341 320x240
  133. case ILI9488: // ILI9488 480x320
  134. case SSD1963: // SSD1963
  135. case ILI9488_ID1: // 0x8066 ILI9488 480x320
  136. io.DataTransferBegin(DATASIZE_8BIT);
  137. // CASET: Column Address Set
  138. io.WriteReg(ILI9341_CASET);
  139. io.WriteData((Xmin >> 8) & 0xFF);
  140. io.WriteData(Xmin & 0xFF);
  141. io.WriteData((Xmax >> 8) & 0xFF);
  142. io.WriteData(Xmax & 0xFF);
  143. // RASET: Row Address Set
  144. io.WriteReg(ILI9341_PASET);
  145. io.WriteData((Ymin >> 8) & 0xFF);
  146. io.WriteData(Ymin & 0xFF);
  147. io.WriteData((Ymax >> 8) & 0xFF);
  148. io.WriteData(Ymax & 0xFF);
  149. // RAMWR: Memory Write
  150. io.WriteReg(ILI9341_RAMWR);
  151. break;
  152. case R61505: // R61505U 320x240
  153. case ILI9328: // ILI9328 320x240
  154. io.DataTransferBegin(DATASIZE_16BIT);
  155. // Mind the mess: with landscape screen orientation 'Horizontal' is Y and 'Vertical' is X
  156. io.WriteReg(ILI9328_HASTART);
  157. io.WriteData(Ymin);
  158. io.WriteReg(ILI9328_HAEND);
  159. io.WriteData(Ymax);
  160. io.WriteReg(ILI9328_VASTART);
  161. io.WriteData(Xmin);
  162. io.WriteReg(ILI9328_VAEND);
  163. io.WriteData(Xmax);
  164. io.WriteReg(ILI9328_HASET);
  165. io.WriteData(Ymin);
  166. io.WriteReg(ILI9328_VASET);
  167. io.WriteData(Xmin);
  168. io.WriteReg(ILI9328_RAMWR);
  169. break;
  170. default:
  171. break;
  172. }
  173. io.DataTransferEnd();
  174. }
  175. void TFT_IO::write_esc_sequence(const uint16_t *Sequence) {
  176. uint16_t dataWidth, data;
  177. dataWidth = *Sequence++;
  178. io.DataTransferBegin(dataWidth);
  179. for (;;) {
  180. data = *Sequence++;
  181. if (data != 0xFFFF) {
  182. io.WriteData(data);
  183. continue;
  184. }
  185. data = *Sequence++;
  186. if (data == 0x7FFF) return;
  187. if (data == 0xFFFF)
  188. io.WriteData(0xFFFF);
  189. else if (data & 0x8000)
  190. delay(data & 0x7FFF);
  191. else if ((data & 0xFF00) == 0)
  192. io.WriteReg(data);
  193. }
  194. io.DataTransferEnd();
  195. }
  196. #endif // HAS_SPI_TFT || HAS_FSMC_TFT