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_st7735.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  commandStart();
39  this->send(0x2A);
40  setDataMode(1); // According to datasheet all args must be passed in data mode
41  this->send(0);
42  this->send(x + m_offset_x);
43  this->send(0);
44  this->send( (rx < m_base.width() ? rx : (m_base.width() - 1)) + m_offset_x);
45  setDataMode(0);
46  this->send(0x2B);
47  setDataMode(1); // According to datasheet all args must be passed in data mode
48  this->send(0);
49  this->send( y + m_offset_y );
50  this->send(0);
51  this->send( m_base.height() - 1 + m_offset_y);
52  setDataMode(0);
53  this->send(0x2C);
54  if ( m_dc >= 0 )
55  {
56  setDataMode(1);
57  }
58  else
59  {
60  this->stop();
61  this->start();
62  this->send(0x40);
63  }
64 }
65 
66 template <class I> void InterfaceST7735<I>::nextBlock()
67 {
68 
69 }
70 
71 template <class I> void InterfaceST7735<I>::endBlock()
72 {
73  this->stop();
74 }
75 
76 template <class I> void InterfaceST7735<I>::setDataMode(uint8_t mode)
77 {
78  if ( m_dc >= 0 )
79  {
80  lcd_gpioWrite(m_dc, mode ? LCD_HIGH : LCD_LOW);
81  }
82 }
83 
84 template <class I> void InterfaceST7735<I>::commandStart()
85 {
86  this->start();
87  if ( m_dc >= 0 )
88  setDataMode(0);
89  else
90  this->send(0x00);
91 }
92 
93 template <class I> void InterfaceST7735<I>::setRotation(uint8_t rotation)
94 {
95  uint8_t ram_mode;
96  if ( (rotation ^ m_rotation) & 0x01 )
97  {
98  m_base.swapDimensions();
99  lcduint_t temp = m_offset_x;
100  m_offset_x = m_offset_y;
101  m_offset_y = temp;
102  }
103  m_rotation = (rotation & 0x03);
104  this->start();
105  setDataMode(0);
106  this->send(0x28);
107  this->send(0x36);
108  setDataMode(1);
109  switch ( m_rotation )
110  {
111  case 0: // 0 degree CW
112  ram_mode = 0b00000000;
113  break;
114  case 1: // 90 degree CW
115  ram_mode = 0b01100000;
116  break;
117  case 2: // 180 degree CW
118  ram_mode = 0b11000000;
119  break;
120  default: // 270 degree CW
121  ram_mode = 0b10100000;
122  break;
123  }
124  this->send(ram_mode | m_rgb_bit);
125  setDataMode(0);
126  this->send(0x29);
127  this->stop();
128 }
129 
130 template <class I> void InterfaceST7735<I>::setOffset(lcdint_t ox, lcdint_t oy)
131 {
132  if (m_rotation & 0x01)
133  {
134  m_offset_x = oy;
135  m_offset_y = ox;
136  }
137  else
138  {
139  m_offset_x = ox;
140  m_offset_y = oy;
141  }
142 }
143 
144 template <class I> void InterfaceST7735<I>::setRgbMode(uint8_t mode)
145 {
146  this->m_rgb_bit = mode ? 0b00001000: 0b00000000;
147  this->setRotation( m_rotation );
148 }
149 
150 
152 // ST7735 basic 16-bit implementation
154 
155 template <class I> void DisplayST7735x16<I>::beginDisplay()
156 {
157 }
158 
159 template <class I> void DisplayST7735x16<I>::endDisplay()
160 {
161 }
162 
163 static const PROGMEM uint8_t s_ST7735_lcd128x128x16_initData[] = {
164 #ifdef SDL_EMULATION
165  SDL_LCD_ST7735, 0x00,
166  0b00000000, 0x00,
167 #endif
168  0x01, CMD_DELAY, 150, // SWRESET sw reset. not needed, we do hardware reset
169  0x11, CMD_DELAY, 255, // SLPOUT exit sleep mode
170  0xB1, 0x03, 0x01, 0x2C, 0x2D, // FRMCTR1 frame rate control 1, use by default
171  0xB2, 0x03, 0x01, 0x2C, 0x2D, // FRMCTR2, Frame Rate Control (In Idle mode/ 8-colors)
172  0xB3, 0x06, // FRMCTR3 (B3h): Frame Rate Control (In Partial mode/ full colors)
173  0x01, 0x2C, 0x2D,
174  0x01, 0x2C, 0x2D,
175  0xB4, 0x01, 0x07, // INVCTR display inversion, use by default
176  0xB6, 0x02, 0x15, 0x02, // DISSET5
177  0xC0, 0x03, 0xA2, 0x02, 0x84, // PWCTR1 power control 1
178  0xC1, 0x01, 0xC5, // PWCTR2 power control 2
179  0xC2, 0x02, 0x0A, 0x00, // PWCTR3 power control 3
180  0xC3, 0x02, 0x8A, 0x2A, // PWCTR4 (C3h): Power Control 4 (in Idle mode/ 8-colors)
181  0xC4, 0x02, 0x8A, 0xEE, // PWCTR5 (C4h): Power Control 5 (in Partial mode/ full-colors)
182  0xC5, 0x01, 0x0E, // VMCTR vcom control 1
183  0x20, 0x00, // INVOFF (20h): Display Inversion Off
184 // 0xFC, 0x02, 0x11, 0x15, // PWCTR6
185  0x36, 0x01, 0b00000000, // MADCTL
186  0x3A, 0x01, 0x05, // COLMOD set 16-bit pixel format
187 // 0x26, 1, 0x08, // GAMSET set gamma curve: valid values 1, 2, 4, 8
188 // 0xF2, 1, 0x01, // enable gamma adjustment, 0 - to disable
189  0xE0, 0x10, // GMCTRP1 positive gamma correction
190  0x0F, 0x1A, 0x0F, 0x18,
191  0x2F, 0x28, 0x20, 0x22,
192  0x1F, 0x1B, 0x23, 0x37,
193  0x00, 0x07, 0x02, 0x10,
194  0xE1, 0x10, // GMCTRN1 negative gamma correction
195  0x0F, 0x1B, 0x0F, 0x17,
196  0x33, 0x2C, 0x29, 0x2E,
197  0x30, 0x30, 0x39, 0x3F,
198  0x00, 0x07, 0x03, 0x10,
199 // 0xC7, 1, 0x40, // vcom offset
200 // 0x2A, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x7F, // set column address, not needed. set by direct API
201 // 0x2B, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x9F, // set page address, not needed. set by direct API
202  0x29, CMD_DELAY, 100, // DISPON display on
203  0x13, CMD_DELAY, 10, // NORON
204 };
205 
207 // ST7735 basic 16-bit implementation
209 
211 {
212  ssd1306_resetController2(this->m_rstPin, 20);
213  this->m_w = 128;
214  this->m_h = 128;
215  // Give LCD some time to initialize. Refer to ST7735 datasheet
216  lcd_delay(120);
217  _configureSpiDisplay<I>(this->m_intf,
218  s_ST7735_lcd128x128x16_initData,
219  sizeof(s_ST7735_lcd128x128x16_initData));
220 
221 }
222 
224 {
225 }
226 
227 static const PROGMEM uint8_t s_ST7735_lcd80x160x16_initData[] = {
228 #ifdef SDL_EMULATION
229  SDL_LCD_ST7735, 0x00,
230  0b00000100, 0x00,
231 #endif
232  0x01, CMD_DELAY, 150, // SWRESET sw reset. not needed, we do hardware reset
233  0x11, CMD_DELAY, 255, // SLPOUT exit sleep mode
234  0xB1, 0x03, 0x01, 0x2C, 0x2D, // FRMCTR1 frame rate control 1, use by default
235  0xB2, 0x03, 0x01, 0x2C, 0x2D, // FRMCTR2, Frame Rate Control (In Idle mode/ 8-colors)
236  0xB3, 0x06, // FRMCTR3 (B3h): Frame Rate Control (In Partial mode/ full colors)
237  0x01, 0x2C, 0x2D,
238  0x01, 0x2C, 0x2D,
239  0xB4, 0x01, 0x07, // INVCTR display inversion, use by default
240  0xB6, 0x02, 0x15, 0x02, // DISSET5
241  0xC0, 0x03, 0xA2, 0x02, 0x84, // PWCTR1 power control 1
242  0xC1, 0x01, 0xC5, // PWCTR2 power control 2
243  0xC2, 0x02, 0x0A, 0x00, // PWCTR3 power control 3
244  0xC3, 0x02, 0x8A, 0x2A, // PWCTR4 (C3h): Power Control 4 (in Idle mode/ 8-colors)
245  0xC4, 0x02, 0x8A, 0xEE, // PWCTR5 (C4h): Power Control 5 (in Partial mode/ full-colors)
246  0xC5, 0x01, 0x0E, // VMCTR vcom control 1
247  0x20, 0x00, // INVOFF (20h): Display Inversion Off
248 // 0xFC, 0x02, 0x11, 0x15, // PWCTR6
249  0x36, 0x01, 0b00000000, // MADCTL
250  0x3A, 0x01, 0x05, // COLMOD set 16-bit pixel format
251 // 0x26, 1, 0x08, // GAMSET set gamma curve: valid values 1, 2, 4, 8
252 // 0xF2, 1, 0x01, // enable gamma adjustment, 0 - to disable
253  0xE0, 0x10, // GMCTRP1 positive gamma correction
254  0x0F, 0x1A, 0x0F, 0x18,
255  0x2F, 0x28, 0x20, 0x22,
256  0x1F, 0x1B, 0x23, 0x37,
257  0x00, 0x07, 0x02, 0x10,
258  0xE1, 0x10, // GMCTRN1 negative gamma correction
259  0x0F, 0x1B, 0x0F, 0x17,
260  0x33, 0x2C, 0x29, 0x2E,
261  0x30, 0x30, 0x39, 0x3F,
262  0x00, 0x07, 0x03, 0x10,
263 // 0xC7, 1, 0x40, // vcom offset
264 // 0x2A, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x7F, // set column address, not needed. set by direct API
265 // 0x2B, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x9F, // set page address, not needed. set by direct API
266  0x29, CMD_DELAY, 100, // DISPON display on
267  0x13, CMD_DELAY, 10, // NORON
268 };
269 
271 // ST7735 basic 16-bit implementation
273 
275 {
276  ssd1306_resetController2(this->m_rstPin, 20);
277  this->m_w = 80;
278  this->m_h = 160;
279  // Give LCD some time to initialize. Refer to ST7735 datasheet
280  lcd_delay(120);
281  _configureSpiDisplay<I>(this->m_intf,
282  s_ST7735_lcd80x160x16_initData,
283  sizeof(s_ST7735_lcd80x160x16_initData));
284  this->m_intf.setOffset( 26, 0 );
285 }
286 
288 {
289 }
290 
291 static const PROGMEM uint8_t s_ST7735_lcd128x160x16_initData[] = {
292 #ifdef SDL_EMULATION
293  SDL_LCD_ST7735, 0x00,
294  0b00000011, 0x00,
295 #endif
296  0x01, CMD_DELAY, 150, // SWRESET sw reset. not needed, we do hardware reset
297  0x11, CMD_DELAY, 255, // SLPOUT exit sleep mode
298  0xB1, 0x03, 0x01, 0x2C, 0x2D, // FRMCTR1 frame rate control 1, use by default
299  0xB2, 0x03, 0x01, 0x2C, 0x2D, // FRMCTR2, Frame Rate Control (In Idle mode/ 8-colors)
300  0xB3, 0x06, // FRMCTR3 (B3h): Frame Rate Control (In Partial mode/ full colors)
301  0x01, 0x2C, 0x2D,
302  0x01, 0x2C, 0x2D,
303  0xB4, 0x01, 0x07, // INVCTR display inversion, use by default
304  0xB6, 0x02, 0x15, 0x02, // DISSET5
305  0xC0, 0x03, 0xA2, 0x02, 0x84, // PWCTR1 power control 1
306  0xC1, 0x01, 0xC5, // PWCTR2 power control 2
307  0xC2, 0x02, 0x0A, 0x00, // PWCTR3 power control 3
308  0xC3, 0x02, 0x8A, 0x2A, // PWCTR4 (C3h): Power Control 4 (in Idle mode/ 8-colors)
309  0xC4, 0x02, 0x8A, 0xEE, // PWCTR5 (C4h): Power Control 5 (in Partial mode/ full-colors)
310  0xC5, 0x01, 0x0E, // VMCTR vcom control 1
311  0x20, 0x00, // INVOFF (20h): Display Inversion Off
312 // 0xFC, 0x02, 0x11, 0x15, // PWCTR6
313  0x36, 0x01, 0b00000000, // MADCTL
314  0x3A, 0x01, 0x05, // COLMOD set 16-bit pixel format
315 // 0x26, 1, 0x08, // GAMSET set gamma curve: valid values 1, 2, 4, 8
316 // 0xF2, 1, 0x01, // enable gamma adjustment, 0 - to disable
317  0xE0, 0x10, // GMCTRP1 positive gamma correction
318  0x0F, 0x1A, 0x0F, 0x18,
319  0x2F, 0x28, 0x20, 0x22,
320  0x1F, 0x1B, 0x23, 0x37,
321  0x00, 0x07, 0x02, 0x10,
322  0xE1, 0x10, // GMCTRN1 negative gamma correction
323  0x0F, 0x1B, 0x0F, 0x17,
324  0x33, 0x2C, 0x29, 0x2E,
325  0x30, 0x30, 0x39, 0x3F,
326  0x00, 0x07, 0x03, 0x10,
327 // 0xC7, 1, 0x40, // vcom offset
328 // 0x2A, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x7F, // set column address, not needed. set by direct API
329 // 0x2B, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x9F, // set page address, not needed. set by direct API
330  0x29, CMD_DELAY, 100, // DISPON display on
331  0x13, CMD_DELAY, 10, // NORON
332 };
333 
335 // ST7735 basic 16-bit implementation
337 
339 {
340  ssd1306_resetController2(this->m_rstPin, 20);
341  this->m_w = 128;
342  this->m_h = 160;
343  // Give LCD some time to initialize. Refer to ST7735 datasheet
344  lcd_delay(120);
345  _configureSpiDisplay<I>(this->m_intf,
346  s_ST7735_lcd128x160x16_initData,
347  sizeof(s_ST7735_lcd128x160x16_initData));
348 
349 }
350 
352 {
353 }
uint8_t lcduint_t
Definition: canvas_types.h:79
void lcd_gpioWrite(int pin, int level)
void setDataMode(uint8_t mode)
Definition: lcd_st7735.inl:76
void commandStart()
Definition: lcd_st7735.inl:84
int8_t lcdint_t
Definition: canvas_types.h:77
void ssd1306_resetController2(int8_t rstPin, uint8_t delayMs)
Does hardware reset for oled controller.
void setOffset(lcdint_t ox, lcdint_t oy)
Sets display offset in GDRAM memory.
Definition: lcd_st7735.inl:130
void setRotation(uint8_t rotation)
Sets screen orientation (rotation)
Definition: lcd_st7735.inl:93
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_st7735.inl:35
#define LCD_LOW
Definition: io.h:175
void setRgbMode(uint8_t mode)
Sets RGB mode used by dispay controller.
Definition: lcd_st7735.inl:144
#define LCD_HIGH
Definition: io.h:177
void lcd_delay(unsigned long ms)