UniGraphic-Fork for ST7920-LCD-controller and SH1106. Tested with 128x64 LCD with SPI and 128x64-OLED with IIC

Dependents:   UniGraphic-St7920-Test AfficheurUTILECO

Fork of UniGraphic by GraphicsDisplay

Fork of the UniGraphic-Library for monochrome LCDs with ST7920 controller and 128x64-IIC-OLED-Display with SH1106-Controller

/media/uploads/charly/20170522_210344.jpg

/media/uploads/charly/20180425_230623.jpg

Had to adapt LCD for following reasons:

  • Give access to screenbuffer buffer[] to parent class
  • pixel() and pixel_read() as they are hardware-dependent
  • added reset-pin to IIC-Interface

GraphicDisplay:: sends buffer to LCD when auto_update is set to true.

Testprogram for ST7920 can be found here:

https://developer.mbed.org/users/charly/code/UniGraphic-St7920-Test/

Committer:
charly
Date:
Sun Apr 22 21:41:24 2018 +0000
Revision:
36:668396f861d2
Parent:
33:f87f06292637
Child:
37:5de028b08308
Added SH1106 for OLED Display 128x64 via IIC

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dreschpe 12:9c8f3076347c 1 #ifndef MBED_SSD1306_H
dreschpe 12:9c8f3076347c 2 #define MBED_SSD1306_H
dreschpe 12:9c8f3076347c 3
dreschpe 12:9c8f3076347c 4 #include "mbed.h"
dreschpe 12:9c8f3076347c 5 #include "LCD.h"
dreschpe 12:9c8f3076347c 6
dreschpe 14:29bab588ba75 7 /** Class for SSD1306 display controller
dreschpe 12:9c8f3076347c 8 * to be copypasted and adapted for other controllers
dreschpe 12:9c8f3076347c 9 */
dreschpe 12:9c8f3076347c 10 class SSD1306 : public LCD
dreschpe 12:9c8f3076347c 11 {
dreschpe 12:9c8f3076347c 12
dreschpe 12:9c8f3076347c 13 public:
dreschpe 12:9c8f3076347c 14
dreschpe 12:9c8f3076347c 15 /** Create a PAR display interface
dreschpe 12:9c8f3076347c 16 * @param displayproto only supports PAR_8
dreschpe 12:9c8f3076347c 17 * @param port GPIO port name to use
dreschpe 12:9c8f3076347c 18 * @param CS pin connected to CS of display
dreschpe 12:9c8f3076347c 19 * @param reset pin connected to RESET of display
dreschpe 12:9c8f3076347c 20 * @param DC pin connected to data/command of display
dreschpe 12:9c8f3076347c 21 * @param WR pin connected to SDI of display
dreschpe 12:9c8f3076347c 22 * @param RD pin connected to RS of display
dreschpe 12:9c8f3076347c 23 * @param name The name used by the parent class to access the interface
dreschpe 12:9c8f3076347c 24 * @param LCDSIZE_X x size in pixel - optional
dreschpe 12:9c8f3076347c 25 * @param LCDSIZE_Y y size in pixel - optional
dreschpe 12:9c8f3076347c 26 */
dreschpe 12:9c8f3076347c 27 SSD1306(proto_t displayproto, PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char* name, unsigned int LCDSIZE_X = 128, unsigned int LCDSIZE_Y = 64);
dreschpe 12:9c8f3076347c 28
dreschpe 12:9c8f3076347c 29 /** Create an SPI display interface
Geremia 18:ffa58f1a680a 30 * @param displayproto SPI_8 or SPI_16
dreschpe 12:9c8f3076347c 31 * @param Hz SPI speed in Hz
dreschpe 12:9c8f3076347c 32 * @param mosi SPI pin
dreschpe 12:9c8f3076347c 33 * @param miso SPI pin
dreschpe 12:9c8f3076347c 34 * @param sclk SPI pin
dreschpe 12:9c8f3076347c 35 * @param CS pin connected to CS of display
dreschpe 12:9c8f3076347c 36 * @param reset pin connected to RESET of display
dreschpe 12:9c8f3076347c 37 * @param DC pin connected to data/command of display
dreschpe 12:9c8f3076347c 38 * @param name The name used by the parent class to access the interface
dreschpe 12:9c8f3076347c 39 * @param LCDSIZE_X x size in pixel - optional
dreschpe 12:9c8f3076347c 40 * @param LCDSIZE_Y y size in pixel - optional
dreschpe 12:9c8f3076347c 41 */
dreschpe 12:9c8f3076347c 42 SSD1306(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const char* name , unsigned int LCDSIZE_X = 128, unsigned int LCDSIZE_Y = 64);
Geremia 15:b9483ba842c8 43
dreschpe 33:f87f06292637 44 /** Create an I2C display interface
dreschpe 33:f87f06292637 45 * @param displayproto I2C_
dreschpe 33:f87f06292637 46 * @param Hz I2C speed in Hz
dreschpe 33:f87f06292637 47 * @param address I2C address
dreschpe 33:f87f06292637 48 * @param sda I2C pin
dreschpe 33:f87f06292637 49 * @param scl I2C pin
charly 36:668396f861d2 50 * @param reset pin connected to RESET of display
dreschpe 33:f87f06292637 51 * @param name The name used by the parent class to access the interface
dreschpe 33:f87f06292637 52 * @param LCDSIZE_X x size in pixel - optional
dreschpe 33:f87f06292637 53 * @param LCDSIZE_Y y size in pixel - optional
dreschpe 33:f87f06292637 54 */
charly 36:668396f861d2 55 SSD1306(proto_t displayproto, int Hz, int address, PinName sda, PinName scl, PinName reset, const char* name , unsigned int LCDSIZE_X = 128, unsigned int LCDSIZE_Y = 64);
dreschpe 33:f87f06292637 56
dreschpe 33:f87f06292637 57
dreschpe 33:f87f06292637 58
Geremia 15:b9483ba842c8 59 /** set the contrast of the screen
Geremia 15:b9483ba842c8 60 * @note here overrided because of not standard value range
Geremia 15:b9483ba842c8 61 * @param o contrast 0-255
Geremia 15:b9483ba842c8 62 */
Geremia 15:b9483ba842c8 63 virtual void set_contrast(int o);
Geremia 15:b9483ba842c8 64
dreschpe 17:1dafb896c6f5 65 /** set automatc horizontal scroll mode
dreschpe 17:1dafb896c6f5 66 * @param l_r direction - left = 0, right = 1
dreschpe 17:1dafb896c6f5 67 * @param s_page start page
dreschpe 17:1dafb896c6f5 68 * @param e_page end page
dreschpe 17:1dafb896c6f5 69 * @param speed time between horizontal shift. 0 slow .. 7 fast
dreschpe 17:1dafb896c6f5 70 */
charly 36:668396f861d2 71
charly 36:668396f861d2 72 /** Framebuffer is used, it needs to be sent to LCD from time to time
charly 36:668396f861d2 73 */
charly 36:668396f861d2 74 virtual void copy_to_lcd();
charly 36:668396f861d2 75
charly 36:668396f861d2 76 /** clear the entire screen
charly 36:668396f861d2 77 */
charly 36:668396f861d2 78 virtual void cls();
charly 36:668396f861d2 79
charly 36:668396f861d2 80 /** Draw a pixel in the specified color.
charly 36:668396f861d2 81 * @param x is the horizontal offset to this pixel.
charly 36:668396f861d2 82 * @param y is the vertical offset to this pixel.
charly 36:668396f861d2 83 * @param color defines the color for the pixel.
charly 36:668396f861d2 84 */
charly 36:668396f861d2 85 virtual void pixel(int x, int y, unsigned short color);
charly 36:668396f861d2 86
dreschpe 17:1dafb896c6f5 87 void horizontal_scroll(int l_r,int s_page,int e_page,int speed);
dreschpe 17:1dafb896c6f5 88
dreschpe 17:1dafb896c6f5 89 /** automatic horizontal + vertical scroll mode
dreschpe 17:1dafb896c6f5 90 * @param l_r direction - left = 0, right = 1
dreschpe 17:1dafb896c6f5 91 * @param s_page start page
dreschpe 17:1dafb896c6f5 92 * @param e_page end page
dreschpe 17:1dafb896c6f5 93 * @param v_off vertical offset for scroll
dreschpe 17:1dafb896c6f5 94 * @param speed time between horizontal shift. 0 slow .. 7 fast
dreschpe 17:1dafb896c6f5 95 */
dreschpe 17:1dafb896c6f5 96 void horiz_vert_scroll(int l_r,int s_page,int e_page,int v_off,int speed);
dreschpe 17:1dafb896c6f5 97
dreschpe 17:1dafb896c6f5 98 /** end scroll mode
dreschpe 17:1dafb896c6f5 99 *
dreschpe 17:1dafb896c6f5 100 */
dreschpe 17:1dafb896c6f5 101 void end_scroll(void);
dreschpe 17:1dafb896c6f5 102 protected:
dreschpe 12:9c8f3076347c 103
dreschpe 12:9c8f3076347c 104
dreschpe 12:9c8f3076347c 105 /** Init command sequence
dreschpe 12:9c8f3076347c 106 */
dreschpe 12:9c8f3076347c 107 void init();
dreschpe 12:9c8f3076347c 108
dreschpe 12:9c8f3076347c 109 /** set mirror mode
dreschpe 12:9c8f3076347c 110 * @note here overriding the LCD class default one because of not standard commands
dreschpe 12:9c8f3076347c 111 * @param mode NONE, X, Y, XY
dreschpe 12:9c8f3076347c 112 */
dreschpe 12:9c8f3076347c 113 virtual void mirrorXY(mirror_t mode);
dreschpe 12:9c8f3076347c 114
dreschpe 12:9c8f3076347c 115 };
dreschpe 12:9c8f3076347c 116
dreschpe 12:9c8f3076347c 117
dreschpe 12:9c8f3076347c 118 #endif