LCDGFX LCD display driver  1.2.0
Lightweight graphics library for SSD1306, SSD1325, SSD1327, SSD1331, SSD1351, SH1106, SH1107, IL9163, ST7735, ST7789, ILI9341, PCD8544 displays over I2C/SPI
lcd_sh1106.h
Go to the documentation of this file.
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 !!! */
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 <typename I> class InterfaceSH1106: public I
44 {
45 public:
53  template <typename... Args>
54  InterfaceSH1106(NanoDisplayBase<InterfaceSH1106<I>> &base, int8_t dc, Args &&... data)
55  : I(data...)
56  , m_dc(dc)
57  , m_base(base)
58  {
59  }
60 
77 
85  void nextBlock();
86 
90  void endBlock();
91 
96  void setDataMode(uint8_t mode);
97 
102  void commandStart();
103 
110  void setStartLine(uint8_t line);
111 
117  uint8_t getStartLine();
118 
123  void normalMode();
124 
130  void invertMode();
131 
138  void setContrast(uint8_t contrast);
139 
145  void displayOff();
146 
151  void displayOn();
152 
162  void flipHorizontal(uint8_t mode);
163 
173  void flipVertical(uint8_t mode);
174 
175 private:
176  int8_t m_dc = -1;
178  uint8_t m_startLine = 0;
179  uint8_t m_column = 0;
180  uint8_t m_page = 0;
181 };
185 template <typename I> class DisplaySH1106: public NanoDisplayOps<NanoDisplayOps1<I>, I>
186 {
187 public:
194  DisplaySH1106(I &intf, int8_t rstPin)
195  : NanoDisplayOps<NanoDisplayOps1<I>, I>(intf)
196  , m_rstPin(rstPin)
197  {
198  }
199 
200 protected:
201  int8_t m_rstPin;
202 
206  void beginDisplay();
207 
211  void endDisplay();
212 };
213 
217 template <typename I> class DisplaySH1106_128x64: public DisplaySH1106<I>
218 {
219 public:
226  DisplaySH1106_128x64(I &intf, int8_t rstPin)
227  : DisplaySH1106<I>(intf, rstPin)
228  {
229  }
230 
231 protected:
235  void beginController();
236 
240  void endController();
241 };
242 #ifdef CONFIG_LCDGFX_PLATFORM_SPI
243 
246 class DisplaySH1106_128x64_SPI: public DisplaySH1106_128x64<InterfaceSH1106<PlatformSpi>>
247 {
248 public:
256  explicit DisplaySH1106_128x64_SPI(int8_t rstPin, const SPlatformSpiConfig &config = {-1, {-1}, -1, 0U, -1, -1})
257  : DisplaySH1106_128x64(m_spi, rstPin)
258  , m_spi(*this, config.dc,
260  config.busId, {config.cs}, config.dc, config.frequency ?: static_cast<uint32_t>(10000000), config.scl, config.sda})
261  {
262  }
263 
267  void begin() override;
268 
272  void end() override;
273 
274 private:
276 };
277 #endif
278 
283 template <typename I> class DisplaySH1106_128x64_CustomSPI: public DisplaySH1106_128x64<InterfaceSH1106<I>>
284 {
285 public:
294  template <typename... Args>
295  DisplaySH1106_128x64_CustomSPI(int8_t rstPin, int8_t dcPin, Args &&... data)
296  : DisplaySH1106_128x64<InterfaceSH1106<I>>(m_spi, rstPin)
297  , m_spi(*this, dcPin, data...)
298  {
299  }
300 
304  void begin() override
305  {
306  m_spi.begin();
307  DisplaySH1106_128x64<InterfaceSH1106<I>>::beginController();
308  }
309 
313  void end() override
314  {
315  DisplaySH1106_128x64<InterfaceSH1106<I>>::endController();
316  m_spi.end();
317  }
318 
319 private:
320  InterfaceSH1106<I> m_spi;
321 };
322 #ifdef CONFIG_LCDGFX_PLATFORM_I2C
323 
326 class DisplaySH1106_128x64_I2C: public DisplaySH1106_128x64<InterfaceSH1106<PlatformI2c>>
327 {
328 public:
336  explicit DisplaySH1106_128x64_I2C(int8_t rstPin, const SPlatformI2cConfig &config = {-1, 0x3C, -1, -1, 0U})
337  : DisplaySH1106_128x64(m_i2c, rstPin)
338  , m_i2c(*this, -1,
339  SPlatformI2cConfig{config.busId, static_cast<uint8_t>(config.addr ?: 0x3C), config.scl, config.sda,
340  config.frequency ?: 400000U})
341  {
342  }
343 
347  void begin() override;
348 
352  void end() override;
353 
354 private:
356 };
357 #endif
358 
363 template <typename I> class DisplaySH1106_128x64_CustomI2C: public DisplaySH1106_128x64<InterfaceSH1106<I>>
364 {
365 public:
373  template <typename... Args>
374  DisplaySH1106_128x64_CustomI2C(int8_t rstPin, Args &&... data)
375  : DisplaySH1106_128x64<InterfaceSH1106<I>>(m_i2c, rstPin)
376  , m_i2c(*this, -1, data...)
377  {
378  }
379 
383  void begin() override
384  {
385  m_i2c.begin();
386  DisplaySH1106_128x64<InterfaceSH1106<I>>::beginController();
387  }
388 
392  void end() override
393  {
394  DisplaySH1106_128x64<InterfaceSH1106<I>>::endController();
395  m_i2c.end();
396  }
397 
398 private:
399  InterfaceSH1106<I> m_i2c;
400 };
401 #include "lcd_sh1106.inl"
402 
void displayOn()
Turns on the display, resuming normal output.
Definition: lcd_sh1106.inl:125
Structure describes spi platform configuration.
Definition: interface.h:80
uint8_t lcduint_t
internal int type, used by the library.
Definition: canvas_types.h:79
global lcd settings
void setDataMode(uint8_t mode)
Enables either data or command mode on SPI bus.
Definition: lcd_sh1106.inl:66
int8_t busId
bus id number.
Definition: interface.h:49
void begin() override
Initializes SH1106 lcd in 1-bit mode.
Definition: lcd_sh1106.h:383
Structure describes i2c platform configuration.
Definition: interface.h:43
DisplaySH1106_128x64(I &intf, int8_t rstPin)
Creates instance of SH1106 128x64 controller class for 1-bit mode.
Definition: lcd_sh1106.h:226
void flipHorizontal(uint8_t mode)
Performs horizontal flip.
Definition: lcd_sh1106.inl:132
DisplaySH1106_128x64_CustomSPI(int8_t rstPin, int8_t dcPin, Args &&... data)
Inits 128x64 lcd display over spi (based on SH1106 controller): 1-bit mode.
Definition: lcd_sh1106.h:295
SSD1306 HAL IO communication functions.
int8_t m_rstPin
indicates hardware reset pin used, -1 if it is not required
Definition: lcd_sh1106.h:201
void setStartLine(uint8_t line)
Sets start line in GDRAM to begin display content with.
Definition: lcd_sh1106.inl:83
InterfaceSH1106(NanoDisplayBase< InterfaceSH1106< I >> &base, int8_t dc, Args &&... data)
Creates instance of interface to LCD display.
Definition: lcd_sh1106.h:54
Class implements basic functions for 1-bit mode of SH1106-based displays.
Definition: lcd_sh1106.h:217
void begin() override
Initializes SH1106 lcd in 1-bit mode.
Definition: lcd_sh1106.h:304
int8_t dc
Data command control pin number.
Definition: interface.h:102
Template class implements SH1106 128x64 lcd display in 1 bit mode over custom SPI implementation (use...
Definition: lcd_sh1106.h:283
void flipVertical(uint8_t mode)
Performs vertical flip.
Definition: lcd_sh1106.inl:139
void endBlock()
Closes data send operation to lcd display.
Definition: lcd_sh1106.inl:61
NanoDisplayOps1 is template class for 1-bit operations.
Definition: display.h:47
void commandStart()
Starts communication with LCD display in command mode.
Definition: lcd_sh1106.inl:74
void nextBlock()
Switches to the start of next RAM page for the block, specified by startBlock().
Definition: lcd_sh1106.inl:55
Class implements interface functions to SH1106 displays.
Definition: lcd_sh1106.h:43
void end() override
Closes connection to display.
Definition: lcd_sh1106.h:313
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_sh1106.inl:35
void invertMode()
Switches display to inverted mode.
Definition: lcd_sh1106.inl:103
void normalMode()
Switches display back to normal (non-inverted) mode.
Definition: lcd_sh1106.inl:96
void displayOff()
Turns off the display (enters sleep mode).
Definition: lcd_sh1106.inl:118
Template class implements SH1106 128x64 lcd display in 1 bit mode over custom I2C implementation (use...
Definition: lcd_sh1106.h:363
NanoCanvasOps provides operations for drawing in memory buffer.
Definition: display.h:978
Class implements basic display operations for the library: It stores reference to communication inter...
Definition: display_base.h:55
uint8_t getStartLine()
Returns the current start line offset in GDRAM.
Definition: lcd_sh1106.inl:91
DisplaySH1106_128x64_CustomI2C(int8_t rstPin, Args &&... data)
Inits 128x64 lcd display over i2c (based on SH1106 controller): 1-bit mode.
Definition: lcd_sh1106.h:374
void setContrast(uint8_t contrast)
Sets display contrast (brightness level).
Definition: lcd_sh1106.inl:110
void end() override
Closes connection to display.
Definition: lcd_sh1106.h:392
DisplaySH1106(I &intf, int8_t rstPin)
Creates instance of SH1106 controller class for 1-bit mode.
Definition: lcd_sh1106.h:194
Class implements basic functions for 1-bit mode of SH1106-based displays.
Definition: lcd_sh1106.h:185