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