Kevin Kadooka / SSD1351

Dependencies:   BurstSPI

Embed: (wiki syntax)

« Back to documentation index

SSD1351 Class Reference

SSD1351 Class Reference

SSD1351 Library for STM32F401RE Nucleo or STMstation P.1 development boards - may work with other targets, but not tested yet. More...

#include <SSD1351.h>

Public Member Functions

 SSD1351 (PinName mosi_pin, PinName sclk_pin, PinName dc_pin, PinName cs_pin, PinName rst_pin)
 Connect to an SSD1351 on specified pins Connect to: (MOSI, SCLK) <-- Native SPI pins (DC, CS, RST) <-- Any digital pins.
 SSD1351 ()
 Connect to SSD1351 on STMstation P.1, or default pins specified in defines in SSD1351.h Default pins are: MOSI PA_7 SCLK PA_5 CS PA_6 DC PC_5 RST PA_4.
void enableWrite ()
 Enable writing directly to the VRAM.
void fillBuf (uint16_t fillcolor)
 Fill the buffer with a single color.
void writeBuf ()
 Write the buffer to the VRAM.
void drawSpritePtr (const uint16_t s[], int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t mask)
 Draw a sprite from flash memory, into the buffer.
void fillCMask (uint8_t state)
 Fill the collision mask with a single value.
void drawCMask (const uint16_t s[], int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t mask, uint8_t state)
 Draw a sprite from flash memory, into the collision map.
uint8_t checkCollision (const uint16_t s[], int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t mask)
 Check if a sprite (not yet written to collision map) is going to collide with anything.
void drawChar (char c, int16_t x, int16_t y, uint16_t color, uint8_t zoom)
 Draw a single character.
void printText (const char c[], int16_t x, int16_t y, uint16_t color, uint8_t zoom)
 Draw a single character.
void setBuf (uint8_t *_buf)
 Set the display buffer.
void setCMask (uint8_t *_cmask)
 Set the collision map.
void fillRect (int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t color)
 Draw a filled rectangle to buffer.
void openRect (int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t color)
 Draw a open rectangle to buffer.
void drawHLine (int16_t x, int16_t y, int16_t length, uint16_t color)
 Draw a horizontal line without position calculations.
void drawVLine (int16_t x, int16_t y, int16_t length, uint16_t color)
 Draw a vertical line without position calculations.
void drawLine (int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color)
 Draw a line using Bresenham algorithm.
void openCircle (int16_t x0, int16_t y0, uint16_t radius, uint16_t color)
 Draw open circle.
void fillCircle (int16_t x0, int16_t y0, uint16_t radius, uint16_t color)
 Draw filled circle.

Detailed Description

SSD1351 Library for STM32F401RE Nucleo or STMstation P.1 development boards - may work with other targets, but not tested yet.

Standard mbed SPI library is VERY slow, limiting frame rate. Using EricWieser's BurstSPI (which fixes compilation errors on the STM32F4XX improves throughput significantly.

Tested on SSD1351 P/N UG-2828GDEDF11. May work with other SSD1351 panels but this is untested.

Example:

  #include "mbed.h"
  #include "SSD1351.h"

  uint8_t buffer[128*128*2];

  SSD1351 oled;
  //SSD1351 oled(PA_7,PA_5,PA_6,PC_5,PA_4);
  

  int main(){
      oled.enableWrite();
      oled.setBuf(buffer);
      oled.fillBuf(0x0000);
      oled.printText("Hello World!",0,0,0x07E0,1)
      oled.writeBuf();
  }

Definition at line 77 of file SSD1351.h.


Constructor & Destructor Documentation

SSD1351 ( PinName  mosi_pin,
PinName  sclk_pin,
PinName  dc_pin,
PinName  cs_pin,
PinName  rst_pin 
)

Connect to an SSD1351 on specified pins Connect to: (MOSI, SCLK) <-- Native SPI pins (DC, CS, RST) <-- Any digital pins.

Definition at line 17 of file SSD1351.cpp.

SSD1351 (  )

Connect to SSD1351 on STMstation P.1, or default pins specified in defines in SSD1351.h Default pins are: MOSI PA_7 SCLK PA_5 CS PA_6 DC PC_5 RST PA_4.

Definition at line 22 of file SSD1351.cpp.


Member Function Documentation

uint8_t checkCollision ( const uint16_t  s[],
int16_t  x,
int16_t  y,
uint16_t  w,
uint16_t  h,
uint16_t  mask 
)

Check if a sprite (not yet written to collision map) is going to collide with anything.

Parameters:
s[]Sprite containing unsigned 16-bit 565 RGB values (1D vector)
xx-coordinate of sprite
yy-coordinate of sprite
wWidth of sprite
hHeight of sprite
maskThis value in the sprite is "skipped" - transparancy value

Definition at line 513 of file SSD1351.cpp.

void drawChar ( char  c,
int16_t  x,
int16_t  y,
uint16_t  color,
uint8_t  zoom 
)

Draw a single character.

Parameters:
cASCII character
xx-coordinate of character
yy-coordinate of character
colorUnsigned 16-bit 565 RGB
zoomScaling factor

Definition at line 544 of file SSD1351.cpp.

void drawCMask ( const uint16_t  s[],
int16_t  x,
int16_t  y,
uint16_t  w,
uint16_t  h,
uint16_t  mask,
uint8_t  state 
)

Draw a sprite from flash memory, into the collision map.

Parameters:
s[]Sprite containing unsigned 16-bit 565 RGB values (1D vector)
xx-coordinate of sprite
yy-coordinate of sprite
wWidth of sprite
hHeight of sprite
maskThis value in the sprite is "skipped" - transparancy value
stateValue written to the collision map

Definition at line 483 of file SSD1351.cpp.

void drawHLine ( int16_t  x,
int16_t  y,
int16_t  length,
uint16_t  color 
)

Draw a horizontal line without position calculations.

Parameters:
xx-coordinate
yy-coordinate
lengthLength, can be positive or negative
colorUnsigned 16-bit 565 RGB

Definition at line 252 of file SSD1351.cpp.

void drawLine ( int16_t  x1,
int16_t  y1,
int16_t  x2,
int16_t  y2,
uint16_t  color 
)

Draw a line using Bresenham algorithm.

Parameters:
x1Start x-coordinate
y1Start y-coordinate
x2End x-coordinate
y2End y-coordinate
colorUnsigned 16-bit 565 RGB

Definition at line 320 of file SSD1351.cpp.

void drawSpritePtr ( const uint16_t  s[],
int16_t  x,
int16_t  y,
uint16_t  w,
uint16_t  h,
uint16_t  mask 
)

Draw a sprite from flash memory, into the buffer.

Parameters:
s[]Sprite containing unsigned 16-bit 565 RGB values (1D vector)
xx-coordinate of sprite
yy-coordinate of sprite
wWidth of sprite
hHeight of sprite
maskThis value in the sprite is "skipped" - transparancy value

Definition at line 445 of file SSD1351.cpp.

void drawVLine ( int16_t  x,
int16_t  y,
int16_t  length,
uint16_t  color 
)

Draw a vertical line without position calculations.

Parameters:
xx-coordinate
yy-coordinate
lengthLength, can be positive or negative
colorUnsigned 16-bit 565 RGB

Definition at line 286 of file SSD1351.cpp.

void enableWrite (  )

Enable writing directly to the VRAM.

This must be called at least once before calling writeBuf().

Definition at line 164 of file SSD1351.cpp.

void fillBuf ( uint16_t  fillcolor )

Fill the buffer with a single color.

Parameters:
fillcolorUnsigned 16-bit 565 RGB

Definition at line 178 of file SSD1351.cpp.

void fillCircle ( int16_t  x0,
int16_t  y0,
uint16_t  radius,
uint16_t  color 
)

Draw filled circle.

Parameters:
x0Center x-coordinate
y0Center y-coordinate
radiusCircle radius
colorUnsigned 16-bit 565 RGB

Definition at line 417 of file SSD1351.cpp.

void fillCMask ( uint8_t  state )

Fill the collision mask with a single value.

Parameters:
stateFill value

Definition at line 476 of file SSD1351.cpp.

void fillRect ( int16_t  x,
int16_t  y,
uint16_t  w,
uint16_t  h,
uint16_t  color 
)

Draw a filled rectangle to buffer.

Parameters:
xx-coordinate
yy-coordinate
wWidth
hHeight
colorUnsigned 16-bit 565 RGB

Definition at line 193 of file SSD1351.cpp.

void openCircle ( int16_t  x0,
int16_t  y0,
uint16_t  radius,
uint16_t  color 
)

Draw open circle.

Parameters:
x0Center x-coordinate
y0Center y-coordinate
radiusCircle radius
colorUnsigned 16-bit 565 RGB

Definition at line 368 of file SSD1351.cpp.

void openRect ( int16_t  x,
int16_t  y,
uint16_t  w,
uint16_t  h,
uint16_t  color 
)

Draw a open rectangle to buffer.

Parameters:
xx-coordinate
yy-coordinate
wWidth
hHeight
colorUnsigned 16-bit 565 RGB

Definition at line 222 of file SSD1351.cpp.

void printText ( const char  c[],
int16_t  x,
int16_t  y,
uint16_t  color,
uint8_t  zoom 
)

Draw a single character.

Parameters:
cChar array
xx-coordinate of character
yy-coordinate of character
colorUnsigned 16-bit 565 RGB
zoomScaling factor

Definition at line 578 of file SSD1351.cpp.

void setBuf ( uint8_t *  _buf )

Set the display buffer.

Parameters:
_bufBuffer, must be uint8_t name[32768]

Definition at line 29 of file SSD1351.cpp.

void setCMask ( uint8_t *  _cmask )

Set the collision map.

Parameters:
_cmaskCollision map, must be uint8_t name[16384]

Definition at line 34 of file SSD1351.cpp.

void writeBuf (  )

Write the buffer to the VRAM.

Make sure you call enableWrte() before doing this!

Definition at line 186 of file SSD1351.cpp.