40 SSD1306_OLD_FIXED_FORMAT = 0x00,
41 SSD1306_NEW_FIXED_FORMAT = 0x01,
42 SSD1306_NEW_FORMAT = 0x02,
43 SSD1306_SQUIX_FORMAT = 0x03,
46 uint16_t ssd1306_color = 0xFFFF;
47 lcduint_t ssd1306_cursorX = 0;
48 lcduint_t ssd1306_cursorY = 0;
50 #ifdef CONFIG_SSD1306_UNICODE_ENABLE 51 uint8_t g_ssd1306_unicode = 1;
53 static void (*s_ssd1306_getCharBitmap)(uint16_t unicode,
SCharInfo *info) = NULL;
55 static const uint8_t *ssd1306_getCharGlyph(
char ch);
56 static const uint8_t *ssd1306_getU16CharGlyph(uint16_t unicode);
76 r->
start_code =( pgm_read_byte(&p[0]) << 8) | (pgm_read_byte(&p[1]));
77 r->
count = pgm_read_byte(&p[2]);
78 return (r->
count > 0) ? (&p[3]): NULL;
84 #ifdef CONFIG_SSD1306_UNICODE_ENABLE 95 return s_ssd1306_getCharBitmap( unicode, info );
98 uint16_t ssd1306_unicode16FromUtf8(uint8_t ch)
100 #ifdef CONFIG_SSD1306_UNICODE_ENABLE 101 static uint16_t unicode = 0;
112 uint16_t code = ((unicode & 0x1f) << 6) | (ch & 0x3f);
122 #ifdef CONFIG_SSD1306_UNICODE_ENABLE 123 g_ssd1306_unicode = 1;
129 #ifdef CONFIG_SSD1306_UNICODE_ENABLE 130 g_ssd1306_unicode = 0;
142 static const uint8_t *ssd1306_getCharGlyph(
char ch)
149 #ifdef CONFIG_SSD1306_UNICODE_ENABLE 150 static const uint8_t *ssd1306_searchCharGlyph(
const uint8_t * unicode_table, uint16_t unicode)
153 const uint8_t *data = unicode_table;
157 ssd1306_readUnicodeRecord( &r, data );
178 static const uint8_t *ssd1306_getU16CharGlyph(uint16_t unicode)
180 #ifdef CONFIG_SSD1306_UNICODE_ENABLE 181 const uint8_t * glyph = NULL;
182 if (g_ssd1306_unicode)
184 if ((unicode < 128) && (s_fixedFont.
h.
type == 0x00) && (s_fixedFont.
primary_table != NULL))
186 return ssd1306_getCharGlyph(unicode);
190 glyph = ssd1306_searchCharGlyph( s_fixedFont.
primary_table, unicode );
194 glyph = ssd1306_searchCharGlyph( s_fixedFont.
secondary_table, unicode );
205 return ssd1306_getCharGlyph(unicode);
209 static void __ssd1306_oldFormatGetBitmap(uint16_t unicode,
SCharInfo *info)
216 info->
glyph = ssd1306_getU16CharGlyph( unicode );
222 s_fixedFont.
h.
type = pgm_read_byte( &progmemFont[0] );
223 s_fixedFont.
h.
width = pgm_read_byte(&progmemFont[1]);
224 s_fixedFont.
h.
height = pgm_read_byte(&progmemFont[2]);
227 s_ssd1306_getCharBitmap = __ssd1306_oldFormatGetBitmap;
230 #ifdef CONFIG_SSD1306_UNICODE_ENABLE 235 void ssd1306_setFixedFont_oldStyle(
const uint8_t * progmemFont)
237 s_fixedFont.
h.
type = pgm_read_byte( &progmemFont[0] );
238 s_fixedFont.
h.
width = pgm_read_byte(&progmemFont[1]);
239 s_fixedFont.
h.
height = pgm_read_byte(&progmemFont[2]);
250 static void __ssd1306_newFormatGetBitmap(uint16_t unicode,
SCharInfo *info)
254 #ifdef CONFIG_SSD1306_UNICODE_ENABLE 255 uint8_t table_index = 0;
261 data = ssd1306_readUnicodeRecord( &r, data );
264 #ifdef CONFIG_SSD1306_UNICODE_ENABLE 265 if ( table_index == 0 )
280 data += ((pgm_read_byte(&data[0]) << 8) | (pgm_read_byte(&data[1]))) + 2;
286 uint16_t offset = (pgm_read_byte(&data[0]) << 8) | (pgm_read_byte(&data[1]));
287 uint8_t glyph_width = pgm_read_byte(&data[2]);
288 uint8_t glyph_height = pgm_read_byte(&data[3]);
289 info->
width = glyph_width;
290 info->
height = glyph_height;
291 info->
spacing = glyph_width ? 1 : (s_fixedFont.
h.
width >> 1);
292 info->
glyph = data + (r.
count - unicode) * 4 + 2 + offset;
307 s_fixedFont.
h.
type = pgm_read_byte( &progmemFont[0] );
308 s_fixedFont.
h.
width = pgm_read_byte(&progmemFont[1]);
309 s_fixedFont.
h.
height = pgm_read_byte(&progmemFont[2]);
312 s_ssd1306_getCharBitmap = __ssd1306_newFormatGetBitmap;
314 #ifdef CONFIG_SSD1306_UNICODE_ENABLE 323 static void __ssd1306_squixFormatGetBitmap(uint16_t unicode,
SCharInfo *info)
338 const uint8_t * bitmap_data = data + (uint16_t)s_fixedFont.
count * 4;
340 data += (unicode * 4);
341 uint16_t offset = (pgm_read_byte(&data[0]) << 8) | pgm_read_byte(&data[1]);
342 uint8_t glyph_bytes = pgm_read_byte(&data[2]);
344 info->
width = glyph_bytes;
348 info->
glyph = bitmap_data;
349 if ( offset != 0xFFFF )
351 info->
glyph += offset;
356 void ssd1306_setSquixFont(
const uint8_t * progmemFont)
358 s_fixedFont.
h.
type = SSD1306_SQUIX_FORMAT;
359 s_fixedFont.
h.
width = pgm_read_byte(&progmemFont[0]);
360 s_fixedFont.
h.
height = pgm_read_byte(&progmemFont[1]);
362 s_fixedFont.
count = pgm_read_byte(&progmemFont[3]);
364 s_ssd1306_getCharBitmap = __ssd1306_squixFormatGetBitmap;
367 #ifdef CONFIG_SSD1306_UNICODE_ENABLE 377 if (*text ==
'\r' || *text ==
'\n')
382 uint16_t unicode = ssd1306_unicode16FromUtf8(*text);
391 if ( height ) *height = char_info.
height;
void ssd1306_setSecondaryFont(const uint8_t *progmemUnicode)
lcduint_t ssd1306_displayWidth()
uint8_t height
char height in pixels
const uint8_t * primary_table
font chars bits
uint16_t start_code
unicode start code
void ssd1306_setFixedFont(const uint8_t *progmemFont)
void ssd1306_setFreeFont(const uint8_t *progmemFont)
ssd1306_lcd_t ssd1306_lcd
void ssd1306_enableAsciiMode(void)
uint8_t count
count of unicode chars in block
uint8_t width
char width in pixels
const uint8_t * secondary_table
font chars bits
void ssd1306_setCursor(lcdint_t x, lcdint_t y)
Sets cursor position for text mode print functions.
SFixedFontInfo s_fixedFont
SFontHeaderRecord h
record, containing information on font
lcduint_t ssd1306_getTextSize(const char *text, lcduint_t *height)
const uint8_t * glyph
char data, located in progmem.
lcduint_t ssd1306_displayHeight()
uint8_t spacing
additional spaces after char in pixels
void ssd1306_getCharBitmap(uint16_t unicode, SCharInfo *info)
returns char data for currently set (active) font.
#define SSD1306_MORE_CHARS_REQUIRED
uint8_t glyph_size
glyph size in bytes
uint8_t pages
height in pages (each page height is 8-pixels)
uint8_t count
count of characters
void ssd1306_enableUtf8Mode(void)