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/
Inits/SH1106.h@36:668396f861d2, 2018-04-22 (annotated)
- Committer:
- charly
- Date:
- Sun Apr 22 21:41:24 2018 +0000
- Revision:
- 36:668396f861d2
Added SH1106 for OLED Display 128x64 via IIC
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
charly | 36:668396f861d2 | 1 | #ifndef MBED_SH1106_H |
charly | 36:668396f861d2 | 2 | #define MBED_SH1106_H |
charly | 36:668396f861d2 | 3 | |
charly | 36:668396f861d2 | 4 | #include "mbed.h" |
charly | 36:668396f861d2 | 5 | #include "LCD.h" |
charly | 36:668396f861d2 | 6 | |
charly | 36:668396f861d2 | 7 | /** Class for SH1106 display controller |
charly | 36:668396f861d2 | 8 | * to be copypasted and adapted for other controllers |
charly | 36:668396f861d2 | 9 | */ |
charly | 36:668396f861d2 | 10 | class SH1106 : public LCD |
charly | 36:668396f861d2 | 11 | { |
charly | 36:668396f861d2 | 12 | |
charly | 36:668396f861d2 | 13 | public: |
charly | 36:668396f861d2 | 14 | |
charly | 36:668396f861d2 | 15 | /** Create a PAR display interface |
charly | 36:668396f861d2 | 16 | * @param displayproto only supports PAR_8 |
charly | 36:668396f861d2 | 17 | * @param port GPIO port name to use |
charly | 36:668396f861d2 | 18 | * @param CS pin connected to CS of display |
charly | 36:668396f861d2 | 19 | * @param reset pin connected to RESET of display |
charly | 36:668396f861d2 | 20 | * @param DC pin connected to data/command of display |
charly | 36:668396f861d2 | 21 | * @param WR pin connected to SDI of display |
charly | 36:668396f861d2 | 22 | * @param RD pin connected to RS of display |
charly | 36:668396f861d2 | 23 | * @param name The name used by the parent class to access the interface |
charly | 36:668396f861d2 | 24 | * @param LCDSIZE_X x size in pixel - optional |
charly | 36:668396f861d2 | 25 | * @param LCDSIZE_Y y size in pixel - optional |
charly | 36:668396f861d2 | 26 | */ |
charly | 36:668396f861d2 | 27 | SH1106(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); |
charly | 36:668396f861d2 | 28 | |
charly | 36:668396f861d2 | 29 | /** Create an SPI display interface |
charly | 36:668396f861d2 | 30 | * @param displayproto SPI_8 or SPI_16 |
charly | 36:668396f861d2 | 31 | * @param Hz SPI speed in Hz |
charly | 36:668396f861d2 | 32 | * @param mosi SPI pin |
charly | 36:668396f861d2 | 33 | * @param miso SPI pin |
charly | 36:668396f861d2 | 34 | * @param sclk SPI pin |
charly | 36:668396f861d2 | 35 | * @param CS pin connected to CS of display |
charly | 36:668396f861d2 | 36 | * @param reset pin connected to RESET of display |
charly | 36:668396f861d2 | 37 | * @param DC pin connected to data/command of display |
charly | 36:668396f861d2 | 38 | * @param name The name used by the parent class to access the interface |
charly | 36:668396f861d2 | 39 | * @param LCDSIZE_X x size in pixel - optional |
charly | 36:668396f861d2 | 40 | * @param LCDSIZE_Y y size in pixel - optional |
charly | 36:668396f861d2 | 41 | */ |
charly | 36:668396f861d2 | 42 | SH1106(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); |
charly | 36:668396f861d2 | 43 | |
charly | 36:668396f861d2 | 44 | /** Create an I2C display interface |
charly | 36:668396f861d2 | 45 | * @param displayproto I2C_ |
charly | 36:668396f861d2 | 46 | * @param Hz I2C speed in Hz |
charly | 36:668396f861d2 | 47 | * @param address I2C address |
charly | 36:668396f861d2 | 48 | * @param sda I2C pin |
charly | 36:668396f861d2 | 49 | * @param scl I2C pin |
charly | 36:668396f861d2 | 50 | * @param reset pin connected to RESET of display |
charly | 36:668396f861d2 | 51 | * @param name The name used by the parent class to access the interface |
charly | 36:668396f861d2 | 52 | * @param LCDSIZE_X x size in pixel - optional |
charly | 36:668396f861d2 | 53 | * @param LCDSIZE_Y y size in pixel - optional |
charly | 36:668396f861d2 | 54 | */ |
charly | 36:668396f861d2 | 55 | SH1106(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); |
charly | 36:668396f861d2 | 56 | |
charly | 36:668396f861d2 | 57 | |
charly | 36:668396f861d2 | 58 | |
charly | 36:668396f861d2 | 59 | /** set the contrast of the screen |
charly | 36:668396f861d2 | 60 | * @note here overrided because of not standard value range |
charly | 36:668396f861d2 | 61 | * @param o contrast 0-255 |
charly | 36:668396f861d2 | 62 | */ |
charly | 36:668396f861d2 | 63 | virtual void set_contrast(int o); |
charly | 36:668396f861d2 | 64 | |
charly | 36:668396f861d2 | 65 | /** set automatc horizontal scroll mode |
charly | 36:668396f861d2 | 66 | * @param l_r direction - left = 0, right = 1 |
charly | 36:668396f861d2 | 67 | * @param s_page start page |
charly | 36:668396f861d2 | 68 | * @param e_page end page |
charly | 36:668396f861d2 | 69 | * @param speed time between horizontal shift. 0 slow .. 7 fast |
charly | 36:668396f861d2 | 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 | |
charly | 36:668396f861d2 | 87 | /** Read pixel color at location |
charly | 36:668396f861d2 | 88 | * @param x is the horizontal offset to this pixel. |
charly | 36:668396f861d2 | 89 | * @param y is the vertical offset to this pixel. |
charly | 36:668396f861d2 | 90 | * @returns 16bit color, 0000=Black(pixel set), FFFF=White(pixel clear). |
charly | 36:668396f861d2 | 91 | */ |
charly | 36:668396f861d2 | 92 | virtual unsigned short pixelread(int x, int y); |
charly | 36:668396f861d2 | 93 | protected: |
charly | 36:668396f861d2 | 94 | |
charly | 36:668396f861d2 | 95 | |
charly | 36:668396f861d2 | 96 | /** Init command sequence |
charly | 36:668396f861d2 | 97 | */ |
charly | 36:668396f861d2 | 98 | void init(); |
charly | 36:668396f861d2 | 99 | |
charly | 36:668396f861d2 | 100 | /** set mirror mode |
charly | 36:668396f861d2 | 101 | * @note here overriding the LCD class default one because of not standard commands |
charly | 36:668396f861d2 | 102 | * @param mode NONE, X, Y, XY |
charly | 36:668396f861d2 | 103 | */ |
charly | 36:668396f861d2 | 104 | virtual void mirrorXY(mirror_t mode); |
charly | 36:668396f861d2 | 105 | |
charly | 36:668396f861d2 | 106 | }; |
charly | 36:668396f861d2 | 107 | |
charly | 36:668396f861d2 | 108 | |
charly | 36:668396f861d2 | 109 | #endif |