for TFT2P0327 aitendo.com 128*160 TFT LCD. LCD driver is S6D0151 Sumsung.
Dependents: FRDM_tocos_x2_FIXED
Diff: S6D0151_TFT.cpp
- Revision:
- 1:a3651128e297
- Parent:
- 0:de7db46990d0
- Child:
- 2:1e3ac0621559
- Child:
- 4:648a364412e4
diff -r de7db46990d0 -r a3651128e297 S6D0151_TFT.cpp --- a/S6D0151_TFT.cpp Sun Aug 23 12:28:24 2015 +0000 +++ b/S6D0151_TFT.cpp Wed Aug 26 14:58:55 2015 +0000 @@ -1,22 +1,6 @@ - /* mbed library for 128*160 pixel display TFT based on ST7735 LCD Controller - * ST7735 specific routines (initialization, window addressing, pixel output) - * Copyright (c) 2011 Jonne Valola - * - * WARNING !! WORK IN PROGRESS !!! - * - * Graphics routines and SPI routines derived work used with permission from: - * mbed library for 240*320 pixel display TFT based on HX8347D LCD Controller - * Copyright (c) 2011 Peter Drescher - DC2PD - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - + /* mbed library for 128*160 pixel display TFT based on S6D0151 LCD Controller + * + */ #include "S6D0151_TFT.h" #include "mbed.h" @@ -45,6 +29,7 @@ void S6D0151_TFT::set_orientation(unsigned int o) { orientation = o; + /* I do NOT understand rotation methods. */ #if 0 switch (orientation) { case 0: @@ -96,7 +81,7 @@ data = (reg )&0x00ff; _spi.write( data ); _cs = 1; - wait_us(1); // cs=highの時間規定は無かった + wait_us(1); // cs=high Time has not been defined. _cs = 0; _spi.write(0x72); // RW=0,ID=0,RS=1(data write) data = (dat>>8)&0x00ff; @@ -119,18 +104,19 @@ void S6D0151_TFT::tft_reset() { // init SPI _spi.format(8,3); // 8 bit spi mode 3 - _spi.frequency(6000000); // 6Mhz SPI clock ... 10Mhz is maximum for display, but it seems to work + _spi.frequency(6000000); // 6Mhz SPI clock ... 10Mhz is maximum for display - // reset exactly like in Arduino version _cs = 0; - _reset = 1; // reset + _reset = 1; wait_ms(500); _reset = 0; // reset wait_ms(500); - _reset = 1; // reset + _reset = 1; wait_ms(500); /* Start Initial Sequence ----------------------------------------------------*/ + /* follow code is aitendo demo-code...........................................*/ + /* I have changed the part in the demo code to reference----------------------*/ regwr(0x0007,0x0020); //DISPLAY CONTROL (R07h) // X X X PT1 PT0 X X SPT X X GON DTE CL REV D1 D0 //PT[1:0]=00 V63/V0 Normal Drive @@ -196,7 +182,7 @@ regwr(0x0001,0x0014); //DRIVER OUTPUT CONTROL (R01h) // X X X DPL EPL SM GS SS X X X NL4 NL3 NL2 NL1 NL0 - // demo codeは0x0114だったが、SSビットを0にすると方向が正常になった。 + // demo code was 0x0114,SS bit=1 is reverse horizontal. //DPL=0,EPL=0 //SM=0 even/odd division is selected //GS=0 G1 is output first and G160 is finally output. @@ -346,10 +332,12 @@ regwr(0x0007,0x0037); //DISPLAY CONTROL (R07h) // X X X PT1 PT0 X X SPT X X GON DTE CL REV D1 D0 //GON=1,DTE=1 VGH/VGL Normal operation - //Revは色反転の模様 + //Rev bit mean Color reverse. //REV=1 Displays all character and graphics display sections with Reverse //D[1:0]=11 Display is RAM data + /* Up to here, demo code reference partsas ------------------------------*/ + WindowMax (); } @@ -357,7 +345,6 @@ void S6D0151_TFT::pixel(int x, int y, int color) { if ((x >= width()) || (y >= height())) return; -// window(x,y,x+1,y+1); window(x,y,1,1); wr_dat_start(); @@ -379,8 +366,8 @@ dd=((vea&0xff)<<8)|(vsa&0xff); regwr(0x0045, dd ); //VERTICAL RAM ADDRESS POSITION (R45h) -// wr_cmd(ST7735_RAMWR); // write to RAM - set_start_address(hea,vea); +// set_start_address(hea,vea); + set_start_address(hsa,vsa); reg0(0x0022); //Write data to GRAM } @@ -773,92 +760,3 @@ } -int S6D0151_TFT::BMP_16(unsigned int x, unsigned int y, const char *Name_BMP) { -// BEWARE ! -// NOT TESTED -#define OffsetPixelWidth 18 -#define OffsetPixelHeigh 22 -#define OffsetFileSize 34 -#define OffsetPixData 10 -#define OffsetBPP 28 - - char filename[50]; - unsigned char BMP_Header[54]; - unsigned short BPP_t; - unsigned int PixelWidth,PixelHeigh,start_data; - unsigned int i,off; - int padd,j; - unsigned short *line; - - // get the filename -#if 0 - LocalFileSystem local("local"); -#endif - sprintf(&filename[0],"/local/"); - i=7; - while (*Name_BMP!='\0') { - filename[i++]=*Name_BMP++; - } - FILE *Image = fopen((const char *)&filename[0], "r"); // open the bmp file - if (!Image) { - return(0); // error file not found ! - } - - fread(&BMP_Header[0],1,54,Image); // get the BMP Header - - if (BMP_Header[0] != 0x42 || BMP_Header[1] != 0x4D) { // check magic byte - fclose(Image); - return(-1); // error no BMP file - } - - BPP_t = BMP_Header[OffsetBPP] + (BMP_Header[OffsetBPP + 1] << 8); - if (BPP_t != 0x0010) { - fclose(Image); - return(-2); // error no 16 bit BMP - } - - PixelHeigh = BMP_Header[OffsetPixelHeigh] + (BMP_Header[OffsetPixelHeigh + 1] << 8) + (BMP_Header[OffsetPixelHeigh + 2] << 16) + (BMP_Header[OffsetPixelHeigh + 3] << 24); - PixelWidth = BMP_Header[OffsetPixelWidth] + (BMP_Header[OffsetPixelWidth + 1] << 8) + (BMP_Header[OffsetPixelWidth + 2] << 16) + (BMP_Header[OffsetPixelWidth + 3] << 24); - if (PixelHeigh > height() + y || PixelWidth > width() + x) { - fclose(Image); - return(-3); // to big - } - - start_data = BMP_Header[OffsetPixData] + (BMP_Header[OffsetPixData + 1] << 8) + (BMP_Header[OffsetPixData + 2] << 16) + (BMP_Header[OffsetPixData + 3] << 24); - - line = (unsigned short *) malloc (PixelWidth); // we need a buffer for a line - if (line == NULL) { - return(-4); // error no memory - } - - // the lines are padded to multiple of 4 bytes - padd = -1; - do { - padd ++; - } while ((PixelWidth * 2 + padd)%4 != 0); - - window(x, y,PixelWidth,PixelHeigh); - //wr_cmd(0x2C); - wr_dat_start(); - #ifndef TARGET_KL25Z // only 8 Bit SPI - _spi.format(16,3); - #endif // switch to 16 bit Mode 3 - for (j = PixelHeigh - 1; j >= 0; j--) { //Lines bottom up - off = j * (PixelWidth * 2 + padd) + start_data; // start of line - fseek(Image, off ,SEEK_SET); - fread(line,1,PixelWidth * 2,Image); // read a line - slow ! - for (i = 0; i < PixelWidth; i++) { // copy pixel data to TFT - #ifndef TARGET_KL25Z // only 8 Bit SPI - _spi.write(line[i]); // one 16 bit pixel - #else - _spi.write(line[i] >> 8); - _spi.write(line[i]); - #endif - } - } - _spi.format(8,3); - wr_dat_stop(); - free (line); - fclose(Image); - return(1); -} \ No newline at end of file