LCDGFX LCD display driver  1.1.5
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 2019-2022 (C) 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 
36 {
37  lcduint_t rx = w ? (x + w - 1) : (m_base.width() - 1);
38  rx = rx < m_base.width() ? rx: (m_base.width() -1);
39  this->start();
40  setDataMode(0);
41  this->send(0x2A);
42  setDataMode(1); // According to datasheet all args must be passed in data mode
43  this->send(x >> 8);
44  this->send(x & 0xFF);
45  this->send(rx >> 8);
46  this->send(rx & 0xFF);
47  setDataMode(0);
48  this->send(0x2B);
49  setDataMode(1); // According to datasheet all args must be passed in data mode
50  this->send(y >> 8);
51  this->send(y & 0xFF);
52  this->send((m_base.height() - 1) >> 8);
53  this->send((m_base.height() - 1) & 0xFF);
54  setDataMode(0);
55  this->send(0x2C);
56  setDataMode(1);
57 }
58 
59 template <class I> void InterfaceILI9341<I>::nextBlock()
60 {
61 
62 }
63 
64 template <class I> void InterfaceILI9341<I>::endBlock()
65 {
66  this->stop();
67 }
68 
69 template <class I> void InterfaceILI9341<I>::setDataMode(uint8_t mode)
70 {
71  if ( m_dc >= 0 )
72  {
73  lcd_gpioWrite(m_dc, mode ? LCD_HIGH : LCD_LOW);
74  }
75 }
76 
77 template <class I> void InterfaceILI9341<I>::commandStart()
78 {
79  this->start();
80  if ( m_dc >= 0 )
81  setDataMode(0);
82  else
83  this->send(0x00);
84 }
85 
86 template <class I> void InterfaceILI9341<I>::setRotation(uint8_t rotation)
87 {
88  uint8_t ram_mode;
89  if ( (rotation ^ m_rotation) & 0x01 )
90  {
91  m_base.swapDimensions();
92  }
93  m_rotation = (rotation & 0x03);
94  this->start();
95  setDataMode(0);
96  this->send(0x28);
97  this->send(0x36);
98  setDataMode(1);
99  switch ( m_rotation )
100  {
101  case 0: // 0 degree CW
102  ram_mode = m_rotate_output ? 0b11100100: 0b10000100;
103  break;
104  case 1: // 90 degree CW
105  ram_mode = 0b11100000;
106  break;
107  case 2: // 180 degree CW
108  ram_mode = 0b01010100;
109  break;
110  default: // 270 degree CW
111  ram_mode = 0b00100000;
112  break;
113  }
114  this->send(ram_mode | m_rgb_bit);
115  setDataMode(0);
116  this->send(0x29);
117  this->stop();
118 }
119 
120 template <class I> void InterfaceILI9341<I>::rotateOutput(uint8_t rotate)
121 {
122  m_rotate_output = rotate;
123  this->setRotation( m_rotation );
124 }
125 
126 
128 // ILI9341 basic 16-bit implementation
130 
131 template <class I> void DisplayILI9341x16<I>::beginDisplay()
132 {
133 }
134 
135 template <class I> void DisplayILI9341x16<I>::endDisplay()
136 {
137 }
138 
139 static const PROGMEM uint8_t s_ILI9341_lcd240x320x16_initData[] = {
140 #ifdef SDL_EMULATION
141  SDL_LCD_ILI9341, 0x00,
142  0x00, 0x00,
143 #endif
144  0x01, 0x00, // sw reset. not needed, we do hardware reset
145  0x11, 0x00, // exit sleep mode
146  0x3A, 0x01, 0x05, // set 16-bit pixel format
147  0x26, 0x01, 0x04, // set gamma curve: valid values 1, 2, 4, 8
148  0xF2, 0x01, 0x01, // enable gamma adjustment, 0 - to disable
149  0xE0, 15, 0x3F, 0x25, 0x1C,
150  0x1E, 0x20, 0x12,
151  0x2A, 0x90, 0x24,
152  0x11, 0x00, 0x00,
153  0x00, 0x00, 0x00, // positive gamma correction
154  0xE1, 15, 0x20, 0x20, 0x20,
155  0x20, 0x05, 0x00,
156  0x15, 0xA7, 0x3D,
157  0x18, 0x25, 0x2A,
158  0x2B, 0x2B, 0x3A, // negative gamma correction
159 // 0xB1, CMD_ARG, 0x08, CMD_ARG, 0x08, // frame rate control 1, use by default
160 // 0xB4, CMD_ARG, 0x07, // display inversion, use by default
161  0xC0, 0x02, 0x0A, 0x02, // power control 1
162  0xC1, 0x01, 0x02, // power control 2
163  0xC5, 0x02, 0x50, 0x5B, // vcom control 1
164  0xC7, 0x01, 0x40, // vcom offset
165  0x36, 0x01, 0b10001100, // set addressing mode
166  0x29, 0x00, // display on
167 };
168 
170 // ILI9341 basic 16-bit implementation
172 
174 {
175  ssd1306_resetController2(this->m_rstPin, 100);
176  this->m_w = 240;
177  this->m_h = 320;
178  // Give LCD some time to initialize. Refer to ILI9341 datasheet
179  lcd_delay(100);
180  _configureSpiDisplay<I>(this->m_intf,
181  s_ILI9341_lcd240x320x16_initData,
182  sizeof(s_ILI9341_lcd240x320x16_initData));
183 
184 }
185 
187 {
188 }
189 
190 static const PROGMEM uint8_t s_ILI9341_lcd128x160x16_initData[] = {
191 #ifdef SDL_EMULATION
192  SDL_LCD_ST7735, 0x00,
193  0b00000011, 0x00,
194 #endif
195  0x01, CMD_DELAY, 150, // SWRESET sw reset. not needed, we do hardware reset
196  0x11, CMD_DELAY, 255, // SLPOUT exit sleep mode
197  0xB1, 0x03, 0x01, 0x2C, 0x2D, // FRMCTR1 frame rate control 1, use by default
198  0xB2, 0x03, 0x01, 0x2C, 0x2D, // FRMCTR2, Frame Rate Control (In Idle mode/ 8-colors)
199  0xB3, 0x06, // FRMCTR3 (B3h): Frame Rate Control (In Partial mode/ full colors)
200  0x01, 0x2C, 0x2D,
201  0x01, 0x2C, 0x2D,
202  0xB4, 0x01, 0x07, // INVCTR display inversion, use by default
203  0xB6, 0x02, 0x15, 0x02, // DISSET5
204  0xC0, 0x03, 0xA2, 0x02, 0x84, // PWCTR1 power control 1
205  0xC1, 0x01, 0xC5, // PWCTR2 power control 2
206  0xC2, 0x02, 0x0A, 0x00, // PWCTR3 power control 3
207  0xC3, 0x02, 0x8A, 0x2A, // PWCTR4 (C3h): Power Control 4 (in Idle mode/ 8-colors)
208  0xC4, 0x02, 0x8A, 0xEE, // PWCTR5 (C4h): Power Control 5 (in Partial mode/ full-colors)
209  0xC5, 0x01, 0x0E, // VMCTR vcom control 1
210  0x20, 0x00, // INVOFF (20h): Display Inversion Off
211 // 0xFC, 0x02, 0x11, 0x15, // PWCTR6
212  0x36, 0x01, 0b00000000, // MADCTL
213  0x3A, 0x01, 0x05, // COLMOD set 16-bit pixel format
214 // 0x26, 1, 0x08, // GAMSET set gamma curve: valid values 1, 2, 4, 8
215 // 0xF2, 1, 0x01, // enable gamma adjustment, 0 - to disable
216  0xE0, 0x10, // GMCTRP1 positive gamma correction
217  0x0F, 0x1A, 0x0F, 0x18,
218  0x2F, 0x28, 0x20, 0x22,
219  0x1F, 0x1B, 0x23, 0x37,
220  0x00, 0x07, 0x02, 0x10,
221  0xE1, 0x10, // GMCTRN1 negative gamma correction
222  0x0F, 0x1B, 0x0F, 0x17,
223  0x33, 0x2C, 0x29, 0x2E,
224  0x30, 0x30, 0x39, 0x3F,
225  0x00, 0x07, 0x03, 0x10,
226 // 0xC7, 1, 0x40, // vcom offset
227 // 0x2A, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x7F, // set column address, not needed. set by direct API
228 // 0x2B, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x9F, // set page address, not needed. set by direct API
229  0x29, CMD_DELAY, 100, // DISPON display on
230  0x13, CMD_DELAY, 10, // NORON
231 };
232 
234 // ILI9341 basic 16-bit implementation
236 
238 {
239  ssd1306_resetController2(this->m_rstPin, 100);
240  this->m_w = 128;
241  this->m_h = 160;
242  // Give LCD some time to initialize. Refer to ILI9341 datasheet
243  lcd_delay(100);
244  _configureSpiDisplay<I>(this->m_intf,
245  s_ILI9341_lcd128x160x16_initData,
246  sizeof(s_ILI9341_lcd128x160x16_initData));
247 
248 }
249 
251 {
252 }
uint8_t lcduint_t
Definition: canvas_types.h:79
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.
void setDataMode(uint8_t mode)
Definition: lcd_ili9341.inl:69
#define LCD_LOW
Definition: io.h:175
void setRotation(uint8_t rotation)
Sets screen orientation (rotation)
Definition: lcd_ili9341.inl:86
#define LCD_HIGH
Definition: io.h:177
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:35