Color OLED module library  v0.5
Library for the WaveShare 0.96-inch color OLED (SSD1331) module
Macros | Functions
ssd1331.h File Reference
#include "simplegfx.h"
#include "simpletools.h"

Go to the source code of this file.

Drawing, Text, and Bitmap Functions

 simplegfx Library
 This display driver calls and uses functions from the simplegfx library.
 

Functions

screen_t * ssd1331_init (char sdi, char sclk, char cs, char rs, char rst, int _width, int _height)
 
void ssd1331_drawPixel (screen_t *dev, int x, int y, int color)
 Draws a single pixel on the screen in the specified color. No checking. More...
 
void ssd1331_drawLine (screen_t *dev, int x0, int y0, int x1, int y1, int color)
 Draws a line on the screen in the specified color. More...
 
void ssd1331_drawFastVLine (screen_t *dev, int x, int y, int w, int color)
 Draws a vertical line on the screen in the specified color. No bounds checking (used by other functions that do the bounds checking first) More...
 
void ssd1331_drawFastHLine (screen_t *dev, int x, int y, int h, int color)
 Draws a horizontal line on the screen in the specified color. No bounds checking (used by other functions that do the bounds checking first) More...
 
void ssd1331_fillRect (screen_t *dev, int x0, int y0, int x1, int y1, int color)
 Draws a filled rectangle on the screen in the specified color. More...
 
void ssd1331_clearDisplay (screen_t *dev)
 Clears the screen by setting the full area of the display to black. More...
 
void ssd1331_resetDisplay (screen_t *dev)
 Resets the display. More...
 
void ssd1331_writeByte (int mask_cs, int mask_sdi, int mask_clk, int mask_dc, char c, char dc)
 Low level function that transfers bytes to the screen. More...
 
char ssd1331_writeLock ()
 Returns the status of the SPI communication lockout so multiple cogs don't try to write to it at the same time. More...
 
void ssd1331_writeLockSet (char devId)
 Sets the SPI communication lockout. More...
 
void ssd1331_writeLockClear (char devId)
 Clears the SPI communication lockout. More...
 
void ssd1331_copy (screen_t *dev, int x0, int y0, int w, int h, int x2, int y2)
 Creates a copy a rectangular area of the screen at another position on the screen. More...
 
void ssd1331_scrollDisplay (screen_t *dev, int h, int v)
 Starts scrolling the entire image on the screen horizontally, vertically, or both. More...
 
void ssd1331_invertDisplay (screen_t *dev, char i)
 Inverts the screen. More...
 
void ssd1331_sleepWakeDisplay (screen_t *dev, char i)
 Sleeps or Wakes the display. More...
 

Macros

#define WHITE   0xFFFF
 
#define PINK   0xFD59
 
#define MAGENTA   0xC9D4
 
#define RED   0xC082
 
#define DARKRED   0xA000
 
#define REDORANGE   0xD261
 
#define LIGHTORANGE   0xDDB2
 
#define ORANGE   0xFC00
 
#define YELLOWORANGE   0xFCE0
 
#define GOLD   0xF704
 
#define YELLOW   0xF744
 
#define LEMON   0xD6CF
 
#define YELLOWGREEN   0x5600
 
#define GREEN   0x1C62
 
#define DARKGREEN   0x02C0
 
#define GREENBLUE   0x0C75
 
#define CYAN   0x5E97
 
#define LIGHTBLUE   0x857B
 
#define SKYBLUE   0x0E3E
 
#define BLUE   0x2B16
 
#define NAVYBLUE   0x0009
 
#define VIOLET   0x7817
 
#define PURPLE   0xA017
 
#define RASPBERRY   0x902A
 
#define TAN   0xCC2A
 
#define LIGHTBROWN   0xBB44
 
#define BRONZE   0xA440
 
#define BROWN   0x9201
 
#define DARKBROWN   0x51E7
 
#define LIGHTGRAY   0xBDD7
 
#define GRAY   0x8410
 
#define DARKGRAY   0x3186
 
#define BLACK   0x0000
 
#define SSD1331_CMD_DRAWLINE   0x21
 
#define SSD1331_CMD_DRAWRECT   0x22
 
#define SSD1331_CMD_COPY   0x23
 
#define SSD1331_CMD_CLEAR   0x25
 
#define SSD1331_CMD_FILL   0x26
 
#define SSD1331_CMD_SCROLLSETUP   0x27
 
#define SSD1331_CMD_SCROLLSTOP   0x2E
 
#define SSD1331_CMD_SCROLLSTART   0x2F
 
#define SSD1331_CMD_SETCOLUMN   0x15
 
#define SSD1331_CMD_SETROW   0x75
 
#define SSD1331_CMD_CONTRASTA   0x81
 
#define SSD1331_CMD_CONTRASTB   0x82
 
#define SSD1331_CMD_CONTRASTC   0x83
 
#define SSD1331_CMD_MASTERCURRENT   0x87
 
#define SSD1331_CMD_SETREMAP   0xA0
 
#define SSD1331_CMD_STARTLINE   0xA1
 
#define SSD1331_CMD_DISPLAYOFFSET   0xA2
 
#define SSD1331_CMD_NORMALDISPLAY   0xA4
 
#define SSD1331_CMD_DISPLAYALLON   0xA5
 
#define SSD1331_CMD_DISPLAYALLOFF   0xA6
 
#define SSD1331_CMD_INVERTDISPLAY   0xA7
 
#define SSD1331_CMD_SETMULTIPLEX   0xA8
 
#define SSD1331_CMD_SETMASTER   0xAD
 
#define SSD1331_CMD_DISPLAYOFF   0xAE
 
#define SSD1331_CMD_DISPLAYON   0xAF
 
#define SSD1331_CMD_POWERMODE   0xB0
 
#define SSD1331_CMD_PRECHARGE   0xB1
 
#define SSD1331_CMD_CLOCKDIV   0xB3
 
#define SSD1331_CMD_PRECHARGEA   0x8A
 
#define SSD1331_CMD_PRECHARGEB   0x8B
 
#define SSD1331_CMD_PRECHARGEC   0x8C
 
#define SSD1331_CMD_PRECHARGELEVEL   0xBB
 
#define SSD1331_CMD_VCOMH   0xBE
 

Function Documentation

◆ ssd1331_clearDisplay()

void ssd1331_clearDisplay ( screen_t *  dev)

Clears the screen by setting the full area of the display to black.

Parameters
devPointer to the display's device structure returned by the initialization function.

◆ ssd1331_copy()

void ssd1331_copy ( screen_t *  dev,
int  x0,
int  y0,
int  w,
int  h,
int  x2,
int  y2 
)

Creates a copy a rectangular area of the screen at another position on the screen.

Parameters
devPointer to the display's device structure returned by the initialization function.
x0Starting horizontal coordinate of the box to be copied, counted from the left side of the screen.
y0Starting vertical coordinate of the box to be copied, counted down from the top of the screen.
wWidth of the box to be copied.
hHeight of the box to be copied.
x2Horizontal coordinate where the copied box is to be pasted.
y2Vertical coordinate where the copied box is to be pasted.

◆ ssd1331_drawFastHLine()

void ssd1331_drawFastHLine ( screen_t *  dev,
int  x,
int  y,
int  h,
int  color 
)

Draws a horizontal line on the screen in the specified color. No bounds checking (used by other functions that do the bounds checking first)

Parameters
devPointer to the display's device structure returned by the initialization function.
xHorizontal coordinate of the line, counted from the left side of the screen.
yVertical coordinate of the line.
hLength of the line in pixels.
colorColor of the line.

◆ ssd1331_drawFastVLine()

void ssd1331_drawFastVLine ( screen_t *  dev,
int  x,
int  y,
int  w,
int  color 
)

Draws a vertical line on the screen in the specified color. No bounds checking (used by other functions that do the bounds checking first)

Parameters
devPointer to the display's device structure returned by the initialization function.
xHorizontal coordinate of the line.
yVertical coordinate of the line, counted down from the top of the screen.
wLength of the line in pixels.
colorColor of the line.

◆ ssd1331_drawLine()

void ssd1331_drawLine ( screen_t *  dev,
int  x0,
int  y0,
int  x1,
int  y1,
int  color 
)

Draws a line on the screen in the specified color.

Parameters
devPointer to the display's device structure returned by the initialization function.
x0Starting horizontal coordinate of the line, counted from the left side of the screen.
y0Starting vertical coordinate of the line, counted down from the top of the screen.
x1Ending horizontal coordinate of the line.
y1Ending vertical coordinate of the line.
colorColor of the pixel, in r5g6b5 format.

◆ ssd1331_drawPixel()

void ssd1331_drawPixel ( screen_t *  dev,
int  x,
int  y,
int  color 
)

Draws a single pixel on the screen in the specified color. No checking.

Parameters
devPointer to the display's device structure returned by the initialization function.
xHorizontal coordinate of the pixel, counted from the left side of the screen.
yVertical coordinate of the pixel, counted down from the top of the screen.
colorColor of the pixel.

◆ ssd1331_fillRect()

void ssd1331_fillRect ( screen_t *  dev,
int  x0,
int  y0,
int  x1,
int  y1,
int  color 
)

Draws a filled rectangle on the screen in the specified color.

Parameters
devPointer to the display's device structure returned by the initialization function.
x0Starting horizontal coordinate of the rectangle, counted from the left side of the screen.
y0Starting vertical coordinate of the rectangle, counted down from the top of the screen.
x1Ending horizontal coordinate of the rectangle, counted from the left side of the screen.
y1Ending vertical coordinate of the rectangle, counted down from the top of the screen.
colorColor of the rectangle, in r5g6b5 format.

◆ ssd1331_init()

screen_t* ssd1331_init ( char  sdi,
char  sclk,
char  cs,
char  rs,
char  rst,
int  _width,
int  _height 
)

◆ ssd1331_invertDisplay()

void ssd1331_invertDisplay ( screen_t *  dev,
char  i 
)

Inverts the screen.

Parameters
devPointer to the display's device structure returned by the initialization function.
iMode to set the inversion to: (0) sets the display to normal and (1) inverts the colors of the display.

◆ ssd1331_resetDisplay()

void ssd1331_resetDisplay ( screen_t *  dev)

Resets the display.

Parameters
devPointer to the display's device structure returned by the initialization function.

◆ ssd1331_scrollDisplay()

void ssd1331_scrollDisplay ( screen_t *  dev,
int  h,
int  v 
)

Starts scrolling the entire image on the screen horizontally, vertically, or both.

Parameters
devPointer to the display's device structure returned by the initialization function.
Note
the screen's horizontal displacement will persist after scrolling has stopped, but its vertical displacement will not.
Parameters
hHorizontal scrolling in rows per interval. (0) turns off horizontal scrolling, negative integers scroll to the left and positive integers scroll to the right.
vVertical scrolling columns per interval. (0) turns off vertical scrolling, negative integers scroll down and positive integers scroll up.

◆ ssd1331_sleepWakeDisplay()

void ssd1331_sleepWakeDisplay ( screen_t *  dev,
char  i 
)

Sleeps or Wakes the display.

Parameters
devPointer to the display's device structure returned by the initialization function.
iMode to set the display to: (0) wakes the display (1) sleeps the display.

◆ ssd1331_writeByte()

void ssd1331_writeByte ( int  mask_cs,
int  mask_sdi,
int  mask_clk,
int  mask_dc,
char  c,
char  dc 
)

Low level function that transfers bytes to the screen.

Parameters
mask_csPin mask for the display's chip select pin.
mask_sdiPin mask for the display's serial data in pin.
mask_clkPin mask for the display's clock pin.
mask_dcPin mask for the display's data/command pin.
cByte to be transferred.
dcToggle whether the byte is a command or data.

◆ ssd1331_writeLock()

char ssd1331_writeLock ( )

Returns the status of the SPI communication lockout so multiple cogs don't try to write to it at the same time.

◆ ssd1331_writeLockClear()

void ssd1331_writeLockClear ( char  devId)

Clears the SPI communication lockout.

Parameters
devIdThe ID of the device (usually the chip select pin).

◆ ssd1331_writeLockSet()

void ssd1331_writeLockSet ( char  devId)

Sets the SPI communication lockout.

Parameters
devIdThe ID of the device (usually the chip select pin).