SSD1306 OLED display driver  1.7.6
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-2018, 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 typedef void (*InitFunction)(void);
56 
58 typedef enum
59 {
60  STYLE_NORMAL,
61  STYLE_BOLD,
62  STYLE_ITALIC,
63 } EFontStyle;
64 
66 typedef enum
67 {
68  FONT_SIZE_NORMAL = 0,
69  FONT_SIZE_2X = 1,
70  FONT_SIZE_4X = 2,
71  FONT_SIZE_8X = 3,
72 } EFontSize;
73 
74 #pragma pack(push, 1)
75 
76 typedef struct
77 {
78  uint8_t type;
79  uint8_t width;
80  uint8_t height;
81  uint8_t ascii_offset;
83 
85 typedef struct
86 {
87  uint16_t start_code;
88  uint8_t count;
90 
91 #pragma pack(pop)
92 
94 typedef struct
95 {
97  uint8_t pages;
98  uint8_t glyph_size;
99  const uint8_t *primary_table;
100 #ifdef CONFIG_SSD1306_UNICODE_ENABLE
101  const uint8_t *secondary_table;
102 #endif
104 
106 typedef struct
107 {
108  uint8_t width;
109  uint8_t height;
110  const uint8_t *data;
111 } SCharInfo;
112 
116 typedef struct
117 {
119  uint8_t left;
121  uint8_t top;
123  uint8_t right;
125  uint8_t bottom;
126 } SSD1306_RECT;
127 
128 
133 typedef struct SPRITE
134 {
136  uint8_t x;
138  uint8_t y;
140  uint8_t w;
142  uint8_t lx;
144  uint8_t ly;
146  const uint8_t * data;
148  const uint8_t * transparentMask;
149 
150 #ifdef __cplusplus
151 
156  void setPos(uint8_t x, uint8_t y);
157 
162  void draw();
163 
167  void eraseTrace();
168 
172  void erase();
173 
178  inline bool isNearMove() const
179  {
180  /* We emulate abs function for unsigned vars here */
181  return (((uint8_t)(x-lx)<w) || ((uint8_t)(lx-x)<w)) &&
182  (((uint8_t)(y-ly)<8) || ((uint8_t)(ly-y)<8));
183  };
184 
193  inline SSD1306_RECT getRect() const
194  {
195  uint8_t right = ((x + w - 1)>>3);
196  uint8_t bottom = ((y + 7)>>3);
197  uint8_t left = x>>3; left = left < right ? left: 0;
198  uint8_t top = y>>3; top = top < bottom ? top: 0;
199  return (SSD1306_RECT){ left, top, right, bottom };
200  };
201 
209  inline SSD1306_RECT getLRect() const
210  {
211  uint8_t left = lx;
212  uint8_t top = ly;
213  uint8_t right = (uint8_t)(lx + w - 1);
214  uint8_t bottom = (uint8_t)(ly + 7);
215  left = left < right ? left: 0;
216  top = top < bottom ? top: 0;
217  return (SSD1306_RECT){ left, top, right, bottom };
218  };
219 
227  {
228  uint8_t left = min(x,lx);
229  uint8_t top = min(y,ly);
230  uint8_t right = max((uint8_t)(x + w - 1), (uint8_t)(lx + w - 1));
231  if (((uint8_t)(lx + w - 1) < w) && (right > 2*w))
232  {
233  right = (uint8_t)(lx + w - 1);
234  }
235  uint8_t bottom = max((uint8_t)(y + 7), (uint8_t)(ly + 7));
236  if (((uint8_t)(ly + 7) < 8) && (bottom > 16))
237  {
238  bottom = (uint8_t)(ly + 7);
239  }
240  if ( left > right ) left = 0;
241  if ( top > bottom ) top = 0;
242  return (SSD1306_RECT){ left, top, right, bottom };
243  };
244 #endif
245 } SPRITE;
246 
247 // ----------------------------------------------------------------------------
248 #endif // _NANO_GFX_TYPES_H_
const uint8_t * data
char data, located in progmem.
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
SSD1306_RECT getRect() const
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
SSD1306_RECT getUpdateRect() const
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 getLRect() const
bool isNearMove() const
SFontHeaderRecord h
record, containing information on font
uint8_t x
draw position X on the screen
uint8_t w
sprite width
uint8_t lx
last draw position X on the screen
EFontStyle
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 ly
last draw position Y on the screen
uint8_t left
left