LCDGFX LCD display driver  1.0.2
This library is developed to control SSD1306/SSD1325/SSD1327/SSD1331/SSD1351/IL9163/PCD8554 RGB i2c/spi LED displays
lcd_ili9341.inl
1 /*
2  MIT License
3 
4  Copyright (c) 2019-2020, Alexey Dynda
5 
6  Permission is hereby granted, free of charge, to any person obtaining a copy
7  of this software and associated documentation files (the "Software"), to deal
8  in the Software without restriction, including without limitation the rights
9  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  copies of the Software, and to permit persons to whom the Software is
11  furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in all
14  copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  SOFTWARE.
23 */
24 /* !!! THIS FILE IS AUTO GENERATED !!! */
25 #include "lcd_hal/io.h"
26 #ifdef SDL_EMULATION
27 #include "sdl_core.h"
28 #endif
29 #include "nano_gfx_types.h"
30 
31 #ifndef CMD_ARG
32 #define CMD_ARG 0xFF
33 #endif
34 
35 template <class I>
37 {
38  lcduint_t rx = w ? (x + w - 1) : (m_base.width() - 1);
39  rx = rx < m_base.width() ? rx: (m_base.width() -1);
40  this->start();
41  spiDataMode(0);
42  this->send(0x2A);
43  spiDataMode(1); // According to datasheet all args must be passed in data mode
44  this->send(x >> 8);
45  this->send(x & 0xFF);
46  this->send(rx >> 8);
47  this->send(rx & 0xFF);
48  spiDataMode(0);
49  this->send(0x2B);
50  spiDataMode(1); // According to datasheet all args must be passed in data mode
51  this->send(y >> 8);
52  this->send(y & 0xFF);
53  this->send((m_base.height() - 1) >> 8);
54  this->send((m_base.height() - 1) & 0xFF);
55  spiDataMode(0);
56  this->send(0x2C);
57  spiDataMode(1);
58 }
59 
60 template <class I>
62 {
63 
64 }
65 
66 template <class I>
68 {
69  this->stop();
70 }
71 
72 template <class I>
74 {
75  if ( m_dc >= 0 )
76  {
77  lcd_gpioWrite( m_dc, mode ? LCD_HIGH : LCD_LOW );
78  }
79 }
80 
81 template <class I>
83 {
84  this->start();
85  if (m_dc >= 0)
86  spiDataMode(0);
87  else
88  this->send(0x00);
89 }
90 
91 template <class I>
92 void InterfaceILI9341<I>::setRotation(uint8_t rotation)
93 {
94  uint8_t ram_mode;
95  if ((rotation^m_rotation) & 0x01)
96  {
97  m_base.swapDimensions();
98  }
99  m_rotation = (rotation & 0x03);
100  this->start();
101  spiDataMode(0);
102  this->send(0x28);
103  this->send(0x36);
104  spiDataMode(1);
105  switch (m_rotation)
106  {
107  case 0:
108  ram_mode = m_rotate_output ? 0b11100100: 0b10000100;
109  break;
110  case 1: // 90 degree CW
111  ram_mode = 0b11100000;
112  break;
113  case 2: // 180 degree CW
114  ram_mode = 0b01010100;
115  break;
116  default: // 270 degree CW
117  ram_mode = 0b00100000;
118  break;
119  }
120  this->send( ram_mode | m_rgb_bit );
121  spiDataMode(0);
122  this->send(0x29);
123  this->stop();
124 }
125 
126 template <class I>
128 {
129  m_rotate_output = rotate;
130  this->setRotation( m_rotation );
131 }
132 
133 
135 // ILI9341 basic 16-bit implementation
137 
138 template <class I>
140 {
141 }
142 
143 template <class I>
145 {
146 }
147 
148 static const PROGMEM uint8_t s_ILI9341_lcd240x320x16_initData[] =
149 {
150 #ifdef SDL_EMULATION
151  SDL_LCD_ILI9341, 0x00,
152  0x00, 0x00,
153 #endif
154  0x01, 0x00, // sw reset. not needed, we do hardware reset
155  0x11, 0x00, // exit sleep mode
156  0x3A, 0x01, 0x05, // set 16-bit pixel format
157  0x26, 0x01, 0x04, // set gamma curve: valid values 1, 2, 4, 8
158  0xF2, 0x01, 0x01, // enable gamma adjustment, 0 - to disable
159  0xE0, 15, 0x3F, 0x25, 0x1C,
160  0x1E, 0x20, 0x12,
161  0x2A, 0x90, 0x24,
162  0x11, 0x00, 0x00,
163  0x00, 0x00, 0x00, // positive gamma correction
164  0xE1, 15, 0x20, 0x20, 0x20,
165  0x20, 0x05, 0x00,
166  0x15, 0xA7, 0x3D,
167  0x18, 0x25, 0x2A,
168  0x2B, 0x2B, 0x3A, // negative gamma correction
169 // 0xB1, CMD_ARG, 0x08, CMD_ARG, 0x08, // frame rate control 1, use by default
170 // 0xB4, CMD_ARG, 0x07, // display inversion, use by default
171  0xC0, 0x02, 0x0A, 0x02, // power control 1
172  0xC1, 0x01, 0x02, // power control 2
173  0xC5, 0x02, 0x50, 0x5B, // vcom control 1
174  0xC7, 0x01, 0x40, // vcom offset
175  0x36, 0x01, 0b10001100, // set addressing mode
176  0x29, 0x00, // display on
177 };
178 
180 // ILI9341 basic 16-bit implementation
182 
183 template <class I>
185 {
186  ssd1306_resetController2( this->m_rstPin, 100 );
187  this->m_w = 240;
188  this->m_h = 320;
189  // Give LCD some time to initialize. Refer to ILI9341 datasheet
190  lcd_delay(100);
191  _configureSpiDisplay<I>(this->m_intf,
192  s_ILI9341_lcd240x320x16_initData,
193  sizeof(s_ILI9341_lcd240x320x16_initData));
194 }
195 
196 template <class I>
198 {
199 }
200 
201 static const PROGMEM uint8_t s_ILI9341_lcd128x160x16_initData[] =
202 {
203 #ifdef SDL_EMULATION
204  SDL_LCD_ST7735, 0x00,
205  0b00000011, 0x00,
206 #endif
207  0x01, CMD_DELAY, 150, // SWRESET sw reset. not needed, we do hardware reset
208  0x11, CMD_DELAY, 255, // SLPOUT exit sleep mode
209  0xB1, 0x03, 0x01, 0x2C, 0x2D, // FRMCTR1 frame rate control 1, use by default
210  0xB2, 0x03, 0x01, 0x2C, 0x2D, // FRMCTR2, Frame Rate Control (In Idle mode/ 8-colors)
211  0xB3, 0x06, // FRMCTR3 (B3h): Frame Rate Control (In Partial mode/ full colors)
212  0x01, 0x2C, 0x2D,
213  0x01, 0x2C, 0x2D,
214  0xB4, 0x01, 0x07, // INVCTR display inversion, use by default
215  0xB6, 0x02, 0x15, 0x02, // DISSET5
216  0xC0, 0x03, 0xA2, 0x02, 0x84, // PWCTR1 power control 1
217  0xC1, 0x01, 0xC5, // PWCTR2 power control 2
218  0xC2, 0x02, 0x0A, 0x00, // PWCTR3 power control 3
219  0xC3, 0x02, 0x8A, 0x2A, // PWCTR4 (C3h): Power Control 4 (in Idle mode/ 8-colors)
220  0xC4, 0x02, 0x8A, 0xEE, // PWCTR5 (C4h): Power Control 5 (in Partial mode/ full-colors)
221  0xC5, 0x01, 0x0E, // VMCTR vcom control 1
222  0x20, 0x00, // INVOFF (20h): Display Inversion Off
223 // 0xFC, 0x02, 0x11, 0x15, // PWCTR6
224  0x36, 0x01, 0b00000000, // MADCTL
225  0x3A, 0x01, 0x05, // COLMOD set 16-bit pixel format
226 // 0x26, 1, 0x08, // GAMSET set gamma curve: valid values 1, 2, 4, 8
227 // 0xF2, 1, 0x01, // enable gamma adjustment, 0 - to disable
228  0xE0, 0x10, // GMCTRP1 positive gamma correction
229  0x0F, 0x1A, 0x0F, 0x18,
230  0x2F, 0x28, 0x20, 0x22,
231  0x1F, 0x1B, 0x23, 0x37,
232  0x00, 0x07, 0x02, 0x10,
233  0xE1, 0x10, // GMCTRN1 negative gamma correction
234  0x0F, 0x1B, 0x0F, 0x17,
235  0x33, 0x2C, 0x29, 0x2E,
236  0x30, 0x30, 0x39, 0x3F,
237  0x00, 0x07, 0x03, 0x10,
238 // 0xC7, 1, 0x40, // vcom offset
239 // 0x2A, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x7F, // set column address, not needed. set by direct API
240 // 0x2B, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x9F, // set page address, not needed. set by direct API
241  0x29, CMD_DELAY, 100, // DISPON display on
242  0x13, CMD_DELAY, 10, // NORON
243 };
244 
246 // ILI9341 basic 16-bit implementation
248 
249 template <class I>
251 {
252  ssd1306_resetController2( this->m_rstPin, 100 );
253  this->m_w = 128;
254  this->m_h = 160;
255  // Give LCD some time to initialize. Refer to ILI9341 datasheet
256  lcd_delay(100);
257  _configureSpiDisplay<I>(this->m_intf,
258  s_ILI9341_lcd128x160x16_initData,
259  sizeof(s_ILI9341_lcd128x160x16_initData));
260 }
261 
262 template <class I>
264 {
265 }
uint8_t lcduint_t
Definition: canvas_types.h:81
void lcd_gpioWrite(int pin, int level)
void rotateOutput(uint8_t rotate)
Sets rotation of all output functions.
void ssd1306_resetController2(int8_t rstPin, uint8_t delayMs)
Does hardware reset for oled controller.
#define LCD_LOW
Definition: io.h:140
void setRotation(uint8_t rotation)
Sets screen orientation (rotation)
Definition: lcd_ili9341.inl:92
void begin() override
#define LCD_HIGH
Definition: io.h:142
void spiDataMode(uint8_t mode)
Definition: lcd_ili9341.inl:73
void lcd_delay(unsigned long ms)
void startBlock(lcduint_t x, lcduint_t y, lcduint_t w)
Sets block in RAM of lcd display controller to write data to.
Definition: lcd_ili9341.inl:36
void end() override