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
display.h
1 /*
2  MIT License
3 
4  Copyright (c) 2018-2022, 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> class NanoDisplayOps1: public NanoDisplayBase<I>
48 {
49 public:
51  static const uint8_t BITS_PER_PIXEL = 1;
52 
54 
61  void putPixel(lcdint_t x, lcdint_t y) __attribute__((noinline));
62 
70  void drawVLine(lcdint_t x1, lcdint_t y1, lcdint_t y2);
71 
79  void drawHLine(lcdint_t x1, lcdint_t y1, lcdint_t x2);
80 
89  void fillRect(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2) __attribute__((noinline));
90 
101  void drawXBitmap(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
102 
117  void drawBitmap1(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap) __attribute__((noinline));
118 
129  void gfx_drawMonoBitmap(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buf);
130 
140  void drawBitmap4(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
141 
151  void drawBitmap8(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
152 
163  void drawBitmap16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
164 
181  void drawBuffer1(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__((noinline));
182 
192  void drawBuffer1Fast(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer);
193 
205  void drawBuffer4(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__((noinline));
206 
218  void drawBuffer8(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__((noinline));
219 
230  void drawBuffer16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *buffer)
231  __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)
269  __attribute__((noinline));
270 
271 #ifndef DOXYGEN_SHOULD_SKIP_THIS
272  void printFixed_oldStyle(uint8_t xpos, uint8_t y, const char *ch, EFontStyle style) __attribute__((noinline));
273 #endif
274 
291  void printFixedN(lcdint_t xpos, lcdint_t y, const char *ch, EFontStyle style, uint8_t factor)
292  __attribute__((noinline));
293 
294 protected:
295 };
296 
300 template <class I> class NanoDisplayOps4: public NanoDisplayBase<I>
301 {
302 public:
304  static const uint8_t BITS_PER_PIXEL = 4;
305 
307 
314  void putPixel(lcdint_t x, lcdint_t y) __attribute__((noinline));
315 
323  void drawVLine(lcdint_t x1, lcdint_t y1, lcdint_t y2);
324 
332  void drawHLine(lcdint_t x1, lcdint_t y1, lcdint_t x2);
333 
342  void fillRect(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2) __attribute__((noinline));
343 
354  void drawXBitmap(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
355 
370  void drawBitmap1(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap) __attribute__((noinline));
371 
381  void drawBitmap4(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap) __attribute__((noinline));
382 
392  void drawBitmap8(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
393 
404  void drawBitmap16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
405 
422  void drawBuffer1(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__((noinline));
423 
433  void drawBuffer1Fast(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer);
434 
446  void drawBuffer4(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__((noinline));
447 
459  void drawBuffer8(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer);
460 
471  void drawBuffer16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *buffer)
472  __attribute__((noinline));
473 
477  void clear();
478 
484  void fill(uint16_t color);
485 
491  uint8_t printChar(uint8_t c);
492 
497  size_t write(uint8_t c) __attribute__((noinline));
498 
509  void printFixed(lcdint_t xpos, lcdint_t y, const char *ch, EFontStyle style = STYLE_NORMAL)
510  __attribute__((noinline));
511 
512 protected:
513 private:
514  lcdint_t m_lastRow = 0;
515  lcdint_t m_lastColumn = 0;
516  uint8_t m_lastByte = 0;
517 };
518 
522 template <class I> class NanoDisplayOps8: public NanoDisplayBase<I>
523 {
524 public:
526  static const uint8_t BITS_PER_PIXEL = 8;
527 
529 
536  void putPixel(lcdint_t x, lcdint_t y) __attribute__((noinline));
537 
545  void drawVLine(lcdint_t x1, lcdint_t y1, lcdint_t y2);
546 
554  void drawHLine(lcdint_t x1, lcdint_t y1, lcdint_t x2);
555 
564  void fillRect(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2) __attribute__((noinline));
565 
576  void drawXBitmap(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
577 
592  void drawBitmap1(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap) __attribute__((noinline));
593 
603  void drawBitmap4(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap) __attribute__((noinline));
604 
614  void drawBitmap8(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
615 
626  void drawBitmap16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
627 
644  void drawBuffer1(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__((noinline));
645 
655  void drawBuffer1Fast(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer);
656 
668  void drawBuffer4(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__((noinline));
669 
681  void drawBuffer8(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer);
682 
693  void drawBuffer16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *buffer)
694  __attribute__((noinline));
695 
699  void clear();
700 
706  void fill(uint16_t color);
707 
713  uint8_t printChar(uint8_t c);
714 
719  size_t write(uint8_t c) __attribute__((noinline));
720 
731  void printFixed(lcdint_t xpos, lcdint_t y, const char *ch, EFontStyle style = STYLE_NORMAL)
732  __attribute__((noinline));
733 
734 protected:
735 };
736 
740 template <class I> class NanoDisplayOps16: public NanoDisplayBase<I>
741 {
742 public:
744  static const uint8_t BITS_PER_PIXEL = 1;
745 
747 
754  void putPixel(lcdint_t x, lcdint_t y) __attribute__((noinline));
755 
763  void drawVLine(lcdint_t x1, lcdint_t y1, lcdint_t y2);
764 
772  void drawHLine(lcdint_t x1, lcdint_t y1, lcdint_t x2);
773 
782  void fillRect(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2) __attribute__((noinline));
783 
794  void drawXBitmap(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
795 
810  void drawBitmap1(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap) __attribute__((noinline));
811 
821  void drawBitmap4(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap) __attribute__((noinline));
822 
832  void drawBitmap8(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
833 
844  void drawBitmap16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *bitmap);
845 
862  void drawBuffer1(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__((noinline));
863 
873  void drawBuffer1Fast(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer);
874 
886  void drawBuffer4(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer) __attribute__((noinline));
887 
899  void drawBuffer8(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buffer);
900 
911  void drawBuffer16(lcdint_t xpos, lcdint_t ypos, lcduint_t w, lcduint_t h, const uint8_t *buffer)
912  __attribute__((noinline));
913 
917  void clear();
918 
924  void fill(uint16_t color);
925 
931  uint8_t printChar(uint8_t c);
932 
937  size_t write(uint8_t c) __attribute__((noinline));
938 
949  void printFixed(lcdint_t xpos, lcdint_t y, const char *ch, EFontStyle style = STYLE_NORMAL)
950  __attribute__((noinline));
951 
968  void printFixedN(lcdint_t xpos, lcdint_t y, const char *ch, EFontStyle style, uint8_t factor)
969  __attribute__((noinline));
970 
971 protected:
972 };
973 
978 template <typename O, typename I> class NanoDisplayOps: public O
979 {
980 public:
981  using O::O;
982 
983  using O::putPixel;
984 
987 
993  void putPixel(const NanoPoint &p);
994 
1003  void drawLine(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2);
1004 
1010  void drawLine(const NanoRect &rect);
1011 
1020  void drawRect(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2);
1021 
1027  void drawRect(const NanoRect &rect);
1028 
1029  using O::fillRect;
1030 
1036  void fillRect(const NanoRect &rect);
1037 
1045  void drawCircle(lcdint_t xc, lcdint_t yc, lcdint_t r, uint8_t options = 0x0F);
1046 
1054  void drawCanvas(lcdint_t x, lcdint_t y, NanoCanvasOps<1> &canvas) __attribute__((noinline));
1055 
1063  void drawCanvas(lcdint_t x, lcdint_t y, NanoCanvasOps<4> &canvas) __attribute__((noinline));
1064 
1072  void drawCanvas(lcdint_t x, lcdint_t y, NanoCanvasOps<8> &canvas) __attribute__((noinline));
1073 
1081  void drawCanvas(lcdint_t x, lcdint_t y, NanoCanvasOps<16> &canvas) __attribute__((noinline));
1082 
1093  void printFixedPgm(lcdint_t xpos, lcdint_t y, const char *ch, EFontStyle style = STYLE_NORMAL)
1094  __attribute__((noinline));
1095 
1096  using O::write;
1097 
1104  void write(const char *str);
1105 
1112  void print(int number);
1113 
1120  void print(float number);
1121 
1128  void print(char c);
1129 
1140  void createMenu(SAppMenu *menu, const char **items, uint8_t count, const NanoRect &rect = {});
1141 
1148  void showMenu(SAppMenu *menu);
1149 
1157  void showMenuSmooth(SAppMenu *menu);
1158 
1165  void updateMenu(SAppMenu *menu);
1166 
1175  void updateMenuSmooth(SAppMenu *menu);
1176 
1184  uint8_t menuSelection(const SAppMenu *menu);
1185 
1193  void menuDown(SAppMenu *menu);
1194 
1202  void menuUp(SAppMenu *menu);
1203 
1209  void drawProgressBar(int8_t progress);
1210 
1221  void drawWindow(lcdint_t x, lcdint_t y, lcduint_t width, lcduint_t height, const char *caption, bool blank);
1222 
1223 protected:
1227  virtual void begin() = 0;
1228 
1232  virtual void end() = 0;
1233 };
1234 
1235 #include "ssd1306_1bit.inl"
1236 #include "ssd1306_4bit.inl"
1237 #include "ssd1306_8bit.inl"
1238 #include "ssd1306_16bit.inl"
1239 #include "ssd1306_common.inl"
1240 
1245 #endif
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:79
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:98
int8_t lcdint_t
Definition: canvas_types.h:77
lcduint_t height()
Definition: display_base.h:106
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:51
NanoDisplayOps< O, I > T
Definition: display.h:986
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:90
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:88
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))