esp32-warm-water
esp32 based project for the control of a heating element based on temperature
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"
Include dependency graph for ssd1306.h:
This graph shows which files directly or indirectly include this file:

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_hardware_scroll_line (SSD1306_t *dev, int page, 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 i2c_hardware_scroll_line (SSD1306_t *dev, int page, 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)
 
void spi_hardware_scroll_line (SSD1306_t *dev, int page, 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

Definition in file ssd1306.h.

Macro Definition Documentation

◆ I2CAddress

#define I2CAddress   0x3C

Definition at line 101 of file ssd1306.h.

◆ OLED_CMD_ACTIVE_SCROLL

#define OLED_CMD_ACTIVE_SCROLL   0x2F

Definition at line 98 of file ssd1306.h.

◆ OLED_CMD_CONTINUOUS_SCROLL

#define OLED_CMD_CONTINUOUS_SCROLL   0x29

Definition at line 96 of file ssd1306.h.

◆ OLED_CMD_DEACTIVE_SCROLL

#define OLED_CMD_DEACTIVE_SCROLL   0x2E

Definition at line 97 of file ssd1306.h.

◆ OLED_CMD_DISPLAY_ALLON

#define OLED_CMD_DISPLAY_ALLON   0xA5

Definition at line 61 of file ssd1306.h.

◆ OLED_CMD_DISPLAY_INVERTED

#define OLED_CMD_DISPLAY_INVERTED   0xA7

Definition at line 63 of file ssd1306.h.

◆ OLED_CMD_DISPLAY_NORMAL

#define OLED_CMD_DISPLAY_NORMAL   0xA6

Definition at line 62 of file ssd1306.h.

◆ OLED_CMD_DISPLAY_OFF

#define OLED_CMD_DISPLAY_OFF   0xAE

Definition at line 64 of file ssd1306.h.

◆ OLED_CMD_DISPLAY_ON

#define OLED_CMD_DISPLAY_ON   0xAF

Definition at line 65 of file ssd1306.h.

◆ OLED_CMD_DISPLAY_RAM

#define OLED_CMD_DISPLAY_RAM   0xA4

Definition at line 60 of file ssd1306.h.

◆ OLED_CMD_HORIZONTAL_LEFT

#define OLED_CMD_HORIZONTAL_LEFT   0x27

Definition at line 95 of file ssd1306.h.

◆ OLED_CMD_HORIZONTAL_RIGHT

#define OLED_CMD_HORIZONTAL_RIGHT   0x26

Definition at line 94 of file ssd1306.h.

◆ OLED_CMD_NOP

#define OLED_CMD_NOP   0xE3

Definition at line 83 of file ssd1306.h.

◆ OLED_CMD_SET_CHARGE_PUMP

#define OLED_CMD_SET_CHARGE_PUMP   0x8D

Definition at line 91 of file ssd1306.h.

◆ OLED_CMD_SET_COLUMN_RANGE

#define OLED_CMD_SET_COLUMN_RANGE   0x21

Definition at line 72 of file ssd1306.h.

◆ OLED_CMD_SET_COM_PIN_MAP

#define OLED_CMD_SET_COM_PIN_MAP   0xDA

Definition at line 82 of file ssd1306.h.

◆ OLED_CMD_SET_COM_SCAN_MODE

#define OLED_CMD_SET_COM_SCAN_MODE   0xC8

Definition at line 80 of file ssd1306.h.

◆ OLED_CMD_SET_CONTRAST

#define OLED_CMD_SET_CONTRAST   0x81

Definition at line 59 of file ssd1306.h.

◆ OLED_CMD_SET_DISPLAY_CLK_DIV

#define OLED_CMD_SET_DISPLAY_CLK_DIV   0xD5

Definition at line 86 of file ssd1306.h.

◆ OLED_CMD_SET_DISPLAY_OFFSET

#define OLED_CMD_SET_DISPLAY_OFFSET   0xD3

Definition at line 81 of file ssd1306.h.

◆ OLED_CMD_SET_DISPLAY_START_LINE

#define OLED_CMD_SET_DISPLAY_START_LINE   0x40

Definition at line 76 of file ssd1306.h.

◆ OLED_CMD_SET_HORI_ADDR_MODE

#define OLED_CMD_SET_HORI_ADDR_MODE   0x00

Definition at line 69 of file ssd1306.h.

◆ OLED_CMD_SET_MEMORY_ADDR_MODE

#define OLED_CMD_SET_MEMORY_ADDR_MODE   0x20

Definition at line 68 of file ssd1306.h.

◆ OLED_CMD_SET_MUX_RATIO

#define OLED_CMD_SET_MUX_RATIO   0xA8

Definition at line 79 of file ssd1306.h.

◆ OLED_CMD_SET_PAGE_ADDR_MODE

#define OLED_CMD_SET_PAGE_ADDR_MODE   0x02

Definition at line 71 of file ssd1306.h.

◆ OLED_CMD_SET_PAGE_RANGE

#define OLED_CMD_SET_PAGE_RANGE   0x22

Definition at line 73 of file ssd1306.h.

◆ OLED_CMD_SET_PRECHARGE

#define OLED_CMD_SET_PRECHARGE   0xD9

Definition at line 87 of file ssd1306.h.

◆ OLED_CMD_SET_SEGMENT_REMAP_0

#define OLED_CMD_SET_SEGMENT_REMAP_0   0xA0

Definition at line 77 of file ssd1306.h.

◆ OLED_CMD_SET_SEGMENT_REMAP_1

#define OLED_CMD_SET_SEGMENT_REMAP_1   0xA1

Definition at line 78 of file ssd1306.h.

◆ OLED_CMD_SET_VCOMH_DESELCT

#define OLED_CMD_SET_VCOMH_DESELCT   0xDB

Definition at line 88 of file ssd1306.h.

◆ OLED_CMD_SET_VERT_ADDR_MODE

#define OLED_CMD_SET_VERT_ADDR_MODE   0x01

Definition at line 70 of file ssd1306.h.

◆ OLED_CMD_VERTICAL

#define OLED_CMD_VERTICAL   0xA3

Definition at line 99 of file ssd1306.h.

◆ OLED_CONTROL_BYTE_CMD_SINGLE

#define OLED_CONTROL_BYTE_CMD_SINGLE   0x80

Definition at line 53 of file ssd1306.h.

◆ OLED_CONTROL_BYTE_CMD_STREAM

#define OLED_CONTROL_BYTE_CMD_STREAM   0x00

Definition at line 54 of file ssd1306.h.

◆ OLED_CONTROL_BYTE_DATA_SINGLE

#define OLED_CONTROL_BYTE_DATA_SINGLE   0xC0

Definition at line 55 of file ssd1306.h.

◆ OLED_CONTROL_BYTE_DATA_STREAM

#define OLED_CONTROL_BYTE_DATA_STREAM   0x40

Definition at line 56 of file ssd1306.h.

◆ SPIAddress

#define SPIAddress   0xFF

Definition at line 102 of file ssd1306.h.

Enumeration Type Documentation

◆ ssd1306_scroll_type_t

Enumerator
SCROLL_RIGHT 
SCROLL_LEFT 
SCROLL_DOWN 
SCROLL_UP 
SCROLL_STOP 

Definition at line 104 of file ssd1306.h.

Function Documentation

◆ 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

Definition at line 211 of file ssd1306_i2c.c.

Here is the caller graph for this function:

◆ 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

Definition at line 159 of file ssd1306_i2c.c.

Here is the caller graph for this function:

◆ 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

Definition at line 236 of file ssd1306_i2c.c.

Here is the caller graph for this function:

◆ i2c_hardware_scroll_line()

void i2c_hardware_scroll_line ( SSD1306_t dev,
int  page,
ssd1306_scroll_type_t  scroll 
)

send the command for a continues scroll via hardware

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

Definition at line 335 of file ssd1306_i2c.c.

Here is the caller graph for this function:

◆ 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

Definition at line 80 of file ssd1306_i2c.c.

Here is the caller graph for this function:

◆ 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

Definition at line 50 of file ssd1306_i2c.c.

Here is the caller graph for this function:

◆ 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

Definition at line 258 of file ssd1306_spi.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

Definition at line 226 of file ssd1306_spi.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

Definition at line 275 of file ssd1306_spi.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ spi_hardware_scroll_line()

void spi_hardware_scroll_line ( SSD1306_t dev,
int  page,
ssd1306_scroll_type_t  scroll 
)

send the command for a continues scroll via hardware

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

Definition at line 352 of file ssd1306_spi.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

Definition at line 165 of file ssd1306_spi.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

Definition at line 65 of file ssd1306_spi.c.

Here is the caller graph for this function:

◆ 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

Definition at line 119 of file ssd1306_spi.c.

◆ 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

Definition at line 139 of file ssd1306_spi.c.

Here is the caller graph for this function:

◆ 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

Definition at line 153 of file ssd1306_spi.c.

Here is the caller graph for this function:

◆ 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

Definition at line 190 of file ssd1306.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

Definition at line 175 of file ssd1306.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

Definition at line 201 of file ssd1306.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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:

Definition at line 100 of file ssd1306.c.

Here is the caller graph for this function:

◆ 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

Definition at line 159 of file ssd1306.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

Definition at line 112 of file ssd1306.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ssd1306_dump()

void ssd1306_dump ( SSD1306_t  dev)

dump the screen data

Parameters
devthe screen device to interact with

Definition at line 449 of file ssd1306.c.

◆ ssd1306_fadeout()

void ssd1306_fadeout ( SSD1306_t dev)

fadeout the screen

Parameters
devthe screen device to interact with

Definition at line 412 of file ssd1306.c.

Here is the call graph for this function:

◆ 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

Definition at line 383 of file ssd1306.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

Definition at line 334 of file ssd1306.c.

Here is the call graph for this function:

◆ ssd1306_hardware_scroll_line()

void ssd1306_hardware_scroll_line ( SSD1306_t dev,
int  page,
ssd1306_scroll_type_t  scroll 
)

start scrolling the screen via hardware

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

Definition at line 351 of file ssd1306.c.

Here is the call graph for this function:

◆ ssd1306_init()

void ssd1306_init ( SSD1306_t dev)

initialise the screen device

Definition at line 53 of file ssd1306.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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

Definition at line 367 of file ssd1306.c.

Here is the caller graph for this function:

◆ ssd1306_rotate()

uint8_t ssd1306_rotate ( uint8_t  ch1)

rotate a buffer of data

Parameters
bufbuffer to rotate
blenthe length of the buffer

Definition at line 398 of file ssd1306.c.

Here is the caller graph for this function:

◆ ssd1306_scroll_clear()

void ssd1306_scroll_clear ( SSD1306_t dev)

stop scrolling the screen via software

Parameters
devthe screen device to interact with

Definition at line 311 of file ssd1306.c.

Here is the call graph for this function:

◆ 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

Definition at line 251 of file ssd1306.c.

Here is the call graph for this function:

◆ 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

Definition at line 218 of file ssd1306.c.

◆ 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

Definition at line 146 of file ssd1306.c.

Here is the call graph for this function:
Here is the caller graph for this function: