SSD1306 OLED display driver  1.4.4
This library is developed to control SSD1306/SSD1331 RGB i2c/spi OLED displays and spi PCD8544 LED display
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 <stdint.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 typedef void (*InitFunction)();
45 
47 typedef enum
48 {
49  STYLE_NORMAL,
50  STYLE_BOLD,
51  STYLE_ITALIC,
52 } EFontStyle;
53 
55 typedef struct
56 {
57  uint8_t width;
58  uint8_t pages;
59  uint8_t ascii_offset;
60  const uint8_t *data;
62 
66 typedef struct
67 {
69  uint8_t left;
71  uint8_t top;
73  uint8_t right;
75  uint8_t bottom;
76 } SSD1306_RECT;
77 
78 
82 typedef struct SPRITE
83 {
85  uint8_t x;
87  uint8_t y;
89  uint8_t w;
91  uint8_t lx;
93  uint8_t ly;
95  const uint8_t * data;
97  const uint8_t * transparentMask;
98 
99 #ifdef __cplusplus
100 
105  void setPos(uint8_t x, uint8_t y);
106 
111  void draw();
112 
116  void eraseTrace();
117 
121  void erase();
122 
127  inline bool isNearMove() const
128  {
129  /* We emulate abs function for unsigned vars here */
130  return (((uint8_t)(x-lx)<w) || ((uint8_t)(lx-x)<w)) &&
131  (((uint8_t)(y-ly)<8) || ((uint8_t)(ly-y)<8));
132  };
133 
142  inline SSD1306_RECT getRect() const
143  {
144  uint8_t right = ((x + w - 1)>>3);
145  uint8_t bottom = ((y + 7)>>3);
146  uint8_t left = x>>3; left = left < right ? left: 0;
147  uint8_t top = y>>3; top = top < bottom ? top: 0;
148  return (SSD1306_RECT){ left, top, right, bottom };
149  };
150 
158  inline SSD1306_RECT getLRect() const
159  {
160  uint8_t left = lx;
161  uint8_t top = ly;
162  uint8_t right = (uint8_t)(lx + w - 1);
163  uint8_t bottom = (uint8_t)(ly + 7);
164  left = left < right ? left: 0;
165  top = top < bottom ? top: 0;
166  return (SSD1306_RECT){ left, top, right, bottom };
167  };
168 
176  {
177  uint8_t left = min(x,lx);
178  uint8_t top = min(y,ly);
179  uint8_t right = max((uint8_t)(x + w - 1), (uint8_t)(lx + w - 1));
180  if (((uint8_t)(lx + w - 1) < w) && (right > 2*w))
181  {
182  right = (uint8_t)(lx + w - 1);
183  }
184  uint8_t bottom = max((uint8_t)(y + 7), (uint8_t)(ly + 7));
185  if (((uint8_t)(ly + 7) < 8) && (bottom > 16))
186  {
187  bottom = (uint8_t)(ly + 7);
188  }
189  if ( left > right ) left = 0;
190  if ( top > bottom ) top = 0;
191  return (SSD1306_RECT){ left, top, right, bottom };
192  };
193 #endif
194 } SPRITE;
195 
196 // ----------------------------------------------------------------------------
197 #endif // _NANO_GFX_TYPES_H_
struct SPRITE SPRITE
uint8_t top
top
const uint8_t * data
Pointer to PROGMEM data, representing sprite image.
const uint8_t * transparentMask
Pointer to PROGMEM data, representing sprite transparencyMask (can be nullptr)
void eraseTrace()
void erase()
uint8_t ascii_offset
ascii offset
void draw()
void setPos(uint8_t x, uint8_t y)
uint8_t bottom
bottom
void(* InitFunction)()
#define max(a, b)
uint8_t y
draw position Y on the screen
#define min(a, b)
uint8_t width
width in pixels
SSD1306_RECT getUpdateRect() const
uint8_t x
draw position X on the screen
uint8_t w
sprite width
SSD1306_RECT getRect() const
uint8_t lx
last draw position X on the screen
const uint8_t * data
font chars bits
EFontStyle
bool isNearMove() const
uint8_t pages
height in pages
uint8_t right
right
uint8_t ly
last draw position Y on the screen
SSD1306_RECT getLRect() const
uint8_t left
left