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
canvas_types.h
Go to the documentation of this file.
1 /*
2  MIT License
3 
4  Copyright (c) 2017-2020, 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 #pragma once
29 
30 #include "canvas/UserSettings.h"
31 
32 #if defined(ARDUINO)
33 #include <Arduino.h>
34 #elif defined(__AVR__)
35 #include <avr/pgmspace.h>
36 #else
37 #endif
38 
39 #include <stdint.h>
40 #include <stddef.h>
41 
43 #define SSD1306_MORE_CHARS_REQUIRED 0xffff
44 
45 #ifndef DOXYGEN_SHOULD_SKIP_THIS
46 #ifndef PROGMEM
47 #define PROGMEM
48 #endif
49 #endif
50 
52 #define RGB_COLOR8(r, g, b) ((r & 0xE0) | ((g >> 3) & 0x1C) | (b >> 6))
53 
55 #define GRAY_COLOR4(gray) (((gray >> 4) & 0x0F) | (gray & 0xF0))
56 
58 #define RGB_COLOR4(r, g, b) ((r >> 2) + (g >> 1) + (b >> 2))
59 
61 #define RGB8_TO_GRAY4(rgb) ((rgb >> 6) + ((rgb >> 2) & 0x07) + (rgb & 0x03))
62 
64 #define RGB_COLOR16(r, g, b) (((r << 8) & 0xF800) | ((g << 3) & 0x07E0) | (b >> 3))
65 
67 #define RGB8_TO_RGB16(c) \
68  ((((uint16_t)c & 0b11100000) << 8) | (((uint16_t)c & 0b00011100) << 6) | (((uint16_t)c & 0b00000011) << 3))
69 
71 #define RGB16_TO_RGB8(c) \
72  (((uint16_t)(c >> 8) & 0b11100000) | ((uint16_t)(c >> 6) & 0b00011100) | ((uint16_t)(c >> 3) & 0b00000011))
73 
74 #if defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) || \
75  defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
76 
77 typedef int8_t lcdint_t;
79 typedef uint8_t lcduint_t;
80 #else
81 
82 typedef int lcdint_t;
84 typedef unsigned int lcduint_t;
85 #endif
86 
88 typedef enum
89 {
90  STYLE_NORMAL,
91  STYLE_BOLD,
92  STYLE_ITALIC,
93 } EFontStyle;
94 
95 enum
96 {
97  CANVAS_MODE_BASIC = 0x00,
104 };
105 
107 typedef enum
108 {
109  FONT_SIZE_NORMAL = 0,
110  FONT_SIZE_2X = 1,
111  FONT_SIZE_4X = 2,
112  FONT_SIZE_8X = 3,
113 } EFontSize;
114 
115 #pragma pack(push, 1)
116 
117 typedef struct
118 {
119  uint8_t type;
120  uint8_t width;
121  uint8_t height;
122  uint8_t ascii_offset;
124 #pragma pack(pop)
125 
127 typedef struct
128 {
130  uint8_t count;
131  uint8_t pages;
132  uint8_t glyph_size;
133  uint8_t spacing;
134  const uint8_t *primary_table;
135 #ifdef CONFIG_SSD1306_UNICODE_ENABLE
136  const uint8_t *secondary_table;
137 #endif
139 
141 typedef struct
142 {
143  uint8_t width;
144  uint8_t height;
145  uint8_t spacing;
146  const uint8_t *glyph;
147 } SCharInfo;
148 
152 typedef struct
153 {
155  const char **items;
157  uint8_t count;
159  uint8_t selection;
161  uint8_t oldSelection;
163  uint8_t scrollPosition;
172 } SAppMenu;
lcdint_t left
left offset
Definition: canvas_types.h:167
uint8_t height
char height in pixels
Definition: canvas_types.h:144
uint8_t lcduint_t
Definition: canvas_types.h:79
const uint8_t * primary_table
font chars bits
Definition: canvas_types.h:134
uint8_t width
width in pixels
Definition: canvas_types.h:120
int8_t lcdint_t
Definition: canvas_types.h:77
lcduint_t width
width of menu
Definition: canvas_types.h:169
uint8_t type
font type: 0 - Fixed Font
Definition: canvas_types.h:119
uint8_t height
height in pixels
Definition: canvas_types.h:121
lcduint_t height
height of menu
Definition: canvas_types.h:171
uint8_t ascii_offset
ascii offset
Definition: canvas_types.h:122
uint8_t selection
currently selected item. Internally updated.
Definition: canvas_types.h:159
uint8_t scrollPosition
position of menu scrolling. Internally updated
Definition: canvas_types.h:163
uint8_t count
count of menu items in the menu
Definition: canvas_types.h:157
uint8_t width
char width in pixels
Definition: canvas_types.h:143
const uint8_t * secondary_table
font chars bits
Definition: canvas_types.h:136
lcdint_t top
top offset
Definition: canvas_types.h:165
SFontHeaderRecord h
record, containing information on font
Definition: canvas_types.h:129
const uint8_t * glyph
char data, located in progmem.
Definition: canvas_types.h:146
uint8_t spacing
additional spaces after char in pixels
Definition: canvas_types.h:145
EFontStyle
Definition: canvas_types.h:88
EFontSize
Definition: canvas_types.h:107
uint8_t spacing
spacing between two characters
Definition: canvas_types.h:133
uint8_t glyph_size
glyph size in bytes
Definition: canvas_types.h:132
uint8_t pages
height in pages (each page height is 8-pixels)
Definition: canvas_types.h:131
uint8_t count
count of characters
Definition: canvas_types.h:130
uint8_t oldSelection
selected item, when last redraw operation was performed. Internally updated.
Definition: canvas_types.h:161
const char ** items
list of menu items of the menu
Definition: canvas_types.h:155