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