Repo for ESP32 Weather Station Development
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.

752 lines
26KB

  1. /*
  2. *
  3. * HIGH SPEED LOW LEVEL DISPLAY FUNCTIONS USING DIRECT TRANSFER MODE
  4. *
  5. */
  6. #ifndef _TFTSPI_H_
  7. #define _TFTSPI_H_
  8. #include "tftspi.h"
  9. #include "spi_master_lobo.h"
  10. #include "sdkconfig.h"
  11. #include "stmpe610.h"
  12. #define TOUCH_TYPE_NONE 0
  13. #define TOUCH_TYPE_XPT2046 1
  14. #define TOUCH_TYPE_STMPE610 2
  15. #define TP_CALX_XPT2046 7472920
  16. #define TP_CALY_XPT2046 122224794
  17. #define TP_CALX_STMPE610 21368532
  18. #define TP_CALY_STMPE610 11800144
  19. // === Screen tft_orientation constants ===
  20. #define PORTRAIT 0
  21. #define LANDSCAPE 1
  22. #define PORTRAIT_FLIP 2
  23. #define LANDSCAPE_FLIP 3
  24. #define DISP_TYPE_ILI9341 0
  25. #define DISP_TYPE_ILI9488 1
  26. #define DISP_TYPE_ST7789V 2
  27. #define DISP_TYPE_ST7735 3
  28. #define DISP_TYPE_ST7735R 4
  29. #define DISP_TYPE_ST7735B 5
  30. #if CONFIG_TFT_PREDEFINED_DISPLAY_TYPE == 1
  31. // ** Set the correct configuration for ESP-WROVER-KIT v3
  32. // --------------------------------------------------------
  33. #define DEFAULT_DISP_TYPE DISP_TYPE_ST7789V
  34. #define DEFAULT_TFT_DISPLAY_WIDTH 240
  35. #define DEFAULT_TFT_DISPLAY_HEIGHT 320
  36. #define DISP_COLOR_BITS_24 0x66
  37. #define DEFAULT_GAMMA_CURVE 0
  38. #define DEFAULT_SPI_CLOCK 26000000
  39. #define TFT_INVERT_ROTATION 0
  40. #define TFT_INVERT_ROTATION1 1
  41. #define TFT_RGB_BGR 0x00
  42. #define USE_TOUCH TOUCH_TYPE_NONE
  43. #define PIN_NUM_MISO 25 // SPI MISO
  44. #define PIN_NUM_MOSI 23 // SPI MOSI
  45. #define PIN_NUM_CLK 19 // SPI CLOCK pin
  46. #define PIN_NUM_CS 22 // Display CS pin
  47. #define PIN_NUM_DC 21 // Display command/data pin
  48. #define PIN_NUM_TCS 0 // Touch screen CS pin
  49. #define PIN_NUM_RST 18 // GPIO used for RESET control
  50. #define PIN_NUM_BCKL 5 // GPIO used for backlight control
  51. #define PIN_BCKL_ON 0 // GPIO value for backlight ON
  52. #define PIN_BCKL_OFF 1 // GPIO value for backlight OFF
  53. // --------------------------------------------------------
  54. #elif CONFIG_TFT_PREDEFINED_DISPLAY_TYPE == 2
  55. // ** Set the correct configuration for Adafruit TFT Feather
  56. // ---------------------------------------------------------
  57. #define DEFAULT_DISP_TYPE DISP_TYPE_ILI9341
  58. #define DEFAULT_TFT_DISPLAY_WIDTH 240
  59. #define DEFAULT_TFT_DISPLAY_HEIGHT 320
  60. #define DISP_COLOR_BITS_24 0x66
  61. #define DEFAULT_GAMMA_CURVE 0
  62. #define DEFAULT_SPI_CLOCK 26000000
  63. #define TFT_INVERT_ROTATION 0
  64. #define TFT_INVERT_ROTATION1 0
  65. #define TFT_RGB_BGR 0x08
  66. #define USE_TOUCH TOUCH_TYPE_STMPE610
  67. #define PIN_NUM_MISO 19 // SPI MISO
  68. #define PIN_NUM_MOSI 18 // SPI MOSI
  69. #define PIN_NUM_CLK 5 // SPI CLOCK pin
  70. #define PIN_NUM_CS 15 // Display CS pin
  71. #define PIN_NUM_DC 33 // Display command/data pin
  72. #define PIN_NUM_TCS 32 // Touch screen CS pin (NOT used if USE_TOUCH=0)
  73. #define PIN_NUM_RST 0 // GPIO used for RESET control (#16)
  74. #define PIN_NUM_BCKL 0 // GPIO used for backlight control
  75. #define PIN_BCKL_ON 0 // GPIO value for backlight ON
  76. #define PIN_BCKL_OFF 1 // GPIO value for backlight OFF
  77. // ---------------------------------------------------------
  78. #elif CONFIG_TFT_PREDEFINED_DISPLAY_TYPE == 3
  79. // ** Set the correct configuration for M5Stack TFT
  80. // ---------------------------------------------------------
  81. #define DEFAULT_DISP_TYPE DISP_TYPE_ILI9341
  82. #define DEFAULT_TFT_DISPLAY_WIDTH 320
  83. #define DEFAULT_TFT_DISPLAY_HEIGHT 240
  84. #define DISP_COLOR_BITS_24 0x66
  85. #define DEFAULT_GAMMA_CURVE 0
  86. #define DEFAULT_SPI_CLOCK 26000000
  87. #define TFT_INVERT_ROTATION 0
  88. #define TFT_INVERT_ROTATION1 0
  89. #define TFT_INVERT_ROTATION2 1 // Adapte M5Stack TFT
  90. #define TFT_RGB_BGR 0x08
  91. #define USE_TOUCH TOUCH_TYPE_NONE
  92. #define PIN_NUM_MISO 19 // SPI MISO
  93. #define PIN_NUM_MOSI 23 // SPI MOSI
  94. #define PIN_NUM_CLK 18 // SPI CLOCK pin
  95. #define PIN_NUM_CS 14 // Display CS pin
  96. #define PIN_NUM_DC 27 // Display command/data pin
  97. #define PIN_NUM_TCS 0 // Touch screen CS pin (NOT used if USE_TOUCH=0)
  98. #define PIN_NUM_RST 33 // GPIO used for RESET control (#16)
  99. #define PIN_NUM_BCKL 32 // GPIO used for backlight control
  100. #define PIN_BCKL_ON 1 // GPIO value for backlight ON
  101. #define PIN_BCKL_OFF 0 // GPIO value for backlight OFF
  102. // ---------------------------------------------------------
  103. #elif CONFIG_TFT_PREDEFINED_DISPLAY_TYPE == 4
  104. // ** Set the correct configuration for ESP-WROVER-KIT v4.1
  105. // --------------------------------------------------------
  106. #define DEFAULT_DISP_TYPE DISP_TYPE_ILI9341
  107. #define DEFAULT_TFT_DISPLAY_WIDTH 240
  108. #define DEFAULT_TFT_DISPLAY_HEIGHT 320
  109. #define DISP_COLOR_BITS_24 0x66
  110. #define DEFAULT_GAMMA_CURVE 0
  111. #define DEFAULT_SPI_CLOCK 26000000
  112. #define TFT_INVERT_ROTATION 0
  113. #define TFT_INVERT_ROTATION1 0
  114. #define TFT_INVERT_ROTATION2 0
  115. #define TFT_RGB_BGR 0x08
  116. #define USE_TOUCH TOUCH_TYPE_NONE
  117. #define PIN_NUM_MISO 25 // SPI MISO
  118. #define PIN_NUM_MOSI 23 // SPI MOSI
  119. #define PIN_NUM_CLK 19 // SPI CLOCK pin
  120. #define PIN_NUM_CS 22 // Display CS pin
  121. #define PIN_NUM_DC 21 // Display command/data pin
  122. #define PIN_NUM_TCS 0 // Touch screen CS pin
  123. #define PIN_NUM_RST 18 // GPIO used for RESET control
  124. #define PIN_NUM_BCKL 5 // GPIO used for backlight control
  125. #define PIN_BCKL_ON 0 // GPIO value for backlight ON
  126. #define PIN_BCKL_OFF 1 // GPIO value for backlight OFF
  127. // --------------------------------------------------------
  128. #elif CONFIG_TFT_PREDEFINED_DISPLAY_TYPE == 5
  129. //CONFIG FOR TTGO T-DISPLAY
  130. #define DEFAULT_DISP_TYPE DISP_TYPE_ST7789V
  131. #define DEFAULT_TFT_DISPLAY_WIDTH 135
  132. #define DEFAULT_TFT_DISPLAY_HEIGHT 240
  133. //Need to be defined together so they can be swapped for x;y when rotating
  134. #define TFT_STATIC_WIDTH_OFFSET 53
  135. #define TFT_STATIC_HEIGHT_OFFSET 40
  136. #define DISP_COLOR_BITS_24 0x66
  137. #define DEFAULT_GAMMA_CURVE 0
  138. #define DEFAULT_SPI_CLOCK 20000000
  139. #define TFT_INVERT_ROTATION 0
  140. #define TFT_INVERT_ROTATION1 1
  141. #define TFT_RGB_BGR 0x00
  142. //To be used by user application for initialization
  143. #define TFT_START_COLORS_INVERTED
  144. #define USE_TOUCH TOUCH_TYPE_NONE
  145. #define PIN_NUM_MISO 0 // SPI MISO
  146. #define PIN_NUM_MOSI 19 // SPI MOSI
  147. #define PIN_NUM_CLK 18 // SPI CLOCK pin
  148. #define PIN_NUM_CS 5 // Display CS pin
  149. #define PIN_NUM_DC 16 // Display command/data pin
  150. #define PIN_NUM_TCS 0 // Touch screen CS pin
  151. #define PIN_NUM_RST 23 // GPIO used for RESET control
  152. #define PIN_NUM_BCKL 4 // GPIO used for backlight control
  153. #define PIN_BCKL_ON 1 // GPIO value for backlight ON
  154. #define PIN_BCKL_OFF 0 // GPIO value for backlight OFF
  155. //END TTGO T_DISPLAY
  156. #else
  157. // Configuration for other boards, set the correct values for the display used
  158. //----------------------------------------------------------------------------
  159. #define DISP_COLOR_BITS_24 0x66
  160. //#define DISP_COLOR_BITS_16 0x55 // Do not use!
  161. #define TFT_INVERT_ROTATION 0
  162. #define TFT_INVERT_ROTATION1 CONFIG_TFT_INVERT_ROTATION1
  163. // ################################################
  164. // ### SET TO 0X00 FOR DISPLAYS WITH RGB MATRIX ###
  165. // ### SET TO 0X08 FOR DISPLAYS WITH BGR MATRIX ###
  166. // ### For ESP-WROWER-KIT set to 0x00 ###
  167. // ################################################
  168. #if CONFIG_TFT_RGB_BGR
  169. #define TFT_RGB_BGR 0x00
  170. #else
  171. #define TFT_RGB_BGR 0x08
  172. #endif
  173. // ##############################################################
  174. // ### Define ESP32 SPI pins to which the display is attached ###
  175. // ##############################################################
  176. // The pins configured here are the native spi pins for HSPI interface
  177. // Any other valid pin combination can be used
  178. #define PIN_NUM_MISO CONFIG_TFT_PIN_NUM_MISO
  179. #define PIN_NUM_MOSI CONFIG_TFT_PIN_NUM_MOSI
  180. #define PIN_NUM_CLK CONFIG_TFT_PIN_NUM_CLK
  181. #define PIN_NUM_CS CONFIG_TFT_PIN_NUM_CS
  182. #define PIN_NUM_DC CONFIG_TFT_PIN_NUM_DC
  183. #define PIN_NUM_TCS CONFIG_TFT_PIN_NUM_TCS
  184. #define PIN_NUM_RST CONFIG_TFT_PIN_NUM_RST
  185. #define PIN_NUM_BCKL CONFIG_TFT_PIN_NUM_BCKL
  186. #define PIN_BCKL_ON 0 // GPIO value for backlight ON
  187. #define PIN_BCKL_OFF 1 // GPIO value for backlight OFF
  188. // --------------------------------------------------------------
  189. #define USE_TOUCH CONFIG_TFT_TOUCH_CONTROLLER
  190. // #######################################################################
  191. // Default display width (smaller dimension) and height (larger dimension)
  192. // #######################################################################
  193. #define DEFAULT_TFT_DISPLAY_WIDTH CONFIG_TFT_DISPLAY_WIDTH
  194. #define DEFAULT_TFT_DISPLAY_HEIGHT CONFIG_TFT_DISPLAY_HEIGHT
  195. // #######################################################################
  196. #define DEFAULT_GAMMA_CURVE 0
  197. #define DEFAULT_SPI_CLOCK 26000000
  198. #if defined(CONFIG_TFT_DISPLAY_CONTROLLER_MODEL)
  199. #define DEFAULT_DISP_TYPE CONFIG_TFT_DISPLAY_CONTROLLER_MODEL
  200. #else
  201. #define DEFAULT_DISP_TYPE DISP_TYPE_ILI9341
  202. #endif
  203. //----------------------------------------------------------------------------
  204. #endif // CONFIG_PREDEFINED_DISPLAY_TYPE
  205. // Define offset generation, or ignore offsets if none are needed
  206. #ifdef TFT_STATIC_WIDTH_OFFSET
  207. #define TFT_STATIC_X_OFFSET (tft_orientation & 1 ? TFT_STATIC_HEIGHT_OFFSET : TFT_STATIC_WIDTH_OFFSET)
  208. #define TFT_STATIC_Y_OFFSET (tft_orientation & 1 ? TFT_STATIC_WIDTH_OFFSET : TFT_STATIC_HEIGHT_OFFSET)
  209. #else
  210. #define TFT_STATIC_WIDTH_OFFSET 0
  211. #define TFT_STATIC_X_OFFSET 0
  212. #define TFT_STATIC_HEIGHT_OFFSET 0
  213. #define TFT_STATIC_Y_OFFSET 0
  214. #endif
  215. // ##############################################################
  216. // #### Global variables ####
  217. // ##############################################################
  218. // ==== Converts colors to grayscale if 1 =======================
  219. extern uint8_t tft_gray_scale;
  220. // ==== Spi clock for reading data from display memory in Hz ====
  221. extern uint32_t tft_max_rdclock;
  222. // ==== Display dimensions in pixels ============================
  223. extern int tft_width;
  224. extern int tft_height;
  225. // ==== Display type, DISP_TYPE_ILI9488 or DISP_TYPE_ILI9341 ====
  226. extern uint8_t tft_disp_type;
  227. // ==== Spi device handles for display and touch screen =========
  228. extern spi_lobo_device_handle_t tft_disp_spi;
  229. extern spi_lobo_device_handle_t tft_ts_spi;
  230. // ##############################################################
  231. // 24-bit color type structure
  232. typedef struct __attribute__((__packed__)) {
  233. //typedef struct {
  234. uint8_t r;
  235. uint8_t g;
  236. uint8_t b;
  237. } color_t ;
  238. // ==== Display commands constants ====
  239. #define TFT_INVOFF 0x20
  240. #define TFT_INVONN 0x21
  241. #define TFT_DISPOFF 0x28
  242. #define TFT_DISPON 0x29
  243. #define TFT_MADCTL 0x36
  244. #define TFT_PTLAR 0x30
  245. #define TFT_ENTRYM 0xB7
  246. #define TFT_CMD_NOP 0x00
  247. #define TFT_CMD_SWRESET 0x01
  248. #define TFT_CMD_RDDID 0x04
  249. #define TFT_CMD_RDDST 0x09
  250. #define TFT_CMD_SLPIN 0x10
  251. #define TFT_CMD_SLPOUT 0x11
  252. #define TFT_CMD_PTLON 0x12
  253. #define TFT_CMD_NORON 0x13
  254. #define TFT_CMD_RDMODE 0x0A
  255. #define TFT_CMD_RDMADCTL 0x0B
  256. #define TFT_CMD_RDPIXFMT 0x0C
  257. #define TFT_CMD_RDIMGFMT 0x0D
  258. #define TFT_CMD_RDSELFDIAG 0x0F
  259. #define TFT_CMD_GAMMASET 0x26
  260. #define TFT_CMD_FRMCTR1 0xB1
  261. #define TFT_CMD_FRMCTR2 0xB2
  262. #define TFT_CMD_FRMCTR3 0xB3
  263. #define TFT_CMD_INVCTR 0xB4
  264. #define TFT_CMD_DFUNCTR 0xB6
  265. #define TFT_CMD_PWCTR1 0xC0
  266. #define TFT_CMD_PWCTR2 0xC1
  267. #define TFT_CMD_PWCTR3 0xC2
  268. #define TFT_CMD_PWCTR4 0xC3
  269. #define TFT_CMD_PWCTR5 0xC4
  270. #define TFT_CMD_VMCTR1 0xC5
  271. #define TFT_CMD_VMCTR2 0xC7
  272. #define TFT_CMD_RDID1 0xDA
  273. #define TFT_CMD_RDID2 0xDB
  274. #define TFT_CMD_RDID3 0xDC
  275. #define TFT_CMD_RDID4 0xDD
  276. #define TFT_CMD_GMCTRP1 0xE0
  277. #define TFT_CMD_GMCTRN1 0xE1
  278. #define TFT_CMD_POWERA 0xCB
  279. #define TFT_CMD_POWERB 0xCF
  280. #define TFT_CMD_POWER_SEQ 0xED
  281. #define TFT_CMD_DTCA 0xE8
  282. #define TFT_CMD_DTCB 0xEA
  283. #define TFT_CMD_PRC 0xF7
  284. #define TFT_CMD_3GAMMA_EN 0xF2
  285. #define ST_CMD_VCOMS 0xBB
  286. #define ST_CMD_FRCTRL2 0xC6
  287. #define ST_CMD_PWCTR1 0xD0
  288. #define ST7735_FRMCTR1 0xB1
  289. #define ST7735_FRMCTR2 0xB2
  290. #define ST7735_FRMCTR3 0xB3
  291. #define ST7735_INVCTR 0xB4
  292. #define ST7735_DISSET5 0xB6
  293. #define ST7735_PWCTR1 0xC0
  294. #define ST7735_PWCTR2 0xC1
  295. #define ST7735_PWCTR3 0xC2
  296. #define ST7735_PWCTR4 0xC3
  297. #define ST7735_PWCTR5 0xC4
  298. #define ST7735_VMCTR1 0xC5
  299. #define ST7735_RDID1 0xDA
  300. #define ST7735_RDID2 0xDB
  301. #define ST7735_RDID3 0xDC
  302. #define ST7735_RDID4 0xDD
  303. #define ST7735_NOP 0x00
  304. #define ST7735_SWRESET 0x01
  305. #define ST7735_RDDID 0x04
  306. #define ST7735_RDDST 0x09
  307. #define ST7735_SLPIN 0x10
  308. #define ST7735_SLPOUT 0x11
  309. #define ST7735_PTLON 0x12
  310. #define ST7735_NORON 0x13
  311. #define ST7735_PWCTR6 0xFC
  312. #define ST7735_GMCTRP1 0xE0
  313. #define ST7735_GMCTRN1 0xE1
  314. #define MADCTL_MY 0x80
  315. #define MADCTL_MX 0x40
  316. #define MADCTL_MV 0x20
  317. #define MADCTL_ML 0x10
  318. #define MADCTL_MH 0x04
  319. #define TFT_CASET 0x2A
  320. #define TFT_PASET 0x2B
  321. #define TFT_RAMWR 0x2C
  322. #define TFT_RAMRD 0x2E
  323. #define TFT_CMD_PIXFMT 0x3A
  324. #define TFT_CMD_DELAY 0x80
  325. // Initialization sequence for ILI7749
  326. // ====================================
  327. static const uint8_t ST7789V_init[] = {
  328. #if PIN_NUM_RST
  329. 15, // 15 commands in list
  330. #else
  331. 16, // 16 commands in list
  332. TFT_CMD_SWRESET, TFT_CMD_DELAY, // 1: Software reset, no args, w/delay
  333. 200, // 200 ms delay
  334. #endif
  335. TFT_CMD_FRMCTR2, 5, 0x0c, 0x0c, 0x00, 0x33, 0x33,
  336. TFT_ENTRYM, 1, 0x45,
  337. ST_CMD_VCOMS, 1, 0x2B,
  338. TFT_CMD_PWCTR1, 1, 0x2C,
  339. TFT_CMD_PWCTR3, 2, 0x01, 0xff,
  340. TFT_CMD_PWCTR4, 1, 0x11,
  341. TFT_CMD_PWCTR5, 1, 0x20,
  342. ST_CMD_FRCTRL2, 1, 0x0f,
  343. ST_CMD_PWCTR1, 2, 0xA4, 0xA1,
  344. TFT_CMD_GMCTRP1, 14, 0xD0, 0x00, 0x05, 0x0E, 0x15, 0x0D, 0x37, 0x43, 0x47, 0x09, 0x15, 0x12, 0x16, 0x19,
  345. TFT_CMD_GMCTRN1, 14, 0xD0, 0x00, 0x05, 0x0D, 0x0C, 0x06, 0x2D, 0x44, 0x40, 0x0E, 0x1C, 0x18, 0x16, 0x19,
  346. TFT_MADCTL, 1, (MADCTL_MX | TFT_RGB_BGR), // Memory Access Control (tft_orientation)
  347. TFT_CMD_PIXFMT, 1, DISP_COLOR_BITS_24, // *** INTERFACE PIXEL FORMAT: 0x66 -> 18 bit; 0x55 -> 16 bit
  348. TFT_CMD_SLPOUT, TFT_CMD_DELAY, 120, // Sleep out, // 120 ms delay
  349. TFT_DISPON, TFT_CMD_DELAY, 120,
  350. };
  351. // Initialization sequence for ILI7341
  352. // ====================================
  353. static const uint8_t ILI9341_init[] = {
  354. #if PIN_NUM_RST
  355. 23, // 24 commands in list
  356. #else
  357. 24, // 24 commands in list
  358. TFT_CMD_SWRESET, TFT_CMD_DELAY, // 1: Software reset, no args, w/delay
  359. 250, // 200 ms delay
  360. #endif
  361. TFT_CMD_POWERA, 5, 0x39, 0x2C, 0x00, 0x34, 0x02,
  362. TFT_CMD_POWERB, 3, 0x00, 0XC1, 0X30,
  363. 0xEF, 3, 0x03, 0x80, 0x02,
  364. TFT_CMD_DTCA, 3, 0x85, 0x00, 0x78,
  365. TFT_CMD_DTCB, 2, 0x00, 0x00,
  366. TFT_CMD_POWER_SEQ, 4, 0x64, 0x03, 0X12, 0X81,
  367. TFT_CMD_PRC, 1, 0x20,
  368. TFT_CMD_PWCTR1, 1, 0x23, //Power control VRH[5:0]
  369. TFT_CMD_PWCTR2, 1, 0x10, //Power control SAP[2:0];BT[3:0]
  370. TFT_CMD_VMCTR1, 2, 0x3e, 0x28, //VCM control
  371. TFT_CMD_VMCTR2, 1, 0x86, //VCM control2
  372. TFT_MADCTL, 1, // Memory Access Control (tft_orientation)
  373. (MADCTL_MX | TFT_RGB_BGR),
  374. // *** INTERFACE PIXEL FORMAT: 0x66 -> 18 bit; 0x55 -> 16 bit
  375. TFT_CMD_PIXFMT, 1, DISP_COLOR_BITS_24,
  376. TFT_INVOFF, 0,
  377. TFT_CMD_FRMCTR1, 2, 0x00, 0x18,
  378. TFT_CMD_DFUNCTR, 4, 0x08, 0x82, 0x27, 0x00, // Display Function Control
  379. TFT_PTLAR, 4, 0x00, 0x00, 0x01, 0x3F,
  380. TFT_CMD_3GAMMA_EN, 1, 0x00, // 3Gamma Function: Disable (0x02), Enable (0x03)
  381. TFT_CMD_GAMMASET, 1, 0x01, //Gamma curve selected (0x01, 0x02, 0x04, 0x08)
  382. TFT_CMD_GMCTRP1, 15, //Positive Gamma Correction
  383. 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00,
  384. TFT_CMD_GMCTRN1, 15, //Negative Gamma Correction
  385. 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F,
  386. TFT_CMD_SLPOUT, TFT_CMD_DELAY, // Sleep out
  387. 200, // 120 ms delay
  388. TFT_DISPON, TFT_CMD_DELAY, 200,
  389. };
  390. // Initialization sequence for ILI9488
  391. // ====================================
  392. static const uint8_t ILI9488_init[] = {
  393. #if PIN_NUM_RST
  394. 17, // 17 commands in list
  395. #else
  396. 18, // 18 commands in list
  397. TFT_CMD_SWRESET, TFT_CMD_DELAY, // 1: Software reset, no args, w/delay
  398. 200, // 200 ms delay
  399. #endif
  400. 0xE0, 15, 0x00, 0x03, 0x09, 0x08, 0x16, 0x0A, 0x3F, 0x78, 0x4C, 0x09, 0x0A, 0x08, 0x16, 0x1A, 0x0F,
  401. 0xE1, 15, 0x00, 0x16, 0x19, 0x03, 0x0F, 0x05, 0x32, 0x45, 0x46, 0x04, 0x0E, 0x0D, 0x35, 0x37, 0x0F,
  402. 0xC0, 2, //Power Control 1
  403. 0x17, //Vreg1out
  404. 0x15, //Verg2out
  405. 0xC1, 1, //Power Control 2
  406. 0x41, //VGH,VGL
  407. 0xC5, 3, //Power Control 3
  408. 0x00,
  409. 0x12, //Vcom
  410. 0x80,
  411. #if TFT_INVERT_ROTATION
  412. TFT_MADCTL, 1, (MADCTL_MV | TFT_RGB_BGR), // Memory Access Control (tft_orientation), set to portrait
  413. #else
  414. TFT_MADCTL, 1, (MADCTL_MX | TFT_RGB_BGR), // Memory Access Control (tft_orientation), set to portrait
  415. #endif
  416. // *** INTERFACE PIXEL FORMAT: 0x66 -> 18 bit;
  417. TFT_CMD_PIXFMT, 1, DISP_COLOR_BITS_24,
  418. 0xB0, 1, // Interface Mode Control
  419. 0x00, // 0x80: SDO NOT USE; 0x00 USE SDO
  420. 0xB1, 1, //Frame rate
  421. 0xA0, //60Hz
  422. 0xB4, 1, //Display Inversion Control
  423. 0x02, //2-dot
  424. 0xB6, 2, //Display Function Control RGB/MCU Interface Control
  425. 0x02, //MCU
  426. 0x02, //Source,Gate scan direction
  427. 0xE9, 1, // Set Image Function
  428. 0x00, // Disable 24 bit data
  429. 0x53, 1, // Write CTRL Display Value
  430. 0x28, // BCTRL && DD on
  431. 0x51, 1, // Write Display Brightness Value
  432. 0x7F, //
  433. 0xF7, 4, // Adjust Control
  434. 0xA9,
  435. 0x51,
  436. 0x2C,
  437. 0x02, // D7 stream, loose
  438. 0x11, TFT_CMD_DELAY, //Exit Sleep
  439. 120,
  440. 0x29, 0, //Display on
  441. };
  442. // Initialization commands for 7735B screens
  443. // ------------------------------------
  444. static const uint8_t STP7735_init[] = {
  445. #if PIN_NUM_RST
  446. 16, // 17 commands in list
  447. #else
  448. 17, // 18 commands in list:
  449. ST7735_SLPOUT, TFT_CMD_DELAY, // 2: Out of sleep mode, no args, w/delay
  450. 255, // 255 = 500 ms delay
  451. #endif
  452. TFT_CMD_PIXFMT, 1+TFT_CMD_DELAY, // 3: Set color mode, 1 arg + delay:
  453. 0x06, // 18-bit color 6-6-6 color format
  454. 10, // 10 ms delay
  455. ST7735_FRMCTR1, 3+TFT_CMD_DELAY, // 4: Frame rate control, 3 args + delay:
  456. 0x00, // fastest refresh
  457. 0x06, // 6 lines front porch
  458. 0x03, // 3 lines back porch
  459. 10, // 10 ms delay
  460. TFT_MADCTL , 1 , // 5: Memory access ctrl (directions), 1 arg:
  461. 0x08, // Row addr/col addr, bottom to top refresh
  462. ST7735_DISSET5, 2 , // 6: Display settings #5, 2 args, no delay:
  463. 0x15, // 1 clk cycle nonoverlap, 2 cycle gate
  464. // rise, 3 cycle osc equalize
  465. 0x02, // Fix on VTL
  466. ST7735_INVCTR , 1 , // 7: Display inversion control, 1 arg:
  467. 0x0, // Line inversion
  468. ST7735_PWCTR1 , 2+TFT_CMD_DELAY, // 8: Power control, 2 args + delay:
  469. 0x02, // GVDD = 4.7V
  470. 0x70, // 1.0uA
  471. 10, // 10 ms delay
  472. ST7735_PWCTR2 , 1 , // 9: Power control, 1 arg, no delay:
  473. 0x05, // VGH = 14.7V, VGL = -7.35V
  474. ST7735_PWCTR3 , 2 , // 10: Power control, 2 args, no delay:
  475. 0x01, // Opamp current small
  476. 0x02, // Boost frequency
  477. ST7735_VMCTR1 , 2+TFT_CMD_DELAY, // 11: Power control, 2 args + delay:
  478. 0x3C, // VCOMH = 4V
  479. 0x38, // VCOML = -1.1V
  480. 10, // 10 ms delay
  481. ST7735_PWCTR6 , 2 , // 12: Power control, 2 args, no delay:
  482. 0x11, 0x15,
  483. ST7735_GMCTRP1,16 , // 13: Magical unicorn dust, 16 args, no delay:
  484. 0x09, 0x16, 0x09, 0x20, // (seriously though, not sure what
  485. 0x21, 0x1B, 0x13, 0x19, // these config values represent)
  486. 0x17, 0x15, 0x1E, 0x2B,
  487. 0x04, 0x05, 0x02, 0x0E,
  488. ST7735_GMCTRN1,16+TFT_CMD_DELAY, // 14: Sparkles and rainbows, 16 args + delay:
  489. 0x0B, 0x14, 0x08, 0x1E, // (ditto)
  490. 0x22, 0x1D, 0x18, 0x1E,
  491. 0x1B, 0x1A, 0x24, 0x2B,
  492. 0x06, 0x06, 0x02, 0x0F,
  493. 10, // 10 ms delay
  494. TFT_CASET , 4 , // 15: Column addr set, 4 args, no delay:
  495. 0x00, 0x02, // XSTART = 2
  496. 0x00, 0x81, // XEND = 129
  497. TFT_PASET , 4 , // 16: Row addr set, 4 args, no delay:
  498. 0x00, 0x02, // XSTART = 1
  499. 0x00, 0x81, // XEND = 160
  500. ST7735_NORON , TFT_CMD_DELAY, // 17: Normal display on, no args, w/delay
  501. 10, // 10 ms delay
  502. TFT_DISPON , TFT_CMD_DELAY, // 18: Main screen turn on, no args, w/delay
  503. 255 // 255 = 500 ms delay
  504. };
  505. // Init for 7735R, part 1 (red or green tab)
  506. // --------------------------------------
  507. static const uint8_t STP7735R_init[] = {
  508. #if PIN_NUM_RST
  509. 14, // 14 commands in list
  510. #else
  511. 15, // 15 commands in list:
  512. ST7735_SWRESET, TFT_CMD_DELAY, // 1: Software reset, 0 args, w/delay
  513. 150, // 150 ms delay
  514. #endif
  515. ST7735_SLPOUT , TFT_CMD_DELAY, // 2: Out of sleep mode, 0 args, w/delay
  516. 255, // 500 ms delay
  517. ST7735_FRMCTR1, 3 , // 3: Frame rate ctrl - normal mode, 3 args:
  518. 0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D)
  519. ST7735_FRMCTR2, 3 , // 4: Frame rate control - idle mode, 3 args:
  520. 0x01, 0x2C, 0x2D, // Rate = fosc/(1x2+40) * (LINE+2C+2D)
  521. ST7735_FRMCTR3, 6 , // 5: Frame rate ctrl - partial mode, 6 args:
  522. 0x01, 0x2C, 0x2D, // Dot inversion mode
  523. 0x01, 0x2C, 0x2D, // Line inversion mode
  524. ST7735_INVCTR , 1 , // 6: Display inversion ctrl, 1 arg, no delay:
  525. 0x07, // No inversion
  526. ST7735_PWCTR1 , 3 , // 7: Power control, 3 args, no delay:
  527. 0xA2,
  528. 0x02, // -4.6V
  529. 0x84, // AUTO mode
  530. ST7735_PWCTR2 , 1 , // 8: Power control, 1 arg, no delay:
  531. 0xC5, // VGH25 = 2.4C VGSEL = -10 VGH = 3 * AVDD
  532. ST7735_PWCTR3 , 2 , // 9: Power control, 2 args, no delay:
  533. 0x0A, // Opamp current small
  534. 0x00, // Boost frequency
  535. ST7735_PWCTR4 , 2 , // 10: Power control, 2 args, no delay:
  536. 0x8A, // BCLK/2, Opamp current small & Medium low
  537. 0x2A,
  538. ST7735_PWCTR5 , 2 , // 11: Power control, 2 args, no delay:
  539. 0x8A, 0xEE,
  540. ST7735_VMCTR1 , 1 , // 12: Power control, 1 arg, no delay:
  541. 0x0E,
  542. TFT_INVOFF , 0 , // 13: Don't invert display, no args, no delay
  543. TFT_MADCTL , 1 , // 14: Memory access control (directions), 1 arg:
  544. 0xC0, // row addr/col addr, bottom to top refresh, RGB order
  545. TFT_CMD_PIXFMT , 1+TFT_CMD_DELAY, // 15: Set color mode, 1 arg + delay:
  546. 0x06, // 18-bit color 6-6-6 color format
  547. 10 // 10 ms delay
  548. };
  549. // Init for 7735R, part 2 (green tab only)
  550. // ---------------------------------------
  551. static const uint8_t Rcmd2green[] = {
  552. 2, // 2 commands in list:
  553. TFT_CASET , 4 , // 1: Column addr set, 4 args, no delay:
  554. 0x00, 0x02, // XSTART = 0
  555. 0x00, 0x7F+0x02, // XEND = 129
  556. TFT_PASET , 4 , // 2: Row addr set, 4 args, no delay:
  557. 0x00, 0x01, // XSTART = 0
  558. 0x00, 0x9F+0x01 // XEND = 160
  559. };
  560. // Init for 7735R, part 2 (red tab only)
  561. // -------------------------------------
  562. static const uint8_t Rcmd2red[] = {
  563. 2, // 2 commands in list:
  564. TFT_CASET , 4 , // 1: Column addr set, 4 args, no delay:
  565. 0x00, 0x00, // XSTART = 0
  566. 0x00, 0x7F, // XEND = 127
  567. TFT_PASET , 4 , // 2: Row addr set, 4 args, no delay:
  568. 0x00, 0x00, // XSTART = 0
  569. 0x00, 0x9F // XEND = 159
  570. };
  571. // Init for 7735R, part 3 (red or green tab)
  572. // -----------------------------------------
  573. static const uint8_t Rcmd3[] = {
  574. 4, // 4 commands in list:
  575. ST7735_GMCTRP1, 16 , // 1: Magical unicorn dust, 16 args, no delay:
  576. 0x02, 0x1c, 0x07, 0x12,
  577. 0x37, 0x32, 0x29, 0x2d,
  578. 0x29, 0x25, 0x2B, 0x39,
  579. 0x00, 0x01, 0x03, 0x10,
  580. ST7735_GMCTRN1, 16 , // 2: Sparkles and rainbows, 16 args, no delay:
  581. 0x03, 0x1d, 0x07, 0x06,
  582. 0x2E, 0x2C, 0x29, 0x2D,
  583. 0x2E, 0x2E, 0x37, 0x3F,
  584. 0x00, 0x00, 0x02, 0x10,
  585. ST7735_NORON , TFT_CMD_DELAY, // 3: Normal display on, no args, w/delay
  586. 10, // 10 ms delay
  587. TFT_DISPON , TFT_CMD_DELAY, // 4: Main screen turn on, no args w/delay
  588. 100 // 100 ms delay
  589. };
  590. // ==== Public functions =========================================================
  591. // == Low level functions; usually not used directly ==
  592. esp_err_t wait_trans_finish(uint8_t free_line);
  593. void disp_spi_transfer_cmd(int8_t cmd);
  594. void disp_spi_transfer_cmd_data(int8_t cmd, uint8_t *data, uint32_t len);
  595. void drawPixel(int16_t x, int16_t y, color_t color, uint8_t sel);
  596. void send_data(int x1, int y1, int x2, int y2, uint32_t len, color_t *buf);
  597. void TFT_pushColorRep(int x1, int y1, int x2, int y2, color_t data, uint32_t len);
  598. int read_data(int x1, int y1, int x2, int y2, int len, uint8_t *buf, uint8_t set_sp);
  599. color_t readPixel(int16_t x, int16_t y);
  600. int touch_get_data(uint8_t type);
  601. // Deactivate display's CS line
  602. //========================
  603. esp_err_t disp_deselect();
  604. // Activate display's CS line and configure SPI interface if necessary
  605. //======================
  606. esp_err_t disp_select();
  607. // Find maximum spi clock for successful read from display RAM
  608. // ** Must be used AFTER the display is initialized **
  609. //======================
  610. uint32_t find_rd_speed();
  611. // Change the screen rotation.
  612. // Input: m new rotation value (0 to 3)
  613. //=================================
  614. void _tft_setRotation(uint8_t rot);
  615. // Initialize all pins used by display driver
  616. // ** MUST be executed before SPI interface initialization
  617. //=================
  618. void TFT_PinsInit();
  619. // Perform display initialization sequence
  620. // Sets tft_orientation to landscape; clears the screen
  621. // * All pins must be configured
  622. // * SPI interface must already be setup
  623. // * 'tft_disp_type', 'COLOR_BITS', 'tft_width', 'tft_height' variables must be set
  624. //======================
  625. void TFT_display_init();
  626. //===================
  627. void stmpe610_Init();
  628. //============================================================
  629. int stmpe610_get_touch(uint16_t *x, uint16_t *y, uint16_t *z);
  630. //========================
  631. uint32_t stmpe610_getID();
  632. // ===============================================================================
  633. #endif