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_ssd1306.h
Go to the documentation of this file.
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 !!! */
29 #pragma once
30 
31 #include "lcd_hal/io.h"
32 #include "v2/lcd/lcd_common.h"
33 #include "v2/lcd/base/display.h"
34 
43 template <class I>
44 class InterfaceSSD1306: public I
45 {
46 public:
54  template <typename... Args>
55  InterfaceSSD1306(NanoDisplayBase<InterfaceSSD1306<I>> &base, int8_t dc, Args&&... data)
56  : I(data...)
57  , m_dc( dc )
58  , m_base(base)
59  {
60  }
61 
78 
85  void nextBlock();
86 
90  void endBlock();
91 
96  void setDataMode(uint8_t mode);
97 
102  void commandStart();
103 
109  void setStartLine(uint8_t line);
110 
114  uint8_t getStartLine();
115 
120  void normalMode();
121 
126  void invertMode();
127 
132  void setContrast(uint8_t contrast);
133 
137  void displayOff();
138 
142  void displayOn();
143 
153  void flipHorizontal(uint8_t mode);
154 
164  void flipVertical(uint8_t mode);
165 
166 private:
167  int8_t m_dc = -1;
169  uint8_t m_startLine = 0;
170 };
171 
172 
176 template <class I>
177 class DisplaySSD1306: public NanoDisplayOps<NanoDisplayOps1<I>,I>
178 {
179 public:
186  DisplaySSD1306(I &intf, int8_t rstPin)
187  : NanoDisplayOps<NanoDisplayOps1<I>, I>(intf)
188  , m_rstPin( rstPin ) { }
189 
190 protected:
191  int8_t m_rstPin;
192 
196  void begin() override;
197 
201  void end() override;
202 };
203 
207 template <class I>
209 {
210 public:
217  DisplaySSD1306_128x32(I &intf, int8_t rstPin)
218  : DisplaySSD1306<I>(intf, rstPin) { }
219 
220 protected:
221 
225  void begin() override;
226 
230  void end() override;
231 };
232 
236 class DisplaySSD1306_128x32_SPI: public DisplaySSD1306_128x32<InterfaceSSD1306<PlatformSpi>>
237 {
238 public:
246  DisplaySSD1306_128x32_SPI( int8_t rstPin, const SPlatformSpiConfig &config = { -1, { -1 }, -1, 0, -1, -1 } )
247  : DisplaySSD1306_128x32(m_spi, rstPin)
248  , m_spi( *this, config.dc,
249  SPlatformSpiConfig{ config.busId,
250  { config.cs },
251  config.dc,
252  config.frequency ?: 10000000,
253  config.scl,
254  config.sda } ) {}
255 
259  void begin() override;
260 
264  void end() override;
265 
266 private:
268 };
269 
274 template <class I>
275 class DisplaySSD1306_128x32_CustomSPI: public DisplaySSD1306_128x32<InterfaceSSD1306<I>>
276 {
277 public:
286  template <typename... Args>
287  DisplaySSD1306_128x32_CustomSPI( int8_t rstPin, int8_t dcPin, Args&&... data )
288  : DisplaySSD1306_128x32<InterfaceSSD1306<I>>(m_spi, rstPin)
289  , m_spi( *this, dcPin,
290  data... ) {}
291 
295  void begin() override
296  {
297  m_spi.begin();
299  }
300 
304  void end() override
305  {
307  m_spi.end();
308  }
309 
310 private:
311  InterfaceSSD1306<I> m_spi;
312 };
316 class DisplaySSD1306_128x32_I2C: public DisplaySSD1306_128x32<InterfaceSSD1306<PlatformI2c>>
317 {
318 public:
326  DisplaySSD1306_128x32_I2C( int8_t rstPin, const SPlatformI2cConfig &config = { -1, 0x3C, -1, -1, 0 } )
327  : DisplaySSD1306_128x32(m_i2c, rstPin)
328  , m_i2c( *this, -1,
329  SPlatformI2cConfig{ config.busId,
330  static_cast<uint8_t>(config.addr ?: 0x3C),
331  config.scl,
332  config.sda,
333  config.frequency ?: 400000 } ) {}
334 
338  void begin() override;
339 
343  void end() override;
344 
345 private:
347 };
348 
353 template <class I>
354 class DisplaySSD1306_128x32_CustomI2C: public DisplaySSD1306_128x32<InterfaceSSD1306<I>>
355 {
356 public:
364  template <typename... Args>
365  DisplaySSD1306_128x32_CustomI2C( int8_t rstPin, Args&&... data )
366  : DisplaySSD1306_128x32<InterfaceSSD1306<I>>(m_i2c, rstPin)
367  , m_i2c( *this, -1,
368  data... ) {}
369 
373  void begin() override
374  {
375  m_i2c.begin();
377  }
378 
382  void end() override
383  {
385  m_i2c.end();
386  }
387 
388 private:
389  InterfaceSSD1306<I> m_i2c;
390 };
391 
392 
398 template <class I>
399 class DisplaySSD1306_128x32_Custom: public DisplaySSD1306_128x32<InterfaceSSD1306<I>>
400 {
401 public:
414  template <typename... Args>
415  DisplaySSD1306_128x32_Custom( int8_t rstPin, int8_t dcPin, uint32_t frequency, Args&&... data )
416  : DisplaySSD1306_128x32<InterfaceSSD1306<I>>(m_custom, rstPin)
417  , m_custom( *this, dcPin, frequency= frequency ? : 3000000,
418  data... ) {}
419 
423  void begin() override
424  {
425  m_custom.begin();
427  }
428 
432  void end() override
433  {
435  m_custom.end();
436  }
437 
438 private:
439  InterfaceSSD1306<I> m_custom;
440 };
444 template <class I>
446 {
447 public:
454  DisplaySSD1306_128x64(I &intf, int8_t rstPin)
455  : DisplaySSD1306<I>(intf, rstPin) { }
456 
457 protected:
458 
462  void begin() override;
463 
467  void end() override;
468 };
469 
473 class DisplaySSD1306_128x64_SPI: public DisplaySSD1306_128x64<InterfaceSSD1306<PlatformSpi>>
474 {
475 public:
483  DisplaySSD1306_128x64_SPI( int8_t rstPin, const SPlatformSpiConfig &config = { -1, { -1 }, -1, 0, -1, -1 } )
484  : DisplaySSD1306_128x64(m_spi, rstPin)
485  , m_spi( *this, config.dc,
486  SPlatformSpiConfig{ config.busId,
487  { config.cs },
488  config.dc,
489  config.frequency ?: 10000000,
490  config.scl,
491  config.sda } ) {}
492 
496  void begin() override;
497 
501  void end() override;
502 
503 private:
505 };
506 
511 template <class I>
512 class DisplaySSD1306_128x64_CustomSPI: public DisplaySSD1306_128x64<InterfaceSSD1306<I>>
513 {
514 public:
523  template <typename... Args>
524  DisplaySSD1306_128x64_CustomSPI( int8_t rstPin, int8_t dcPin, Args&&... data )
525  : DisplaySSD1306_128x64<InterfaceSSD1306<I>>(m_spi, rstPin)
526  , m_spi( *this, dcPin,
527  data... ) {}
528 
532  void begin() override
533  {
534  m_spi.begin();
536  }
537 
541  void end() override
542  {
544  m_spi.end();
545  }
546 
547 private:
548  InterfaceSSD1306<I> m_spi;
549 };
553 class DisplaySSD1306_128x64_I2C: public DisplaySSD1306_128x64<InterfaceSSD1306<PlatformI2c>>
554 {
555 public:
563  DisplaySSD1306_128x64_I2C( int8_t rstPin, const SPlatformI2cConfig &config = { -1, 0x3C, -1, -1, 0 } )
564  : DisplaySSD1306_128x64(m_i2c, rstPin)
565  , m_i2c( *this, -1,
566  SPlatformI2cConfig{ config.busId,
567  static_cast<uint8_t>(config.addr ?: 0x3C),
568  config.scl,
569  config.sda,
570  config.frequency ?: 400000 } ) {}
571 
575  void begin() override;
576 
580  void end() override;
581 
582 private:
584 };
585 
590 template <class I>
591 class DisplaySSD1306_128x64_CustomI2C: public DisplaySSD1306_128x64<InterfaceSSD1306<I>>
592 {
593 public:
601  template <typename... Args>
602  DisplaySSD1306_128x64_CustomI2C( int8_t rstPin, Args&&... data )
603  : DisplaySSD1306_128x64<InterfaceSSD1306<I>>(m_i2c, rstPin)
604  , m_i2c( *this, -1,
605  data... ) {}
606 
610  void begin() override
611  {
612  m_i2c.begin();
614  }
615 
619  void end() override
620  {
622  m_i2c.end();
623  }
624 
625 private:
626  InterfaceSSD1306<I> m_i2c;
627 };
628 
629 
635 template <class I>
636 class DisplaySSD1306_128x64_Custom: public DisplaySSD1306_128x64<InterfaceSSD1306<I>>
637 {
638 public:
651  template <typename... Args>
652  DisplaySSD1306_128x64_Custom( int8_t rstPin, int8_t dcPin, uint32_t frequency, Args&&... data )
653  : DisplaySSD1306_128x64<InterfaceSSD1306<I>>(m_custom, rstPin)
654  , m_custom( *this, dcPin, frequency= frequency ? : 3000000,
655  data... ) {}
656 
660  void begin() override
661  {
662  m_custom.begin();
664  }
665 
669  void end() override
670  {
672  m_custom.end();
673  }
674 
675 private:
676  InterfaceSSD1306<I> m_custom;
677 };
678 #include "lcd_ssd1306.inl"
679 
DisplaySSD1306_128x32_Custom(int8_t rstPin, int8_t dcPin, uint32_t frequency, Args &&... data)
Inits 128x32 lcd display over custom interface (based on SSD1306 controller): 1-bit mode...
Definition: lcd_ssd1306.h:415
void setStartLine(uint8_t line)
Definition: lcd_ssd1306.inl:89
uint8_t lcduint_t
Definition: canvas_types.h:81
DisplaySSD1306_128x64(I &intf, int8_t rstPin)
Definition: lcd_ssd1306.h:454
DisplaySSD1306_128x64_CustomSPI(int8_t rstPin, int8_t dcPin, Args &&... data)
Inits 128x64 lcd display over spi (based on SSD1306 controller): 1-bit mode.
Definition: lcd_ssd1306.h:524
DisplaySSD1306_128x32_I2C(int8_t rstPin, const SPlatformI2cConfig &config={ -1, 0x3C, -1, -1, 0 })
Inits 128x32 lcd display over i2c (based on SSD1306 controller): 1-bit mode.
Definition: lcd_ssd1306.h:326
void flipVertical(uint8_t mode)
performs vertical flip
DisplaySSD1306(I &intf, int8_t rstPin)
Definition: lcd_ssd1306.h:186
DisplaySSD1306_128x64_I2C(int8_t rstPin, const SPlatformI2cConfig &config={ -1, 0x3C, -1, -1, 0 })
Inits 128x64 lcd display over i2c (based on SSD1306 controller): 1-bit mode.
Definition: lcd_ssd1306.h:563
DisplaySSD1306_128x64_Custom(int8_t rstPin, int8_t dcPin, uint32_t frequency, Args &&... data)
Inits 128x64 lcd display over custom interface (based on SSD1306 controller): 1-bit mode...
Definition: lcd_ssd1306.h:652
DisplaySSD1306_128x32_CustomSPI(int8_t rstPin, int8_t dcPin, Args &&... data)
Inits 128x32 lcd display over spi (based on SSD1306 controller): 1-bit mode.
Definition: lcd_ssd1306.h:287
uint8_t getStartLine()
Definition: lcd_ssd1306.inl:98
InterfaceSSD1306(NanoDisplayBase< InterfaceSSD1306< I >> &base, int8_t dc, Args &&... data)
Definition: lcd_ssd1306.h:55
int8_t m_rstPin
indicates hardware reset pin used, -1 if it is not required
Definition: lcd_ssd1306.h:191
DisplaySSD1306_128x32_SPI(int8_t rstPin, const SPlatformSpiConfig &config={ -1, { -1 }, -1, 0, -1, -1 })
Inits 128x32 lcd display over spi (based on SSD1306 controller): 1-bit mode.
Definition: lcd_ssd1306.h:246
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:36
void flipHorizontal(uint8_t mode)
performs horizontal flip
DisplaySSD1306_128x32_CustomI2C(int8_t rstPin, Args &&... data)
Inits 128x32 lcd display over i2c (based on SSD1306 controller): 1-bit mode.
Definition: lcd_ssd1306.h:365
void setDataMode(uint8_t mode)
Definition: lcd_ssd1306.inl:70
DisplaySSD1306_128x64_CustomI2C(int8_t rstPin, Args &&... data)
Inits 128x64 lcd display over i2c (based on SSD1306 controller): 1-bit mode.
Definition: lcd_ssd1306.h:602
void setContrast(uint8_t contrast)
DisplaySSD1306_128x32(I &intf, int8_t rstPin)
Definition: lcd_ssd1306.h:217
DisplaySSD1306_128x64_SPI(int8_t rstPin, const SPlatformSpiConfig &config={ -1, { -1 }, -1, 0, -1, -1 })
Inits 128x64 lcd display over spi (based on SSD1306 controller): 1-bit mode.
Definition: lcd_ssd1306.h:483