SSD1306 OLED display driver 1.8.2 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 RGB8_TO_GRAY4(rgb) ( (rgb >> 6) + ((rgb >> 2) & 0x07) + (rgb & 0x03) )
56
58 #define GRAY_COLOR4(gray) ( ((gray >> 4) & 0x0F) | (gray & 0xF0) )
59
61 #define RGB16_TO_RGB8(c) ( ((uint16_t)(c >> 8) & 0b11100000) | \
62 ((uint16_t)(c >> 6) & 0b00011100) | \
63 ((uint16_t)(c >> 3) & 0b00000011) )
64
66 typedef void (*InitFunction)(void);
67
69 typedef enum
70 {
71 STYLE_NORMAL,
72 STYLE_BOLD,
73 STYLE_ITALIC,
74 } EFontStyle;
75
77 typedef enum
78 {
79 FONT_SIZE_NORMAL = 0,
80 FONT_SIZE_2X = 1,
81 FONT_SIZE_4X = 2,
82 FONT_SIZE_8X = 3,
83 } EFontSize;
84
85 #pragma pack(push, 1)
86
87 typedef struct
88 {
89 uint8_t type;
90 uint8_t width;
91 uint8_t height;
92 uint8_t ascii_offset;
93 } SFontHeaderRecord;
94
96 typedef struct
97 {
98 uint16_t start_code;
99 uint8_t count;
100 } SUnicodeBlockRecord;
101
102 #pragma pack(pop)
103
105 typedef struct
106 {
107 SFontHeaderRecord h;
108 uint8_t count;
109 uint8_t pages;
110 uint8_t glyph_size;
111 const uint8_t *primary_table;
112 #ifdef CONFIG_SSD1306_UNICODE_ENABLE
113 const uint8_t *secondary_table;
114 #endif
115 } SFixedFontInfo;
116
118 typedef struct
119 {
120 uint8_t width;
121 uint8_t height;
122 uint8_t spacing;
123 const uint8_t *glyph;
124 } SCharInfo;
125
129 typedef struct
130 {
132 uint8_t left;
134 uint8_t top;
136 uint8_t right;
138 uint8_t bottom;
139 } SSD1306_RECT;
140
141
146 typedef struct SPRITE
147 {
149 uint8_t x;
151 uint8_t y;
153 uint8_t w;
155 uint8_t lx;
157 uint8_t ly;
159 const uint8_t * data;
161 const uint8_t * transparentMask;
162
163 #ifdef __cplusplus
164
169 void setPos(uint8_t x, uint8_t y);
170
175 void draw();
176
180 void eraseTrace();
181
185 void erase();
186
191 inline bool isNearMove() const
192 {
193 /* We emulate abs function for unsigned vars here */
194 return (((uint8_t)(x-lx)<w) || ((uint8_t)(lx-x)<w)) &&
195 (((uint8_t)(y-ly)<8) || ((uint8_t)(ly-y)<8));
196 };
197
206 inline SSD1306_RECT getRect() const
207 {
208 uint8_t right = ((x + w - 1)>>3);
209 uint8_t bottom = ((y + 7)>>3);
210 uint8_t left = x>>3; left = left < right ? left: 0;
211 uint8_t top = y>>3; top = top < bottom ? top: 0;
212 return (SSD1306_RECT){ left, top, right, bottom };
213 };
214
222 inline SSD1306_RECT getLRect() const
223 {
224 uint8_t left = lx;
225 uint8_t top = ly;
226 uint8_t right = (uint8_t)(lx + w - 1);
227 uint8_t bottom = (uint8_t)(ly + 7);
228 left = left < right ? left: 0;
229 top = top < bottom ? top: 0;
230 return (SSD1306_RECT){ left, top, right, bottom };
231 };
232
239 inline SSD1306_RECT getUpdateRect() const
240 {
241 uint8_t left = min(x,lx);
242 uint8_t top = min(y,ly);
243 uint8_t right = max((uint8_t)(x + w - 1), (uint8_t)(lx + w - 1));
244 if (((uint8_t)(lx + w - 1) < w) && (right > 2*w))
245 {
246 right = (uint8_t)(lx + w - 1);
247 }
248 uint8_t bottom = max((uint8_t)(y + 7), (uint8_t)(ly + 7));
249 if (((uint8_t)(ly + 7) < 8) && (bottom > 16))
250 {
251 bottom = (uint8_t)(ly + 7);
252 }
253 if ( left > right ) left = 0;
254 if ( top > bottom ) top = 0;
255 return (SSD1306_RECT){ left, top, right, bottom };
256 };
257 #endif
258 } SPRITE;
259
260 // ----------------------------------------------------------------------------
261 #endif // _NANO_GFX_TYPES_H_
SPRITE
struct SPRITE SPRITE
SCharInfo::height
uint8_t height
char height in pixels
Definition: nano_gfx_types.h:121
SSD1306_RECT::top
uint8_t top
top
Definition: nano_gfx_types.h:134
SPRITE::data
const uint8_t * data
Pointer to PROGMEM data, representing sprite image.
Definition: nano_gfx_types.h:159
SFixedFontInfo::primary_table
const uint8_t * primary_table
font chars bits
Definition: nano_gfx_types.h:111
SCharInfo
Definition: nano_gfx_types.h:118
SUnicodeBlockRecord::start_code
uint16_t start_code
unicode start code
Definition: nano_gfx_types.h:98
SFontHeaderRecord::width
uint8_t width
width in pixels
Definition: nano_gfx_types.h:90
SPRITE::transparentMask
const uint8_t * transparentMask
Pointer to PROGMEM data, representing sprite transparencyMask (can be nullptr)
Definition: nano_gfx_types.h:161
SPRITE::eraseTrace
void eraseTrace()
io.h
SFontHeaderRecord::type
uint8_t type
font type: 0 - Fixed Font
Definition: nano_gfx_types.h:89
SFontHeaderRecord::height
uint8_t height
height in pixels
Definition: nano_gfx_types.h:91
SPRITE::erase
void erase()
SFixedFontInfo
Definition: nano_gfx_types.h:105
SPRITE
Definition: nano_gfx_types.h:146
SUnicodeBlockRecord
Definition: nano_gfx_types.h:96
SFontHeaderRecord::ascii_offset
uint8_t ascii_offset
ascii offset
Definition: nano_gfx_types.h:92
InitFunction
void(* InitFunction)(void)
Definition: nano_gfx_types.h:66
SPRITE::draw
void draw()
SPRITE::setPos
void setPos(uint8_t x, uint8_t y)
SSD1306_RECT::bottom
uint8_t bottom
bottom
Definition: nano_gfx_types.h:138
max
#define max(a, b)
Definition: nano_gfx_types.h:40
SPRITE::y
uint8_t y
draw position Y on the screen
Definition: nano_gfx_types.h:151
min
#define min(a, b)
Definition: nano_gfx_types.h:35
SUnicodeBlockRecord::count
uint8_t count
count of unicode chars in block
Definition: nano_gfx_types.h:99
SCharInfo::width
uint8_t width
char width in pixels
Definition: nano_gfx_types.h:120
SFixedFontInfo::secondary_table
const uint8_t * secondary_table
font chars bits
Definition: nano_gfx_types.h:113
SPRITE::getUpdateRect
SSD1306_RECT getUpdateRect() const
Definition: nano_gfx_types.h:239
SFixedFontInfo::h
SFontHeaderRecord h
record, containing information on font
Definition: nano_gfx_types.h:107
SPRITE::x
uint8_t x
draw position X on the screen
Definition: nano_gfx_types.h:149
SCharInfo::glyph
const uint8_t * glyph
char data, located in progmem.
Definition: nano_gfx_types.h:123
SFontHeaderRecord
Definition: nano_gfx_types.h:87
SPRITE::w
uint8_t w
sprite width
Definition: nano_gfx_types.h:153
SPRITE::getRect
SSD1306_RECT getRect() const
Definition: nano_gfx_types.h:206
SCharInfo::spacing
uint8_t spacing
additional spaces after char in pixels
Definition: nano_gfx_types.h:122
SPRITE::lx
uint8_t lx
last draw position X on the screen
Definition: nano_gfx_types.h:155
SSD1306_RECT
Definition: nano_gfx_types.h:129
EFontStyle
EFontStyle
Definition: nano_gfx_types.h:69
SPRITE::isNearMove
bool isNearMove() const
Definition: nano_gfx_types.h:191
EFontSize
EFontSize
Definition: nano_gfx_types.h:77
SFixedFontInfo::glyph_size
uint8_t glyph_size
glyph size in bytes
Definition: nano_gfx_types.h:110
SFixedFontInfo::pages
uint8_t pages
height in pages (each page height is 8-pixels)
Definition: nano_gfx_types.h:109
SSD1306_RECT::right
uint8_t right
right
Definition: nano_gfx_types.h:136
SFixedFontInfo::count
uint8_t count
count of characters
Definition: nano_gfx_types.h:108
SPRITE::ly
uint8_t ly
last draw position Y on the screen
Definition: nano_gfx_types.h:157
SPRITE::getLRect
SSD1306_RECT getLRect() const
Definition: nano_gfx_types.h:222
SSD1306_RECT::left
uint8_t left
left
Definition: nano_gfx_types.h:132