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
display_base.h
Go to the documentation of this file.
1 /*
2  MIT License
3 
4  Copyright (c) 2018-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 */
28 #ifndef _DISPLAY_BASE_H_
29 #define _DISPLAY_BASE_H_
30 
31 #include "lcd_hal/io.h"
32 #include "nano_gfx_types.h"
33 #include "canvas/point.h"
34 #include "canvas/rect.h"
35 #include "canvas/font.h"
36 
42 #ifdef __cplusplus
43 extern "C"
44 {
45 #endif
46 extern uint8_t s_ssd1306_invertByte;
47 #ifdef __cplusplus
48 }
49 #endif
50 
55 template <class I>
57 {
58 public:
64  NanoDisplayBase(I& intf): m_intf( intf ) {}
65 
66 #ifndef DOXYGEN_SHOULD_SKIP_THIS
67 
72  void setOffset(lcdint_t ox, lcdint_t oy) { };
73 #endif
74 
79  const NanoPoint offsetEnd() const
80  {
81  return (NanoPoint){ (lcdint_t)(m_w-1), (lcdint_t)(m_h-1) };
82  }
83 
88  const NanoRect rect() const
89  {
90  return { (NanoPoint){0,0}, offsetEnd() };
91  }
92 
96  lcduint_t width() { return m_w; }
97 
101  lcduint_t height() { return m_h; }
102 
107  {
108  lcduint_t t = m_w;
109  m_w = m_h;
110  m_h = t;
111  }
112 
117  void setColor(uint16_t color) { m_color = color; };
118 
123  void negativeMode() { s_ssd1306_invertByte = 0xFF; }
124 
129  void positiveMode() { s_ssd1306_invertByte = 0x00; }
130 
136  I& getInterface() { return m_intf; }
137 
146  void setFont( NanoFont &font ) { m_font = &font; }
147 
154  void setFontSpacing(uint8_t spacing)
155  {
156  if (m_font) m_font->setSpacing(spacing);
157  }
158 
162  NanoFont &getFont() { return *m_font; }
163 
173  void setFixedFont( const uint8_t *progmemFont )
174  {
175  g_canvas_font.loadFixedFont( progmemFont );
176  setFont( g_canvas_font );
177  }
178 
179 #ifndef DOXYGEN_SHOULD_SKIP_THIS
180  void setFixedFont_oldStyle( const uint8_t *progmemFont )
181  {
182  g_canvas_font.loadFixedFont_oldStyle( progmemFont );
183  setFont( g_canvas_font );
184  }
185 #endif
186 
197  void setFixedFont( const uint8_t *progmemFont, const uint8_t *secondaryFont )
198  {
199  g_canvas_font.loadFixedFont( progmemFont );
200  if ( secondaryFont )
201  {
202  g_canvas_font.loadSecondaryFont( secondaryFont );
203  }
204  setFont( g_canvas_font );
205  }
206 
217  void setFreeFont( const uint8_t *progmemFont, const uint8_t *secondaryFont = nullptr )
218  {
219  g_canvas_font.loadFreeFont( progmemFont );
220  if ( secondaryFont )
221  {
222  g_canvas_font.loadSecondaryFont( secondaryFont );
223  }
224  setFont( g_canvas_font );
225  }
226 
234  {
235  m_cursorX = x;
236  m_cursorY = y;
237  }
238 
239 protected:
245  uint8_t m_textMode = 0;
247  uint16_t m_color = 0xFFFF;
248  NanoFont *m_font = nullptr;
249 
250  I& m_intf;
251 };
252 
257 #endif
258 
EFontStyle m_fontStyle
currently active font style
Definition: display_base.h:246
lcdint_t m_cursorY
current Y cursor position for text output
Definition: display_base.h:244
uint8_t lcduint_t
Definition: canvas_types.h:81
struct _NanoPoint NanoPoint
Definition: rect.h:42
const NanoPoint offsetEnd() const
Definition: display_base.h:79
void swapDimensions()
Definition: display_base.h:106
NanoFont * m_font
currently set font
Definition: display_base.h:248
lcduint_t m_w
width of NanoCanvas area in pixels
Definition: display_base.h:240
lcduint_t width()
Definition: display_base.h:96
int8_t lcdint_t
Definition: canvas_types.h:79
lcduint_t height()
Definition: display_base.h:101
void setFixedFont(const uint8_t *progmemFont, const uint8_t *secondaryFont)
Definition: display_base.h:197
void setFont(NanoFont &font)
Definition: display_base.h:146
void setColor(uint16_t color)
Definition: display_base.h:117
uint16_t m_color
current color for monochrome operations
Definition: display_base.h:247
Definition: font.h:45
void setFixedFont(const uint8_t *progmemFont)
Definition: display_base.h:173
void setSpacing(uint8_t spacing)
Definition: font.h:144
NanoDisplayBase(I &intf)
Definition: display_base.h:64
const NanoRect rect() const
Definition: display_base.h:88
lcduint_t m_h
height of NanoCanvas area in pixels
Definition: display_base.h:241
void setFontSpacing(uint8_t spacing)
Definition: display_base.h:154
uint8_t m_textMode
Flags for current NanoCanvas mode.
Definition: display_base.h:245
NanoFont & getFont()
Definition: display_base.h:162
void setTextCursor(lcdint_t x, lcdint_t y)
Definition: display_base.h:233
void loadFixedFont(const uint8_t *progmemFont)
lcdint_t m_cursorX
current X cursor position for text output
Definition: display_base.h:243
EFontStyle
Definition: canvas_types.h:90
void loadSecondaryFont(const uint8_t *progmemUnicode)
void setFreeFont(const uint8_t *progmemFont, const uint8_t *secondaryFont=nullptr)
Definition: display_base.h:217
I & m_intf
communication interface with the display
Definition: display_base.h:250
void loadFreeFont(const uint8_t *progmemFont)
lcduint_t m_p
number of bits, used by width value: 3 equals to 8 pixels width
Definition: display_base.h:242