-
-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathssd1306_generic.h
298 lines (257 loc) · 9.33 KB
/
ssd1306_generic.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
/*
MIT License
Copyright (c) 2016-2019, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/**
* @file ssd1306_generic.h SSD1306 generic API functions
*/
#ifndef _SSD1306_GENERIC_H_
#define _SSD1306_GENERIC_H_
#include "nano_gfx_types.h"
#ifdef __cplusplus
extern "C" {
#endif
///////////////////////////////////////////////////////////////////////
// GENERIC GRAPH FUNCTIONS
///////////////////////////////////////////////////////////////////////
/** Flag means that more chars are required to decode utf-8 */
#define SSD1306_MORE_CHARS_REQUIRED 0xffff
/**
* @defgroup LCD_GENERIC_API DIRECT DRAW: Generic API functions, common for all displays and all display modes.
* @{
* @brief Generic API functions, common for all displays and all display modes.
*
* @details Generic API functions, common for all displays and all display modes.
*/
/**
* Set position in terms of display.
* @param x - horizontal position in pixels
* @param y - vertical position in blocks (pixels/8)
*/
void ssd1306_setPos(uint8_t x, uint8_t y);
/**
* @brief Sets cursor position for text mode print functions.
*
* Sets cursor position for text mode print functions.
* @param x xpos in pixels
* @param y ypos in pixels
*/
void ssd1306_setCursor(lcdint_t x, lcdint_t y);
/**
* Function allows to set another fixed font for the library.
* By default, the font supports only first 128 - 32 ascii chars.
* Please refer to github wiki on how to generate new fonts.
* @param progmemFont - font to setup located in Flash area
*/
void ssd1306_setFixedFont(const uint8_t * progmemFont);
#ifndef DOXYGEN_SHOULD_SKIP_THIS
void ssd1306_setFixedFont_oldStyle(const uint8_t * progmemFont);
#endif
/**
* Function allows to set another free font for the library.
* By default, the font supports only first 128 - 32 ascii chars.
* Please refer to github wiki on how to generate new fonts.
* @param progmemFont - font to setup located in Flash area
* @note This function supports new fonts of ssd1306 library 1.7.8 and above
*/
void ssd1306_setFreeFont(const uint8_t * progmemFont);
/**
* Function allows sets secondary font for specific language.
* Use it if you want to use additional font to combine capabilities of
* ascii fonts and language specific font.
* @param progmemUnicode font containing unicode table (refer to
* ssd1306xled_font6x8_German as example).
*/
void ssd1306_setSecondaryFont(const uint8_t * progmemUnicode);
/**
* Function allows to set another font for the library.
* By default, the font supports only first 128 - 32 ascii chars.
* First 32 chars of ascii table are non-printable, and removed
* from the font table to reduce flash memory consumption.
* Default font doesn't support russian characters. Using
* this function you can implement your own fonts.
* First font char must be started with \<space\> image.
* @param progmemFont - font to setup located in Flash area
* @deprecated Use ssd1306_setFixedFont() instead.
*/
void ssd1306_setFont6x8(const uint8_t * progmemFont) __attribute__ ((deprecated));
/**
* @brief returns char data for currently set (active) font.
*
* Function returns char data for currently set font: pointer to progmem
* data for specified char, and width, height of the char. You can use these
* data to draw char manually using ssd1306_drawBitmap(), ssd1306_drawMonoBitmap8()
* or NanoCanvasOps::drawBitmap1().
*
* @param ch char to read from set font
* @param info pointer to SCharInfo structure to fill with char data
*
* @see ssd1306_setFixedFont
*/
void ssd1306_getCharBitmap(uint16_t ch, SCharInfo *info);
/**
* Enables utf8 support for all text-functions.
* @note Unicode-16 only supported in text decoding functions.
*/
void ssd1306_enableUtf8Mode(void);
/**
* Enables ascii mode for all text-functions. No any decoding will be performed
*/
void ssd1306_enableAsciiMode(void);
#ifndef DOXYGEN_SHOULD_SKIP_THIS
/**
* Function allows to set and use squix font.
* @param progmemFont - font to setup located in Flash area
* @note This function supports squix fonts for ssd1306 library 1.7.8 and above
* @warning Squix fonts are not fully supported, use them at your own risk
*/
void ssd1306_setSquixFont(const uint8_t * progmemFont);
/**
* Returns 16-bit unicode char, encoded in utf8
* SSD1306_MORE_CHARS_REQUIRED if more characters is expected
* @param ch character byte to decode
* @return 16-bit unicode char, encoded in utf8
* SSD1306_MORE_CHARS_REQUIRED if more characters is expected
*/
uint16_t ssd1306_unicode16FromUtf8(uint8_t ch);
#endif
///////////////////////////////////////////////////////////////////////
// HIGH-LEVEL GRAPH FUNCTIONS
///////////////////////////////////////////////////////////////////////
/**
* Describes menu object
*/
typedef struct
{
/// list of menu items of the menu
const char **items;
/// count of menu items in the menu
uint8_t count;
/// currently selected item. Internally updated.
uint8_t selection;
/// selected item, when last redraw operation was performed. Internally updated.
uint8_t oldSelection;
/// position of menu scrolling. Internally updated
uint8_t scrollPosition;
} SAppMenu;
/**
* Creates menu object with the provided list of menu items.
* List of menu items (strings) must exist all until menu object is no longer needed.
* Selection is set to the first item by default.
*
* @param menu - Pointer to SAppMenu structure
* @param items - array of null-termintated strings (located in SRAM)
* @param count - count of menu items in the array
*/
void ssd1306_createMenu(SAppMenu *menu, const char **items, uint8_t count);
/**
* Shows menu items on the display. If menu items cannot fit the display,
* the function provides scrolling.
*
* @param menu - Pointer to SAppMenu structure
*
* @warning works only in SSD1306 compatible mode.
*/
void ssd1306_showMenu(SAppMenu *menu);
/**
* Shows menu items on the display. If menu items cannot fit the display,
* the function provides scrolling.
*
* @param menu - Pointer to SAppMenu structure
*
* @warning works only in 8-bit RGB normal mode.
*/
void ssd1306_showMenu8(SAppMenu *menu);
/**
* Shows menu items on the display. If menu items cannot fit the display,
* the function provides scrolling.
*
* @param menu - Pointer to SAppMenu structure
*
* @warning works only in 16-bit RGB normal mode.
*/
void ssd1306_showMenu16(SAppMenu *menu);
#ifndef DOXYGEN_SHOULD_SKIP_THIS
static inline void ssd1331_showMenu8(SAppMenu *menu)
{
ssd1306_showMenu8(menu);
}
#endif
/**
* Updates menu items on the display. That is if selection is changed,
* the function will update only those areas, affected by the change.
*
* @param menu - Pointer to SAppMenu structure
*/
void ssd1306_updateMenu(SAppMenu *menu);
/**
* Updates menu items on the display. That is if selection is changed,
* the function will update only those areas, affected by the change.
*
* @param menu - Pointer to SAppMenu structure
*
* @warning works only in SSD1306 compatible mode.
*/
void ssd1306_updateMenu8(SAppMenu *menu);
/**
* Updates menu items on the display. That is if selection is changed,
* the function will update only those areas, affected by the change.
*
* @param menu - Pointer to SAppMenu structure
*
* @warning works only in SSD1306 compatible mode.
*/
void ssd1306_updateMenu16(SAppMenu *menu);
#ifndef DOXYGEN_SHOULD_SKIP_THIS
static inline void ssd1331_updateMenu8(SAppMenu *menu)
{
ssd1306_updateMenu8(menu);
}
#endif
/**
* Returns currently selected menu item.
* First item has zero-index.
*
* @param menu - Pointer to SAppMenu structure
*
* @warning works only in 8-bit RGB normal mode.
*/
uint8_t ssd1306_menuSelection(SAppMenu *menu);
/**
* Moves selection pointer down by 1 item. If there are no items below,
* it will set selection pointer to the first item.
* Use ssd1306_updateMenu() to refresh menu state on the display.
*
* @param menu - Pointer to SAppMenu structure
*/
void ssd1306_menuDown(SAppMenu *menu);
/**
* Moves selection pointer up by 1 item. If selected item is the first one,
* then selection pointer will set to the last item in menu list.
* Use ssd1306_updateMenu() to refresh menu state on the display.
*
* @param menu - Pointer to SAppMenu structure
*/
void ssd1306_menuUp(SAppMenu *menu);
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif // _SSD1306_GENERIC_H_