Linduino  1.3.0
Linear Technology Arduino-Compatible Demonstration Board
Adafruit_ILI9341.h
Go to the documentation of this file.
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 __AVR
27 #include <avr/pgmspace.h>
28 #elif defined(ESP8266)
29 #include <pgmspace.h>
30 #endif
31 
32 
33 #if defined (__AVR__) || defined(TEENSYDUINO) || defined (__arm__)
34 #define USE_FAST_PINIO
35 #endif
36 
37 #define ILI9341_TFTWIDTH 240
38 #define ILI9341_TFTHEIGHT 320
39 
40 #define ILI9341_NOP 0x00
41 #define ILI9341_SWRESET 0x01
42 #define ILI9341_RDDID 0x04
43 #define ILI9341_RDDST 0x09
44 
45 #define ILI9341_SLPIN 0x10
46 #define ILI9341_SLPOUT 0x11
47 #define ILI9341_PTLON 0x12
48 #define ILI9341_NORON 0x13
49 
50 #define ILI9341_RDMODE 0x0A
51 #define ILI9341_RDMADCTL 0x0B
52 #define ILI9341_RDPIXFMT 0x0C
53 #define ILI9341_RDIMGFMT 0x0D
54 #define ILI9341_RDSELFDIAG 0x0F
55 
56 #define ILI9341_INVOFF 0x20
57 #define ILI9341_INVON 0x21
58 #define ILI9341_GAMMASET 0x26
59 #define ILI9341_DISPOFF 0x28
60 #define ILI9341_DISPON 0x29
61 
62 #define ILI9341_CASET 0x2A
63 #define ILI9341_PASET 0x2B
64 #define ILI9341_RAMWR 0x2C
65 #define ILI9341_RAMRD 0x2E
66 
67 #define ILI9341_PTLAR 0x30
68 #define ILI9341_MADCTL 0x36
69 #define ILI9341_PIXFMT 0x3A
70 
71 #define ILI9341_FRMCTR1 0xB1
72 #define ILI9341_FRMCTR2 0xB2
73 #define ILI9341_FRMCTR3 0xB3
74 #define ILI9341_INVCTR 0xB4
75 #define ILI9341_DFUNCTR 0xB6
76 
77 #define ILI9341_PWCTR1 0xC0
78 #define ILI9341_PWCTR2 0xC1
79 #define ILI9341_PWCTR3 0xC2
80 #define ILI9341_PWCTR4 0xC3
81 #define ILI9341_PWCTR5 0xC4
82 #define ILI9341_VMCTR1 0xC5
83 #define ILI9341_VMCTR2 0xC7
84 
85 #define ILI9341_RDID1 0xDA
86 #define ILI9341_RDID2 0xDB
87 #define ILI9341_RDID3 0xDC
88 #define ILI9341_RDID4 0xDD
89 
90 #define ILI9341_GMCTRP1 0xE0
91 #define ILI9341_GMCTRN1 0xE1
92 /*
93 #define ILI9341_PWCTR6 0xFC
94 
95 */
96 
97 // Color definitions
98 #define ILI9341_BLACK 0x0000 /* 0, 0, 0 */
99 #define ILI9341_NAVY 0x000F /* 0, 0, 128 */
100 #define ILI9341_DARKGREEN 0x03E0 /* 0, 128, 0 */
101 #define ILI9341_DARKCYAN 0x03EF /* 0, 128, 128 */
102 #define ILI9341_MAROON 0x7800 /* 128, 0, 0 */
103 #define ILI9341_PURPLE 0x780F /* 128, 0, 128 */
104 #define ILI9341_OLIVE 0x7BE0 /* 128, 128, 0 */
105 #define ILI9341_LIGHTGREY 0xC618 /* 192, 192, 192 */
106 #define ILI9341_DARKGREY 0x7BEF /* 128, 128, 128 */
107 #define ILI9341_BLUE 0x001F /* 0, 0, 255 */
108 #define ILI9341_GREEN 0x07E0 /* 0, 255, 0 */
109 #define ILI9341_CYAN 0x07FF /* 0, 255, 255 */
110 #define ILI9341_RED 0xF800 /* 255, 0, 0 */
111 #define ILI9341_MAGENTA 0xF81F /* 255, 0, 255 */
112 #define ILI9341_YELLOW 0xFFE0 /* 255, 255, 0 */
113 #define ILI9341_WHITE 0xFFFF /* 255, 255, 255 */
114 #define ILI9341_ORANGE 0xFD20 /* 255, 165, 0 */
115 #define ILI9341_GREENYELLOW 0xAFE5 /* 173, 255, 47 */
116 #define ILI9341_PINK 0xF81F
117 
119 {
120 
121  public:
122 
123  Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK,
124  int8_t _RST, int8_t _MISO);
125  Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _RST = -1);
126 
127  void begin(void),
128  setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1),
129  pushColor(uint16_t color),
130  fillScreen(uint16_t color),
131  drawPixel(int16_t x, int16_t y, uint16_t color),
132  drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
133  drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
134  fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
135  uint16_t color),
136  setRotation(uint8_t r),
137  invertDisplay(boolean i);
138  uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
139 
140  /* These are not for current use, 8-bit protocol only! */
141  uint8_t readdata(void),
142  readcommand8(uint8_t reg, uint8_t index = 0);
143  /*
144  uint16_t readcommand16(uint8_t);
145  uint32_t readcommand32(uint8_t);
146  void dummyclock(void);
147  */
148 
149  void spiwrite(uint8_t),
150  writecommand(uint8_t c),
151  writedata(uint8_t d),
152  commandList(uint8_t *addr);
153  uint8_t spiread(void);
154 
155  private:
156  uint8_t tabcolor;
157 
158 
159 
160  boolean hwSPI;
161 #if defined (__AVR__) || defined(TEENSYDUINO)
162  uint8_t mySPCR;
163  volatile uint8_t *mosiport, *clkport, *dcport, *rsport, *csport;
164  int8_t _cs, _dc, _rst, _mosi, _miso, _sclk;
165  uint8_t mosipinmask, clkpinmask, cspinmask, dcpinmask;
166 ////This def is for the Arduino.ORG M0!!!
167 //#elif defined(ARDUINO_SAM_ZERO)
168 // volatile PORT_OUT_Type *mosiport, *clkport, *dcport, *rsport, *csport;
169 // int32_t _cs, _dc, _rst, _mosi, _miso, _sclk;
170 // PORT_OUT_Type mosipinmask, clkpinmask, cspinmask, dcpinmask;
171 #elif defined (__arm__)
172  volatile RwReg *mosiport, *clkport, *dcport, *rsport, *csport;
173  int32_t _cs, _dc, _rst, _mosi, _miso, _sclk;
174  uint32_t mosipinmask, clkpinmask, cspinmask, dcpinmask;
175 #elif defined (ARDUINO_ARCH_ARC32)
176  int8_t _cs, _dc, _rst, _mosi, _miso, _sclk;
177 #elif defined (ESP8266)
178  int32_t _cs, _dc, _rst, _mosi, _miso, _sclk;
179 #endif
180 };
181 
182 #endif
uint8_t readdata(void)
void writecommand(uint8_t c)
void spiwrite(uint8_t)
void drawPixel(int16_t x, int16_t y, uint16_t color)
Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK, int8_t _RST, int8_t _MISO)
void pushColor(uint16_t color)
uint16_t color565(uint8_t r, uint8_t g, uint8_t b)
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
uint8_t readcommand8(uint8_t reg, uint8_t index=0)
void setRotation(uint8_t r)
uint8_t spiread(void)
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
void writedata(uint8_t d)
static int index
void setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
void fillScreen(uint16_t color)
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
static int i
Definition: DC2430A.ino:184
void commandList(uint8_t *addr)
void invertDisplay(boolean i)