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.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 _NANO_DISPLAY_H_
29 #define _NANO_DISPLAY_H_
30 
31 #include "canvas/point.h"
32 #include "canvas/rect.h"
33 #include "canvas/canvas.h"
34 #include "canvas/font.h"
35 #include "lcd_hal/io.h"
36 #include "nano_gfx_types.h"
37 #include "display_base.h"
38 
47 template <class I>
49 {
50 public:
52  static const uint8_t BITS_PER_PIXEL = 1;
53 
55 
62  void putPixel(lcdint_t x, lcdint_t y) __attribute__ ((noinline));
63 
71  void drawVLine(lcdint_t x1, lcdint_t y1, lcdint_t y2);
72 
80  void drawHLine(lcdint_t x1, lcdint_t y1, lcdint_t x2);
81 
90  void fillRect(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2) __attribute__((noinline));
91 
102  void drawXBitmap(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
103 
118  void drawBitmap1(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap) __attribute__ ((noinline));
119 
130  void gfx_drawMonoBitmap(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buf);
131 
141  void drawBitmap4(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
142 
152  void drawBitmap8(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
153 
164  void drawBitmap16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
165 
182  void drawBuffer1(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__ ((noinline));
183 
193  void drawBuffer1Fast(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer);
194 
206  void drawBuffer4(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__ ((noinline));
207 
219  void drawBuffer8(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__ ((noinline));
220 
231  void drawBuffer16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__ ((noinline));
232 
236  void clear();
237 
243  void fill(uint16_t color);
244 
250  uint8_t printChar(uint8_t c);
251 
256  size_t write(uint8_t c) __attribute__ ((noinline));
257 
268  void printFixed(lcdint_t xpos, lcdint_t y, const char *ch, EFontStyle style = STYLE_NORMAL) __attribute__ ((noinline));
269 
270 #ifndef DOXYGEN_SHOULD_SKIP_THIS
271  void printFixed_oldStyle(uint8_t xpos, uint8_t y, const char *ch, EFontStyle style) __attribute__ ((noinline));
272 #endif
273 
293  void printFixedN(lcdint_t xpos, lcdint_t y, const char *ch, EFontStyle style, uint8_t factor) __attribute__ ((noinline));
294 
295 protected:
296 };
297 
301 template <class I>
303 {
304 public:
306  static const uint8_t BITS_PER_PIXEL = 4;
307 
309 
316  void putPixel(lcdint_t x, lcdint_t y) __attribute__ ((noinline));
317 
325  void drawVLine(lcdint_t x1, lcdint_t y1, lcdint_t y2);
326 
334  void drawHLine(lcdint_t x1, lcdint_t y1, lcdint_t x2);
335 
344  void fillRect(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2) __attribute__((noinline));
345 
356  void drawXBitmap(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
357 
372  void drawBitmap1(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap) __attribute__ ((noinline));
373 
383  void drawBitmap4(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap) __attribute__ ((noinline));
384 
394  void drawBitmap8(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
395 
406  void drawBitmap16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
407 
424  void drawBuffer1(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__ ((noinline));
425 
435  void drawBuffer1Fast(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer);
436 
448  void drawBuffer4(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__ ((noinline));
449 
461  void drawBuffer8(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer);
462 
473  void drawBuffer16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__ ((noinline));
474 
478  void clear();
479 
485  void fill(uint16_t color);
486 
492  uint8_t printChar(uint8_t c);
493 
498  size_t write(uint8_t c) __attribute__ ((noinline));
499 
510  void printFixed(lcdint_t xpos, lcdint_t y, const char *ch, EFontStyle style = STYLE_NORMAL) __attribute__ ((noinline));
511 
512 protected:
513 };
514 
518 template <class I>
520 {
521 public:
523  static const uint8_t BITS_PER_PIXEL = 8;
524 
526 
533  void putPixel(lcdint_t x, lcdint_t y) __attribute__ ((noinline));
534 
542  void drawVLine(lcdint_t x1, lcdint_t y1, lcdint_t y2);
543 
551  void drawHLine(lcdint_t x1, lcdint_t y1, lcdint_t x2);
552 
561  void fillRect(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2) __attribute__((noinline));
562 
573  void drawXBitmap(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
574 
589  void drawBitmap1(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap) __attribute__ ((noinline));
590 
600  void drawBitmap4(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap) __attribute__ ((noinline));
601 
611  void drawBitmap8(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
612 
623  void drawBitmap16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
624 
641  void drawBuffer1(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__ ((noinline));
642 
652  void drawBuffer1Fast(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer);
653 
665  void drawBuffer4(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__ ((noinline));
666 
678  void drawBuffer8(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer);
679 
690  void drawBuffer16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__ ((noinline));
691 
695  void clear();
696 
702  void fill(uint16_t color);
703 
709  uint8_t printChar(uint8_t c);
710 
715  size_t write(uint8_t c) __attribute__ ((noinline));
716 
727  void printFixed(lcdint_t xpos, lcdint_t y, const char *ch, EFontStyle style = STYLE_NORMAL) __attribute__ ((noinline));
728 
729 protected:
730 };
731 
735 template <class I>
737 {
738 public:
740  static const uint8_t BITS_PER_PIXEL = 1;
741 
743 
750  void putPixel(lcdint_t x, lcdint_t y) __attribute__ ((noinline));
751 
759  void drawVLine(lcdint_t x1, lcdint_t y1, lcdint_t y2);
760 
768  void drawHLine(lcdint_t x1, lcdint_t y1, lcdint_t x2);
769 
778  void fillRect(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2) __attribute__((noinline));
779 
790  void drawXBitmap(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
791 
806  void drawBitmap1(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap) __attribute__ ((noinline));
807 
817  void drawBitmap4(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap) __attribute__ ((noinline));
818 
828  void drawBitmap8(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
829 
840  void drawBitmap16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
841 
858  void drawBuffer1(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__ ((noinline));
859 
869  void drawBuffer1Fast(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer);
870 
882  void drawBuffer4(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__ ((noinline));
883 
895  void drawBuffer8(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer);
896 
907  void drawBuffer16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__ ((noinline));
908 
912  void clear();
913 
919  void fill(uint16_t color);
920 
926  uint8_t printChar(uint8_t c);
927 
932  size_t write(uint8_t c) __attribute__ ((noinline));
933 
944  void printFixed(lcdint_t xpos, lcdint_t y, const char *ch, EFontStyle style = STYLE_NORMAL) __attribute__ ((noinline));
945 
946 protected:
947 };
948 
953 template <class O, class I>
954 class NanoDisplayOps: public O
955 {
956 public:
957  using O::O;
958 
959  using O::putPixel;
960 
966  void putPixel(const NanoPoint &p);
967 
976  void drawLine(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2);
977 
983  void drawLine(const NanoRect &rect);
984 
993  void drawRect(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2);
994 
1000  void drawRect(const NanoRect &rect);
1001 
1002  using O::fillRect;
1003 
1009  void fillRect(const NanoRect &rect);
1010 
1018  void drawCanvas(lcdint_t x, lcdint_t y, NanoCanvasOps<1> &canvas) __attribute__ ((noinline));
1019 
1027  void drawCanvas(lcdint_t x, lcdint_t y, NanoCanvasOps<4> &canvas) __attribute__ ((noinline));
1028 
1036  void drawCanvas(lcdint_t x, lcdint_t y, NanoCanvasOps<8> &canvas) __attribute__ ((noinline));
1037 
1045  void drawCanvas(lcdint_t x, lcdint_t y, NanoCanvasOps<16> &canvas) __attribute__ ((noinline));
1046 
1057  void printFixedPgm(lcdint_t xpos, lcdint_t y, const char *ch, EFontStyle style = STYLE_NORMAL) __attribute__ ((noinline));
1058 
1059  using O::write;
1060 
1067  void write(const char *str);
1068 
1075  void print(int number);
1076 
1087  void createMenu(SAppMenu *menu, const char **items, uint8_t count, const NanoRect &rect = {});
1088 
1095  void showMenu( SAppMenu *menu);
1096 
1104  void showMenuSmooth( SAppMenu *menu );
1105 
1112  void updateMenu(SAppMenu *menu);
1113 
1122  void updateMenuSmooth(SAppMenu *menu);
1123 
1131  uint8_t menuSelection(SAppMenu *menu);
1132 
1140  void menuDown(SAppMenu *menu);
1141 
1149  void menuUp(SAppMenu *menu);
1150 
1156  void drawProgressBar(int8_t progress);
1157 
1168  void drawWindow(lcdint_t x, lcdint_t y,
1170  const char *caption, bool blank);
1171 
1172 protected:
1176  virtual void begin() = 0;
1177 
1181  virtual void end() = 0;
1182 };
1183 
1184 #include "ssd1306_1bit.inl"
1185 #include "ssd1306_4bit.inl"
1186 #include "ssd1306_8bit.inl"
1187 #include "ssd1306_16bit.inl"
1188 #include "ssd1306_common.inl"
1189 
1194 #endif
1195 
void drawBitmap8(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap)
Draws 8-bit color bitmap in color buffer. Draws 8-bit color bitmap in color buffer.
void fill(uint16_t color)
void drawBitmap16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *bitmap)
uint8_t lcduint_t
Definition: canvas_types.h:81
void drawBitmap1(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap) __attribute__((noinline))
Draws monochrome bitmap in color buffer using color, specified via setColor() method Draws monochrome...
void drawBuffer4(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__((noinline))
Definition: rect.h:42
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 fillRect(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2) __attribute__((noinline))
static const uint8_t BITS_PER_PIXEL
Definition: display.h:52
void gfx_drawMonoBitmap(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buf)
void drawBuffer1(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__((noinline))
uint8_t printChar(uint8_t c)
const NanoRect rect() const
Definition: display_base.h:88
void drawBuffer1Fast(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer)
void drawXBitmap(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap)
void putPixel(lcdint_t x, lcdint_t y) __attribute__((noinline))
void printFixedN(lcdint_t xpos, lcdint_t y, const char *ch, EFontStyle style, uint8_t factor) __attribute__((noinline))
void drawBuffer8(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__((noinline))
size_t write(uint8_t c) __attribute__((noinline))
void printFixed(lcdint_t xpos, lcdint_t y, const char *ch, EFontStyle style=STYLE_NORMAL) __attribute__((noinline))
void drawBitmap4(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap)
Draws 4-bit gray-color bitmap in color buffer. Draws 4-bit gray-color bitmap in color buffer...
void drawVLine(lcdint_t x1, lcdint_t y1, lcdint_t y2)
EFontStyle
Definition: canvas_types.h:90
void drawHLine(lcdint_t x1, lcdint_t y1, lcdint_t x2)
void drawBuffer16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__((noinline))