esp32-ssd1306
ssd1306 interface component for esp-idf
Data Structures | Macros | Enumerations | Functions
ssd1306.h File Reference

defininitions for setting up, interacting with and sending commands to an ssd1306 driven screen via i2c or spi More...

#include "driver/spi_master.h"

Go to the source code of this file.

Data Structures

struct  PAGE_t
 
struct  SSD1306_t
 

Macros

#define OLED_CONTROL_BYTE_CMD_SINGLE   0x80
 
#define OLED_CONTROL_BYTE_CMD_STREAM   0x00
 
#define OLED_CONTROL_BYTE_DATA_SINGLE   0xC0
 
#define OLED_CONTROL_BYTE_DATA_STREAM   0x40
 
#define OLED_CMD_SET_CONTRAST   0x81
 
#define OLED_CMD_DISPLAY_RAM   0xA4
 
#define OLED_CMD_DISPLAY_ALLON   0xA5
 
#define OLED_CMD_DISPLAY_NORMAL   0xA6
 
#define OLED_CMD_DISPLAY_INVERTED   0xA7
 
#define OLED_CMD_DISPLAY_OFF   0xAE
 
#define OLED_CMD_DISPLAY_ON   0xAF
 
#define OLED_CMD_SET_MEMORY_ADDR_MODE   0x20
 
#define OLED_CMD_SET_HORI_ADDR_MODE   0x00
 
#define OLED_CMD_SET_VERT_ADDR_MODE   0x01
 
#define OLED_CMD_SET_PAGE_ADDR_MODE   0x02
 
#define OLED_CMD_SET_COLUMN_RANGE   0x21
 
#define OLED_CMD_SET_PAGE_RANGE   0x22
 
#define OLED_CMD_SET_DISPLAY_START_LINE   0x40
 
#define OLED_CMD_SET_SEGMENT_REMAP_0   0xA0
 
#define OLED_CMD_SET_SEGMENT_REMAP_1   0xA1
 
#define OLED_CMD_SET_MUX_RATIO   0xA8
 
#define OLED_CMD_SET_COM_SCAN_MODE   0xC8
 
#define OLED_CMD_SET_DISPLAY_OFFSET   0xD3
 
#define OLED_CMD_SET_COM_PIN_MAP   0xDA
 
#define OLED_CMD_NOP   0xE3
 
#define OLED_CMD_SET_DISPLAY_CLK_DIV   0xD5
 
#define OLED_CMD_SET_PRECHARGE   0xD9
 
#define OLED_CMD_SET_VCOMH_DESELCT   0xDB
 
#define OLED_CMD_SET_CHARGE_PUMP   0x8D
 
#define OLED_CMD_HORIZONTAL_RIGHT   0x26
 
#define OLED_CMD_HORIZONTAL_LEFT   0x27
 
#define OLED_CMD_CONTINUOUS_SCROLL   0x29
 
#define OLED_CMD_DEACTIVE_SCROLL   0x2E
 
#define OLED_CMD_ACTIVE_SCROLL   0x2F
 
#define OLED_CMD_VERTICAL   0xA3
 
#define I2CAddress   0x3C
 
#define SPIAddress   0xFF
 

Enumerations

enum  ssd1306_scroll_type_t {
  SCROLL_RIGHT = 1 , SCROLL_LEFT = 2 , SCROLL_DOWN = 3 , SCROLL_UP = 4 ,
  SCROLL_STOP = 5
}
 

Functions

void ssd1306_init (SSD1306_t *dev)
 
void ssd1306_deinit (SSD1306_t *dev)
 
void ssd1306_display_text (SSD1306_t *dev, int page, char *text, int text_len, bool invert)
 
void ssd1306_wrapped_display_text (SSD1306_t *dev, int line, char *text)
 
void ssd1306_display_image (SSD1306_t *dev, int page, int seg, uint8_t *images, int width)
 
void ssd1306_clear_screen (SSD1306_t *dev, bool invert)
 
void ssd1306_clear_line (SSD1306_t *dev, int page, bool invert)
 
void ssd1306_contrast (SSD1306_t *dev, int contrast)
 
void ssd1306_software_scroll (SSD1306_t *dev, int start, int end)
 
void ssd1306_scroll_text (SSD1306_t *dev, char *text, int text_len, bool invert)
 
void ssd1306_scroll_clear (SSD1306_t *dev)
 
void ssd1306_hardware_scroll (SSD1306_t *dev, ssd1306_scroll_type_t scroll)
 
void ssd1306_invert (uint8_t *buf, size_t blen)
 
void ssd1306_flip (uint8_t *buf, size_t blen)
 
uint8_t ssd1306_rotate (uint8_t ch1)
 
void ssd1306_fadeout (SSD1306_t *dev)
 
void ssd1306_dump (SSD1306_t dev)
 
void i2c_master_init (SSD1306_t *dev, int16_t sda, int16_t scl, int16_t reset)
 
void i2c_init (SSD1306_t *dev, int width, int height)
 
void i2c_display_image (SSD1306_t *dev, int page, int seg, uint8_t *images, int width)
 
void i2c_contrast (SSD1306_t *dev, int contrast)
 
void i2c_hardware_scroll (SSD1306_t *dev, ssd1306_scroll_type_t scroll)
 
void spi_master_init (SSD1306_t *dev, int16_t GPIO_MOSI, int16_t GPIO_SCLK, int16_t GPIO_CS, int16_t GPIO_DC, int16_t GPIO_RESET)
 
bool spi_master_write_byte (spi_device_handle_t SPIHandle, const uint8_t *Data, size_t DataLength)
 
bool spi_master_write_command (SSD1306_t *dev, uint8_t Command)
 
bool spi_master_write_data (SSD1306_t *dev, const uint8_t *Data, size_t DataLength)
 
void spi_init (SSD1306_t *dev, int width, int height)
 
void spi_display_image (SSD1306_t *dev, int page, int seg, uint8_t *images, int width)
 
void spi_contrast (SSD1306_t *dev, int contrast)
 
void spi_hardware_scroll (SSD1306_t *dev, ssd1306_scroll_type_t scroll)
 

Detailed Description

defininitions for setting up, interacting with and sending commands to an ssd1306 driven screen via i2c or spi

Function Documentation

◆ ssd1306_init()

void ssd1306_init ( SSD1306_t dev)

initialise the screen device

◆ ssd1306_deinit()

void ssd1306_deinit ( SSD1306_t dev)

de-initialise the screen device and free resources

Todo:
make sure to free more resources and de-init the actual spi/i2c session
Todo:

◆ ssd1306_display_text()

void ssd1306_display_text ( SSD1306_t dev,
int  page,
char *  text,
int  text_len,
bool  invert 
)

display some text on the screen

Parameters
devthe screen device to interact with
pagethe line to display the text on
textthe text data
text_lenthe text length
invertwhether or not to invert the text and background colours

◆ ssd1306_wrapped_display_text()

void ssd1306_wrapped_display_text ( SSD1306_t dev,
int  line,
char *  text 
)

display some text on the screen

Parameters
devthe screen device to interact with
linethe line to display the text on
textthe text data

◆ ssd1306_display_image()

void ssd1306_display_image ( SSD1306_t dev,
int  page,
int  seg,
uint8_t *  images,
int  width 
)

display an image on the screen

Parameters
devthe screen device to interact with
pagethe line to display the image on
segthe segment of the image
imagesthe image data to display
widththe width of the image

◆ ssd1306_clear_screen()

void ssd1306_clear_screen ( SSD1306_t dev,
bool  invert 
)

clear the screen (fills the screen with spaces)

Parameters
devthe screen device to interact with
invertwhether or not the cleared screen should be inverted

◆ ssd1306_clear_line()

void ssd1306_clear_line ( SSD1306_t dev,
int  page,
bool  invert 
)

clear a specific line (fills the line with spaces)

Parameters
devthe screen device to interact with
pagethe line to clear
invertwhether or not the cleared line should be inverted

◆ ssd1306_contrast()

void ssd1306_contrast ( SSD1306_t dev,
int  contrast 
)

set the contrast of the screen

Parameters
devthe screen device to interact with
contrastthe level of contrast

◆ ssd1306_software_scroll()

void ssd1306_software_scroll ( SSD1306_t dev,
int  start,
int  end 
)

start scrolling the screen via software

Parameters
devthe screen device to interact with
startthe start of the scroll
endthe end of the scroll

◆ ssd1306_scroll_text()

void ssd1306_scroll_text ( SSD1306_t dev,
char *  text,
int  text_len,
bool  invert 
)

display some scrolling text on the screen

Parameters
devthe screen device to interact with
textthe text data
text_lenthe text length
invertwhether or not the scrolling text should be inverted

◆ ssd1306_scroll_clear()

void ssd1306_scroll_clear ( SSD1306_t dev)

stop scrolling the screen via software

Parameters
devthe screen device to interact with

◆ ssd1306_hardware_scroll()

void ssd1306_hardware_scroll ( SSD1306_t dev,
ssd1306_scroll_type_t  scroll 
)

start scrolling the screen via hardware

Parameters
devthe screen device to interact with
scrollthe direction of the scroll

◆ ssd1306_invert()

void ssd1306_invert ( uint8_t *  buf,
size_t  blen 
)

invert a buffer of data

Parameters
bufbuffer to invert
blenthe length of the buffer

◆ ssd1306_flip()

void ssd1306_flip ( uint8_t *  buf,
size_t  blen 
)

flip a buffer of data

Parameters
bufbuffer to flip
blenthe length of the buffer

◆ ssd1306_rotate()

uint8_t ssd1306_rotate ( uint8_t  ch1)

rotate a buffer of data

Parameters
bufbuffer to rotate
blenthe length of the buffer

◆ ssd1306_fadeout()

void ssd1306_fadeout ( SSD1306_t dev)

fadeout the screen

Parameters
devthe screen device to interact with

◆ ssd1306_dump()

void ssd1306_dump ( SSD1306_t  dev)

dump the screen data

Parameters
devthe screen device to interact with

◆ i2c_master_init()

void i2c_master_init ( SSD1306_t dev,
int16_t  sda,
int16_t  scl,
int16_t  reset 
)

initialise an i2c device

Parameters
devthe device to interact with
sdathe pin to use for SDA
sclthe pin to use for SCL
resetthe reset pin to use

◆ i2c_init()

void i2c_init ( SSD1306_t dev,
int  width,
int  height 
)

initialise the screen i2c session

Parameters
devthe screen device to interact with
widththe width of the screen
heightthe height of the screen

◆ i2c_display_image()

void i2c_display_image ( SSD1306_t dev,
int  page,
int  seg,
uint8_t *  images,
int  width 
)

display an image on the screen

Parameters
devthe screen device to interact with
pagethe line to display the image on
segthe segment of the image
imagesthe image data to display
widththe width of the image

◆ i2c_contrast()

void i2c_contrast ( SSD1306_t dev,
int  contrast 
)

set the contrast of the screen

Parameters
devthe screen device to interact with
contrastthe level of contrast

◆ i2c_hardware_scroll()

void i2c_hardware_scroll ( SSD1306_t dev,
ssd1306_scroll_type_t  scroll 
)

send the command for a continues scroll via hardware

Parameters
devthe screen device to interact with
scrollthe direction of the scroll

◆ spi_master_init()

void spi_master_init ( SSD1306_t dev,
int16_t  GPIO_MOSI,
int16_t  GPIO_SCLK,
int16_t  GPIO_CS,
int16_t  GPIO_DC,
int16_t  GPIO_RESET 
)

initialise an spi device

Parameters
devthe device to interact with
GPIO_MOSIthe pin to use for GPIO_MOSI
GPIO_SCLKthe pin to use for GPIO_SCLK
GPIO_CSthe pin to use for GPIO_CS
GPIO_DCthe pin to use for GPIO_DC
GPIO_RESETthe pin to use for GPIO_RESET

◆ spi_master_write_byte()

bool spi_master_write_byte ( spi_device_handle_t  SPIHandle,
const uint8_t *  Data,
size_t  DataLength 
)

write a byte to the spi device

Parameters
SPIHandlethe spi device to interact with
Datathe data being sent
DataLengththe length of the data being sent

◆ spi_master_write_command()

bool spi_master_write_command ( SSD1306_t dev,
uint8_t  Command 
)

write a command to the screen

Parameters
devthe screen device to interact with
Commandthe command being sent

◆ spi_master_write_data()

bool spi_master_write_data ( SSD1306_t dev,
const uint8_t *  Data,
size_t  DataLength 
)

write data to the screen

Parameters
devthe screen device to interact with
Datathe data being sent
DataLengththe length of the data being sent

◆ spi_init()

void spi_init ( SSD1306_t dev,
int  width,
int  height 
)

initialise the screen spi session

Parameters
devthe screen device to interact with
widththe width of the screen
heightthe height of the screen

◆ spi_display_image()

void spi_display_image ( SSD1306_t dev,
int  page,
int  seg,
uint8_t *  images,
int  width 
)

display an image on the screen

Parameters
devthe screen device to interact with
pagethe line to display the image on
segthe segment of the image
imagesthe image data to display
widththe width of the image

◆ spi_contrast()

void spi_contrast ( SSD1306_t dev,
int  contrast 
)

set the contrast of the screen

Parameters
devthe screen device to interact with
contrastthe level of contrast

◆ spi_hardware_scroll()

void spi_hardware_scroll ( SSD1306_t dev,
ssd1306_scroll_type_t  scroll 
)

send the command for a continues scroll via hardware

Parameters
devthe screen device to interact with
scrollthe direction of the scroll