SSD1306 OLED display driver  1.7.20
This library is developed to control SSD1306/SSD1331/SSD1351/IL9163/PCD8554 RGB i2c/spi LED displays
nano_gfx_types.h
Go to the documentation of this file.
1 /*
2  MIT License
3 
4  Copyright (c) 2017-2019, 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_GFX_TYPES_H_
29 #define _NANO_GFX_TYPES_H_
30 
31 #include "ssd1306_hal/io.h"
32 
33 #ifndef min
34 
35 #define min(a,b) ((a)<(b)?(a):(b))
36 #endif
37 
38 #ifndef max
39 
40 #define max(a,b) ((a)>(b)?(a):(b))
41 #endif
42 
44 #define RGB_COLOR8(r,g,b) ( (r & 0xE0) | ((g >> 3)&0x1C) | (b>>6) )
45 
47 #define RGB_COLOR16(r,g,b) ( ((r<<8) & 0xF800) | ((g << 3)&0x07E0) | (b>>3) )
48 
50 #define RGB8_TO_RGB16(c) ( (((uint16_t)c & 0b11100000) << 8) | \
51  (((uint16_t)c & 0b00011100) << 6) | \
52  (((uint16_t)c & 0b00000011) << 3) )
53 
55 #define RGB16_TO_RGB8(c) ( ((uint16_t)(c >> 8) & 0b11100000) | \
56  ((uint16_t)(c >> 6) & 0b00011100) | \
57  ((uint16_t)(c >> 3) & 0b00000011) )
58 
60 typedef void (*InitFunction)(void);
61 
63 typedef enum
64 {
65  STYLE_NORMAL,
66  STYLE_BOLD,
67  STYLE_ITALIC,
68 } EFontStyle;
69 
71 typedef enum
72 {
73  FONT_SIZE_NORMAL = 0,
74  FONT_SIZE_2X = 1,
75  FONT_SIZE_4X = 2,
76  FONT_SIZE_8X = 3,
77 } EFontSize;
78 
79 #pragma pack(push, 1)
80 
81 typedef struct
82 {
83  uint8_t type;
84  uint8_t width;
85  uint8_t height;
86  uint8_t ascii_offset;
88 
90 typedef struct
91 {
92  uint16_t start_code;
93  uint8_t count;
95 
96 #pragma pack(pop)
97 
99 typedef struct
100 {
102  uint8_t count;
103  uint8_t pages;
104  uint8_t glyph_size;
105  const uint8_t *primary_table;
106 #ifdef CONFIG_SSD1306_UNICODE_ENABLE
107  const uint8_t *secondary_table;
108 #endif
110 
112 typedef struct
113 {
114  uint8_t width;
115  uint8_t height;
116  uint8_t spacing;
117  const uint8_t *glyph;
118 } SCharInfo;
119 
123 typedef struct
124 {
126  uint8_t left;
128  uint8_t top;
130  uint8_t right;
132  uint8_t bottom;
133 } SSD1306_RECT;
134 
135 
140 typedef struct SPRITE
141 {
143  uint8_t x;
145  uint8_t y;
147  uint8_t w;
149  uint8_t lx;
151  uint8_t ly;
153  const uint8_t * data;
155  const uint8_t * transparentMask;
156 
157 #ifdef __cplusplus
158 
163  void setPos(uint8_t x, uint8_t y);
164 
169  void draw();
170 
174  void eraseTrace();
175 
179  void erase();
180 
185  inline bool isNearMove() const
186  {
187  /* We emulate abs function for unsigned vars here */
188  return (((uint8_t)(x-lx)<w) || ((uint8_t)(lx-x)<w)) &&
189  (((uint8_t)(y-ly)<8) || ((uint8_t)(ly-y)<8));
190  };
191 
200  inline SSD1306_RECT getRect() const
201  {
202  uint8_t right = ((x + w - 1)>>3);
203  uint8_t bottom = ((y + 7)>>3);
204  uint8_t left = x>>3; left = left < right ? left: 0;
205  uint8_t top = y>>3; top = top < bottom ? top: 0;
206  return (SSD1306_RECT){ left, top, right, bottom };
207  };
208 
216  inline SSD1306_RECT getLRect() const
217  {
218  uint8_t left = lx;
219  uint8_t top = ly;
220  uint8_t right = (uint8_t)(lx + w - 1);
221  uint8_t bottom = (uint8_t)(ly + 7);
222  left = left < right ? left: 0;
223  top = top < bottom ? top: 0;
224  return (SSD1306_RECT){ left, top, right, bottom };
225  };
226 
234  {
235  uint8_t left = min(x,lx);
236  uint8_t top = min(y,ly);
237  uint8_t right = max((uint8_t)(x + w - 1), (uint8_t)(lx + w - 1));
238  if (((uint8_t)(lx + w - 1) < w) && (right > 2*w))
239  {
240  right = (uint8_t)(lx + w - 1);
241  }
242  uint8_t bottom = max((uint8_t)(y + 7), (uint8_t)(ly + 7));
243  if (((uint8_t)(ly + 7) < 8) && (bottom > 16))
244  {
245  bottom = (uint8_t)(ly + 7);
246  }
247  if ( left > right ) left = 0;
248  if ( top > bottom ) top = 0;
249  return (SSD1306_RECT){ left, top, right, bottom };
250  };
251 #endif
252 } SPRITE;
253 
254 // ----------------------------------------------------------------------------
255 #endif // _NANO_GFX_TYPES_H_
struct SPRITE SPRITE
uint8_t height
char height in pixels
uint8_t top
top
const uint8_t * data
Pointer to PROGMEM data, representing sprite image.
const uint8_t * primary_table
font chars bits
uint16_t start_code
unicode start code
uint8_t width
width in pixels
const uint8_t * transparentMask
Pointer to PROGMEM data, representing sprite transparencyMask (can be nullptr)
void eraseTrace()
uint8_t type
font type: 0 - Fixed Font
uint8_t height
height in pixels
void erase()
uint8_t ascii_offset
ascii offset
void(* InitFunction)(void)
void draw()
void setPos(uint8_t x, uint8_t y)
uint8_t bottom
bottom
#define max(a, b)
uint8_t y
draw position Y on the screen
#define min(a, b)
uint8_t count
count of unicode chars in block
uint8_t width
char width in pixels
const uint8_t * secondary_table
font chars bits
SSD1306_RECT getUpdateRect() const
SFontHeaderRecord h
record, containing information on font
uint8_t x
draw position X on the screen
const uint8_t * glyph
char data, located in progmem.
uint8_t w
sprite width
SSD1306_RECT getRect() const
uint8_t spacing
additional spaces after char in pixels
uint8_t lx
last draw position X on the screen
EFontStyle
bool isNearMove() const
EFontSize
uint8_t glyph_size
glyph size in bytes
uint8_t pages
height in pages (each page height is 8-pixels)
uint8_t right
right
uint8_t count
count of characters
uint8_t ly
last draw position Y on the screen
SSD1306_RECT getLRect() const
uint8_t left
left