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_st7789.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 = x + (w ? w : m_base.width()) - 1;
38  commandStart();
39  this->send(0x2A);
40  setDataMode(1); // According to datasheet all args must be passed in data mode
41  lcduint_t pos = x + m_offset_x;
42  this->send(pos >> 8);
43  this->send(pos & 0xFF);
44  pos = rx + m_offset_x;
45  this->send(pos >> 8);
46  this->send(pos & 0xFF);
47  setDataMode(0);
48  this->send(0x2B);
49  setDataMode(1); // According to datasheet all args must be passed in data mode
50  pos = y + m_offset_y;
51  this->send(pos >> 8);
52  this->send(pos & 0xFF);
53  pos = m_base.height() - 1 + m_offset_y;
54  this->send(pos >> 8);
55  this->send(pos & 0xFF);
56  setDataMode(0);
57  this->send(0x2C);
58  if ( m_dc >= 0 )
59  {
60  setDataMode(1);
61  }
62  else
63  {
64  this->stop();
65  this->start();
66  this->send(0x40);
67  }
68 }
69 
70 template <class I> void InterfaceST7789<I>::nextBlock()
71 {
72 
73 }
74 
75 template <class I> void InterfaceST7789<I>::endBlock()
76 {
77  this->stop();
78 }
79 
80 template <class I> void InterfaceST7789<I>::setDataMode(uint8_t mode)
81 {
82  if ( m_dc >= 0 )
83  {
84  lcd_gpioWrite(m_dc, mode ? LCD_HIGH : LCD_LOW);
85  }
86 }
87 
88 template <class I> void InterfaceST7789<I>::commandStart()
89 {
90  this->start();
91  if ( m_dc >= 0 )
92  setDataMode(0);
93  else
94  this->send(0x00);
95 }
96 
97 template <class I> void InterfaceST7789<I>::setRotation(uint8_t rotation)
98 {
99  uint8_t ram_mode;
100  if ( (rotation ^ m_rotation) & 0x01 )
101  {
102  m_base.swapDimensions();
103  lcduint_t temp = m_offset_x;
104  m_offset_x = m_offset_y;
105  m_offset_y = temp;
106  }
107  if ( (rotation ^ m_rotation) == 0x01 || (rotation ^ m_rotation) == 0x11 )
108  {
109  // if one of the dimensions is odd
110  if ( (m_base.width() & 0x01) || (m_base.height() & 0x01) )
111  {
112  switch (rotation)
113  {
114  case 0:
115  m_offset_x--;
116  break;
117  case 1:
118  m_offset_y++;
119  break;
120  case 2:
121  m_offset_x++;
122  break;
123  case 3:
124  m_offset_y--;
125  break;
126  default:
127  break;
128  }
129  }
130  }
131  m_rotation = (rotation & 0x03);
132  this->start();
133  setDataMode(0);
134  this->send(0x28);
135  this->send(0x36);
136  setDataMode(1);
137  switch ( m_rotation )
138  {
139  case 0: // 0 degree CW
140  ram_mode = 0b00000000;
141  break;
142  case 1: // 90 degree CW
143  ram_mode = 0b01100000;
144  break;
145  case 2: // 180 degree CW
146  ram_mode = 0b11000000;
147  break;
148  default: // 270 degree CW
149  ram_mode = 0b10100000;
150  break;
151  }
152  this->send(ram_mode | m_rgb_bit);
153  setDataMode(0);
154  this->send(0x29);
155  this->stop();
156 }
157 
158 template <class I> void InterfaceST7789<I>::setOffset(lcdint_t ox, lcdint_t oy)
159 {
160  if (m_rotation & 0x01)
161  {
162  m_offset_x = oy;
163  m_offset_y = ox;
164  }
165  else
166  {
167  m_offset_x = ox;
168  m_offset_y = oy;
169  }
170 }
171 
172 
174 // ST7789 basic 16-bit implementation
176 
177 template <class I> void DisplayST7789x16<I>::beginDisplay()
178 {
179 }
180 
181 template <class I> void DisplayST7789x16<I>::endDisplay()
182 {
183 }
184 
185 static const PROGMEM uint8_t s_ST7789_lcd135x240x16_initData[] = {
186 #ifdef SDL_EMULATION
187  SDL_LCD_ST7789, 0x00,
188  0b00010000, 0x00,
189 #endif
190  0x01, CMD_DELAY, 150, // SWRESET sw reset. not needed, we do hardware reset
191  0x11, CMD_DELAY, 20, // SLPOUT exit sleep mode
192  0x13, CMD_DELAY, 10, // NORON
193  0x3A, 0x01, 0x55, // COLMOD set 16-bit pixel format 0x55
194  0x36, 0x01, 0b00001000, // MADCTL 08 Adafruit
195  0xB6, 0x02, 0x0A, 0x82, // DISSET5
196  0xB2, 0x05, 0x0C, 0x0C, 0x00, 0x33, 0x33, // FRMCTR2 / PORCTL, Frame Rate Control (In Idle mode/ 8-colors)
197  0xB7, 0x01, 0x35, // VGH / VGL
198  0xBB, 0x01, 0x28, // VCOM
199  0xC0, 0x01, 0x0C, // LCM / PWCTR1 power control 1
200  0xC2, 0x02, 0x01, 0xFF, // VDV PWCTR3 power control 3
201  0xC3, 0x01, 0x10, // VRH
202  0xC4, 0x01, 0x20, // VDV
203  0xC6, 0x01, 0x0F, // FRCTR2
204  0xD0, 0x02, 0xA4, 0xA1, // PWCTRL1
205  0xE0, 0x0E, // GMCTRP1 positive gamma correction
206  0xD0, 0x00, 0x02, 0x07,
207  0x0A, 0x28, 0x32, 0x44,
208  0x42, 0x06, 0x0E, 0x12,
209  0x14, 0x17,
210  0xE1, 0x0E, // GMCTRN1 negative gamma correction
211  0xD0, 0x00, 0x02, 0x07,
212  0x0A, 0x28, 0x31, 0x54,
213  0x47, 0x0E, 0x1C, 0x17,
214  0x1B, 0x1E,
215 // 0x2A, 0x04, 0x00, 0x00, 0x00, 0x7F, // set column address, not needed. set by direct API
216 // 0x2B, 0x04, 0x00, 0x00, 0x00, 0x9F, // set page address, not needed. set by direct API
217  0x21, CMD_DELAY, 10, // INVON (21h): Display Inversion On
218  0x29, CMD_DELAY, 120, // DISPON display on
219 };
220 
222 // ST7789 basic 16-bit implementation
224 
226 {
227  ssd1306_resetController2(this->m_rstPin, 20);
228  this->m_w = 135;
229  this->m_h = 240;
230  // Give LCD some time to initialize. Refer to ST7789 datasheet
231  lcd_delay(120);
232  _configureSpiDisplay<I>(this->m_intf,
233  s_ST7789_lcd135x240x16_initData,
234  sizeof(s_ST7789_lcd135x240x16_initData));
235 
236 }
237 
239 {
240 }
241 
242 static const PROGMEM uint8_t s_ST7789_lcd240x240x16_initData[] = {
243 #ifdef SDL_EMULATION
244  SDL_LCD_ST7789, 0x00,
245  0b00010000, 0x00,
246 #endif
247  0x01, CMD_DELAY, 150, // SWRESET sw reset. not needed, we do hardware reset
248  0x11, CMD_DELAY, 20, // SLPOUT exit sleep mode
249  0x13, CMD_DELAY, 10, // NORON
250  0x3A, 0x01, 0x55, // COLMOD set 16-bit pixel format 0x55
251  0x36, 0x01, 0b00001000, // MADCTL 08 Adafruit
252  0xB6, 0x02, 0x0A, 0x82, // DISSET5
253  0xB2, 0x05, 0x0C, 0x0C, 0x00, 0x33, 0x33, // FRMCTR2 / PORCTL, Frame Rate Control (In Idle mode/ 8-colors)
254  0xB7, 0x01, 0x35, // VGH / VGL
255  0xBB, 0x01, 0x28, // VCOM
256  0xC0, 0x01, 0x0C, // LCM / PWCTR1 power control 1
257  0xC2, 0x02, 0x01, 0xFF, // VDV PWCTR3 power control 3
258  0xC3, 0x01, 0x10, // VRH
259  0xC4, 0x01, 0x20, // VDV
260  0xC6, 0x01, 0x0F, // FRCTR2
261  0xD0, 0x02, 0xA4, 0xA1, // PWCTRL1
262  0xE0, 0x0E, // GMCTRP1 positive gamma correction
263  0xD0, 0x00, 0x02, 0x07,
264  0x0A, 0x28, 0x32, 0x44,
265  0x42, 0x06, 0x0E, 0x12,
266  0x14, 0x17,
267  0xE1, 0x0E, // GMCTRN1 negative gamma correction
268  0xD0, 0x00, 0x02, 0x07,
269  0x0A, 0x28, 0x31, 0x54,
270  0x47, 0x0E, 0x1C, 0x17,
271  0x1B, 0x1E,
272 // 0x2A, 0x04, 0x00, 0x00, 0x00, 0x7F, // set column address, not needed. set by direct API
273 // 0x2B, 0x04, 0x00, 0x00, 0x00, 0x9F, // set page address, not needed. set by direct API
274  0x21, CMD_DELAY, 10, // INVON (21h): Display Inversion On
275  0x29, CMD_DELAY, 120, // DISPON display on
276 };
277 
279 // ST7789 basic 16-bit implementation
281 
283 {
284  ssd1306_resetController2(this->m_rstPin, 20);
285  this->m_w = 240;
286  this->m_h = 240;
287  // Give LCD some time to initialize. Refer to ST7789 datasheet
288  lcd_delay(120);
289  _configureSpiDisplay<I>(this->m_intf,
290  s_ST7789_lcd240x240x16_initData,
291  sizeof(s_ST7789_lcd240x240x16_initData));
292 
293 }
294 
296 {
297 }
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_st7789.inl:35
uint8_t lcduint_t
Definition: canvas_types.h:79
void lcd_gpioWrite(int pin, int level)
void setRotation(uint8_t rotation)
Sets screen orientation (rotation)
Definition: lcd_st7789.inl:97
void setDataMode(uint8_t mode)
Definition: lcd_st7789.inl:80
int8_t lcdint_t
Definition: canvas_types.h:77
void ssd1306_resetController2(int8_t rstPin, uint8_t delayMs)
Does hardware reset for oled controller.
#define LCD_LOW
Definition: io.h:175
void setOffset(lcdint_t ox, lcdint_t oy)
Sets display offset in GDRAM memory.
Definition: lcd_st7789.inl:158
#define LCD_HIGH
Definition: io.h:177
void commandStart()
Definition: lcd_st7789.inl:88
void lcd_delay(unsigned long ms)