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 38:1b6f9fc49a03, committed 2018-10-30
- Comitter:
- charly
- Date:
- Tue Oct 30 20:00:29 2018 +0000
- Parent:
- 37:5de028b08308
- Commit message:
- some modifications.
Changed in this revision
diff -r 5de028b08308 -r 1b6f9fc49a03 Display/LCD.cpp --- a/Display/LCD.cpp Wed Apr 25 20:55:59 2018 +0000 +++ b/Display/LCD.cpp Tue Oct 30 20:00:29 2018 +0000 @@ -35,7 +35,9 @@ { if(displayproto==PAR_8) proto = new PAR8(port, CS, reset, DC, WR, RD); useNOP=false; - buffer = (unsigned char*) malloc (screensize_X*_LCDPAGES); + //buffer = (unsigned char*) malloc (screensize_X*_LCDPAGES); + //posix_memalign(void **memptr, size_t alignment, size_t size); + posix_memalign((void **)&buffer, 16,screensize_X*_LCDPAGES); buffer16 = (unsigned short*)buffer; draw_mode = NORMAL; set_orientation(1); @@ -59,7 +61,9 @@ proto = new BUS8(pins, CS, reset, DC, WR, RD); } useNOP=false; - buffer = (unsigned char*) malloc (screensize_X*_LCDPAGES); + //buffer = (unsigned char*) malloc (screensize_X*_LCDPAGES); + //posix_memalign(void **memptr, size_t alignment, size_t size); + posix_memalign((void **)&buffer, 16,screensize_X*_LCDPAGES); buffer16 = (unsigned short*)buffer; draw_mode = NORMAL; set_orientation(1); @@ -83,7 +87,9 @@ proto = new SPI16(Hz, mosi, miso, sclk, CS, reset, DC); useNOP=true; } - buffer = (unsigned char*) malloc (screensize_X*_LCDPAGES); + //buffer = (unsigned char*) malloc (screensize_X*_LCDPAGES); + //posix_memalign(void **memptr, size_t alignment, size_t size); + posix_memalign((void **)&buffer, 16,screensize_X*_LCDPAGES); buffer16 = (unsigned short*)buffer; draw_mode = NORMAL; // cls(); @@ -101,8 +107,11 @@ proto = new I2C_bus(Hz,address,sda,scl, reset); useNOP=false; } - buffer = (unsigned char*) malloc (screensize_X*_LCDPAGES); + //buffer = (unsigned char*) malloc (screensize_X*_LCDPAGES); + //posix_memalign(void **memptr, size_t alignment, size_t size); + posix_memalign((void **)&buffer, 16,screensize_X*_LCDPAGES); buffer16 = (unsigned short*)buffer; + draw_mode = NORMAL; // cls(); set_orientation(1); @@ -283,8 +292,10 @@ lenght--; } } + void LCD::pixel(int x, int y, unsigned short color) { + /* if(!(orientation&1)) SWAP(x,y); // first check parameter if((x >= screensize_X) || (y >= screensize_Y)) return; @@ -296,10 +307,12 @@ //buffer[0]=0xFF; //buffer[16]=0xAA; //buffer[1023]=0xFF; +*/ +} -} unsigned short LCD::pixelread(int x, int y) { + /* if(!(orientation&1)) SWAP(x,y); // first check parameter if((x >= screensize_X) || (y >= screensize_Y)) return 0; @@ -307,9 +320,12 @@ if((buffer[(x>>3)+(y*_IC_X_SEGS>>4)] & (1 << (7-(x&7))))==0) return 0xFFFF ; // pixel not set, White else return 0; // pixel set, Black + */ + return 0; } void LCD::copy_to_lcd(void) { + /* unsigned short i=0; unsigned short setcolcmd = 0x0010 | ((col_offset&0xF)<<8) | (col_offset>>4); for(int page=0; page<_LCDPAGES; page++) @@ -321,9 +337,11 @@ wr_grambuf(buffer16+i, screensize_X>>1); // send whole page pixels i+=screensize_X>>1; } + */ } void LCD::cls(void) { + /* unsigned short tmp = _background^0xFFFF; memset(buffer,tmp,screensize_X*_LCDPAGES); // clear display buffer unsigned short setcolcmd = 0x0010 | ((col_offset&0xF)<<8) | (col_offset>>4); @@ -335,6 +353,7 @@ wr_cmd8(0xB0|(page+page_offset)); // set page wr_gram(tmp, screensize_X>>1); // send whole page pixels = background } + */ } int LCD::sizeX() {
diff -r 5de028b08308 -r 1b6f9fc49a03 Display/LCD.h --- a/Display/LCD.h Wed Apr 25 20:55:59 2018 +0000 +++ b/Display/LCD.h Tue Oct 30 20:00:29 2018 +0000 @@ -261,6 +261,7 @@ int orientation; bool useNOP; + unsigned char *buffer; unsigned short *buffer16; };
diff -r 5de028b08308 -r 1b6f9fc49a03 Inits/SH1106.cpp --- a/Inits/SH1106.cpp Wed Apr 25 20:55:59 2018 +0000 +++ b/Inits/SH1106.cpp Tue Oct 30 20:00:29 2018 +0000 @@ -1,5 +1,5 @@ /* mbed UniGraphic library - Device specific class - * SH1106 by Karl Zweimüller, based on + * SH1106 by Karl Zweimüller, based on * SSD1306 by Copyright (c) 2015 Peter Drescher * Released under the MIT License: http://mbed.org/license/mit */ @@ -46,6 +46,7 @@ cls(); set_orientation(1); locate(0,0); + copy_to_lcd(); } SH1106::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, unsigned int LCDSIZE_Y) : LCD(displayproto, Hz, mosi, miso, sclk, CS, reset, DC, LCDSIZE_X, LCDSIZE_Y, IC_X_SEGS, IC_Y_COMS, name) @@ -56,6 +57,7 @@ cls(); set_orientation(1); locate(0,0); + copy_to_lcd(); } SH1106::SH1106(proto_t displayproto, int Hz, int address, PinName sda, PinName scl, PinName reset, const char* name , unsigned int LCDSIZE_X, unsigned int LCDSIZE_Y) @@ -66,6 +68,7 @@ cls(); set_orientation(1); locate(0,0); + copy_to_lcd(); } @@ -155,10 +158,10 @@ void SH1106::copy_to_lcd(void) { - for(int page=0; page<8 /*_LCDPAGES */; page++) { + for(uint8_t page=0; page<8 /*_LCDPAGES */; page++) { + wr_cmd8(0xB0+page); // set page wr_cmd8(0x02); // set column low nibble My Display starts at column 2 (up to column 130 of 132) wr_cmd8(0x10); // set column hi nibble - wr_cmd8(0xB0+page); // set page wr_grambuf(buffer16+(page*screensize_X>>1), screensize_X>>1); // send whole page pixels as shorts(16bit) not bytes! } } @@ -168,7 +171,9 @@ unsigned short tmp = _background^0xFFFF; //memset(buffer,tmp,/*screensize_X*_LCDPAGES*/ 128*64/8); // clear display buffer memset(buffer,0x00,screensize_X*(screensize_Y>>3)); // clear display buffer - copy_to_lcd(); + if (get_auto_up()) { + copy_to_lcd(); + } } void SH1106::mirrorXY(mirror_t mode) @@ -204,12 +209,10 @@ //Buffer[(Xpoint + (Ypoint / 8) * sOLED_DIS.OLED_Dis_Column)] |= 1 << (Ypoint % 8); //Buffer[(Xpoint + (Ypoint / 8) * sOLED_DIS.OLED_Dis_Column)] |= 0 << (Ypoint % 8); if (color) { - buffer[x+((y>>3)*screensize_X)] |= 0 << (y % 8); + buffer[x+((y>>3)*screensize_X)] |= 1 << (y % 8); } else { - buffer[x+((y>>3)*screensize_X)] |= 1 << (y % 8); + buffer[x+((y>>3)*screensize_X)] |= 0 << (y % 8); } - - } @@ -221,6 +224,6 @@ //Buffer[(Xpoint + (Ypoint / 8) * sOLED_DIS.OLED_Dis_Column)] |= 1 << (Ypoint % 8); //Buffer[(Xpoint + (Ypoint / 8) * sOLED_DIS.OLED_Dis_Column)] |= 0 << (Ypoint % 8); if (buffer[x+((y>>3)*screensize_X)] & 1 << (y % 8) == 0) - return 0xFFFF ; // pixel not set, White - else return 0; // pixel set, Black + return Black ; // pixel not set, Black + else return White; // pixel set, White }