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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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 "../../inc/MarlinConfigPre.h"
  23. #if HAS_SPI_TFT || HAS_FSMC_TFT || HAS_LTDC_TFT
  24. #include "tft_io.h"
  25. #include "tft_ids.h"
  26. #if TFT_DRIVER == ST7735 || TFT_DRIVER == AUTO
  27. #include "st7735.h"
  28. #endif
  29. #if TFT_DRIVER == ST7789 || TFT_DRIVER == AUTO
  30. #include "st7789v.h"
  31. #endif
  32. #if TFT_DRIVER == ST7796 || TFT_DRIVER == AUTO
  33. #include "st7796s.h"
  34. #endif
  35. #if TFT_DRIVER == R61505 || TFT_DRIVER == AUTO
  36. #include "r65105.h"
  37. #endif
  38. #if TFT_DRIVER == ILI9488 || TFT_DRIVER == ILI9488_ID1 || TFT_DRIVER == AUTO
  39. #include "ili9488.h"
  40. #endif
  41. #if TFT_DRIVER == SSD1963 || TFT_DRIVER == AUTO
  42. #include "ssd1963.h"
  43. #endif
  44. #include "ili9341.h"
  45. #include "ili9328.h"
  46. #if HAS_LCD_BRIGHTNESS
  47. #include "../marlinui.h"
  48. #endif
  49. #define DEBUG_OUT ENABLED(DEBUG_GRAPHICAL_TFT)
  50. #include "../../core/debug_out.h"
  51. TFT_IO_DRIVER TFT_IO::io;
  52. uint32_t TFT_IO::lcd_id = 0xFFFFFFFF;
  53. void TFT_IO::InitTFT() {
  54. if (lcd_id != 0xFFFFFFFF) return;
  55. #if PIN_EXISTS(TFT_BACKLIGHT)
  56. OUT_WRITE(TFT_BACKLIGHT_PIN, LOW);
  57. #endif
  58. #if PIN_EXISTS(TFT_RESET)
  59. OUT_WRITE(TFT_RESET_PIN, HIGH);
  60. delay(10);
  61. WRITE(TFT_RESET_PIN, LOW);
  62. delay(10);
  63. WRITE(TFT_RESET_PIN, HIGH);
  64. #endif
  65. #if PIN_EXISTS(TFT_BACKLIGHT)
  66. WRITE(TFT_BACKLIGHT_PIN, DISABLED(DELAYED_BACKLIGHT_INIT));
  67. #if HAS_LCD_BRIGHTNESS && DISABLED(DELAYED_BACKLIGHT_INIT)
  68. ui._set_brightness();
  69. #endif
  70. #endif
  71. // io.Init();
  72. delay(100);
  73. #if TFT_DRIVER != AUTO
  74. lcd_id = TFT_DRIVER;
  75. #endif
  76. #if TFT_DRIVER == ST7735
  77. write_esc_sequence(st7735_init);
  78. #elif TFT_DRIVER == SSD1963
  79. write_esc_sequence(ssd1963_init);
  80. #elif TFT_DRIVER == ST7789
  81. write_esc_sequence(st7789v_init);
  82. #elif TFT_DRIVER == ST7796
  83. write_esc_sequence(st7796s_init);
  84. #elif TFT_DRIVER == R61505
  85. write_esc_sequence(r61505_init);
  86. #elif TFT_DRIVER == ILI9328
  87. write_esc_sequence(ili9328_init);
  88. #elif TFT_DRIVER == ILI9341
  89. write_esc_sequence(ili9341_init);
  90. #elif TFT_DRIVER == ILI9488
  91. write_esc_sequence(ili9488_init);
  92. #elif TFT_DRIVER == AUTO // autodetect
  93. lcd_id = io.GetID() & 0xFFFF;
  94. switch (lcd_id) {
  95. case LTDC_RGB:
  96. break;
  97. case ST7796: // ST7796S 480x320
  98. DEBUG_ECHO_MSG(" ST7796S");
  99. write_esc_sequence(st7796s_init);
  100. break;
  101. case ST7789: // ST7789V 320x240
  102. DEBUG_ECHO_MSG(" ST7789V");
  103. write_esc_sequence(st7789v_init);
  104. break;
  105. case SSD1963: // SSD1963
  106. DEBUG_ECHO_MSG(" SSD1963");
  107. write_esc_sequence(ssd1963_init);
  108. break;
  109. case ST7735: // ST7735 160x128
  110. DEBUG_ECHO_MSG(" ST7735");
  111. write_esc_sequence(st7735_init);
  112. break;
  113. case R61505: // R61505U 320x240
  114. DEBUG_ECHO_MSG(" R61505U");
  115. write_esc_sequence(r61505_init);
  116. break;
  117. case ILI9328: // ILI9328 320x240
  118. DEBUG_ECHO_MSG(" ILI9328");
  119. write_esc_sequence(ili9328_init);
  120. break;
  121. case ILI9341: // ILI9341 320x240
  122. DEBUG_ECHO_MSG(" ILI9341");
  123. write_esc_sequence(ili9341_init);
  124. break;
  125. case ILI9488: // ILI9488 480x320
  126. case ILI9488_ID1: // 0x8066 ILI9488 480x320
  127. DEBUG_ECHO_MSG(" ILI9488");
  128. write_esc_sequence(ili9488_init);
  129. break;
  130. default:
  131. lcd_id = 0;
  132. }
  133. #else
  134. #error "Unsupported TFT driver"
  135. #endif
  136. #if PIN_EXISTS(TFT_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT)
  137. TERN(HAS_LCD_BRIGHTNESS, ui._set_brightness(), WRITE(TFT_BACKLIGHT_PIN, HIGH));
  138. #endif
  139. }
  140. void TFT_IO::set_window(uint16_t Xmin, uint16_t Ymin, uint16_t Xmax, uint16_t Ymax) {
  141. #ifdef OFFSET_X
  142. Xmin += OFFSET_X; Xmax += OFFSET_X;
  143. #endif
  144. #ifdef OFFSET_Y
  145. Ymin += OFFSET_Y; Ymax += OFFSET_Y;
  146. #endif
  147. switch (lcd_id) {
  148. case LTDC_RGB:
  149. io.WriteReg(0x01);
  150. io.WriteData(Xmin);
  151. io.WriteReg(0x02);
  152. io.WriteData(Xmax);
  153. io.WriteReg(0x03);
  154. io.WriteData(Ymin);
  155. io.WriteReg(0x04);
  156. io.WriteData(Ymax);
  157. io.WriteReg(0x00);
  158. break;
  159. case ST7735: // ST7735 160x128
  160. case ST7789: // ST7789V 320x240
  161. case ST7796: // ST7796 480x320
  162. case ILI9341: // ILI9341 320x240
  163. case ILI9488: // ILI9488 480x320
  164. case SSD1963: // SSD1963
  165. case ILI9488_ID1: // 0x8066 ILI9488 480x320
  166. io.DataTransferBegin(DATASIZE_8BIT);
  167. // CASET: Column Address Set
  168. io.WriteReg(ILI9341_CASET);
  169. io.WriteData((Xmin >> 8) & 0xFF);
  170. io.WriteData(Xmin & 0xFF);
  171. io.WriteData((Xmax >> 8) & 0xFF);
  172. io.WriteData(Xmax & 0xFF);
  173. // RASET: Row Address Set
  174. io.WriteReg(ILI9341_PASET);
  175. io.WriteData((Ymin >> 8) & 0xFF);
  176. io.WriteData(Ymin & 0xFF);
  177. io.WriteData((Ymax >> 8) & 0xFF);
  178. io.WriteData(Ymax & 0xFF);
  179. // RAMWR: Memory Write
  180. io.WriteReg(ILI9341_RAMWR);
  181. break;
  182. case R61505: // R61505U 320x240
  183. case ILI9328: // ILI9328 320x240
  184. io.DataTransferBegin(DATASIZE_16BIT);
  185. // Mind the mess: with landscape screen orientation 'Horizontal' is Y and 'Vertical' is X
  186. io.WriteReg(ILI9328_HASTART);
  187. io.WriteData(Ymin);
  188. io.WriteReg(ILI9328_HAEND);
  189. io.WriteData(Ymax);
  190. io.WriteReg(ILI9328_VASTART);
  191. io.WriteData(Xmin);
  192. io.WriteReg(ILI9328_VAEND);
  193. io.WriteData(Xmax);
  194. io.WriteReg(ILI9328_HASET);
  195. io.WriteData(Ymin);
  196. io.WriteReg(ILI9328_VASET);
  197. io.WriteData(Xmin);
  198. io.WriteReg(ILI9328_RAMWR);
  199. break;
  200. default:
  201. break;
  202. }
  203. io.DataTransferEnd();
  204. }
  205. void TFT_IO::write_esc_sequence(const uint16_t *Sequence) {
  206. uint16_t dataWidth, data;
  207. dataWidth = *Sequence++;
  208. io.DataTransferBegin(dataWidth);
  209. for (;;) {
  210. data = *Sequence++;
  211. if (data != 0xFFFF) {
  212. io.WriteData(data);
  213. continue;
  214. }
  215. data = *Sequence++;
  216. if (data == 0x7FFF) return;
  217. if (data == 0xFFFF)
  218. io.WriteData(0xFFFF);
  219. else if (data & 0x8000)
  220. delay(data & 0x7FFF);
  221. else if ((data & 0xFF00) == 0)
  222. io.WriteReg(data);
  223. }
  224. io.DataTransferEnd();
  225. }
  226. #endif // HAS_SPI_TFT || HAS_FSMC_TFT || HAS_LTDC_TFT