Adafruit_ILI9341.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*!
  2. * @file Adafruit_ILI9341.h
  3. *
  4. * This is the documentation for Adafruit's ILI9341 driver for the
  5. * Arduino platform.
  6. *
  7. * This library works with the Adafruit 2.8" Touch Shield V2 (SPI)
  8. * http://www.adafruit.com/products/1651
  9. * Adafruit 2.4" TFT LCD with Touchscreen Breakout w/MicroSD Socket - ILI9341
  10. * https://www.adafruit.com/product/2478
  11. * 2.8" TFT LCD with Touchscreen Breakout Board w/MicroSD Socket - ILI9341
  12. * https://www.adafruit.com/product/1770
  13. * 2.2" 18-bit color TFT LCD display with microSD card breakout - ILI9340
  14. * https://www.adafruit.com/product/1770
  15. * TFT FeatherWing - 2.4" 320x240 Touchscreen For All Feathers
  16. * https://www.adafruit.com/product/3315
  17. *
  18. * These displays use SPI to communicate, 4 or 5 pins are required
  19. * to interface (RST is optional).
  20. *
  21. * Adafruit invests time and resources providing this open source code,
  22. * please support Adafruit and open-source hardware by purchasing
  23. * products from Adafruit!
  24. *
  25. *
  26. * This library depends on <a href="https://github.com/adafruit/Adafruit_GFX">
  27. * Adafruit_GFX</a> being present on your system. Please make sure you have
  28. * installed the latest version before using this library.
  29. *
  30. * Written by Limor "ladyada" Fried for Adafruit Industries.
  31. *
  32. * BSD license, all text here must be included in any redistribution.
  33. *
  34. */
  35. #ifndef _ADAFRUIT_ILI9341H_
  36. #define _ADAFRUIT_ILI9341H_
  37. #include "Arduino.h"
  38. #include "Print.h"
  39. #include <SPI.h>
  40. #include "Adafruit_GFX.h"
  41. #include <Adafruit_SPITFT.h>
  42. #include <Adafruit_SPITFT_Macros.h>
  43. #define ILI9341_TFTWIDTH 240 ///< ILI9341 max TFT width
  44. #define ILI9341_TFTHEIGHT 320 ///< ILI9341 max TFT height
  45. #define ILI9341_NOP 0x00 ///< No-op register
  46. #define ILI9341_SWRESET 0x01 ///< Software reset register
  47. #define ILI9341_RDDID 0x04 ///< Read display identification information
  48. #define ILI9341_RDDST 0x09 ///< Read Display Status
  49. #define ILI9341_SLPIN 0x10 ///< Enter Sleep Mode
  50. #define ILI9341_SLPOUT 0x11 ///< Sleep Out
  51. #define ILI9341_PTLON 0x12 ///< Partial Mode ON
  52. #define ILI9341_NORON 0x13 ///< Normal Display Mode ON
  53. #define ILI9341_RDMODE 0x0A ///< Read Display Power Mode
  54. #define ILI9341_RDMADCTL 0x0B ///< Read Display MADCTL
  55. #define ILI9341_RDPIXFMT 0x0C ///< Read Display Pixel Format
  56. #define ILI9341_RDIMGFMT 0x0D ///< Read Display Image Format
  57. #define ILI9341_RDSELFDIAG 0x0F ///< Read Display Self-Diagnostic Result
  58. #define ILI9341_INVOFF 0x20 ///< Display Inversion OFF
  59. #define ILI9341_INVON 0x21 ///< Display Inversion ON
  60. #define ILI9341_GAMMASET 0x26 ///< Gamma Set
  61. #define ILI9341_DISPOFF 0x28 ///< Display OFF
  62. #define ILI9341_DISPON 0x29 ///< Display ON
  63. #define ILI9341_CASET 0x2A ///< Column Address Set
  64. #define ILI9341_PASET 0x2B ///< Page Address Set
  65. #define ILI9341_RAMWR 0x2C ///< Memory Write
  66. #define ILI9341_RAMRD 0x2E ///< Memory Read
  67. #define ILI9341_PTLAR 0x30 ///< Partial Area
  68. #define ILI9341_MADCTL 0x36 ///< Memory Access Control
  69. #define ILI9341_VSCRSADD 0x37 ///< Vertical Scrolling Start Address
  70. #define ILI9341_PIXFMT 0x3A ///< COLMOD: Pixel Format Set
  71. #define ILI9341_FRMCTR1 0xB1 ///< Frame Rate Control (In Normal Mode/Full Colors)
  72. #define ILI9341_FRMCTR2 0xB2 ///< Frame Rate Control (In Idle Mode/8 colors)
  73. #define ILI9341_FRMCTR3 0xB3 ///< Frame Rate control (In Partial Mode/Full Colors)
  74. #define ILI9341_INVCTR 0xB4 ///< Display Inversion Control
  75. #define ILI9341_DFUNCTR 0xB6 ///< Display Function Control
  76. #define ILI9341_PWCTR1 0xC0 ///< Power Control 1
  77. #define ILI9341_PWCTR2 0xC1 ///< Power Control 2
  78. #define ILI9341_PWCTR3 0xC2 ///< Power Control 3
  79. #define ILI9341_PWCTR4 0xC3 ///< Power Control 4
  80. #define ILI9341_PWCTR5 0xC4 ///< Power Control 5
  81. #define ILI9341_VMCTR1 0xC5 ///< VCOM Control 1
  82. #define ILI9341_VMCTR2 0xC7 ///< VCOM Control 2
  83. #define ILI9341_RDID1 0xDA ///< Read ID 1
  84. #define ILI9341_RDID2 0xDB ///< Read ID 2
  85. #define ILI9341_RDID3 0xDC ///< Read ID 3
  86. #define ILI9341_RDID4 0xDD ///< Read ID 4
  87. #define ILI9341_GMCTRP1 0xE0 ///< Positive Gamma Correction
  88. #define ILI9341_GMCTRN1 0xE1 ///< Negative Gamma Correction
  89. //#define ILI9341_PWCTR6 0xFC
  90. // Color definitions
  91. #define ILI9341_BLACK 0x0000 ///< 0, 0, 0
  92. #define ILI9341_NAVY 0x000F ///< 0, 0, 123
  93. #define ILI9341_DARKGREEN 0x03E0 ///< 0, 125, 0
  94. #define ILI9341_DARKCYAN 0x03EF ///< 0, 125, 123
  95. #define ILI9341_MAROON 0x7800 ///< 123, 0, 0
  96. #define ILI9341_PURPLE 0x780F ///< 123, 0, 123
  97. #define ILI9341_OLIVE 0x7BE0 ///< 123, 125, 0
  98. #define ILI9341_LIGHTGREY 0xC618 ///< 198, 195, 198
  99. #define ILI9341_DARKGREY 0x7BEF ///< 123, 125, 123
  100. #define ILI9341_BLUE 0x001F ///< 0, 0, 255
  101. #define ILI9341_GREEN 0x07E0 ///< 0, 255, 0
  102. #define ILI9341_CYAN 0x07FF ///< 0, 255, 255
  103. #define ILI9341_RED 0xF800 ///< 255, 0, 0
  104. #define ILI9341_MAGENTA 0xF81F ///< 255, 0, 255
  105. #define ILI9341_YELLOW 0xFFE0 ///< 255, 255, 0
  106. #define ILI9341_WHITE 0xFFFF ///< 255, 255, 255
  107. #define ILI9341_ORANGE 0xFD20 ///< 255, 165, 0
  108. #define ILI9341_GREENYELLOW 0xAFE5 ///< 173, 255, 41
  109. #define ILI9341_PINK 0xFC18 ///< 255, 130, 198
  110. ///< Class to manage hardware interface with ILI9341 chipset (also seems to work with ILI9340)
  111. class Adafruit_ILI9341 : public Adafruit_SPITFT {
  112. public:
  113. Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK, int8_t _RST = -1, int8_t _MISO = -1);
  114. Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _RST = -1);
  115. void begin(uint32_t freq=0);
  116. void setRotation(uint8_t r);
  117. void invertDisplay(boolean i);
  118. void scrollTo(uint16_t y);
  119. void setScrollMargins(uint16_t top, uint16_t bottom);
  120. // Transaction API not used by GFX
  121. void setAddrWindow(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
  122. uint8_t readcommand8(uint8_t reg, uint8_t index=0);
  123. };
  124. #endif // _ADAFRUIT_ILI9341H_