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
Fork of the UniGraphic-Library for monochrome LCDs with ST7920 controller and 128x64-IIC-OLED-Display with SH1106-Controller
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/
Revision 12:9c8f3076347c, committed 2015-02-22
- Comitter:
- dreschpe
- Date:
- Sun Feb 22 00:05:34 2015 +0000
- Parent:
- 11:b842b8e332cb
- Child:
- 13:d8c593fa7705
- Commit message:
- Add SSD1306 OLED Driver
Changed in this revision
Inits/SSD1306.cpp | Show annotated file Show diff for this revision Revisions of this file |
Inits/SSD1306.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Inits/SSD1306.cpp Sun Feb 22 00:05:34 2015 +0000 @@ -0,0 +1,136 @@ +/* mbed UniGraphic library - Device specific class + * Copyright (c) 2015 Peter Drescher + * Released under the MIT License: http://mbed.org/license/mit + */ + +#include "Protocols.h" +#include "SSD1306.h" + +////////////////////////////////////////////////////////////////////////////////// +// display settings /////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////// + + +#define IC_X_SEGS 128 // UC1608 SEG has range 0-239 (239-0 if MX=1), check your datasheet, important for the orientation +#define IC_Y_COMS 64 // UC1608 COM has range 0-127 (127-0 if MY=1), check your datasheet, important for the orientation + +#define SSD1306_SETCONTRAST 0x81 +#define SSD1306_DISPLAYALLON_RESUME 0xA4 +#define SSD1306_DISPLAYALLON 0xA5 +#define SSD1306_NORMALDISPLAY 0xA6 +#define SSD1306_INVERTDISPLAY 0xA7 +#define SSD1306_DISPLAYOFF 0xAE +#define SSD1306_DISPLAYON 0xAF +#define SSD1306_SETDISPLAYOFFSET 0xD3 +#define SSD1306_SETCOMPINS 0xDA +#define SSD1306_SETVCOMDETECT 0xDB +#define SSD1306_SETDISPLAYCLOCKDIV 0xD5 +#define SSD1306_SETPRECHARGE 0xD9 +#define SSD1306_SETMULTIPLEX 0xA8 +#define SSD1306_SETLOWCOLUMN 0x00 +#define SSD1306_SETHIGHCOLUMN 0x10 +#define SSD1306_SETSTARTLINE 0x40 +#define SSD1306_MEMORYMODE 0x20 +#define SSD1306_COMSCANINC 0xC0 +#define SSD1306_COMSCANDEC 0xC8 +#define SSD1306_SEGREMAP 0xA0 +#define SSD1306_CHARGEPUMP 0x8D + +SSD1306::SSD1306(proto_t displayproto, PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char *name , unsigned int LCDSIZE_X, unsigned int LCDSIZE_Y) + : LCD(displayproto, port, CS, reset, DC, WR, RD, LCDSIZE_X, LCDSIZE_Y, IC_X_SEGS, IC_Y_COMS, name) +{ + hw_reset(); + BusEnable(true); + init(); + cls(); + set_orientation(1); + locate(0,0); +} +SSD1306::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, unsigned int LCDSIZE_Y) + : LCD(displayproto, Hz, mosi, miso, sclk, CS, reset, DC, LCDSIZE_X, LCDSIZE_Y, IC_X_SEGS, IC_Y_COMS, name) +{ + hw_reset(); + BusEnable(true); + init(); + cls(); + set_orientation(1); + locate(0,0); +} +// reset and init the lcd controller +void SSD1306::init() +{ + /* Start Initial Sequence ----------------------------------------------------*/ + + // wr_cmd8(0xE2); // sw reset + wait_ms(15); + + wr_cmd8(SSD1306_DISPLAYOFF); + wr_cmd8(SSD1306_SETDISPLAYCLOCKDIV); + wr_cmd8(0x80); + wr_cmd8(SSD1306_SETMULTIPLEX); + wr_cmd8(63); + + wr_cmd8(SSD1306_SETDISPLAYOFFSET); + wr_cmd8(0x0); + + wr_cmd8(SSD1306_SETSTARTLINE | 0x0); // line #0 + + wr_cmd8(SSD1306_CHARGEPUMP); + wr_cmd8(0x14); // 0x10 + + wr_cmd8(SSD1306_MEMORYMODE); + wr_cmd8(0x00); // 0x0 act like ks0108 + + wr_cmd8(SSD1306_SEGREMAP ); //| 0x1); + + wr_cmd8(SSD1306_COMSCANDEC); + + wr_cmd8(SSD1306_SETCOMPINS); + wr_cmd8(0x12); // LCDSIZE_Y == 32 ? 0x02 : 0x12); + + wr_cmd8(SSD1306_SETCONTRAST); + wr_cmd8(0xCF); // _rawHeight == 32 ? 0x8F : ((vccstate == SSD1306_EXTERNALVCC) ? 0x9F : 0xCF) ); + + wr_cmd8(SSD1306_SETPRECHARGE); + wr_cmd8(0xF1); // : 0x22); + + wr_cmd8(SSD1306_SETVCOMDETECT); + wr_cmd8(0x40); + + wr_cmd8(SSD1306_DISPLAYALLON_RESUME); + + //wr_cmd8(SSD1306_NORMALDISPLAY); + wr_cmd8(SSD1306_INVERTDISPLAY); + + wr_cmd8(SSD1306_DISPLAYON); +} + +//////////////////////////////////////////////////////////////////// +// functions that overrides the standard ones implemented in LCD.cpp +//////////////////////////////////////////////////////////////////// + +void SSD1306::mirrorXY(mirror_t mode) +{ + switch (mode) + { + case(NONE): + wr_cmd16(0xA0C0); + break; + case(X): + wr_cmd16(0xA1C0); + break; + case(Y): + wr_cmd16(0xA0C8); + break; + case(XY): + wr_cmd16(0xA1C8); + break; + } +} + +void SSD1306::set_contrast(int o) +{ + contrast = o; + + wr_cmd16(0x8100|(o)); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Inits/SSD1306.h Sun Feb 22 00:05:34 2015 +0000 @@ -0,0 +1,69 @@ +#ifndef MBED_SSD1306_H +#define MBED_SSD1306_H + + + +#include "mbed.h" +#include "LCD.h" + +/** Class for UC1608 display controller +* to be copypasted and adapted for other controllers +*/ +class SSD1306 : public LCD +{ + + public: + + /** Create a PAR display interface + * @param displayproto only supports PAR_8 + * @param port GPIO port name to use + * @param CS pin connected to CS of display + * @param reset pin connected to RESET of display + * @param DC pin connected to data/command of display + * @param WR pin connected to SDI of display + * @param RD pin connected to RS of display + * @param name The name used by the parent class to access the interface + * @param LCDSIZE_X x size in pixel - optional + * @param LCDSIZE_Y y size in pixel - optional + */ + 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); + + /** Create an SPI display interface + * @param displayproto only supports SPI_8 + * @param Hz SPI speed in Hz + * @param mosi SPI pin + * @param miso SPI pin + * @param sclk SPI pin + * @param CS pin connected to CS of display + * @param reset pin connected to RESET of display + * @param DC pin connected to data/command of display + * @param name The name used by the parent class to access the interface + * @param LCDSIZE_X x size in pixel - optional + * @param LCDSIZE_Y y size in pixel - optional + */ + 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); + + /** set the contrast of the screen + * @note here overrided because of not standard command + * @param o contrast 0-63 + */ + virtual void set_contrast(int o); + + +protected: + + + /** Init command sequence + */ + void init(); + + /** set mirror mode + * @note here overriding the LCD class default one because of not standard commands + * @param mode NONE, X, Y, XY + */ + virtual void mirrorXY(mirror_t mode); + +}; + + +#endif \ No newline at end of file