Dilbert
Firmware for the Dilbert interactive badge.
 All Classes Files Functions Variables Enumerations Macros Pages
Adafruit_ILI9341.h
1 /***************************************************
2  This is our library for the Adafruit ILI9341 Breakout and Shield
3  ----> http://www.adafruit.com/products/1651
4 
5  Check out the links above for our tutorials and wiring diagrams
6  These displays use SPI to communicate, 4 or 5 pins are required to
7  interface (RST is optional)
8  Adafruit invests time and resources providing this open source code,
9  please support Adafruit and open-source hardware by purchasing
10  products from Adafruit!
11 
12  Written by Limor Fried/Ladyada for Adafruit Industries.
13  MIT license, all text above must be included in any redistribution
14  ****************************************************/
15 
16 #ifndef _ADAFRUIT_ILI9341H_
17 #define _ADAFRUIT_ILI9341H_
18 
19 #if ARDUINO >= 100
20  #include "Arduino.h"
21  #include "Print.h"
22 #else
23  #include "WProgram.h"
24 #endif
25 #include <Adafruit_GFX.h>
26 #ifdef ESP8266
27 #include <pgmspace.h>
28 #else
29 #include <avr/pgmspace.h>
30 #endif
31 
32 #define ILI9341_TFTWIDTH 240
33 #define ILI9341_TFTHEIGHT 320
34 
35 #define ILI9341_NOP 0x00
36 #define ILI9341_SWRESET 0x01
37 #define ILI9341_RDDID 0x04
38 #define ILI9341_RDDST 0x09
39 
40 #define ILI9341_SLPIN 0x10
41 #define ILI9341_SLPOUT 0x11
42 #define ILI9341_PTLON 0x12
43 #define ILI9341_NORON 0x13
44 
45 #define ILI9341_RDMODE 0x0A
46 #define ILI9341_RDMADCTL 0x0B
47 #define ILI9341_RDPIXFMT 0x0C
48 #define ILI9341_RDIMGFMT 0x0D
49 #define ILI9341_RDSELFDIAG 0x0F
50 
51 #define ILI9341_INVOFF 0x20
52 #define ILI9341_INVON 0x21
53 #define ILI9341_GAMMASET 0x26
54 #define ILI9341_DISPOFF 0x28
55 #define ILI9341_DISPON 0x29
56 
57 #define ILI9341_CASET 0x2A
58 #define ILI9341_PASET 0x2B
59 #define ILI9341_RAMWR 0x2C
60 #define ILI9341_RAMRD 0x2E
61 
62 #define ILI9341_PTLAR 0x30
63 #define ILI9341_MADCTL 0x36
64 #define ILI9341_PIXFMT 0x3A
65 
66 #define ILI9341_FRMCTR1 0xB1
67 #define ILI9341_FRMCTR2 0xB2
68 #define ILI9341_FRMCTR3 0xB3
69 #define ILI9341_INVCTR 0xB4
70 #define ILI9341_DFUNCTR 0xB6
71 
72 #define ILI9341_PWCTR1 0xC0
73 #define ILI9341_PWCTR2 0xC1
74 #define ILI9341_PWCTR3 0xC2
75 #define ILI9341_PWCTR4 0xC3
76 #define ILI9341_PWCTR5 0xC4
77 #define ILI9341_VMCTR1 0xC5
78 #define ILI9341_VMCTR2 0xC7
79 
80 #define ILI9341_RDID1 0xDA
81 #define ILI9341_RDID2 0xDB
82 #define ILI9341_RDID3 0xDC
83 #define ILI9341_RDID4 0xDD
84 
85 #define ILI9341_GMCTRP1 0xE0
86 #define ILI9341_GMCTRN1 0xE1
87 /*
88 #define ILI9341_PWCTR6 0xFC
89 
90 */
91 
92 // Color definitions
93 #define ILI9341_BLACK 0x0000 /* 0, 0, 0 */
94 #define ILI9341_NAVY 0x000F /* 0, 0, 128 */
95 #define ILI9341_DARKGREEN 0x03E0 /* 0, 128, 0 */
96 #define ILI9341_DARKCYAN 0x03EF /* 0, 128, 128 */
97 #define ILI9341_MAROON 0x7800 /* 128, 0, 0 */
98 #define ILI9341_PURPLE 0x780F /* 128, 0, 128 */
99 #define ILI9341_OLIVE 0x7BE0 /* 128, 128, 0 */
100 #define ILI9341_LIGHTGREY 0xC618 /* 192, 192, 192 */
101 #define ILI9341_DARKGREY 0x7BEF /* 128, 128, 128 */
102 #define ILI9341_BLUE 0x001F /* 0, 0, 255 */
103 #define ILI9341_GREEN 0x07E0 /* 0, 255, 0 */
104 #define ILI9341_LIGHTBLUE 0x061F /* 0, 192, 255 */
105 #define ILI9341_CYAN 0x07FF /* 0, 255, 255 */
106 #define ILI9341_RED 0xF800 /* 255, 0, 0 */
107 #define ILI9341_MAGENTA 0xF81F /* 255, 0, 255 */
108 #define ILI9341_YELLOW 0xFFE0 /* 255, 255, 0 */
109 #define ILI9341_WHITE 0xFFFF /* 255, 255, 255 */
110 #define ILI9341_ORANGE 0xFD20 /* 255, 165, 0 */
111 #define ILI9341_GREENYELLOW 0xAFE5 /* 173, 255, 47 */
112 #define ILI9341_PINK 0xF81F
113 
114 //#define ILI9341_USE_DIGITAL_WRITE
115 //#define ILI9341_USE_NO_CS
116 #ifdef ESP8266
117 //not working
118 //#define ILI9341_USE_HW_CS
119 #endif
120 
121 class Adafruit_ILI9341 : public Adafruit_GFX {
122 
123  public:
124 #ifndef ESP8266
125  Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK,
126  int8_t _RST, int8_t _MISO);
127 #endif
128 #if defined(USE_HW_CS) || defined(USE_NO_CS)
129  Adafruit_ILI9341(int8_t _DC, int8_t _RST = -1);
130 #else
131  Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _RST = -1);
132 #endif
133  void begin(void),
134  setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1),
135  pushColor(uint16_t color),
136  fillScreen(uint16_t color),
137  drawPixel(int16_t x, int16_t y, uint16_t color),
138  drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
139  drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
140  fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
141  uint16_t color),
142  setRotation(uint8_t r),
143  invertDisplay(boolean i);
144  uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
145 
146  void commandList(uint8_t *addr);
147 
148  /* These are not for current use, 8-bit protocol only! */
149  uint8_t readdata(void),
150  readcommand8(uint8_t reg, uint8_t index = 0);
151  /*
152  uint16_t readcommand16(uint8_t);
153  uint32_t readcommand32(uint8_t);
154  void dummyclock(void);
155  */
156 
157  void writecommand(uint8_t c);
158  void writedata(uint8_t d);
159  void writedata(uint8_t * data, uint8_t size);
160  void writeCmdData(uint8_t cmd, uint8_t * data, uint8_t size);
161 
162 
163  uint16_t getHeight(void);
164  uint16_t getWidth(void);
165 
166  void area_update_start(uint32_t x, uint32_t y, uint32_t w, uint32_t h);
167  void area_update_data(uint8_t *data, uint32_t pixel);
168  void area_update_end(void);
169  private:
170 
171  uint8_t spiread(void);
172 
173 
174 #ifdef ESP8266
175  inline void spiwrite(uint8_t data);
176  inline void spiwrite16(uint16_t data);
177  inline void spiwriteBytes(uint8_t * data, uint32_t size);
178  inline void spiwritePattern(uint8_t * data, uint8_t size, uint32_t repeat);
179 
180  inline void setAddrWindow_(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
181 #else
182  void spiwrite(uint8_t);
183  void spiwrite16(uint16_t data);
184  void spiwriteBytes(uint8_t * data, uint8_t size);
185  void spiwritePattern(uint8_t * data, uint8_t size, uint8_t repeat);
186  void setAddrWindow_(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
187 #endif
188 
189  inline void spiCsHigh(void);
190  inline void spiCsLow(void);
191  inline void spiDcHigh(void);
192  inline void spiDcLow(void);
193 
194  uint8_t tabcolor;
195 #ifndef ESP8266
196  boolean hwSPI;
197 #endif
198 #if defined (__AVR__) || defined(TEENSYDUINO)
199  uint8_t mySPCR;
200  volatile uint8_t *mosiport, *clkport, *dcport, *rsport, *csport;
201  int8_t _cs, _dc, _rst, _mosi, _miso, _sclk;
202  uint8_t mosipinmask, clkpinmask, cspinmask, dcpinmask;
203 #elif defined (__arm__)
204  volatile RwReg *mosiport, *clkport, *dcport, *rsport, *csport;
205  uint32_t _cs, _dc, _rst, _mosi, _miso, _sclk;
206  uint32_t mosipinmask, clkpinmask, cspinmask, dcpinmask;
207 #elif defined (ESP8266)
208 #ifndef USE_HW_CS
209  int8_t _cs;
210  uint32_t _csMask;
211 #endif
212  int8_t _dc, _rst;
213  uint32_t _dcMask, _rstMask;
214 #endif
215 };
216 
217 #endif
Definition: Adafruit_ILI9341.h:121