upm  0.5.1
Sensor/Actuator repository for libmraa (v0.9.1)
 All Data Structures Files Functions Variables Enumerations Enumerator Macros Groups Pages
ili9341.h
1 /*
2  * Author: Shawn Hymel
3  * Copyright (c) 2015 SparkFun Electronics
4  *
5  * Credits to Adafruit.
6  * Based on Adafruit ILI9341 library, see original license in license.txt file.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27 
28 #pragma once
29 
30 // Includes
31 #include <string>
32 #include <mraa/common.hpp>
33 #include <mraa/gpio.hpp>
34 #include <mraa/spi.hpp>
35 #include "gfx.h"
36 
37 // Defines
38 #define ILI9341_TFTWIDTH 240
39 #define ILI9341_TFTHEIGHT 320
40 
41 #define SPI_FREQ 15000000
42 
43 #define ILI9341_NOP 0x00
44 #define ILI9341_SWRESET 0x01
45 #define ILI9341_RDDID 0x04
46 #define ILI9341_RDDST 0x09
47 
48 #define ILI9341_SLPIN 0x10
49 #define ILI9341_SLPOUT 0x11
50 #define ILI9341_PTLON 0x12
51 #define ILI9341_NORON 0x13
52 
53 #define ILI9341_RDMODE 0x0A
54 #define ILI9341_RDMADCTL 0x0B
55 #define ILI9341_RDPIXFMT 0x0C
56 #define ILI9341_RDIMGFMT 0x0D
57 #define ILI9341_RDSELFDIAG 0x0F
58 
59 #define ILI9341_INVOFF 0x20
60 #define ILI9341_INVON 0x21
61 #define ILI9341_GAMMASET 0x26
62 #define ILI9341_DISPOFF 0x28
63 #define ILI9341_DISPON 0x29
64 
65 #define ILI9341_CASET 0x2A
66 #define ILI9341_PASET 0x2B
67 #define ILI9341_RAMWR 0x2C
68 #define ILI9341_RAMRD 0x2E
69 
70 #define ILI9341_PTLAR 0x30
71 #define ILI9341_MADCTL 0x36
72 #define ILI9341_PIXFMT 0x3A
73 
74 #define ILI9341_FRMCTR1 0xB1
75 #define ILI9341_FRMCTR2 0xB2
76 #define ILI9341_FRMCTR3 0xB3
77 #define ILI9341_INVCTR 0xB4
78 #define ILI9341_DFUNCTR 0xB6
79 
80 #define ILI9341_PWCTR1 0xC0
81 #define ILI9341_PWCTR2 0xC1
82 #define ILI9341_PWCTR3 0xC2
83 #define ILI9341_PWCTR4 0xC3
84 #define ILI9341_PWCTR5 0xC4
85 #define ILI9341_VMCTR1 0xC5
86 #define ILI9341_VMCTR2 0xC7
87 
88 #define ILI9341_RDID1 0xDA
89 #define ILI9341_RDID2 0xDB
90 #define ILI9341_RDID3 0xDC
91 #define ILI9341_RDID4 0xDD
92 
93 #define ILI9341_GMCTRP1 0xE0
94 #define ILI9341_GMCTRN1 0xE1
95 
96 #define MADCTL_MY 0x80
97 #define MADCTL_MX 0x40
98 #define MADCTL_MV 0x20
99 #define MADCTL_ML 0x10
100 #define MADCTL_RGB 0x00
101 #define MADCTL_BGR 0x08
102 #define MADCTL_MH 0x04
103 
104 #define HIGH 1
105 #define LOW 0
106 
107 #define DELAY 0x80
108 
109 // Color definitions
110 #define ILI9341_BLACK 0x0000 /* 0, 0, 0 */
111 #define ILI9341_NAVY 0x000F /* 0, 0, 128 */
112 #define ILI9341_DARKGREEN 0x03E0 /* 0, 128, 0 */
113 #define ILI9341_DARKCYAN 0x03EF /* 0, 128, 128 */
114 #define ILI9341_MAROON 0x7800 /* 128, 0, 0 */
115 #define ILI9341_PURPLE 0x780F /* 128, 0, 128 */
116 #define ILI9341_OLIVE 0x7BE0 /* 128, 128, 0 */
117 #define ILI9341_LIGHTGREY 0xC618 /* 192, 192, 192 */
118 #define ILI9341_DARKGREY 0x7BEF /* 128, 128, 128 */
119 #define ILI9341_BLUE 0x001F /* 0, 0, 255 */
120 #define ILI9341_GREEN 0x07E0 /* 0, 255, 0 */
121 #define ILI9341_CYAN 0x07FF /* 0, 255, 255 */
122 #define ILI9341_RED 0xF800 /* 255, 0, 0 */
123 #define ILI9341_MAGENTA 0xF81F /* 255, 0, 255 */
124 #define ILI9341_YELLOW 0xFFE0 /* 255, 255, 0 */
125 #define ILI9341_WHITE 0xFFFF /* 255, 255, 255 */
126 #define ILI9341_ORANGE 0xFD20 /* 255, 165, 0 */
127 #define ILI9341_GREENYELLOW 0xAFE5 /* 173, 255, 47 */
128 #define ILI9341_PINK 0xF81F
129 
130 namespace upm {
152  class ILI9341 : public GFX {
153  public:
162  ILI9341(uint8_t csLCD, uint8_t csSD, uint8_t dc, uint8_t rst);
163 
167  std::string name() {
168  return m_name;
169  }
170 
174  void initModule();
175 
179  void configModule();
180 
190  void setAddrWindow(uint16_t x0,
191  uint16_t y0,
192  uint16_t x1,
193  uint16_t y1);
194 
203  void drawPixel(int16_t x, int16_t y, uint16_t color);
204 
213  void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
214 
223  void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
224 
234  void fillRect(int16_t x,
235  int16_t y,
236  int16_t w,
237  int16_t h,
238  uint16_t color);
239 
245  void fillScreen(uint16_t color);
246 
252  void setRotation(uint8_t r);
253 
259  void invertDisplay(bool i);
260 
269  uint16_t color565(uint8_t r, uint8_t g, uint8_t b);
270 
276  void executeCMDList(const uint8_t *addr);
277 
283  void writecommand(uint8_t c);
284 
290  void writedata(uint8_t d);
291 
295  mraa::Result lcdCSOn();
296 
300  mraa::Result lcdCSOff();
301 
305  mraa::Result sdCSOn();
306 
310  mraa::Result sdCSOff();
311 
315  mraa::Result dcHigh();
316 
320  mraa::Result dcLow();
321 
325  mraa::Result rstHigh();
326 
330  mraa::Result rstLow();
331 
332  private:
333  mraa::Spi m_spi;
334  uint8_t m_spiBuffer[32];
335 
336  mraa::Gpio m_csLCDPinCtx;
337  mraa::Gpio m_csSDPinCtx;
338  mraa::Gpio m_dcPinCtx;
339  mraa::Gpio m_rstPinCtx;
340 
341  std::string m_name;
342  };
343 }
344 
uint16_t color565(uint8_t r, uint8_t g, uint8_t b)
Definition: ili9341.cxx:349
void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color)
Definition: ili9341.cxx:285
void invertDisplay(bool i)
Definition: ili9341.cxx:345
void executeCMDList(const uint8_t *addr)
Definition: ili9341.cxx:353
void drawPixel(int16_t x, int16_t y, uint16_t color)
Definition: ili9341.cxx:246
mraa::Result lcdCSOn()
Definition: ili9341.cxx:391
mraa::Result lcdCSOff()
Definition: ili9341.cxx:407
void setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1)
Definition: ili9341.cxx:226
GFX helper class.
Definition: gfx.h:38
std::string name()
Definition: ili9341.h:167
ILI9341(uint8_t csLCD, uint8_t csSD, uint8_t dc, uint8_t rst)
Definition: ili9341.cxx:40
void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color)
Definition: ili9341.cxx:258
mraa::Result dcHigh()
Definition: ili9341.cxx:445
void writecommand(uint8_t c)
Definition: ili9341.cxx:377
mraa::Result rstLow()
Definition: ili9341.cxx:478
mraa::Result rstHigh()
Definition: ili9341.cxx:467
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color)
Definition: ili9341.cxx:312
void fillScreen(uint16_t color)
Definition: ili9341.cxx:341
void initModule()
Definition: ili9341.cxx:48
API for the ILI9342 LCd.
Definition: ili9341.h:152
mraa::Result sdCSOff()
Definition: ili9341.cxx:434
void writedata(uint8_t d)
Definition: ili9341.cxx:384
void configModule()
Definition: ili9341.cxx:107
mraa::Result sdCSOn()
Definition: ili9341.cxx:418
void setRotation(uint8_t r)
Definition: ili9341.cxx:79
mraa::Result dcLow()
Definition: ili9341.cxx:456