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_ssd1306.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  commandStart();
38  this->send(0x21); // column addr
39  this->send(x);
40  this->send(w ? (x + w - 1) : (m_base.width() - 1));
41  this->send(0x22); // page addr
42  this->send(y);
43  this->send((m_base.height() >> 3) - 1);
44  if ( m_dc >= 0 )
45  {
46  setDataMode(1);
47  }
48  else
49  {
50  this->stop();
51  this->start();
52  this->send(0x40);
53  }
54 }
55 
56 template <class I> void InterfaceSSD1306<I>::nextBlock()
57 {
58 
59 }
60 
61 template <class I> void InterfaceSSD1306<I>::endBlock()
62 {
63  this->stop();
64 }
65 
66 template <class I> void InterfaceSSD1306<I>::setDataMode(uint8_t mode)
67 {
68  if ( m_dc >= 0 )
69  {
70  lcd_gpioWrite(m_dc, mode ? LCD_HIGH : LCD_LOW);
71  }
72 }
73 
74 template <class I> void InterfaceSSD1306<I>::commandStart()
75 {
76  this->start();
77  if ( m_dc >= 0 )
78  setDataMode(0);
79  else
80  this->send(0x00);
81 }
82 
83 template <class I> void InterfaceSSD1306<I>::setStartLine(uint8_t line)
84 {
85  m_startLine = line;
86  commandStart();
87  this->send( 0x40 | (line & 0x3F) ); // start line
88  this->stop();
89 }
90 
91 template <class I> uint8_t InterfaceSSD1306<I>::getStartLine()
92 {
93  return m_startLine;
94 }
95 
96 template <class I> void InterfaceSSD1306<I>::normalMode()
97 {
98  commandStart();
99  this->send(0xA6); // Normal display
100  this->stop();
101 }
102 
103 template <class I> void InterfaceSSD1306<I>::invertMode()
104 {
105  commandStart();
106  this->send(0xA7); // Invert display
107  this->stop();
108 }
109 
110 template <class I> void InterfaceSSD1306<I>::setContrast(uint8_t contrast)
111 {
112  commandStart();
113  this->send(0x81); // set contrast
114  this->send(contrast);
115  this->stop();
116 }
117 
118 template <class I> void InterfaceSSD1306<I>::displayOff()
119 {
120  commandStart();
121  this->send(0xAE); // display off
122  this->stop();
123 }
124 
125 template <class I> void InterfaceSSD1306<I>::displayOn()
126 {
127  commandStart();
128  this->send(0xAF); // display on
129  this->stop();
130 }
131 
132 template <class I> void InterfaceSSD1306<I>::flipHorizontal(uint8_t mode)
133 {
134  commandStart();
135  this->send( 0xA0 | (mode ? 0x00: 0x01 ) ); // seg remap
136  this->stop();
137 }
138 
139 template <class I> void InterfaceSSD1306<I>::flipVertical(uint8_t mode)
140 {
141  commandStart();
142  this->send( mode ? 0xC0 : 0xC8 );
143  this->stop();
144 }
145 
146 
148 // SSD1306 basic 1-bit implementation
150 
151 template <class I> void DisplaySSD1306<I>::beginDisplay()
152 {
153 }
154 
155 template <class I> void DisplaySSD1306<I>::endDisplay()
156 {
157 }
158 
159 static const PROGMEM uint8_t s_SSD1306_lcd64x32_initData[] = {
160 #ifdef SDL_EMULATION
161  SDL_LCD_SSD1306, 0x00,
162  0x00, 0x00,
163 #endif
164  0xAE, 0x00, // display off
165  0xD5, 0x01, 0x80, // Clock div
166  0xA8, 0x01, 31, // Set multiplex
167  0xD3, 0x01, 0x00, // --no offset
168  0x40, 0x00, // Set display offset
169  0x8D, 0x01, 0x14, // Set charge pump
170  0xA0| 0x01, 0x00, // Reverse mapping
171  0xC8, 0x00, // Decrement
172  0xDA, 0x01, 0x02, // Set com pins
173  0x81, 0x01, 0x7F, // contast value
174  0xD9, 0x01, 0x22, // 0x1F Precharge
175  0xDB, 0x01, 0x40, // Precharge
176  0x20, 0x01, 0x00, // Set horizontal addressing mode
177  0xA4, 0x00, // Display resume
178  0xA6, 0x00, // Normal display
179  0xAF, 0x00, // Display on
180 };
181 
183 // SSD1306 basic 1-bit implementation
185 
187 {
188  ssd1306_resetController2(this->m_rstPin, 10);
189  this->m_w = 64;
190  this->m_h = 32;
191  // Give LCD some time to initialize. Refer to SSD1306 datasheet
192  lcd_delay(0);
193  _configureSpiDisplayCmdModeOnly<I>(this->m_intf,
194  s_SSD1306_lcd64x32_initData,
195  sizeof(s_SSD1306_lcd64x32_initData));
196 
197 }
198 
199 template <class I> void DisplaySSD1306_64x32<I>::endController()
200 {
201 }
202 
203 static const PROGMEM uint8_t s_SSD1306_lcd64x48_initData[] = {
204 #ifdef SDL_EMULATION
205  SDL_LCD_SSD1306, 0x00,
206  0x00, 0x00,
207 #endif
208  0xAE, 0x00, // display off
209  0xD5, 0x01, 0x80, // Clock div
210  0xA8, 0x01, 47, // Set multiplex
211  0xD3, 0x01, 0x00, // --no offset
212  0x40, 0x00, // Set display offset
213  0x8D, 0x01, 0x14, // Set charge pump
214  0xA0| 0x01, 0x00, // Reverse mapping
215  0xC8, 0x00, // Decrement
216  0xDA, 0x01, 0x02, // Set com pins
217  0x81, 0x01, 0x7F, // contast value
218  0xD9, 0x01, 0x22, // 0x1F Precharge
219  0xDB, 0x01, 0x40, // Precharge
220  0x20, 0x01, 0x00, // Set horizontal addressing mode
221  0xA4, 0x00, // Display resume
222  0xA6, 0x00, // Normal display
223  0xAF, 0x00, // Display on
224 };
225 
227 // SSD1306 basic 1-bit implementation
229 
231 {
232  ssd1306_resetController2(this->m_rstPin, 10);
233  this->m_w = 64;
234  this->m_h = 48;
235  // Give LCD some time to initialize. Refer to SSD1306 datasheet
236  lcd_delay(0);
237  _configureSpiDisplayCmdModeOnly<I>(this->m_intf,
238  s_SSD1306_lcd64x48_initData,
239  sizeof(s_SSD1306_lcd64x48_initData));
240 
241 }
242 
243 template <class I> void DisplaySSD1306_64x48<I>::endController()
244 {
245 }
246 
247 static const PROGMEM uint8_t s_SSD1306_lcd128x32_initData[] = {
248 #ifdef SDL_EMULATION
249  SDL_LCD_SSD1306, 0x00,
250  0x00, 0x00,
251 #endif
252  0xAE, 0x00, // display off
253  0xD5, 0x01, 0x80, // Clock div
254  0xA8, 0x01, 31, // Set multiplex
255  0xD3, 0x01, 0x00, // --no offset
256  0x40, 0x00, // Set display offset
257  0x8D, 0x01, 0x14, // Set charge pump
258  0xA0| 0x01, 0x00, // Reverse mapping
259  0xC8, 0x00, // Decrement
260  0xDA, 0x01, 0x02, // Set com pins
261  0x81, 0x01, 0x7F, // contast value
262  0xD9, 0x01, 0x22, // 0x1F Precharge
263  0xDB, 0x01, 0x40, // Precharge
264  0x20, 0x01, 0x00, // Set horizontal addressing mode
265  0xA4, 0x00, // Display resume
266  0xA6, 0x00, // Normal display
267  0xAF, 0x00, // Display on
268 };
269 
271 // SSD1306 basic 1-bit implementation
273 
275 {
276  ssd1306_resetController2(this->m_rstPin, 10);
277  this->m_w = 128;
278  this->m_h = 32;
279  // Give LCD some time to initialize. Refer to SSD1306 datasheet
280  lcd_delay(0);
281  _configureSpiDisplayCmdModeOnly<I>(this->m_intf,
282  s_SSD1306_lcd128x32_initData,
283  sizeof(s_SSD1306_lcd128x32_initData));
284 
285 }
286 
288 {
289 }
290 
291 static const PROGMEM uint8_t s_SSD1306_lcd128x64_initData[] = {
292 #ifdef SDL_EMULATION
293  SDL_LCD_SSD1306, 0x00,
294  0x00, 0x00,
295 #endif
296  0xAE, 0x00, // display off
297  0x20, 0x01, 0x00, // Page horizontal Addressing mode
298  0xC8, 0x00, // Scan from 127 to 0 (Reverse scan)
299  0x40, 0x00, // First line to start scanning from
300  0x81, 0x01, 0x7F, // contast value to 0x7F according to datasheet
301  0xA0| 0x01, 0x00, // Use reverse mapping. 0x00 - is normal mapping
302  0xA6, 0x00, // Normal display
303  0xA8, 0x01, 63, // Reset to default MUX. See datasheet
304  0xD3, 0x01, 0x00, // no offset
305  0xD5, 0x01, 0x80, // set to default ratio/osc frequency
306  0xD9, 0x01, 0x22, // switch precharge to 0x22 // 0xF1
307  0xDA, 0x01, 0x12, // set divide ratio
308  0xDB, 0x01, 0x20, // vcom deselect to 0x20 // 0x40
309  0x8D, 0x01, 0x14, // Enable charge pump
310  0xA4, 0x00, // Display resume
311  0xAF, 0x00, // Display on
312 };
313 
315 // SSD1306 basic 1-bit implementation
317 
319 {
320  ssd1306_resetController2(this->m_rstPin, 10);
321  this->m_w = 128;
322  this->m_h = 64;
323  // Give LCD some time to initialize. Refer to SSD1306 datasheet
324  lcd_delay(0);
325  _configureSpiDisplayCmdModeOnly<I>(this->m_intf,
326  s_SSD1306_lcd128x64_initData,
327  sizeof(s_SSD1306_lcd128x64_initData));
328 
329 }
330 
332 {
333 }
void setStartLine(uint8_t line)
Definition: lcd_ssd1306.inl:83
uint8_t lcduint_t
Definition: canvas_types.h:79
void lcd_gpioWrite(int pin, int level)
void flipVertical(uint8_t mode)
performs vertical flip
void ssd1306_resetController2(int8_t rstPin, uint8_t delayMs)
Does hardware reset for oled controller.
uint8_t getStartLine()
Definition: lcd_ssd1306.inl:91
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_ssd1306.inl:35
void flipHorizontal(uint8_t mode)
performs horizontal flip
#define LCD_LOW
Definition: io.h:175
void setDataMode(uint8_t mode)
Definition: lcd_ssd1306.inl:66
void setContrast(uint8_t contrast)
#define LCD_HIGH
Definition: io.h:177
void lcd_delay(unsigned long ms)