Skip to content

Implementing own low level interface for ssd1306 library

Aleksei edited this page Oct 14, 2018 · 1 revision

HOW to make ssd1306 library to use your own i2c / spi implementation.

These actions are required if

  • OLED display controller, you're using, supports some non-standard interface
  • or you want to use your own i2c/spi implementation in some large project

It is very simple. You need to implement just 4 functions in C.

#include "intf/ssd1306_interface.h"

void transmission_start(void)
{
    // Prepare your interface for communication here.
    // For i2c, you need to initiate write to oled display device
    // For spi, you need to set CE signal, and set spi communication parameters
}

void interface_send_byte(uint8_t data)
{
    // send byte over interface here
}

void transmission_end(void)
{
    // Complete transmission here, release interface lines
}

void interface_close(void)
{
    // Release resources here. Usually this line is required for Linux only.
    // And this function can be left empty
}

void setup()
{
    ssd1306_intf.start = &transmission_start;
    ssd1306_intf.stop  = &transmission_end;
    ssd1306_intf.send  = &interface_send_byte;
    ssd1306_intf.close = &interface_close;
    ...
    # init your interface
    ...
    # init your display here
    ssd1306_128x64_init();
}

Refer to SPI, I2C interfaces init function to understand required implementation.

SPI details

Since spi oled displays use additional wires to select data/command mode, spi type of interface requires pointing of additional info for the library:

#include "intf/spi/ssd1306_spi.h"

void setup()
{
    ...
    s_ssd1306_dc = YOUR_DC_PIN_NUMBER;
    ...
}