LCDGFX LCD display driver  1.2.0
Lightweight graphics library for SSD1306, SSD1325, SSD1327, SSD1331, SSD1351, SH1106, SH1107, IL9163, ST7735, ST7789, ILI9341, PCD8544 displays over I2C/SPI
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 template <class I> void InterfaceILI9341<I>::normalMode()
127 {
128  this->start();
129  setDataMode(0);
130  this->send(0x20);
131  this->stop();
132 }
133 
134 template <class I> void InterfaceILI9341<I>::invertMode()
135 {
136  this->start();
137  setDataMode(0);
138  this->send(0x21);
139  this->stop();
140 }
141 
142 
144 // ILI9341 basic 16-bit implementation
146 
147 template <class I> void DisplayILI9341x16<I>::beginDisplay()
148 {
149 }
150 
151 template <class I> void DisplayILI9341x16<I>::endDisplay()
152 {
153 }
154 
155 static const PROGMEM uint8_t s_ILI9341_lcd240x320x16_initData[] = {
156 #ifdef SDL_EMULATION
157  SDL_LCD_ILI9341, 0x00,
158  0x00, 0x00,
159 #endif
160  0x01, 0x00, // sw reset. not needed, we do hardware reset
161  0x11, 0x00, // exit sleep mode
162  0x3A, 0x01, 0x05, // set 16-bit pixel format
163  0x26, 0x01, 0x04, // set gamma curve: valid values 1, 2, 4, 8
164  0xF2, 0x01, 0x01, // enable gamma adjustment, 0 - to disable
165  0xE0, 15, 0x3F, 0x25, 0x1C,
166  0x1E, 0x20, 0x12,
167  0x2A, 0x90, 0x24,
168  0x11, 0x00, 0x00,
169  0x00, 0x00, 0x00, // positive gamma correction
170  0xE1, 15, 0x20, 0x20, 0x20,
171  0x20, 0x05, 0x00,
172  0x15, 0xA7, 0x3D,
173  0x18, 0x25, 0x2A,
174  0x2B, 0x2B, 0x3A, // negative gamma correction
175 // 0xB1, CMD_ARG, 0x08, CMD_ARG, 0x08, // frame rate control 1, use by default
176 // 0xB4, CMD_ARG, 0x07, // display inversion, use by default
177  0xC0, 0x02, 0x0A, 0x02, // power control 1
178  0xC1, 0x01, 0x02, // power control 2
179  0xC5, 0x02, 0x50, 0x5B, // vcom control 1
180  0xC7, 0x01, 0x40, // vcom offset
181  0x36, 0x01, 0b10001100, // set addressing mode
182  0x29, 0x00, // display on
183 };
184 
186 // ILI9341 basic 16-bit implementation
188 
190 {
191  ssd1306_resetController2(this->m_rstPin, 100);
192  this->m_w = 240;
193  this->m_h = 320;
194  // Give LCD some time to initialize. Refer to ILI9341 datasheet
195  lcd_delay(100);
196  _configureSpiDisplay<I>(this->m_intf,
197  s_ILI9341_lcd240x320x16_initData,
198  sizeof(s_ILI9341_lcd240x320x16_initData));
199 
200 }
201 
203 {
204 }
205 
206 static const PROGMEM uint8_t s_ILI9341_lcd128x160x16_initData[] = {
207 #ifdef SDL_EMULATION
208  SDL_LCD_ST7735, 0x00,
209  0b00000011, 0x00,
210 #endif
211  0x01, CMD_DELAY, 150, // SWRESET sw reset. not needed, we do hardware reset
212  0x11, CMD_DELAY, 255, // SLPOUT exit sleep mode
213  0xB1, 0x03, 0x01, 0x2C, 0x2D, // FRMCTR1 frame rate control 1, use by default
214  0xB2, 0x03, 0x01, 0x2C, 0x2D, // FRMCTR2, Frame Rate Control (In Idle mode/ 8-colors)
215  0xB3, 0x06, // FRMCTR3 (B3h): Frame Rate Control (In Partial mode/ full colors)
216  0x01, 0x2C, 0x2D,
217  0x01, 0x2C, 0x2D,
218  0xB4, 0x01, 0x07, // INVCTR display inversion, use by default
219  0xB6, 0x02, 0x15, 0x02, // DISSET5
220  0xC0, 0x03, 0xA2, 0x02, 0x84, // PWCTR1 power control 1
221  0xC1, 0x01, 0xC5, // PWCTR2 power control 2
222  0xC2, 0x02, 0x0A, 0x00, // PWCTR3 power control 3
223  0xC3, 0x02, 0x8A, 0x2A, // PWCTR4 (C3h): Power Control 4 (in Idle mode/ 8-colors)
224  0xC4, 0x02, 0x8A, 0xEE, // PWCTR5 (C4h): Power Control 5 (in Partial mode/ full-colors)
225  0xC5, 0x01, 0x0E, // VMCTR vcom control 1
226  0x20, 0x00, // INVOFF (20h): Display Inversion Off
227 // 0xFC, 0x02, 0x11, 0x15, // PWCTR6
228  0x36, 0x01, 0b00000000, // MADCTL
229  0x3A, 0x01, 0x05, // COLMOD set 16-bit pixel format
230 // 0x26, 1, 0x08, // GAMSET set gamma curve: valid values 1, 2, 4, 8
231 // 0xF2, 1, 0x01, // enable gamma adjustment, 0 - to disable
232  0xE0, 0x10, // GMCTRP1 positive gamma correction
233  0x0F, 0x1A, 0x0F, 0x18,
234  0x2F, 0x28, 0x20, 0x22,
235  0x1F, 0x1B, 0x23, 0x37,
236  0x00, 0x07, 0x02, 0x10,
237  0xE1, 0x10, // GMCTRN1 negative gamma correction
238  0x0F, 0x1B, 0x0F, 0x17,
239  0x33, 0x2C, 0x29, 0x2E,
240  0x30, 0x30, 0x39, 0x3F,
241  0x00, 0x07, 0x03, 0x10,
242 // 0xC7, 1, 0x40, // vcom offset
243 // 0x2A, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x7F, // set column address, not needed. set by direct API
244 // 0x2B, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x9F, // set page address, not needed. set by direct API
245  0x29, CMD_DELAY, 100, // DISPON display on
246  0x13, CMD_DELAY, 10, // NORON
247 };
248 
250 // ILI9341 basic 16-bit implementation
252 
254 {
255  ssd1306_resetController2(this->m_rstPin, 100);
256  this->m_w = 128;
257  this->m_h = 160;
258  // Give LCD some time to initialize. Refer to ILI9341 datasheet
259  lcd_delay(100);
260  _configureSpiDisplay<I>(this->m_intf,
261  s_ILI9341_lcd128x160x16_initData,
262  sizeof(s_ILI9341_lcd128x160x16_initData));
263 
264 }
265 
267 {
268 }
void endController()
Basic ILI9341 deinitialization.
uint8_t lcduint_t
internal int type, used by the library.
Definition: canvas_types.h:79
void lcd_gpioWrite(int pin, int level)
Writes value to gpio.
void beginController()
Basic ILI9341 128x160x16 initialization.
void rotateOutput(uint8_t rotate)
Sets rotation of all output functions.
SSD1306 HAL IO communication functions.
void ssd1306_resetController2(int8_t rstPin, uint8_t delayMs)
Does hardware reset for oled controller.
void commandStart()
Starts communication with LCD display in command mode.
Definition: lcd_ili9341.inl:77
void beginController()
Basic ILI9341 240x320x16 initialization.
void setDataMode(uint8_t mode)
Enables either data or command mode on SPI bus.
Definition: lcd_ili9341.inl:69
void beginDisplay()
Basic ILI9341 initialization.
void normalMode()
Switches display to normal (non-inverted) mode (sends INVOFF command).
#define LCD_LOW
Constant corresponds to low level of gpio pin.
Definition: io.h:175
void endController()
Basic ILI9341 deinitialization.
Basic structures of nano gfx library.
void setRotation(uint8_t rotation)
Sets screen orientation (rotation)
Definition: lcd_ili9341.inl:86
void nextBlock()
Switches to the start of next RAM page for the block, specified by startBlock().
Definition: lcd_ili9341.inl:59
#define LCD_HIGH
Constant corresponds to high level of gpio pin.
Definition: io.h:177
void endDisplay()
Basic ILI9341 deinitialization.
void endBlock()
Closes data send operation to lcd display.
Definition: lcd_ili9341.inl:64
void lcd_delay(unsigned long ms)
Forces current thread to sleeps for specified number of milliseconds.
void invertMode()
Switches display to inverted mode (sends INVON command).
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