LCDGFX LCD display driver  1.0.2
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  spiDataMode(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  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 + m_offset_y );
51  this->send(0);
52  this->send( m_base.height() - 1 + m_offset_y);
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  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  spiDataMode(0);
112  this->send(0x28);
113  this->send(0x36);
114  spiDataMode(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  spiDataMode(0);
132  this->send(0x29);
133  this->stop();
134 }
135 
136 template <class I>
138 {
139  m_offset_x = ox;
140  m_offset_y = oy;
141 }
142 
143 
145 // ST7735 basic 16-bit implementation
147 
148 template <class I>
150 {
151 }
152 
153 template <class I>
155 {
156 }
157 
158 static const PROGMEM uint8_t s_ST7735_lcd128x128x16_initData[] =
159 {
160 #ifdef SDL_EMULATION
161  SDL_LCD_ST7735, 0x00,
162  0b00000000, 0x00,
163 #endif
164  0x01, CMD_DELAY, 150, // SWRESET sw reset. not needed, we do hardware reset
165  0x11, CMD_DELAY, 255, // SLPOUT exit sleep mode
166  0xB1, 0x03, 0x01, 0x2C, 0x2D, // FRMCTR1 frame rate control 1, use by default
167  0xB2, 0x03, 0x01, 0x2C, 0x2D, // FRMCTR2, Frame Rate Control (In Idle mode/ 8-colors)
168  0xB3, 0x06, // FRMCTR3 (B3h): Frame Rate Control (In Partial mode/ full colors)
169  0x01, 0x2C, 0x2D,
170  0x01, 0x2C, 0x2D,
171  0xB4, 0x01, 0x07, // INVCTR display inversion, use by default
172  0xB6, 0x02, 0x15, 0x02, // DISSET5
173  0xC0, 0x03, 0xA2, 0x02, 0x84, // PWCTR1 power control 1
174  0xC1, 0x01, 0xC5, // PWCTR2 power control 2
175  0xC2, 0x02, 0x0A, 0x00, // PWCTR3 power control 3
176  0xC3, 0x02, 0x8A, 0x2A, // PWCTR4 (C3h): Power Control 4 (in Idle mode/ 8-colors)
177  0xC4, 0x02, 0x8A, 0xEE, // PWCTR5 (C4h): Power Control 5 (in Partial mode/ full-colors)
178  0xC5, 0x01, 0x0E, // VMCTR vcom control 1
179  0x20, 0x00, // INVOFF (20h): Display Inversion Off
180 // 0xFC, 0x02, 0x11, 0x15, // PWCTR6
181  0x36, 0x01, 0b00000000, // MADCTL
182  0x3A, 0x01, 0x05, // COLMOD set 16-bit pixel format
183 // 0x26, 1, 0x08, // GAMSET set gamma curve: valid values 1, 2, 4, 8
184 // 0xF2, 1, 0x01, // enable gamma adjustment, 0 - to disable
185  0xE0, 0x10, // GMCTRP1 positive gamma correction
186  0x0F, 0x1A, 0x0F, 0x18,
187  0x2F, 0x28, 0x20, 0x22,
188  0x1F, 0x1B, 0x23, 0x37,
189  0x00, 0x07, 0x02, 0x10,
190  0xE1, 0x10, // GMCTRN1 negative gamma correction
191  0x0F, 0x1B, 0x0F, 0x17,
192  0x33, 0x2C, 0x29, 0x2E,
193  0x30, 0x30, 0x39, 0x3F,
194  0x00, 0x07, 0x03, 0x10,
195 // 0xC7, 1, 0x40, // vcom offset
196 // 0x2A, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x7F, // set column address, not needed. set by direct API
197 // 0x2B, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x9F, // set page address, not needed. set by direct API
198  0x29, CMD_DELAY, 100, // DISPON display on
199  0x13, CMD_DELAY, 10, // NORON
200 };
201 
203 // ST7735 basic 16-bit implementation
205 
206 template <class I>
208 {
209  ssd1306_resetController2( this->m_rstPin, 20 );
210  this->m_w = 128;
211  this->m_h = 128;
212  // Give LCD some time to initialize. Refer to ST7735 datasheet
213  lcd_delay(120);
214  _configureSpiDisplay<I>(this->m_intf,
215  s_ST7735_lcd128x128x16_initData,
216  sizeof(s_ST7735_lcd128x128x16_initData));
217 }
218 
219 template <class I>
221 {
222 }
223 
224 static const PROGMEM uint8_t s_ST7735_lcd128x160x16_initData[] =
225 {
226 #ifdef SDL_EMULATION
227  SDL_LCD_ST7735, 0x00,
228  0b00000011, 0x00,
229 #endif
230  0x01, CMD_DELAY, 150, // SWRESET sw reset. not needed, we do hardware reset
231  0x11, CMD_DELAY, 255, // SLPOUT exit sleep mode
232  0xB1, 0x03, 0x01, 0x2C, 0x2D, // FRMCTR1 frame rate control 1, use by default
233  0xB2, 0x03, 0x01, 0x2C, 0x2D, // FRMCTR2, Frame Rate Control (In Idle mode/ 8-colors)
234  0xB3, 0x06, // FRMCTR3 (B3h): Frame Rate Control (In Partial mode/ full colors)
235  0x01, 0x2C, 0x2D,
236  0x01, 0x2C, 0x2D,
237  0xB4, 0x01, 0x07, // INVCTR display inversion, use by default
238  0xB6, 0x02, 0x15, 0x02, // DISSET5
239  0xC0, 0x03, 0xA2, 0x02, 0x84, // PWCTR1 power control 1
240  0xC1, 0x01, 0xC5, // PWCTR2 power control 2
241  0xC2, 0x02, 0x0A, 0x00, // PWCTR3 power control 3
242  0xC3, 0x02, 0x8A, 0x2A, // PWCTR4 (C3h): Power Control 4 (in Idle mode/ 8-colors)
243  0xC4, 0x02, 0x8A, 0xEE, // PWCTR5 (C4h): Power Control 5 (in Partial mode/ full-colors)
244  0xC5, 0x01, 0x0E, // VMCTR vcom control 1
245  0x20, 0x00, // INVOFF (20h): Display Inversion Off
246 // 0xFC, 0x02, 0x11, 0x15, // PWCTR6
247  0x36, 0x01, 0b00000000, // MADCTL
248  0x3A, 0x01, 0x05, // COLMOD set 16-bit pixel format
249 // 0x26, 1, 0x08, // GAMSET set gamma curve: valid values 1, 2, 4, 8
250 // 0xF2, 1, 0x01, // enable gamma adjustment, 0 - to disable
251  0xE0, 0x10, // GMCTRP1 positive gamma correction
252  0x0F, 0x1A, 0x0F, 0x18,
253  0x2F, 0x28, 0x20, 0x22,
254  0x1F, 0x1B, 0x23, 0x37,
255  0x00, 0x07, 0x02, 0x10,
256  0xE1, 0x10, // GMCTRN1 negative gamma correction
257  0x0F, 0x1B, 0x0F, 0x17,
258  0x33, 0x2C, 0x29, 0x2E,
259  0x30, 0x30, 0x39, 0x3F,
260  0x00, 0x07, 0x03, 0x10,
261 // 0xC7, 1, 0x40, // vcom offset
262 // 0x2A, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x7F, // set column address, not needed. set by direct API
263 // 0x2B, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x00, CMD_ARG, 0x9F, // set page address, not needed. set by direct API
264  0x29, CMD_DELAY, 100, // DISPON display on
265  0x13, CMD_DELAY, 10, // NORON
266 };
267 
269 // ST7735 basic 16-bit implementation
271 
272 template <class I>
274 {
275  ssd1306_resetController2( this->m_rstPin, 20 );
276  this->m_w = 128;
277  this->m_h = 160;
278  // Give LCD some time to initialize. Refer to ST7735 datasheet
279  lcd_delay(120);
280  _configureSpiDisplay<I>(this->m_intf,
281  s_ST7735_lcd128x160x16_initData,
282  sizeof(s_ST7735_lcd128x160x16_initData));
283 }
284 
285 template <class I>
287 {
288 }
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:149
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:273
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:207
void end() override
Definition: lcd_st7735.inl:154
void spiDataMode(uint8_t mode)
Definition: lcd_st7735.inl:80
#define LCD_HIGH
Definition: io.h:142
void lcd_delay(unsigned long ms)