I've successfully created a set of core, display driver, and project config libraries for an SSD1351 OLED display (adafruit's breakout board).
How it works:
- uGFX is added in arduino's library folder. It doesn't work as an arduino library, though, but there's a wrapper for that.
- ugfx-arduino is a simple library that includes ugfx's single-file-source and the main header (gfx.h). gfx.h is found in the ugfx directory, so arduino will add that to the compiler's include path. We can exploit this to include src/gfx_mk.c, which is the one file we need to compile to use ugfx.
- ugfx-arduino-ssd1351 is a driver library that has two interfaces: one for ugfx and one for the actual application: pin numbers must be set, and they should not be picked by the driver, but by the application.
- teensy3.1-ssd1351-ugfx-config is the project-specific library that configures ugfx and the driver for a specific sketch.
I have not yet found a way of getting rid of the config library, but I think that's not too bad.
So let's sum it up!
ugfx-arduino
The wrapper around ugfx, to make the include path and core available.
<sketchbook>/libraries/ugfx-arduino/ugfx-arduino.h:
#ifndef UGFX_ARDUINO_H
#define UGFX_ARDUINO_H
#include <gfx.h>
#endif // UGFX_ARDUINO_H
<sketchbook>/libraries/ugfx-arduino/ugfx-arduino.c:#include "src/gfx_mk.c"
ugfx-arduino-ssd1351
A driver I adapted from the ugfx sources. I'll not include the code here because it's simply too much, but this is the place where ugfx is told about the driver's features in gdisp_lld_config.h:
<sketchbook>/libraries/ugfx-arduino-ssd1351/ . ├── board_SSD1351.cpp ├── board_SSD1351.h ├── gdisp_lld_config.h ├── gdisp_lld_SSD1351.c ├── SSD1351.h └── ugfx-arduino-ssd1351.hThe board_ files include hardware specific code, and the initialization and updating logic is in gdisp_lld_SSD1351.c. The code for this driver can be found on github, see links.
teensy3.1-ssd1351-ugfx-config
#ifndef _GFXCONF_H
#define _GFXCONF_H
/* The operating system to use. One of these must be defined - preferably in your Makefile */
//#define GFX_USE_OS_CHIBIOS FALSE
//#define GFX_USE_OS_WIN32 FALSE
//#define GFX_USE_OS_LINUX FALSE
//#define GFX_USE_OS_OSX FALSE
#define GFX_USE_OS_ARDUINO TRUE
//#define GFX_USE_OS_RAW32 TRUE
/* GFX sub-systems to turn on */
#define GFX_USE_GDISP TRUE
/* Features for the GDISP sub-system. */
#define GDISP_NEED_VALIDATION TRUE
#define GDISP_NEED_CLIP TRUE
#endif /* _GFXCONF_H */
Nothing surprising here if you have already used ugfx.#ifndef UGFX_ARDUINO_SSD1351_PINS_H
#define UGFX_ARDUINO_SSD1351_PINS_H
#define GPIO_DC 16
#define GPIO_RESET 15
#define GPIO_CS 14
#endif // UGFX_ARDUINO_SSD1351_PINS_H
the driver library needs these three pin defines to work.#ifndef TEENSY31_SSD1351_UGFX_CONFIG_H
#define TEENSY31_SSD1351_UGFX_CONFIG_H
#include <ugfx-arduino.h> // main library
#include <ugfx-arduino-ssd1351.h> // display driver library
#endif // TEENSY31_SSD1351_UGFX_CONFIG_H
so this file just pulls everything into our project.Sketch
#include <teensy3.1-ssd1351-ugfx-config.h>
#include <SPI.h>
void setup() {
coord_t width, height;
coord_t i, j;
SPI.begin();
// Initialize and clear the display
gfxInit();
// Get the screen size
width = gdispGetWidth();
height = gdispGetHeight();
// Code Here
gdispDrawBox(10, 10, width / 2, height / 2, Yellow);
gdispFillArea(width / 2, height / 2, width / 2 - 10, height / 2 - 10, Blue);
gdispDrawLine(5, 30, width - 50, height - 40, Red);
for (i = 5, j = 0; i < width && j < height; i += 7, j += i / 20)
gdispDrawPixel(i, j, White);
SPI.end();
}
void loop() {
}
Code is on github, see link section of this project. It should get you started if you want to make your own driver libs.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.