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.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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 || HAS_LTDC_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 LTDC_RGB:
  79. break;
  80. case ST7796: // ST7796S 480x320
  81. DEBUG_ECHO_MSG(" ST7796S");
  82. write_esc_sequence(st7796s_init);
  83. break;
  84. case ST7789: // ST7789V 320x240
  85. DEBUG_ECHO_MSG(" ST7789V");
  86. write_esc_sequence(st7789v_init);
  87. break;
  88. case SSD1963: // SSD1963
  89. DEBUG_ECHO_MSG(" SSD1963");
  90. write_esc_sequence(ssd1963_init);
  91. break;
  92. case ST7735: // ST7735 160x128
  93. DEBUG_ECHO_MSG(" ST7735");
  94. write_esc_sequence(st7735_init);
  95. break;
  96. case R61505: // R61505U 320x240
  97. DEBUG_ECHO_MSG(" R61505U");
  98. write_esc_sequence(r61505_init);
  99. break;
  100. case ILI9328: // ILI9328 320x240
  101. DEBUG_ECHO_MSG(" ILI9328");
  102. write_esc_sequence(ili9328_init);
  103. break;
  104. case ILI9341: // ILI9341 320x240
  105. DEBUG_ECHO_MSG(" ILI9341");
  106. write_esc_sequence(ili9341_init);
  107. break;
  108. case ILI9488: // ILI9488 480x320
  109. case ILI9488_ID1: // 0x8066 ILI9488 480x320
  110. DEBUG_ECHO_MSG(" ILI9488");
  111. write_esc_sequence(ili9488_init);
  112. break;
  113. default:
  114. lcd_id = 0;
  115. }
  116. #else
  117. #error Unsupported TFT driver
  118. #endif
  119. #if PIN_EXISTS(TFT_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT)
  120. OUT_WRITE(TFT_BACKLIGHT_PIN, HIGH);
  121. #endif
  122. }
  123. void TFT_IO::set_window(uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) {
  124. #ifdef OFFSET_X
  125. Xmin += OFFSET_X; Xmax += OFFSET_X;
  126. #endif
  127. #ifdef OFFSET_Y
  128. Ymin += OFFSET_Y; Ymax += OFFSET_Y;
  129. #endif
  130. switch (lcd_id) {
  131. case LTDC_RGB:
  132. io.WriteReg(0x01);
  133. io.WriteData(Xmin);
  134. io.WriteReg(0x02);
  135. io.WriteData(Xmax);
  136. io.WriteReg(0x03);
  137. io.WriteData(Ymin);
  138. io.WriteReg(0x04);
  139. io.WriteData(Ymax);
  140. io.WriteReg(0x00);
  141. break;
  142. case ST7735: // ST7735 160x128
  143. case ST7789: // ST7789V 320x240
  144. case ST7796: // ST7796 480x320
  145. case ILI9341: // ILI9341 320x240
  146. case ILI9488: // ILI9488 480x320
  147. case SSD1963: // SSD1963
  148. case ILI9488_ID1: // 0x8066 ILI9488 480x320
  149. io.DataTransferBegin(DATASIZE_8BIT);
  150. // CASET: Column Address Set
  151. io.WriteReg(ILI9341_CASET);
  152. io.WriteData((Xmin >> 8) & 0xFF);
  153. io.WriteData(Xmin & 0xFF);
  154. io.WriteData((Xmax >> 8) & 0xFF);
  155. io.WriteData(Xmax & 0xFF);
  156. // RASET: Row Address Set
  157. io.WriteReg(ILI9341_PASET);
  158. io.WriteData((Ymin >> 8) & 0xFF);
  159. io.WriteData(Ymin & 0xFF);
  160. io.WriteData((Ymax >> 8) & 0xFF);
  161. io.WriteData(Ymax & 0xFF);
  162. // RAMWR: Memory Write
  163. io.WriteReg(ILI9341_RAMWR);
  164. break;
  165. case R61505: // R61505U 320x240
  166. case ILI9328: // ILI9328 320x240
  167. io.DataTransferBegin(DATASIZE_16BIT);
  168. // Mind the mess: with landscape screen orientation 'Horizontal' is Y and 'Vertical' is X
  169. io.WriteReg(ILI9328_HASTART);
  170. io.WriteData(Ymin);
  171. io.WriteReg(ILI9328_HAEND);
  172. io.WriteData(Ymax);
  173. io.WriteReg(ILI9328_VASTART);
  174. io.WriteData(Xmin);
  175. io.WriteReg(ILI9328_VAEND);
  176. io.WriteData(Xmax);
  177. io.WriteReg(ILI9328_HASET);
  178. io.WriteData(Ymin);
  179. io.WriteReg(ILI9328_VASET);
  180. io.WriteData(Xmin);
  181. io.WriteReg(ILI9328_RAMWR);
  182. break;
  183. default:
  184. break;
  185. }
  186. io.DataTransferEnd();
  187. }
  188. void TFT_IO::write_esc_sequence(const uint16_t *Sequence) {
  189. uint16_t dataWidth, data;
  190. dataWidth = *Sequence++;
  191. io.DataTransferBegin(dataWidth);
  192. for (;;) {
  193. data = *Sequence++;
  194. if (data != 0xFFFF) {
  195. io.WriteData(data);
  196. continue;
  197. }
  198. data = *Sequence++;
  199. if (data == 0x7FFF) return;
  200. if (data == 0xFFFF)
  201. io.WriteData(0xFFFF);
  202. else if (data & 0x8000)
  203. delay(data & 0x7FFF);
  204. else if ((data & 0xFF00) == 0)
  205. io.WriteReg(data);
  206. }
  207. io.DataTransferEnd();
  208. }
  209. #endif // HAS_SPI_TFT || HAS_FSMC_TFT