A simple yet powerful library for controlling graphical displays. Multiple display controllers are supported using inheritance.

Dependents:   mbed_rifletool Hexi_Bubble_Game Hexi_Catch-the-dot_Game Hexi_Acceleromagnetic_Synth

Embed: (wiki syntax)

« Back to documentation index

SSD1306_SPI Class Reference

SSD1306_SPI Class Reference

SSD1306_SPI class. More...

#include <SSD1306_SPI.h>

Inherits Display.

Public Types

enum  State { NOT_INITIALIZED, DISPLAY_OFF, DISPLAY_ON }
 

Represents the state of the Display.

More...

Public Member Functions

 SSD1306_SPI (PinName mosi, PinName miso, PinName sclk, PinName cs, PinName dc)
 Create an SSD1306 object connected to the specified SPI pins with the specified /CS and DC pins.
virtual bool open ()
 Probe for the SSD1306 and initialize it if present.
virtual void flush ()
 Send the buffer to the SSD1306.
virtual Display::State state ()
 Get the current state of the SSD1306.
virtual void state (State s)
 Set the state of the SSD1306.
virtual void drawPixel (int x, int y, unsigned int c)
 Draw a single pixel at the specified coordinates.
virtual void clear (unsigned int c=0xFF000000)
 Fill the entire canvas with the specified color using a filled rectangle.
virtual void drawLine (int x0, int y0, int x1, int y1, unsigned int c)
 Draw a line between the specified coordinates using Bresenham's line algorithm.
virtual void drawHLine (int x, int y, int w, unsigned int c)
 Draw a fast horizontal line of the specified width, at the specified coordinates.
virtual void drawVLine (int x, int y, int h, unsigned int c)
 Draw a fast vertical line of the specified height, at the specified coordinates.
virtual void drawRect (int x, int y, int w, int h, unsigned int c)
 Draw an unfilled rectangle of the specified width and height, at the specified coordinates using fast lines.
virtual void fillRect (int x, int y, int w, int h, unsigned int c)
 Draw a filled rectangle of the specified width and height, at the specified coordinates using fast lines.
void drawTriangle (int x0, int y0, int x1, int y1, int x2, int y2, unsigned int c)
 Draw an unfilled triangle with the specified vertices using lines.
void fillTriangle (int x0, int y0, int x1, int y1, int x2, int y2, unsigned int c)
 Draw a filled triangle with the specified vertices using Adafruit's algorithm.
void drawCircle (int x, int y, int r, unsigned int c)
 Draw an unfilled circle of the specified radius, at the specified coordinates using the midpoint circle algorithm.
void fillCircle (int x, int y, int r, unsigned int c)
 Draw a filled circle of the specified radius, at the specified coordinates using Adafruit's modified midpoint circle algorithm.
void drawRoundRect (int x, int y, int w, int h, int r, unsigned int c)
 Draw an unfilled rounded rectangle of the specified width, height, and corner radius, at the specified coordinates using Adafruit's algorithm.
void fillRoundRect (int x, int y, int w, int h, int r, unsigned int c)
 Draw a filled rounded rectangle of the specified width, height, and corner radius, at the specified coordinates using Adafruit's algorithm.
void drawImage (Image *img, int x, int y)
 Draw an Image object at the specified coordinates.
int drawChar (char c, Font *fnt, int x, int y)
 Draw a character at the specified coordinates without wrapping.
void drawString (const char *str, Font *fnt, int x, int y)
 Draw a string at the specified coordinates without wrapping.
void drawString (const char *str, Font *fnt, int x, int y, int w, int h)
 Draw a string within the specified rectangle with wrapping.
int width ()
 Get the width of the canvas.
int height ()
 Get the height of the canvas.

Detailed Description

SSD1306_SPI class.

Used for controlling an SSD1306-based OLED display connected to SPI.

Definition at line 26 of file SSD1306_SPI.h.


Member Enumeration Documentation

enum State [inherited]

Represents the state of the Display.

Enumerator:
NOT_INITIALIZED 

Display has not been initialized yet.

DISPLAY_OFF 

Display is initialized and turned off.

DISPLAY_ON 

Display is initialized and turned on.

Definition at line 31 of file Display.h.


Constructor & Destructor Documentation

SSD1306_SPI ( PinName  mosi,
PinName  miso,
PinName  sclk,
PinName  cs,
PinName  dc 
)

Create an SSD1306 object connected to the specified SPI pins with the specified /CS and DC pins.

Parameters:
mosiThe SPI data out pin.
misoThe SPI data in pin.
sclkThe SPI clock pin.
sclkThe SPI chip select pin.
sclkThe data/command pin.

Definition at line 19 of file SSD1306_SPI.cpp.


Member Function Documentation

void clear ( unsigned int  c = 0xFF000000 ) [virtual, inherited]

Fill the entire canvas with the specified color using a filled rectangle.

Parameters:
cThe color to fill with as a 32-bit ARGB value (black by default).

Definition at line 25 of file Canvas.cpp.

int drawChar ( char  c,
Font fnt,
int  x,
int  y 
) [inherited]

Draw a character at the specified coordinates without wrapping.

Parameters:
cThe character to draw.
fntPointer to the font to draw with.
xThe starting X coordinate.
yThe starting Y coordinate.
Returns:
The width of the drawn character.

Definition at line 288 of file Canvas.cpp.

void drawCircle ( int  x,
int  y,
int  r,
unsigned int  c 
) [inherited]

Draw an unfilled circle of the specified radius, at the specified coordinates using the midpoint circle algorithm.

Parameters:
xThe center X coordinate.
yThe center Y coordinate.
rThe radius of the circle.
cThe color of the circle as a 32-bit ARGB value.

Definition at line 215 of file Canvas.cpp.

void drawHLine ( int  x,
int  y,
int  w,
unsigned int  c 
) [virtual, inherited]

Draw a fast horizontal line of the specified width, at the specified coordinates.

Parameters:
xThe starting X coordinate.
yThe starting Y coordinate.
wThe width of the line.
cThe color of the line as a 32-bit ARGB value.

Definition at line 80 of file Canvas.cpp.

void drawImage ( Image img,
int  x,
int  y 
) [inherited]

Draw an Image object at the specified coordinates.

Parameters:
imgPointer to the image to draw.
xThe starting X coordinate.
yThe starting Y coordinate.

Definition at line 279 of file Canvas.cpp.

void drawLine ( int  x0,
int  y0,
int  x1,
int  y1,
unsigned int  c 
) [virtual, inherited]

Draw a line between the specified coordinates using Bresenham's line algorithm.

Parameters:
x0The starting X coordinate.
y0The starting Y coordinate.
x1The ending X coordinate.
y1The ending Y coordinate.
cThe color of the line as a 32-bit ARGB value.

Definition at line 30 of file Canvas.cpp.

void drawPixel ( int  x,
int  y,
unsigned int  c 
) [virtual]

Draw a single pixel at the specified coordinates.

Parameters:
xThe X coordinate.
yThe Y coordinate.
cThe color of the pixel as a 32-bit ARGB value.

Implements Canvas.

Definition at line 103 of file SSD1306_SPI.cpp.

void drawRect ( int  x,
int  y,
int  w,
int  h,
unsigned int  c 
) [virtual, inherited]

Draw an unfilled rectangle of the specified width and height, at the specified coordinates using fast lines.

Parameters:
xThe starting X coordinate.
yThe starting Y coordinate.
wThe width of the rectangle.
hThe height of the rectangle.
cThe color of the rectangle as a 32-bit ARGB value.

Definition at line 90 of file Canvas.cpp.

void drawRoundRect ( int  x,
int  y,
int  w,
int  h,
int  r,
unsigned int  c 
) [inherited]

Draw an unfilled rounded rectangle of the specified width, height, and corner radius, at the specified coordinates using Adafruit's algorithm.

Parameters:
xThe starting X coordinate.
yThe starting Y coordinate.
wThe width of the rectangle.
hThe height of the rectangle.
rThe radius of the corners.
cThe color of the rectangle as a 32-bit ARGB value.

Definition at line 254 of file Canvas.cpp.

void drawString ( const char *  str,
Font fnt,
int  x,
int  y,
int  w,
int  h 
) [inherited]

Draw a string within the specified rectangle with wrapping.

Parameters:
strPointer to the string to draw.
fntPointer to the font to draw with.
xThe starting X coordinate.
yThe starting Y coordinate.
wThe width of the bounding rectangle.
hThe height of the bounding rectangle.

Definition at line 329 of file Canvas.cpp.

void drawString ( const char *  str,
Font fnt,
int  x,
int  y 
) [inherited]

Draw a string at the specified coordinates without wrapping.

Parameters:
strPointer to the string to draw.
fntPointer to the font to draw with.
xThe starting X coordinate.
yThe starting Y coordinate.

Definition at line 300 of file Canvas.cpp.

void drawTriangle ( int  x0,
int  y0,
int  x1,
int  y1,
int  x2,
int  y2,
unsigned int  c 
) [inherited]

Draw an unfilled triangle with the specified vertices using lines.

Parameters:
x0The first vertex X coordinate.
y0The first vertex Y coordinate.
x1The second vertex X coordinate.
y1The second vertex Y coordinate.
x2The third vertex X coordinate.
y2The third vertex Y coordinate.
cThe color of the triangle as a 32-bit ARGB value.

Definition at line 105 of file Canvas.cpp.

void drawVLine ( int  x,
int  y,
int  h,
unsigned int  c 
) [virtual, inherited]

Draw a fast vertical line of the specified height, at the specified coordinates.

Parameters:
xThe starting X coordinate.
yThe starting Y coordinate.
hThe height of the line.
cThe color of the line as a 32-bit ARGB value.

Definition at line 85 of file Canvas.cpp.

void fillCircle ( int  x,
int  y,
int  r,
unsigned int  c 
) [inherited]

Draw a filled circle of the specified radius, at the specified coordinates using Adafruit's modified midpoint circle algorithm.

Parameters:
xThe center X coordinate.
yThe center Y coordinate.
rThe radius of the circle.
cThe color of the circle as a 32-bit ARGB value.

Definition at line 248 of file Canvas.cpp.

void fillRect ( int  x,
int  y,
int  w,
int  h,
unsigned int  c 
) [virtual, inherited]

Draw a filled rectangle of the specified width and height, at the specified coordinates using fast lines.

Parameters:
xThe starting X coordinate.
yThe starting Y coordinate.
wThe width of the rectangle.
hThe height of the rectangle.
cThe color of the rectangle as a 32-bit ARGB value.

Definition at line 98 of file Canvas.cpp.

void fillRoundRect ( int  x,
int  y,
int  w,
int  h,
int  r,
unsigned int  c 
) [inherited]

Draw a filled rounded rectangle of the specified width, height, and corner radius, at the specified coordinates using Adafruit's algorithm.

Parameters:
xThe starting X coordinate.
yThe starting Y coordinate.
wThe width of the rectangle.
hThe height of the rectangle.
rThe radius of the corners.
cThe color of the rectangle as a 32-bit ARGB value.

Definition at line 269 of file Canvas.cpp.

void fillTriangle ( int  x0,
int  y0,
int  x1,
int  y1,
int  x2,
int  y2,
unsigned int  c 
) [inherited]

Draw a filled triangle with the specified vertices using Adafruit's algorithm.

Parameters:
x0The first vertex X coordinate.
y0The first vertex Y coordinate.
x1The second vertex X coordinate.
y1The second vertex Y coordinate.
x2The third vertex X coordinate.
y2The third vertex Y coordinate.
cThe color of the triangle as a 32-bit ARGB value.

Definition at line 112 of file Canvas.cpp.

void flush (  ) [virtual]

Send the buffer to the SSD1306.

Reimplemented from Display.

Definition at line 63 of file SSD1306_SPI.cpp.

int height (  ) [inherited]

Get the height of the canvas.

Returns:
The height of the canvas.

Definition at line 427 of file Canvas.cpp.

bool open (  ) [virtual]

Probe for the SSD1306 and initialize it if present.

Returns:
'true' if the device exists on the bus, 'false' if the device doesn't exist on the bus.

Implements Display.

Definition at line 31 of file SSD1306_SPI.cpp.

void state ( State  s ) [virtual]

Set the state of the SSD1306.

Parameters:
modeThe new state as a Display::State enum.

Reimplemented from Display.

Definition at line 88 of file SSD1306_SPI.cpp.

Display::State state (  ) [virtual]

Get the current state of the SSD1306.

Returns:
The current state as a Display::State enum.

Reimplemented from Display.

Definition at line 82 of file SSD1306_SPI.cpp.

int width (  ) [inherited]

Get the width of the canvas.

Returns:
The width of the canvas.

Definition at line 422 of file Canvas.cpp.