40 uint8_t s_ssd1306_invertByte = 0x00000000;
41 extern uint16_t ssd1306_color;
43 extern lcduint_t ssd1306_cursorX;
44 extern lcduint_t ssd1306_cursorY;
46 #ifdef CONFIG_SSD1306_UNICODE_ENABLE 47 extern uint8_t g_ssd1306_unicode;
52 fill_Data ^= s_ssd1306_invertByte;
82 uint8_t text_index = 0;
83 uint8_t page_offset = 0;
99 if (page_offset == s_fixedFont.
pages)
118 unicode = ssd1306_unicode16FromUtf8(ch[j]);
125 if (char_info.
height > page_offset * 8)
127 char_info.
glyph += page_offset * char_info.
width;
128 for( i = char_info.
width; i>0; i--)
131 if ( style == STYLE_NORMAL )
133 data = pgm_read_byte(&char_info.
glyph[0]);
135 else if ( style == STYLE_BOLD )
137 uint8_t temp = pgm_read_byte(&char_info.
glyph[0]);
143 uint8_t temp = pgm_read_byte(&char_info.
glyph[1]);
144 data = (temp & 0xF0) | ldata;
145 ldata = (temp & 0x0F);
155 for (i = 0; i < char_info.
spacing; i++)
162 uint8_t ssd1306_printFixed_oldStyle(uint8_t xpos, uint8_t y,
const char *ch,
EFontStyle style)
165 uint8_t text_index = 0;
166 uint8_t page_offset = 0;
184 if (page_offset == s_fixedFont.
pages)
206 offset = (c * s_fixedFont.
pages + page_offset) * s_fixedFont.
h.
width;
207 for( i=s_fixedFont.
h.
width; i>0; i--)
210 if ( style == STYLE_NORMAL )
214 else if ( style == STYLE_BOLD )
216 uint8_t temp = pgm_read_byte(&s_fixedFont.
primary_table[offset]);
222 uint8_t temp = pgm_read_byte(&s_fixedFont.
primary_table[offset + 1]);
223 data = (temp & 0xF0) | ldata;
224 ldata = (temp & 0x0F);
239 uint8_t text_index = 0;
240 uint8_t page_offset = 0;
258 if (page_offset == (s_fixedFont.
pages << 1))
280 offset = (c * s_fixedFont.
pages + (page_offset >> 1)) * s_fixedFont.
h.
width;
281 for( i=s_fixedFont.
h.
width; i>0; i--)
284 if ( style == STYLE_NORMAL )
288 else if ( style == STYLE_BOLD )
290 uint8_t temp = pgm_read_byte(&s_fixedFont.
primary_table[offset]);
296 uint8_t temp = pgm_read_byte(&s_fixedFont.
primary_table[offset + 1]);
297 data = (temp & 0xF0) | ldata;
298 ldata = (temp & 0x0F);
300 if (page_offset & 1) data >>= 4;
301 data = ((data & 0x01) ? 0x03: 0x00) |
302 ((data & 0x02) ? 0x0C: 0x00) |
303 ((data & 0x04) ? 0x30: 0x00) |
304 ((data & 0x08) ? 0xC0: 0x00);
309 x += (s_fixedFont.
h.
width << 1);
320 uint8_t text_index = 0;
321 uint8_t page_offset = 0;
337 if (page_offset == (s_fixedFont.
pages << factor))
356 unicode = ssd1306_unicode16FromUtf8(ch[j]);
363 if (char_info.
height > (page_offset >> factor) * 8)
365 char_info.
glyph += (page_offset >> factor) * char_info.
width;
366 for( i=char_info.
width; i>0; i--)
369 if ( style == STYLE_NORMAL )
371 data = pgm_read_byte(char_info.
glyph);
373 else if ( style == STYLE_BOLD )
375 uint8_t temp = pgm_read_byte(char_info.
glyph);
381 uint8_t temp = pgm_read_byte(char_info.
glyph+1);
382 data = (temp & 0xF0) | ldata;
383 ldata = (temp & 0x0F);
388 uint8_t mask = ~((0xFF) << (1<<factor));
393 data >>= ((page_offset & ((1<<factor) - 1))<<(3-factor));
394 for (uint8_t idx = 0; idx < 1<<(3-factor); idx++)
396 accum |= (((data>>idx) & 0x01) ? (mask<<(idx<<factor)) : 0);
400 for (uint8_t z=(1<<factor); z>0; z--)
411 for (i = 0; i < (char_info.
spacing << factor); i++)
426 uint8_t gotoNewLine = 1;
430 unicode = ssd1306_unicode16FromUtf8(ch);
438 ssd1306_cursorY += s_fixedFont.
h.
height;
450 ssd1306_cursorY >> 3,
476 uint8_t c = ch[j] - 32;
490 if ( style == STYLE_NORMAL )
492 data = pgm_read_byte(&s_font6x8[c*6+i]);
494 else if ( style == STYLE_BOLD )
496 uint8_t temp = pgm_read_byte(&s_font6x8[c*6+i]);
502 uint8_t temp = pgm_read_byte(&s_font6x8[c*6+i + 1]);
503 data = (temp & 0xF0) | ldata;
504 ldata = (temp & 0x0F);
518 uint8_t text_index = 0;
559 if ( style == STYLE_NORMAL )
561 data = pgm_read_byte(&s_font6x8[c*6+i]);
563 else if ( style == STYLE_BOLD )
565 uint8_t temp = pgm_read_byte(&s_font6x8[c*6+i]);
571 uint8_t temp = pgm_read_byte(&s_font6x8[c*6+i + 1]);
572 data = (temp & 0xF0) | ldata;
573 ldata = (temp & 0x0F);
576 data = ((data & 0x01) ? 0x03: 0x00) |
577 ((data & 0x02) ? 0x0C: 0x00) |
578 ((data & 0x04) ? 0x30: 0x00) |
579 ((data & 0x08) ? 0xC0: 0x00);
597 uint8_t text_end_pos = len * 6 + left;
598 if (text_end_pos <= right)
619 void ssd1306_putPixel_delayed(uint8_t x, uint8_t y, uint8_t complete)
621 static uint8_t lx = 0, ly = 0xFF;
622 static uint8_t pixels = 0;
623 if ((lx != x) || ((ly & 0xF8) != (y & 0xF8)) || (complete))
634 pixels |= (1 << (y & 0x07));
641 lcduint_t dx = x1 > x2 ? (x1 - x2): (x2 - x1);
642 lcduint_t dy = y1 > y2 ? (y1 - y2): (y2 - y1);
657 x1 < x2 ? x1++: x1--;
659 ssd1306_putPixel_delayed( x1, y1, 0 );
661 ssd1306_putPixel_delayed( 0, 0, 1 );
676 if (y1 < y2) y1++;
else y1--;
686 for (uint8_t x = x1; x <= x2; x++)
695 uint8_t topPage = y1 >> 3;
696 uint8_t bottomPage = y2 >> 3;
697 uint8_t height = y2-y1;
700 if (topPage == bottomPage)
707 for ( y = (topPage + 1); y <= (bottomPage - 1); y++)
729 for(j=(h >> 3); j>0; j--)
742 for(j=(h >> 3); j>0; j--)
757 uint8_t y_offset = (y & 0x07);
758 uint8_t x_offset = (x & 0x01);
759 for( j = 0; j < ((h + 7 + y_offset) >> 3); j++)
761 for( i = 0; i < w / 2 + x_offset; i++)
763 for( k = 0; k < 8; k++)
765 if ((j*8 + k - y_offset < h) && (k >= y_offset || j != 0))
767 uint8_t data = (i < w / 2) ? buf[ i + (j * 8 + k - y_offset) * w / 2 ]: 0x00;
771 if ( i > 0) data |= buf[ i + (j * 8 + k - y_offset) * w / 2 - 1] >> 4;
792 for(j=(h >> 3); j>0; j--)
808 uint8_t y_offset = (y & 0x07);
809 uint8_t x_offset = (x & 0x01);
810 for( j = 0; j < ((h + 7 + y_offset) >> 3); j++)
812 for( i = 0; i < w / 2 + x_offset; i++)
814 for( k = 0; k < 8; k++)
816 if ((j*8 + k - y_offset < h) && (k >= y_offset || j != 0))
818 uint8_t data = (i < w / 2) ? pgm_read_byte( &buf[ i + (j * 8 + k - y_offset) * w / 2 ] ) : 0x00;
822 if ( i > 0) data |= pgm_read_byte( &buf[ i + (j * 8 + k - y_offset) * w / 2 - 1] ) >> 4;
840 lcduint_t pitch = (w + 7) >> 3;
842 for(j=(h >> 3); j>0; j--)
848 for (uint8_t k = 0; k<8; k++)
850 data |= ( ((pgm_read_byte(&buf[k*pitch]) >> bit) & 0x01) << k );
872 lcduint_t origin_width = w;
873 uint8_t offset = y & 0x07;
874 uint8_t complexFlag = 0;
875 uint8_t mainFlag = 1;
879 if (y + (lcdint_t)h <= 0)
return;
881 if (x + (lcdint_t)w <= 0)
return;
896 max_pages = (
lcduint_t)(h + 15 - offset) >> 3;
905 pages = ((y + h - 1) >> 3) - (y >> 3) + 1;
908 for(j=0; j < pages; j++)
910 if ( j == max_pages - 1 ) mainFlag = !offset;
911 for( i=w; i > 0; i--)
914 if ( mainFlag ) data |= (pgm_read_byte(buf) << offset);
915 if ( complexFlag ) data |= (pgm_read_byte(buf - origin_width) >> (8 - offset));
919 buf += origin_width - w;
920 complexFlag = offset;
931 for(j=(h >> 3); j>0; j--)
944 uint8_t templ = ssd1306_color^s_ssd1306_invertByte;
949 uint8_t bank1 = (y1 >> 3);
950 uint8_t bank2 = (y2 >> 3);
952 for (uint8_t bank = bank1; bank<=bank2; bank++)
957 mask = (mask >> ((y1 & 7) + 7 - (y2 & 7))) << (y1 & 7);
959 else if (bank1 == bank)
961 mask = (mask << (y1 & 7));
963 else if (bank2 == bank)
965 mask = (mask >> (7 - (y2 & 7)));
967 for (uint8_t x=x1; x<=x2; x++)
991 uint8_t offsety = sprite->
y & 0x7;
995 for (uint8_t i=0; i < sprite->
w; i++)
1004 for (uint8_t i=0; i < sprite->
w; i++)
1010 sprite->
lx = sprite->
x;
1011 sprite->
ly = sprite->
y;
1017 uint8_t posy = sprite->
y >> 3;
1018 uint8_t offsety = sprite->
y & 0x7;
1020 for (uint8_t i=sprite->
w; i > 0; i--)
1028 for (uint8_t i=sprite->
w; i > 0; i--)
1039 uint8_t y1 = sprite->
ly >> 3;
1040 uint8_t y2 = (sprite->
ly + 7) >> 3;
1041 if (sprite->
ly < sprite->
y)
1042 y2 =
min(y2, (uint8_t)((sprite->
y >> 3) - 1));
1043 else if (sprite->
y + 8 > sprite->
ly)
1044 y1 =
max(y1, (sprite->
ly + 7) >> 3);
1045 for(uint8_t y = y1; y <= y2; y++)
1048 for(uint8_t x = sprite->
w; x > 0; x--)
1054 if (sprite->
lx != sprite->
x)
1056 uint8_t x1 = sprite->
lx;
1057 uint8_t x2 = sprite->
lx + sprite->
w - 1;
1058 if (sprite->
x < sprite->
lx)
1059 x1 =
max(x1, sprite->
x + sprite->
w);
1061 x2 =
min((uint8_t)(sprite->
x - 1), x2);
1062 for(uint8_t y = sprite->
ly >> 3; y <= (sprite->
ly + 7) >> 3; y++)
1065 for(uint8_t x = x2 - x1 + 1; x > 0; x--)
1076 return (
SPRITE){x,y,w,x,y,data,NULL};
1081 sprite->
data = data;
1086 s_ssd1306_invertByte = 0xFF;
1091 s_ssd1306_invertByte = 0x00;
1096 s_font6x8 = progmemFont + 4;
void ssd1306_drawBuffer(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *buf)
void ssd1306_drawBitmap1_4(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *buf)
lcduint_t ssd1306_displayWidth(void)
uint8_t ssd1306_charF6x8(uint8_t x, uint8_t y, const char ch[], EFontStyle style)
void ssd1306_putPixels(uint8_t x, uint8_t y, uint8_t pixels)
uint8_t height
char height in pixels
void ssd1306_positiveMode()
const uint8_t * data
Pointer to PROGMEM data, representing sprite image.
SPRITE ssd1306_createSprite(uint8_t x, uint8_t y, uint8_t w, const uint8_t *data)
const uint8_t * primary_table
font chars bits
uint8_t ssd1306_printFixed2x(uint8_t xpos, uint8_t y, const char ch[], EFontStyle style)
void ssd1306_drawXBitmap(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *buf)
void ssd1306_drawLine(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2)
uint8_t ssd1306_printFixed(uint8_t xpos, uint8_t y, const char *ch, EFontStyle style)
void ssd1306_drawSprite(SPRITE *sprite)
void ssd1306_drawRect(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2)
void(* set_block)(lcduint_t x, lcduint_t y, lcduint_t w)
Sets block in RAM of lcd display controller to write data to.
void ssd1306_fillScreen(uint8_t fill_Data)
void(* send_pixels8)(uint8_t data)
Sends RGB pixel encoded in 3-3-2 format to OLED driver. Sends RGB pixel encoded in 3-3-2 format to OL...
void ssd1306_eraseTrace(SPRITE *sprite)
void(* send_pixels_buffer1)(const uint8_t *buffer, uint16_t len)
void ssd1306_drawBitmap(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *buf)
const PROGMEM uint8_t ssd1306xled_font6x8[]
void(* send_pixels1)(uint8_t data)
void gfx_drawMonoBitmap(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buf)
ssd1306_lcd_t ssd1306_lcd
size_t ssd1306_print(const char ch[])
Prints null-terminated string to display at current cursor position.
uint8_t ssd1306_charF12x16(uint8_t xpos, uint8_t y, const char ch[], EFontStyle style)
void ssd1306_setFont6x8(const uint8_t *progmemFont)
void ssd1306_eraseSprite(SPRITE *sprite)
void ssd1306_drawVLine(uint8_t x1, uint8_t y1, uint8_t y2)
void ssd1306_fillRect(lcdint_t x1, lcdint_t y1, lcdint_t x2, lcdint_t y2)
ssd1306_interface_t ssd1306_intf
uint8_t y
draw position Y on the screen
uint8_t width
char width in pixels
void ssd1306_drawSpriteEx(uint8_t x, uint8_t y, uint8_t w, const uint8_t *sprite)
SFixedFontInfo s_fixedFont
SFontHeaderRecord h
record, containing information on font
uint8_t x
draw position X on the screen
const uint8_t * glyph
char data, located in progmem.
uint8_t ssd1306_printFixedN(uint8_t xpos, uint8_t y, const char ch[], EFontStyle style, uint8_t factor)
void ssd1306_drawHLine(uint8_t x1, uint8_t y1, uint8_t x2)
lcduint_t ssd1306_displayHeight(void)
uint8_t spacing
additional spaces after char in pixels
uint8_t lx
last draw position X on the screen
void ssd1306_clearBlock(uint8_t x, uint8_t y, uint8_t w, uint8_t h)
void ssd1306_getCharBitmap(uint16_t unicode, SCharInfo *info)
returns char data for currently set (active) font.
uint8_t ssd1306_charF6x8_eol(uint8_t left, uint8_t y, const char ch[], EFontStyle style, uint8_t right)
void ssd1306_clearScreen()
void ssd1306_replaceSprite(SPRITE *sprite, const uint8_t *data)
#define SSD1306_MORE_CHARS_REQUIRED
void ssd1306_drawBufferFast(lcdint_t x, lcdint_t y, lcduint_t w, lcduint_t h, const uint8_t *buf)
uint8_t pages
height in pages (each page height is 8-pixels)
#define ssd1306_swap_data(a, b, type)
uint8_t ly
last draw position Y on the screen
void ssd1306_negativeMode()
void ssd1306_putPixel(uint8_t x, uint8_t y)
void ssd1306_drawBuffer1_4(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *buf)
size_t ssd1306_write(uint8_t ch)
Prints single character to display at current cursor position.