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/

Files at this revision

API Documentation at this revision

Comitter:
Geremia
Date:
Sat Nov 28 18:37:19 2015 +0000
Parent:
28:2b562717a864
Child:
30:87855d03d91a
Commit message:
Add ILI9327 and S6D04D1 (240x400 displays)

Changed in this revision

Inits/ILI9327.cpp Show annotated file Show diff for this revision Revisions of this file
Inits/ILI9327.h Show annotated file Show diff for this revision Revisions of this file
Inits/S6D04D1.cpp Show annotated file Show diff for this revision Revisions of this file
Inits/S6D04D1.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/ILI9327.cpp	Sat Nov 28 18:37:19 2015 +0000
@@ -0,0 +1,153 @@
+ /* mbed UniGraphic library - Device specific class
+ * Copyright (c) 2015 Giuliano Dianda
+ * Released under the MIT License: http://mbed.org/license/mit
+ */
+#include "Protocols.h"
+#include "ILI9327.h"
+
+//////////////////////////////////////////////////////////////////////////////////
+// display settings ///////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////
+
+// put in constructor
+//#define LCDSIZE_X       240 // display X pixels, TFTs are usually portrait view
+//#define LCDSIZE_Y       400  // display Y pixels
+
+
+
+ILI9327::ILI9327(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)
+    : TFT(displayproto, port, CS, reset, DC, WR, RD, LCDSIZE_X, LCDSIZE_Y, name)
+{
+    hw_reset();
+    BusEnable(true);
+    identify(); // will collect tftID, set mipistd flag
+    init();
+    auto_gram_read_format();// try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR. Will set flags accordingly
+//    scrollbugfix=1; // when scrolling 1 line, the last line disappears, set to 1 to fix it, for ili9481 is set automatically in identify()
+    set_orientation(0);
+    FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. Give a try
+    cls();
+    locate(0,0); 
+}
+ILI9327::ILI9327(proto_t displayproto, PinName* buspins, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char *name , unsigned int LCDSIZE_X, unsigned  int LCDSIZE_Y)
+    : TFT(displayproto, buspins, CS, reset, DC, WR, RD, LCDSIZE_X, LCDSIZE_Y, name)
+{
+    hw_reset();
+    BusEnable(true);
+    identify(); // will collect tftID, set mipistd flag
+    init();
+    auto_gram_read_format();// try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR. Will set flags accordingly
+//    scrollbugfix=1; // when scrolling 1 line, the last line disappears, set to 1 to fix it, for ili9481 is set automatically in identify()
+    set_orientation(0);
+    FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. Give a try
+    cls();
+    locate(0,0); 
+}
+ILI9327::ILI9327(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 )
+    : TFT(displayproto, Hz, mosi, miso, sclk, CS, reset, DC, LCDSIZE_X, LCDSIZE_Y, name)
+{
+    hw_reset(); //TFT class forwards to Protocol class
+    BusEnable(true); //TFT class forwards to Protocol class
+    identify(); // will collect tftID and set mipistd flag
+    init(); // per display custom init cmd sequence, implemented here
+    auto_gram_read_format();// try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR. Will set flags accordingly
+ //   scrollbugfix=1; // when scrolling 1 line, the last line disappears, set to 1 to fix it, for ili9481 is set automatically in identify()
+    set_orientation(0); //TFT class does for MIPI standard and some ILIxxx
+    FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. Give a try
+    cls();
+    locate(0,0); 
+}
+// read display ID
+void ILI9327::identify()
+{
+    // ILI9327 custom cmd
+    tftID=rd_reg_data32(0xEF);
+    mipistd=true;
+}
+// reset and init the lcd controller
+void ILI9327::init()
+{
+    wr_cmd8(0x11);
+    wait_ms(150);
+    
+    wr_cmd8(0xF3); //Set EQ 
+    wr_data8(0x08);    
+    wr_data8(0x20);    
+    wr_data8(0x20);    
+    wr_data8(0x08);  
+    
+    wr_cmd8(0xE7);  
+    wr_data8(0x60);   //OPON 
+    
+    wr_cmd8(0xD1);  // Set VCOM 
+    wr_data8(0x00);    
+    wr_data8(0x5D);    
+    wr_data8(0x15);  
+    
+    wr_cmd8(0xD0); //Set power related setting 
+    wr_data8(0x07);    
+    wr_data8(0x02);   //VGH:15V,VGL:-7.16V (BOE LCD: VGH:12~18V,VGL:-6~10V)  
+    wr_data8(0x8B);    
+    wr_data8(0x03);    
+    wr_data8(0xD4); 
+
+    wr_cmd8(0x3A); // Set_pixel_format
+    wr_data8(0x55); //0x55:16bit/pixel,65k;0x66:18bit/pixel,262k;
+
+    wr_cmd8(0x36); //Set_address_mode
+    wr_data8(0x38);
+    
+    wr_cmd8(0x20); //Exit_invert_mode 
+    
+    wr_cmd8(0xC1);   //Set Normal/Partial mode display timing  
+    wr_data8(0x10);    
+    wr_data8(0x1A);    
+    wr_data8(0x02);    
+    wr_data8(0x02); 
+    
+    wr_cmd8(0xC0);  //Set display related setting  
+    wr_data8(0x10);    
+    wr_data8(0x31);    
+    wr_data8(0x00);    
+    wr_data8(0x00);    
+    wr_data8(0x01);    
+    wr_data8(0x02);  
+    
+    wr_cmd8(0xC4);  //Set waveform timing 
+    wr_data8(0x01);    
+    
+    wr_cmd8(0xC5);  //Set oscillator 
+    wr_data8(0x04);   //72Hz
+    wr_data8(0x01); 
+    
+    wr_cmd8(0xD2);  //Set power for normal mode 
+    wr_data8(0x01);    
+    wr_data8(0x44);   
+    
+    wr_cmd8(0xC8);  //Set gamma
+    wr_data8(0x00);    
+    wr_data8(0x77);    
+    wr_data8(0x77);    
+    wr_data8(0x00);    
+    wr_data8(0x04);    
+    wr_data8(0x00);    
+    wr_data8(0x00);    
+    wr_data8(0x00);    
+    wr_data8(0x77);    
+    wr_data8(0x00);    
+    wr_data8(0x00);    
+    wr_data8(0x08);    
+    wr_data8(0x00);    
+    wr_data8(0x00);    
+    wr_data8(0x00); 
+    
+    wr_cmd8(0xCA);  //Set DGC LUT
+    wr_data8(0x00); 
+    
+    wr_cmd8(0xEA);  //3-Gamma Function Control
+    wr_data8(0x80);  // enable
+    
+    wr_cmd8(0x29);  // Set_display_on  
+    wait_ms(150);
+    
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Inits/ILI9327.h	Sat Nov 28 18:37:19 2015 +0000
@@ -0,0 +1,75 @@
+#ifndef MBED_ILI9327_H
+#define MBED_ILI9327_H
+
+
+
+#include "mbed.h"
+#include "TFT.h"
+
+/** Class for ILI9327
+* 
+* to be copypasted and adapted for other controllers
+*/
+class ILI9327 : public TFT
+{
+ 
+ public:
+
+    /** Create a PAR display interface
+    * @param displayproto PAR_8 or PAR_16
+    * @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
+    */ 
+    ILI9327(proto_t displayproto, PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char* name , unsigned int LCDSIZE_X = 240, unsigned  int LCDSIZE_Y = 400);
+    
+    /** Create a BUS display interface
+    * @param displayproto BUS_8 or BUS_16
+    * @param buspins array of PinName to group as Bus
+    * @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
+    */ 
+    ILI9327(proto_t displayproto, PinName* buspins, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char* name ,const unsigned int LCDSIZE_X = 240, unsigned  int LCDSIZE_Y = 400);
+
+    /** Create an SPI display interface
+    * @param displayproto SPI_8 or SPI_16
+    * @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
+    */ 
+    ILI9327(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const char* name , unsigned int LCDSIZE_X = 240, unsigned  int LCDSIZE_Y = 400);
+  
+
+  
+protected:
+    
+    
+    /** Init command sequence  
+    */
+    void init();
+    
+    void identify();
+
+
+
+};
+#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Inits/S6D04D1.cpp	Sat Nov 28 18:37:19 2015 +0000
@@ -0,0 +1,260 @@
+ /* mbed UniGraphic library - Device specific class
+ * Copyright (c) 2015 Giuliano Dianda
+ * Released under the MIT License: http://mbed.org/license/mit
+ */
+#include "Protocols.h"
+#include "S6D04D1.h"
+
+//////////////////////////////////////////////////////////////////////////////////
+// display settings ///////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////
+
+// put in constructor
+//#define LCDSIZE_X       240 // display X pixels, TFTs are usually portrait view
+//#define LCDSIZE_Y       400  // display Y pixels
+
+
+
+S6D04D1::S6D04D1(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)
+    : TFT(displayproto, port, CS, reset, DC, WR, RD, LCDSIZE_X, LCDSIZE_Y, name)
+{
+    hw_reset();
+    BusEnable(true);
+    identify(); // will collect tftID, set mipistd flag
+    init();
+    auto_gram_read_format();// try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR. Will set flags accordingly
+//    scrollbugfix=1; // when scrolling 1 line, the last line disappears, set to 1 to fix it, for ili9481 is set automatically in identify()
+    set_orientation(0);
+    FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. Give a try
+    cls();
+    locate(0,0); 
+}
+S6D04D1::S6D04D1(proto_t displayproto, PinName* buspins, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char *name , unsigned int LCDSIZE_X, unsigned  int LCDSIZE_Y)
+    : TFT(displayproto, buspins, CS, reset, DC, WR, RD, LCDSIZE_X, LCDSIZE_Y, name)
+{
+    hw_reset();
+    BusEnable(true);
+    identify(); // will collect tftID, set mipistd flag
+    init();
+    auto_gram_read_format();// try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR. Will set flags accordingly
+//    scrollbugfix=1; // when scrolling 1 line, the last line disappears, set to 1 to fix it, for ili9481 is set automatically in identify()
+    set_orientation(0);
+    FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. Give a try
+    cls();
+    locate(0,0); 
+}
+S6D04D1::S6D04D1(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 )
+    : TFT(displayproto, Hz, mosi, miso, sclk, CS, reset, DC, LCDSIZE_X, LCDSIZE_Y, name)
+{
+    hw_reset(); //TFT class forwards to Protocol class
+    BusEnable(true); //TFT class forwards to Protocol class
+    identify(); // will collect tftID and set mipistd flag
+    init(); // per display custom init cmd sequence, implemented here
+    auto_gram_read_format();// try to get read gram pixel format, could be 16bit or 18bit, RGB or BGR. Will set flags accordingly
+ //   scrollbugfix=1; // when scrolling 1 line, the last line disappears, set to 1 to fix it, for ili9481 is set automatically in identify()
+    set_orientation(0); //TFT class does for MIPI standard and some ILIxxx
+    FastWindow(true); // most but not all controllers support this, even if datasheet tells they should. Give a try
+    cls();
+    locate(0,0); 
+}
+// reset and init the lcd controller
+void S6D04D1::init()
+{
+    /**********************************************
+        TFT1P CODE Initialization of Truly 
+       
+     ************************************************        
+         Panel:3.0 240400 
+         Driver IC:S6D04D1X21-BAF8
+     
+     ************************************************/
+wr_cmd8(0xE0); 
+wr_data8(0x01); 
+
+wr_cmd8(0x11); 
+wait_ms(150); 
+
+wr_cmd8(0xF3); 
+wr_data8(0x01); 
+wr_data8(0x00); 
+wr_data8(0x00); 
+wr_data8(0x0C);//Do not set any higher VCI1 level than VCI -0.15V. 0C 0A 
+wr_data8(0x03);//VGH和VGL 01 02VGH=6VCI1,VGL=-4VCI1. 
+wr_data8(0x75); 
+wr_data8(0x75); 
+wr_data8(0x30); 
+
+wr_cmd8(0xF4); 
+wr_data8(0x4C); 
+wr_data8(0x4C); 
+wr_data8(0x44); 
+wr_data8(0x44); 
+wr_data8(0x22); 
+
+wr_cmd8(0xF5); 
+wr_data8(0x10); 
+wr_data8(0x22); 
+wr_data8(0x05); 
+wr_data8(0xF0); 
+wr_data8(0x70); 
+wr_data8(0x1F); 
+wait_ms(30); 
+
+wr_cmd8(0xF3); 
+wr_data8(0x03); 
+wait_ms(30); 
+wr_cmd8(0xF3); 
+wr_data8(0x07); 
+wait_ms(30); 
+wr_cmd8(0xF3); 
+wr_data8(0x0F); 
+wait_ms(30); 
+wr_cmd8(0xF3); 
+wr_data8(0x1F); 
+wait_ms(30); 
+wr_cmd8(0xF3); 
+wr_data8(0x7F); 
+wait_ms(30); 
+
+
+wr_cmd8(0xF7); 
+wr_data8(0x80); 
+wr_data8(0x00); 
+wr_data8(0x00); 
+wr_data8(0x05); 
+wr_data8(0x0D); 
+wr_data8(0x1F); 
+wr_data8(0x26); 
+wr_data8(0x2D); 
+wr_data8(0x14); 
+wr_data8(0x15); 
+wr_data8(0x26); 
+wr_data8(0x20); 
+wr_data8(0x01); 
+wr_data8(0x22); 
+wr_data8(0x22); 
+
+wr_cmd8(0xF8); 
+wr_data8(0x80); 
+wr_data8(0x00); 
+wr_data8(0x00); 
+wr_data8(0x00); 
+wr_data8(0x07); 
+wr_data8(0x1E); 
+wr_data8(0x2A); 
+wr_data8(0x32); 
+wr_data8(0x10); 
+wr_data8(0x16); 
+wr_data8(0x36); 
+wr_data8(0x3C); 
+wr_data8(0x3B); 
+wr_data8(0x22); 
+wr_data8(0x22); 
+
+wr_cmd8(0xF9); 
+wr_data8(0x80); 
+wr_data8(0x00); 
+wr_data8(0x00); 
+wr_data8(0x05); 
+wr_data8(0x0D); 
+wr_data8(0x1F); 
+wr_data8(0x26); 
+wr_data8(0x2D); 
+wr_data8(0x14); 
+wr_data8(0x15); 
+wr_data8(0x26); 
+wr_data8(0x20); 
+wr_data8(0x01); 
+wr_data8(0x22); 
+wr_data8(0x22); 
+
+
+wr_cmd8(0xFA); 
+wr_data8(0x80); 
+wr_data8(0x00); 
+wr_data8(0x00); 
+wr_data8(0x00); 
+wr_data8(0x07); 
+wr_data8(0x1E); 
+wr_data8(0x2A); 
+wr_data8(0x32); 
+wr_data8(0x10); 
+wr_data8(0x16); 
+wr_data8(0x36); 
+wr_data8(0x3C); 
+wr_data8(0x3B); 
+wr_data8(0x22); 
+wr_data8(0x22); 
+
+
+wr_cmd8(0xFB); 
+wr_data8(0x80); 
+wr_data8(0x00); 
+wr_data8(0x00); 
+wr_data8(0x05); 
+wr_data8(0x0D); 
+wr_data8(0x1F); 
+wr_data8(0x26); 
+wr_data8(0x2D); 
+wr_data8(0x14); 
+wr_data8(0x15); 
+wr_data8(0x26); 
+wr_data8(0x20); 
+wr_data8(0x01); 
+wr_data8(0x22); 
+wr_data8(0x22); 
+
+wr_cmd8(0xFC); 
+wr_data8(0x80); 
+wr_data8(0x00); 
+wr_data8(0x00); 
+wr_data8(0x00); 
+wr_data8(0x07); 
+wr_data8(0x1E); 
+wr_data8(0x2A); 
+wr_data8(0x32); 
+wr_data8(0x10); 
+wr_data8(0x16); 
+wr_data8(0x36); 
+wr_data8(0x3C); 
+wr_data8(0x3B); 
+wr_data8(0x22); 
+wr_data8(0x22); 
+
+//wr_cmd8(0x35); 
+wr_cmd8(0x34); // tearing effect line off
+
+wr_cmd8(0x36); 
+wr_data8(0x48);//08 
+
+wr_cmd8(0x3A); 
+wr_data8(0x05); 
+
+wr_cmd8(0xF2); 
+wr_data8(0x17); 
+wr_data8(0x17); 
+wr_data8(0x0F); 
+wr_data8(0x08); 
+wr_data8(0x08); 
+wr_data8(0x00); 
+wr_data8(0x00); 
+wr_data8(0x00); 
+wr_data8(0x00); 
+wr_data8(0x13); 
+wr_data8(0x00); 
+
+wr_cmd8(0xF6); 
+wr_data8(0x00); 
+wr_data8(0x08); 
+wr_data8(0x00); 
+wr_data8(0x00); 
+
+wr_cmd8(0xFD); 
+wr_data8(0x02); 
+wr_data8(0x01);//240*400 
+ 
+wait_ms(20); 
+wr_cmd8(0x29); // display on
+wait_ms(20); 
+    
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Inits/S6D04D1.h	Sat Nov 28 18:37:19 2015 +0000
@@ -0,0 +1,75 @@
+#ifndef MBED_S6D04D1_H
+#define MBED_S6D04D1_H
+
+
+
+#include "mbed.h"
+#include "TFT.h"
+
+/** Class for S6D04D1 TFT display controller
+* for BM8K5113 TFT1P3520-E TFT8K5113FPC-A1-E and TFT1P3520
+* to be copypasted and adapted for other controllers
+*/
+class S6D04D1 : public TFT
+{
+ 
+ public:
+
+    /** Create a PAR display interface
+    * @param displayproto PAR_8 or PAR_16
+    * @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
+    */ 
+    S6D04D1(proto_t displayproto, PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char* name , unsigned int LCDSIZE_X = 240, unsigned  int LCDSIZE_Y = 400);
+    
+    /** Create a BUS display interface
+    * @param displayproto BUS_8 or BUS_16
+    * @param buspins array of PinName to group as Bus
+    * @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
+    */ 
+    S6D04D1(proto_t displayproto, PinName* buspins, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char* name ,const unsigned int LCDSIZE_X = 240, unsigned  int LCDSIZE_Y = 400);
+
+    
+    /** Create an SPI display interface
+    * @param displayproto SPI_8 or SPI_16
+    * @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
+    */ 
+    S6D04D1(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const char* name , unsigned int LCDSIZE_X = 240, unsigned  int LCDSIZE_Y = 400);
+    
+   // unsigned int status();
+  
+
+  
+protected:
+    
+    
+    /** Init command sequence  
+    */
+    void init();
+
+
+};
+#endif
\ No newline at end of file