Giter VIP home page Giter VIP logo

ssd1351-driver-library's Introduction

SSD1351 Driver Library

Driver library for the SSD1351 128x128 RGB OLED Display intended for generic use with C in any microcontroller/device. Includes an emulator to run and test programs that use this library on Windows.

Remember to configure the ssd1351.h file GPIO, SPI definitions according to your own hardware

Check the blog entry

Features:

  • Drawing sprites
  • Importing sprites from a .bmp file made in Aseprite
  • Formatted string printing
  • Drawing single pixels
  • Drawing lines
  • Drawing rectangles and filled rectangles
  • Drawing circles and filled circles
  • Display configuration
  • RGB color encoding
  • Screen emulator for Windows

To Do:

  • Extend Display configurations such as color depth, frequency, etc.

Converting sprites

Load a bitmap image created with Aseprite to the same folder where ConvertSprites.py is located, then call:

python3 ConvertSprites.py "<sprite-name0>.bmp"[, "<sprite-name1>.bmp", ...]

Loaded_sprites.c, Loaded_sprites.h and color_palette.c files will be generated with the converted sprites.

Note that the color palette used in Aseprite will be translated to the equivalent colors under the library's color mode and this will be performed just once, so make sure to use the same palette across all the sprites.

Examples

Check the releases to find a sample project that uses this library for the following boards:

Running the emulator

An emulator written in Go is located under SSD1351_Emulator. To use it run the following command inside SSD1351_Emulator:

go run .

It will open a socket on port 9988 and listen for incoming screen data. To see it in action, simply compile and run the program under example_with_emulator_WIN. Note that this example program runs only on Windows.

See the releases section if you're only interested in the binaries for both the demo program and the emulator. Emulator and example binaries

Demo

Sample code includes three demos; printing, lines, circles and a sprite

#include "ssd1351.h" // Remember to configure this file to your own hardware
#include "math.h"
#include "stdlib.h"

#define DEMO_RECTANGLES

int main(){
  SSD1351_init();
  SSD1351_fill(COLOR_BLACK);
  SSD1351_update();
  int r = 50;
  int g = 100;
  int b = 240;
  int gd = 1;
#ifdef DEMO_CIRCLES
  int c0, c1, c2, c3, c4;
  c0 = 5;
  c1 = 25;
  c2 = 45;
  c3 = 65;
  c4 = 85;
#endif // DEMO_CIRCLES
  while(1){
#ifdef DEMO_PRINT
    //          D E M O    P R I N T
    SSD1351_set_cursor(0, 0);
    SSD1351_printf(SSD1351_get_rgb(r, g, b), med_font, "Hello worldI spent \n%i %s\n", 17, "dollars");
    SSD1351_printf(COLOR_RED, small_font, "\nfor this");
    SSD1351_printf(SSD1351_get_rgb(245, 255, 20), big_font, "\nSSD1351");
    if (gd){
      g+=3;
      b-=3;
    }
    else{
      g-=3;
      b+=3;
    }
    if( b <= 100){
      gd = !gd;
    }
    else if (g <= 100){
      gd = !gd;
    }
#endif // DEMO_PRINT
#ifdef DEMO_RECTANGLES
    //          D E M O    R E C T A N G L E S
    for (int i = 128; i > 0;i-=12){
      SSD1351_draw_filled_rect( 64 - i/2, 64 - i/2, i, i, 0x1111 + rand());
    }
#endif // DEMO_RECTANGLES
#ifdef DEMO_CIRCLES
    //          D E M O    C I R C L E S
    c0+=5;
    c1+=5;
    c2+=5;
    c3+=5;
    c4+=5;
    if (c0 > 90){
      c0 = 5;
    }
    if (c1 > 90){
      c1 = 5;
    }
    if (c2 > 90){
      c2 = 5;
    }
    if (c3 > 90){
      c3 = 5;
    }
    if (c4 > 90){
      c4 = 5;
    }
    int arr[5] = {c0, c1, c2, c3, c4};
    int blu[5] = {150, 190, 250, 190, 150};
    int green[5] = {50, 80, 130, 80, 50};
    int maxi, max = 0;
    for (int k = 0; k < 5; k++){
      max = 0;
      for (int j = 0; j < 5; j++){
        if (arr[j] > max){
          max = arr[j];
          maxi = j;
        }
      }
      SSD1351_draw_filled_circle(64, 64, arr[maxi], SSD1351_get_rgb(20, green[maxi], blu[maxi]));
      arr[maxi] = 0;
    }
#endif // DEMO_CIRCLES
  //          D E M O    S P R I T E S
#ifdef DEMO_SPRITES
SSD1351_draw_sprite(0, 0, &sprite0);
#endif // DEMO_SPRITES
    SSD1351_update();
    HAL_Delay(33);
  }
}

ssd1351-driver-library's People

Contributors

dependabot[bot] avatar gecko05 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ssd1351-driver-library's Issues

Create configuration options

Need to be able to use functions to configure different settings during initialization instead of writing the commands by hand.

Write a font converter

A program to convert font files to C arrays in a similar fashion to the sprite converter.

Make it easier to integrate

It's not very clear how to integrate this library into a hardware project. Need some platform code and examples for the most used microcontroller manufacturers.

Write an emulator for the SSD1351 display

An emulator would be really useful in testing drawing routines without needing to flash and run it on the target hardware.
It should pull the files from the library and be located on a different directory to not confuse the users with having all the files in the same place.

Rewrite the fonts implementation

The current font implementation doesn't allow for fonts wider than 16 px and wastes memory space when fonts are smaller. Need to write a more flexible implementation that saves space when fonts are small and allows for different widths.

Support for drawing "in-place"

Currently the whole screen needs to be redrawn each time something changes, no matter how small the change is. In order to possibly improve energy consumption, finding a way to just modify a smaller section of the screen would be a great addition. Some investigation is needed to figure out if this is feasible.
SSD1351_v1.5.pdf

Add pico8 sprite support

Write a script to easily convert the sprite data in a pico8 cartridge to sprites that this library can use.

Add support for other bmp files

Currently only Aseprite is guaranteed to work when converting bitmap images to sprites. Being able to convert bitmap images created in other tools like MS Paint is desired.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.