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:
Sat May 20 21:12:05 2017 +0000
Revision:
34:a9648877491f
Child:
35:b8d3f1e68000
First working Version with 128x64LCD with ST7920-COntroller;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
charly 34:a9648877491f 1 #ifndef MBED_ST7920_H
charly 34:a9648877491f 2 #define MBED_ST7920_H
charly 34:a9648877491f 3
charly 34:a9648877491f 4 #include "mbed.h"
charly 34:a9648877491f 5 #include "LCD.h"
charly 34:a9648877491f 6
charly 34:a9648877491f 7 /** Class for ST7920 and similar display controllers
charly 34:a9648877491f 8 * to be copypasted and adapted for other controllers
charly 34:a9648877491f 9 */
charly 34:a9648877491f 10 class ST7920 : public LCD
charly 34:a9648877491f 11 {
charly 34:a9648877491f 12
charly 34:a9648877491f 13 public:
charly 34:a9648877491f 14
charly 34:a9648877491f 15 /** Create a PAR display interface
charly 34:a9648877491f 16 * @param displayproto only supports PAR_8
charly 34:a9648877491f 17 * @param port GPIO port name to use
charly 34:a9648877491f 18 * @param CS pin connected to CS of display
charly 34:a9648877491f 19 * @param reset pin connected to RESET of display
charly 34:a9648877491f 20 * @param DC pin connected to data/command of display
charly 34:a9648877491f 21 * @param WR pin connected to SDI of display
charly 34:a9648877491f 22 * @param RD pin connected to RS of display
charly 34:a9648877491f 23 * @param name The name used by the parent class to access the interface
charly 34:a9648877491f 24 * @param LCDSIZE_X x size in pixel - optional
charly 34:a9648877491f 25 * @param LCDSIZE_Y y size in pixel - optional
charly 34:a9648877491f 26 */
charly 34:a9648877491f 27 ST7920(proto_t displayproto, PortName port, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char* name, unsigned int LCDSIZE_X = 132, unsigned int LCDSIZE_Y = 64);
charly 34:a9648877491f 28
charly 34:a9648877491f 29 /** Create a BUS display interface
charly 34:a9648877491f 30 * @param displayproto only supports BUS_8
charly 34:a9648877491f 31 * @param buspins array of PinName to group as Bus
charly 34:a9648877491f 32 * @param CS pin connected to CS of display
charly 34:a9648877491f 33 * @param reset pin connected to RESET of display
charly 34:a9648877491f 34 * @param DC pin connected to data/command of display
charly 34:a9648877491f 35 * @param WR pin connected to SDI of display
charly 34:a9648877491f 36 * @param RD pin connected to RS of display
charly 34:a9648877491f 37 * @param name The name used by the parent class to access the interface
charly 34:a9648877491f 38 * @param LCDSIZE_X x size in pixel - optional
charly 34:a9648877491f 39 * @param LCDSIZE_Y y size in pixel - optional
charly 34:a9648877491f 40 */
charly 34:a9648877491f 41 ST7920(proto_t displayproto, PinName* buspins, PinName CS, PinName reset, PinName DC, PinName WR, PinName RD, const char* name, unsigned int LCDSIZE_X = 132, unsigned int LCDSIZE_Y = 64);
charly 34:a9648877491f 42
charly 34:a9648877491f 43 /** Create an SPI display interface
charly 34:a9648877491f 44 * @param displayproto SPI_8 or SPI_16
charly 34:a9648877491f 45 * @param Hz SPI speed in Hz
charly 34:a9648877491f 46 * @param mosi SPI pin
charly 34:a9648877491f 47 * @param miso SPI pin
charly 34:a9648877491f 48 * @param sclk SPI pin
charly 34:a9648877491f 49 * @param CS pin connected to CS of display
charly 34:a9648877491f 50 * @param reset pin connected to RESET of display
charly 34:a9648877491f 51 * @param DC pin connected to data/command of display
charly 34:a9648877491f 52 * @param name The name used by the parent class to access the interface
charly 34:a9648877491f 53 * @param LCDSIZE_X x size in pixel - optional
charly 34:a9648877491f 54 * @param LCDSIZE_Y y size in pixel - optional
charly 34:a9648877491f 55 */
charly 34:a9648877491f 56 ST7920(proto_t displayproto, int Hz, PinName mosi, PinName miso, PinName sclk, PinName CS, PinName reset, PinName DC, const char* name, unsigned int LCDSIZE_X = 132, unsigned int LCDSIZE_Y = 64);
charly 34:a9648877491f 57
charly 34:a9648877491f 58
charly 34:a9648877491f 59
charly 34:a9648877491f 60 protected:
charly 34:a9648877491f 61
charly 34:a9648877491f 62 //WriteInstructionRegister IR
charly 34:a9648877491f 63 void wir(unsigned char data);
charly 34:a9648877491f 64
charly 34:a9648877491f 65 //WriteDataRegister DR
charly 34:a9648877491f 66 void wdr(unsigned char data);
charly 34:a9648877491f 67
charly 34:a9648877491f 68 /** Init command sequence
charly 34:a9648877491f 69 */
charly 34:a9648877491f 70 void init();
charly 34:a9648877491f 71
charly 34:a9648877491f 72 public:
charly 34:a9648877491f 73 /** Mirror
charly 34:a9648877491f 74 */
charly 34:a9648877491f 75 virtual void mirrorXY(mirror_t mode);
charly 34:a9648877491f 76
charly 34:a9648877491f 77 virtual void cls(void);
charly 34:a9648877491f 78
charly 34:a9648877491f 79 virtual void copy_to_lcd(void);
charly 34:a9648877491f 80
charly 34:a9648877491f 81 virtual void set_contrast(int o);
charly 34:a9648877491f 82
charly 34:a9648877491f 83 void invert(unsigned char o);
charly 34:a9648877491f 84
charly 34:a9648877491f 85 virtual void wr_grambuf(unsigned short* data, unsigned int lenght);
charly 34:a9648877491f 86
charly 34:a9648877491f 87 virtual void wr_gram(unsigned short data);
charly 34:a9648877491f 88
charly 34:a9648877491f 89 virtual void wr_gram(unsigned short data, unsigned int count);
charly 34:a9648877491f 90
charly 34:a9648877491f 91 virtual void wr_data16(unsigned short data);
charly 34:a9648877491f 92
charly 34:a9648877491f 93 virtual void wr_cmd16(unsigned short cmd);
charly 34:a9648877491f 94
charly 34:a9648877491f 95 virtual void wr_cmd8(unsigned char cmd);
charly 34:a9648877491f 96
charly 34:a9648877491f 97 virtual unsigned short rd_gram(bool convert);
charly 34:a9648877491f 98
charly 34:a9648877491f 99 virtual unsigned int rd_reg_data32(unsigned char reg);
charly 34:a9648877491f 100
charly 34:a9648877491f 101 virtual unsigned int rd_extcreg_data32(unsigned char reg, unsigned char SPIreadenablecmd);
charly 34:a9648877491f 102
charly 34:a9648877491f 103 };
charly 34:a9648877491f 104 #endif