SSD1306 OLED display driver  1.4.0
This library is developed to control SSD1306 i2c/spi OLED display
Macros | Functions
LCD direct graphics functions

Macros

#define ssd1306_drawCanvas(x, y, w, h, buf)   ssd1306_drawBuffer(x, y, w, h, buf)
 

Functions

void ssd1306_setPos (uint8_t x, uint8_t y)
 
void ssd1306_fillScreen (uint8_t fill_Data)
 
void ssd1306_clearScreen ()
 
void ssd1306_negativeMode ()
 
void ssd1306_positiveMode ()
 
uint8_t ssd1306_printFixed (uint8_t xpos, uint8_t y, const char ch[], EFontStyle style)
 
uint8_t ssd1306_printFixed2x (uint8_t xpos, uint8_t y, const char ch[], EFontStyle style)
 
uint8_t ssd1306_charF6x8 (uint8_t x, uint8_t y, const char ch[], EFontStyle style=STYLE_NORMAL)
 
uint8_t ssd1306_charF12x16 (uint8_t xpos, uint8_t y, const char ch[], EFontStyle style)
 
uint8_t ssd1306_charF6x8_eol (uint8_t left, uint8_t y, const char ch[], EFontStyle style, uint8_t right)
 
void ssd1306_setFixedFont (const uint8_t *progmemFont)
 
void ssd1306_setFont6x8 (const uint8_t *progmemFont)
 
void ssd1306_putPixel (uint8_t x, uint8_t y)
 
void ssd1306_putPixels (uint8_t x, uint8_t y, uint8_t pixels)
 
void ssd1306_drawRect (uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2)
 
void ssd1306_drawHLine (uint8_t x1, uint8_t y1, uint8_t x2)
 
void ssd1306_drawVLine (uint8_t x1, uint8_t y1, uint8_t y2)
 
void ssd1306_drawBuffer (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *buf)
 
void ssd1306_drawBitmap (uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *buf)
 
void ssd1306_clearBlock (uint8_t x, uint8_t y, uint8_t w, uint8_t h)
 
void ssd1306_drawSpriteEx (uint8_t x, uint8_t y, uint8_t w, const uint8_t *sprite)
 
void ssd1306_drawSprite (SPRITE *sprite)
 
void ssd1306_eraseSprite (SPRITE *sprite)
 
void ssd1306_eraseTrace (SPRITE *sprite)
 
SPRITE ssd1306_createSprite (uint8_t x, uint8_t y, uint8_t w, const uint8_t *data)
 
void ssd1306_replaceSprite (SPRITE *sprite, const uint8_t *data)
 

Detailed Description

Macro Definition Documentation

◆ ssd1306_drawCanvas

#define ssd1306_drawCanvas (   x,
  y,
  w,
  h,
  buf 
)    ssd1306_drawBuffer(x, y, w, h, buf)

Draws bitmap, located in SRAM, on the display Each byte represents 8 vertical pixels.

// Draw small rectangle 3x8 at position 10,8
uint8_t buffer[3] = { 0xFF, 0x81, 0xFF };
ssd1306_drawBuffer(10, 1, 3, 8, buffer);
Parameters
x- horizontal position in pixels
y- vertical position in blocks (pixels/8)
w- width of bitmap in pixels
h- height of bitmap in pixels (must be divided by 8)
buf- pointer to data, located in SRAM: each byte represents 8 vertical pixels.

Definition at line 309 of file ssd1306.h.

Function Documentation

◆ ssd1306_charF12x16()

uint8_t ssd1306_charF12x16 ( uint8_t  xpos,
uint8_t  y,
const char  ch[],
EFontStyle  style 
)

Prints text to screen using double size font 12x16.

Parameters
xpos- horizontal position in pixels
y- vertical position in blocks (pixels/8)
ch- NULL-terminated string to print
style- font style (EFontStyle).
Returns
number of chars in string

Definition at line 295 of file ssd1306.c.

◆ ssd1306_charF6x8()

uint8_t ssd1306_charF6x8 ( uint8_t  x,
uint8_t  y,
const char  ch[],
EFontStyle  style = STYLE_NORMAL 
)

Prints text to screen using font 6x8.

Parameters
x- horizontal position in pixels
y- vertical position in blocks (pixels/8)
ch- NULL-terminated string to print
style- font style (EFontStyle), normal by default.
Returns
number of chars in string

Definition at line 249 of file ssd1306.c.

◆ ssd1306_charF6x8_eol()

uint8_t ssd1306_charF6x8_eol ( uint8_t  left,
uint8_t  y,
const char  ch[],
EFontStyle  style,
uint8_t  right 
)

Prints text to screen using set font. If real text ends before right boundary, the remaining part on the display will be erased till right boundary.

Parameters
left- horizontal position in pixels
y- vertical position in blocks (pixels/8)
ch- NULL-terminated string to print
style- font style (EFontStyle), normal by default.
right- right boundary of the text to output
Returns
number of chars in string

Definition at line 370 of file ssd1306.c.

◆ ssd1306_clearBlock()

void ssd1306_clearBlock ( uint8_t  x,
uint8_t  y,
uint8_t  w,
uint8_t  h 
)

Fills block with black pixels

Parameters
x- horizontal position in pixels
y- vertical position in blocks (pixels/8)
w- width of block in pixels
h- height of block in pixels (must be divided by 8)
Note
usually this method is used to erase bitmap on the screen.

Definition at line 490 of file ssd1306.c.

◆ ssd1306_clearScreen()

void ssd1306_clearScreen ( )

Fills screen with zero-byte

Definition at line 69 of file ssd1306.c.

◆ ssd1306_createSprite()

SPRITE ssd1306_createSprite ( uint8_t  x,
uint8_t  y,
uint8_t  w,
const uint8_t *  data 
)

Creates sprite object. Sprite height is fixed to 8 pixels

Parameters
x- horizontal position in pixels
y- vertical position in pixels
w- width of sprite in pixels
data- pointer to data, located in Flash: each byte represents 8 vertical pixels.
Returns
SPRITE structure

Definition at line 611 of file ssd1306.c.

◆ ssd1306_drawBitmap()

void ssd1306_drawBitmap ( uint8_t  x,
uint8_t  y,
uint8_t  w,
uint8_t  h,
const uint8_t *  buf 
)

Draws bitmap, located in Flash, on the display

Parameters
x- horizontal position in pixels
y- vertical position in blocks (pixels/8)
w- width of bitmap in pixels
h- height of bitmap in pixels (must be divided by 8)
buf- pointer to data, located in Flash: each byte represents 8 vertical pixels.

Definition at line 473 of file ssd1306.c.

◆ ssd1306_drawBuffer()

void ssd1306_drawBuffer ( uint8_t  x,
uint8_t  y,
uint8_t  w,
uint8_t  h,
const uint8_t *  buf 
)

Draws bitmap, located in SRAM, on the display Each byte represents 8 vertical pixels.

// Draw small rectangle 3x8 at position 10,8
uint8_t buffer[3] = { 0xFF, 0x81, 0xFF };
ssd1306_drawBuffer(10, 1, 3, 8, buffer);
Parameters
x- horizontal position in pixels
y- vertical position in blocks (pixels/8)
w- width of bitmap in pixels
h- height of bitmap in pixels (must be divided by 8)
buf- pointer to data, located in SRAM: each byte represents 8 vertical pixels.

Definition at line 457 of file ssd1306.c.

◆ ssd1306_drawHLine()

void ssd1306_drawHLine ( uint8_t  x1,
uint8_t  y1,
uint8_t  x2 
)

Draws horizontal line

Parameters
x1- left boundary in pixels
y1- position Y in pixels
x2- right boundary in pixels

Definition at line 413 of file ssd1306.c.

◆ ssd1306_drawRect()

void ssd1306_drawRect ( uint8_t  x1,
uint8_t  y1,
uint8_t  x2,
uint8_t  y2 
)

Draws rectangle

Parameters
x1- left boundary in pixel units
y1- top boundary in pixel units
x2- right boundary in pixel units
y2- bottom boundary int pixel units

Definition at line 449 of file ssd1306.c.

◆ ssd1306_drawSprite()

void ssd1306_drawSprite ( SPRITE sprite)

Draws sprite on the display. Position can be changed by updating x and y fields of SPRITE structure.

Parameters
sprite- pointer to SPRITE structure

Definition at line 520 of file ssd1306.c.

◆ ssd1306_drawSpriteEx()

void ssd1306_drawSpriteEx ( uint8_t  x,
uint8_t  y,
uint8_t  w,
const uint8_t *  sprite 
)

Draws bitmap, located in Flash, on the display. This sprite must have wx8 size

Parameters
x- horizontal position in pixels
y- vertical position in blocks (pixels/8)
w- width in pixels
sprite- pointer to data, located in Flash: each byte represents 8 vertical pixels.

Definition at line 507 of file ssd1306.c.

◆ ssd1306_drawVLine()

void ssd1306_drawVLine ( uint8_t  x1,
uint8_t  y1,
uint8_t  y2 
)

Draws vertical line

Parameters
x1- position X in pixels
y1- top boundary in pixels
y2- bottom boundary in pixels

Definition at line 424 of file ssd1306.c.

◆ ssd1306_eraseSprite()

void ssd1306_eraseSprite ( SPRITE sprite)

Clears sprite from the display leaving black rectangle.

Parameters
sprite- pointer to SPRITE structure

Definition at line 548 of file ssd1306.c.

◆ ssd1306_eraseTrace()

void ssd1306_eraseTrace ( SPRITE sprite)

Clears some sprite parts in old position on the display.

Parameters
sprite- pointer to SPRITE structure

Definition at line 572 of file ssd1306.c.

◆ ssd1306_fillScreen()

void ssd1306_fillScreen ( uint8_t  fill_Data)

Fills screen with pattern byte

Definition at line 53 of file ssd1306.c.

◆ ssd1306_negativeMode()

void ssd1306_negativeMode ( )

All drawing functions start to work in negative mode. Old picture on the display remains unchanged.

Definition at line 631 of file ssd1306.c.

◆ ssd1306_positiveMode()

void ssd1306_positiveMode ( )

All drawing functions start to work in positive (default) mode. Old picture on the display remains unchanged.

Definition at line 636 of file ssd1306.c.

◆ ssd1306_printFixed()

uint8_t ssd1306_printFixed ( uint8_t  xpos,
uint8_t  y,
const char  ch[],
EFontStyle  style 
)

Prints text to screen using fixed font.

Parameters
xpos- horizontal position in pixels
y- vertical position in pixels
ch- NULL-terminated string to print
style- font style (EFontStyle), normal by default.
Returns
number of chars in string
See also
ssd1306_setFixedFont
Warning
ssd1306_printFixed() can output chars at fixed y positions: 0, 8, 16, 24, 32, etc. If you specify [10,18], ssd1306_printFixed() will output text starting at [10,16] position.

Definition at line 96 of file ssd1306.c.

◆ ssd1306_printFixed2x()

uint8_t ssd1306_printFixed2x ( uint8_t  xpos,
uint8_t  y,
const char  ch[],
EFontStyle  style 
)

Prints text to screen using double size fixed font.

Parameters
xpos- horizontal position in pixels
y- vertical position in pixels
ch- NULL-terminated string to print
style- font style (EFontStyle), normal by default.
Returns
number of chars in string
See also
ssd1306_setFixedFont
Warning
ssd1306_printFixed2x() can output chars at fixed y positions: 0, 8, 16, 24, 32, etc. If you specify [10,18], ssd1306_printFixed2x() will output text starting at [10,16] position.

Definition at line 169 of file ssd1306.c.

◆ ssd1306_putPixel()

void ssd1306_putPixel ( uint8_t  x,
uint8_t  y 
)

Put single pixel on the LCD.

Warning
Please, take into account that there is no way to read data from ssd1306, thus since each byte contains 8 pixels, all other pixels in the same byte will be cleared on the display. Use ssd1306_putPixels() instead. If you need to have buffered output, please, refer to NanoCanvas.
Parameters
x- horizontal position in pixels
y- vertical position in pixels

Definition at line 397 of file ssd1306.c.

◆ ssd1306_putPixels()

void ssd1306_putPixels ( uint8_t  x,
uint8_t  y,
uint8_t  pixels 
)

Puts eight vertical pixels on the LCD at once.

// Draw 8 vertical pixels, starting at [10,16] position
ssd1306_putPixels(10,2,0xFF);
// Draw 4 vertical pixels, starting at [32,28] position
ssd1306_putPixels(32,3,0x0F);
Parameters
x- horizontal position in pixels
y- vertical position in blocks (pixels/8)
pixels- bit-pixels to draw on display

Definition at line 405 of file ssd1306.c.

◆ ssd1306_replaceSprite()

void ssd1306_replaceSprite ( SPRITE sprite,
const uint8_t *  data 
)

Replaces image of the sprite with different data. The width must be the same as the width of original sprite image

Parameters
sprite- pointer to SPRITE structure
data- pointer to data, located in Flash: each byte represents 8 vertical pixels.

Definition at line 616 of file ssd1306.c.

◆ ssd1306_setFixedFont()

void ssd1306_setFixedFont ( const uint8_t *  progmemFont)

Function allows to set another fixed 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. Font data should be in the following format: | 0x00 | 0xWW | 0xHH | FONT DATA |, where 0xWW - width in pixels, 0xHH - height in pixels.
For fixed font 6x8 each char is presented by 6 bytes:
COL0, COL1, COL2, COL3, COL4, COL5.
For fixed font 4x16 each char is presented by 4x16/8 = 8 bytes:
ROW0: COL0, COL1, COL2, COL3,
ROW1: COL0, COL1, COL2, COL3

Parameters
progmemFont- font to setup located in Flash area

Definition at line 385 of file ssd1306.c.

◆ ssd1306_setFont6x8()

void ssd1306_setFont6x8 ( const uint8_t *  progmemFont)

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.

Parameters
progmemFont- font to setup located in Flash area

Definition at line 392 of file ssd1306.c.

◆ ssd1306_setPos()

void ssd1306_setPos ( uint8_t  x,
uint8_t  y 
)

Set position in terms of display.

Parameters
x- horizontal position in pixels
y- vertical position in blocks (pixels/8)