Version 3.0.This library can be used for "MIP8f_FRDM_CountUpNumber_sample" , "MIP8f_FRDM_MonochromeDisplay_sample" , "MIP8f_FRDM_sample"
Dependents: MIP8f_FRDM_CountUpNumber_sample
MIP8F_SPI Ver3.0
This library used can be for "MIP8f_FRDM_sample_CountUpDigit" , "MIP8f_FRDM_MonochromeDisplay_sample" , "MIP8f_FRDM_sample"
Revision 2:944f2968c19f, committed 2018-10-31
- Comitter:
- JDI_Mbed_Team
- Date:
- Wed Oct 31 02:05:47 2018 +0000
- Parent:
- 1:2b85e7edcc4e
- Commit message:
- Ver3.0 update
Changed in this revision
MIP8F_SPI.cpp | Show annotated file Show diff for this revision Revisions of this file |
MIP8F_SPI.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 2b85e7edcc4e -r 944f2968c19f MIP8F_SPI.cpp --- a/MIP8F_SPI.cpp Wed Oct 24 02:23:30 2018 +0000 +++ b/MIP8F_SPI.cpp Wed Oct 31 02:05:47 2018 +0000 @@ -1,6 +1,6 @@ /** * @file MIP8F_SPI.cpp -* @brief Library source code file: Class for JDI MIP8 display +* @brief ver3.0 Library source code file: Class for JDI MIP8 display * @details * Copyright 2018 Japan Display Inc. * Licensed under the Apache License, Version 2.0 (the "License"); @@ -40,6 +40,7 @@ _cs = 0; */ + _FixedFontWidth=0;//setting:actual font width display if _FixedFontWidth !=1: font fixed witdh } /** @@ -59,6 +60,34 @@ return value; } +int memLCD8::textout(int x,int y,char* text) +{ + int i=0; + char_x = x; + char_y = y; + + while(text[i] != 0x00 ) + { + character(char_x, char_y, text[i]); + i++; + } + return text[i]; +} + +int memLCD8::obliqueout(int x,int y,char* text) +{ + int i=0; + char_x = x; + char_y = y; + + while(text[i] != 0x00 ) + { + oblique(char_x, char_y, text[i]); + i++; + } + return text[i]; +} + /** * @brief getc */ @@ -76,62 +105,62 @@ } /** -* @brief set allocation for font +* @brief set allocation for font display */ void memLCD8::locate(int x, int y) { char_x = x; char_y = y; } + /** -* @brief dispay character by font. int mode:: =0 :common font(defualt), =1 : big font +* @brief fixed width between charactor and charctor for font display +*/ +void memLCD8::set_FixedFontWidth( unsigned char width ) +{ + _FixedFontWidth = width; +} +void memLCD8::set_ActualFontWidth(void) +{ + _FixedFontWidth = 0; +} +/** +* @brief dispay character by bog font. * big font is that "char data" byte size is over 0xff. * */ -void memLCD8::character(int x, int y, int c,int mode) +void memLCD8::character(int x, int y, int c) { unsigned int hor,vert,offset0,offset1,bpl,j,i,b; // T.Okamoto modified, for big font + unsigned int headroffset;// 2018-10-26 added by Y.Saruhashi unsigned char* zeichen; unsigned char z,w; -// int index; + + if ((c < 32/*31*/) || (c > 127)) return; // test char range - if( mode == 0 ){ - //for common font - if ((c < 31) || (c > 127)) return; // test char range - offset0 = font[0]; // bytes / char - hor = font[1]; // get hor size of font - vert = font[2]; // get vert size of font - bpl = font[3]; // bytes per line + //for big font + offset0 = font[0]; // bytes / char uppser adress + offset1 = font[1]; // bytes / char lower adress + hor = font[2]; // get hor size of font + vert = font[3]; // get vert size of font + bpl = font[4]; // bytes per line + headroffset = 5; - if (char_x + hor > _width) { - char_x = 0; - char_y = char_y + vert; - if (char_y >= _height - font[2]) char_y = 0; // original = font[2] T.Okamoto modified, for big font - } - zeichen = &font[(c -32) * (offset0) + 4]; // start of char bitmap // original = +4 T.Okamoto modified, for big font - }else{ - // for big font - if ((c < 31) || (c > 127)) return; // test char range - offset0 = font[0]; // bytes / char - offset1 = font[1]; // bytes / char - hor = font[2]; // get hor size of font - vert = font[3]; // get vert size of font - bpl = font[4]; // bytes per line + if (char_x + hor > _width) { + char_x = 0; + char_y = char_y + vert; + if (char_y >= _height - vert) char_y = 0; // original = font[2] T.Okamoto modified, for big font + } - if (char_x + hor > _width) { - char_x = 0; - char_y = char_y + vert; - if (char_y >= _height - font[3]) char_y = 0; // original = font[2] T.Okamoto modified, for big font - } - zeichen = &font[(c -32) * (offset0 *256 + offset1) + 5]; // start of char bitmap // original = +4 T.Okamoto modified, for big font - } + zeichen = &font[(c -32) * (offset0 *256 + offset1) + headroffset]; // start of char bitmap // original = +4 T.Okamoto modified, for big font - w = zeichen[0]; // width of actual char + if( _FixedFontWidth == 0 ) w = zeichen[0]; // width of actual char + else w = _FixedFontWidth; // fixed width of char + for (j=0; j<vert; j++) { // vert line for (i=0; i<hor; i++) { // horz line z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1]; b = 1 << (j & 0x07); -// index = (y+j)*_width+(x+i); if (( z & b ) != 0x00) pixel(x+i,y+j,_foreground); else if (_ifMarge == 0) pixel(x+i,y+j,_background);// _background -> _LayerBUF[index]; @@ -142,15 +171,61 @@ } /** -* @brief dispay a image from symbol data +* @brief dispay oblique typte big font. +* +*/ +void memLCD8::oblique(int x, int y, int c) +{ + unsigned int hor,vert,offset0,offset1,bpl,j,i,b; // T.Okamoto modified, for big font + unsigned int headroffset;// 2018-10-26 added by Y.Saruhashi + unsigned char* zeichen; + unsigned char z,w; + if ((c < 32/*31*/) || (c > 127)) return; // test char range + + //for big font + offset0 = font[0]; // bytes / char uppser adress + offset1 = font[1]; // bytes / char lower adress + hor = font[2]; // get hor size of font + vert = font[3]; // get vert size of font + bpl = font[4]; // bytes per line + headroffset = 5; + + int oblique_raio=3; // 3 = 30(%percentage) / 10 + int shift_x = (hor*oblique_raio)/10; //oblique pixel x size, top of char; + int shift_y = vert / shift_x; //oblique ratio for vertical. + + if (char_x + hor > _width) { + char_x = 0; + char_y = char_y + vert; + if (char_y >= _height - vert) char_y = 0; + } + + zeichen = &font[(c -32) * (offset0 *256 + offset1) + headroffset]; + if( _FixedFontWidth == 0 ) w = zeichen[0]; // actual width of char + else w = _FixedFontWidth; // fixed width of char + + for (j=0; j<vert; j++) { // vert line + for (i=0; i<hor; i++) { // horz line + z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1]; + b = 1 << (j & 0x07); + if (( z & b ) != 0x00) pixel(x+i+shift_x-(j/shift_y),y+j,_foreground); + else if (_ifMarge == 0) pixel(x+i+shift_x-(j/shift_y),y+j,_background);// _background -> _LayerBUF[index]; + + } + } + if ((w + 2) < hor) char_x += w + 2; // x offset to next char + else char_x += hor; +} + + +/** +* @brief dispay the image from symbol data */ void memLCD8::Symbol(unsigned int x, unsigned int y, unsigned char *symbol) { unsigned int hor,vert,bpl,j,i,b; unsigned char* zeichen; unsigned char z,w; - -// int index; hor = symbol[0]; // get hor size of font vert = symbol[1]; // get vert size of font bpl = symbol[2]; // bytes per line @@ -160,13 +235,13 @@ char_y = char_y + vert; if (char_y >= _height - symbol[1]) char_y = 0; } + zeichen = &symbol[3]; - w = zeichen[0]; // width of actual char + w = zeichen[0]; // actual width of char for (j=0; j<vert; j++) { // vert line for (i=0; i<hor; i++) { // horz line z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1]; b = 1 << (j & 0x07); -// index = (y+j)*_width+(x+i); if (( z & b ) != 0x00) pixel(x+i,y+j,_foreground); else if (_ifMarge == 0) pixel(x+i,y+j,_background);// _background -> _LayerBUF[index]; } @@ -182,6 +257,7 @@ } */ + /** * @brief dispay a circle line by color data */ @@ -219,6 +295,7 @@ if (e2 > x) err += ++x*2+1; } while (x <= 0); } + /** * @brief dispay a horizontal line by color data */ @@ -310,6 +387,7 @@ } return; } + /** * @brief dispay a rectangle line by color data */ @@ -346,7 +424,6 @@ if(!(x % 2)) _dispBUF[x/2] = _dispBUF[x/2]&0x0F | (color << 4)&0xF0 ; //MASK 0000 1111 else _dispBUF[x/2] = _dispBUF[x/2]&0xF0 | (color )&0x0F ; //MASK 1111 0000 } - //void memLCD8::writeLine(int line) // refresh gate line display void memLCD8::writeDISP(int line,int transfermode) // refresh gate line display { @@ -385,6 +462,7 @@ if(!(x % 2)) _dispBUF[y*_width/2+x/2] = _dispBUF[y*_width/2+x/2]&0x0F | (color << 4)&0xF0 ; //MASK 0000 1111 else _dispBUF[y*_width/2+x/2] = _dispBUF[y*_width/2+x/2]&0xF0 | (color )&0x0F ; //MASK 1111 0000 } + /** * @brief Transfer Pixel Data from buffer to Display * @param[in] int transfermode : instruction the transfer data size ,4bit,3bit,1bit @@ -424,6 +502,42 @@ else pol=0x01; } } +void memLCD8::writeDISP(int startline , int endline , int transfermode) // refresh display selected line +{ + char pol = 0; + //char command = 0x90; // 8b 1*0xNNNN *=POL x=AutoW A 1010 + SetTransfermode(transfermode); + + // frame + for (int i=startline; i<=endline; i++) { + // line + wait_us(6); + _cs = 1; + wait_us(6); + _spi.write(TrModeCommand | (pol << 6) | (i+1)>>8 ); // COMMAND + //pc2.printf("com 0x%x\n",TrModeCommand | (pol << 6) | (i+1)>>8); + + _spi.write((i+1)& 0x00FF ); // V ADDR + //pc2.printf("v adr 0x%x\n",(i+1)& 0x00FF); + + for(int j=0; j<_width; j+=TrAdd) + //for(int j=0; j<100; j+=TrAdd) + { + GetPixelValue(j,i,_dispBUF); + //pc2.printf("data=[%d]{%d][%d]/[%d]\n",j*TrAdd,i,TrValue[0],TrAdd); + for(int k=0;k<TrValNum;k++) + _spi.write(TrValue[k]); + } + _spi.write(0x00); // DUMMY transfer + _spi.write(0x00); // DUMMY transfer +// wait_ms(1); //1.8Hz simulation +// wait_ms(2); //1.35Hz simulation + wait_us(6); + _cs = 0; + if(pol) pol=0x00; + else pol=0x01; + } +} //old function void memLCD8::writeDISP(void) // refresh whole display { @@ -451,6 +565,7 @@ } } #endif + /** * @brief Get Edited data for SPI transfer * @param[in] int x:horizontal allocation left to right @@ -464,12 +579,10 @@ { case 0x90: //TrBIT4: // buffer 2pixel/1byte => 2pixel/1byte buffe 2byte毎進める。 - // 176/4=44 400/4 = 100 640/4=160 TrValue[0] = _dispBUF[_y* _width/2 + _x]; break; case 0x80://TrBIT3: // buffer 2pixel/1byte => 3pixel-1subpixel/1bye (24 pixel/3byte) buffer 3byte毎進める。 - // 176/3=58.666... 400/3 = 133.333... 640/3=213.333... for(int j=0;j<3;j++) TrValue[j] = 0; //for( int i = 0 ; i<12 ; i--) { @@ -502,7 +615,6 @@ break; case 0x88://TrBIT1: // buffer 2pixel/1byte => 8 pixel/1byte buffe 4byte毎進める。 - // 176/4=44 400/4 = 100 640/4=160 for(int j=0;j<3;j++) TrValue[j] = 0; for(int i = 0 ; i<4 ; i++) { @@ -518,6 +630,7 @@ } return TrValue; } + /** * @brief set Configuration for transfer mode * @param[in] int transfermode : instruction the transfer data size ,4bit,3bit,1bit and some parameter @@ -533,19 +646,17 @@ break; case TrBIT3: TrModeCommand = 0x80; - // 176/3=58.666... 400/3 = 133.333... 640/3=213.333... TrAdd = 4; TrValNum = 3; break; case TrBIT1: TrModeCommand = 0x88; - // 176/4=44 400/4 = 100 640/4=160 TrAdd = 4; TrValNum = 1; - //pc2.printf("TrBIT1 TW%d Tvn%d \n",TrAdd,TrValNum); break; } } + /** * @brief clear buffer data by background color data */ @@ -574,6 +685,16 @@ { _background = colour; } + +/** +* @brief get color data of background +*/ + +unsigned char memLCD8::get_Background(void) +{ + return _background; +} + /* void memLCD8::setmarge(bool ifMarge) {
diff -r 2b85e7edcc4e -r 944f2968c19f MIP8F_SPI.h --- a/MIP8F_SPI.h Wed Oct 24 02:23:30 2018 +0000 +++ b/MIP8F_SPI.h Wed Oct 31 02:05:47 2018 +0000 @@ -1,6 +1,6 @@ /** * @file MIP8F_SPI.h -* @brief Library header file: Class for JDI MIP8 display +* @brief ver3.0 Library header file: Class for JDI MIP8 display * @details * <license> * Copyright 2018 Japan Display Inc. @@ -51,7 +51,6 @@ #define RGB8(r,g,b) (((r & 0x80) >>4) | ((g & 0x80)>>5) | ((b & 0x80)>>6) ) & 0x0E //24bit->4bit ??6bit(8bit)?? MIP MASK 0000 1110?? - /** * @brief display class for JDI MIP8(memory in pixel 8 color display) * @details spi-transfer has 3 mode. @@ -69,6 +68,7 @@ #ifndef LINEBUFF_MODE void writeDISP(void); void writeDISP(int transfermode); // transfermode : 4bit,3bit,1bit + void writeDISP(int startline , int endline , int transfermode); // refresh display selected line void pixel(int x, int y, uint8_t color); //for framebuffer #else void writeDISP(int line,int transfermode);// for linebuffer @@ -82,7 +82,7 @@ void setmarge(bool ifMarge); void setWH(int width, int height); void SwDisp(bool ONorOFF); - void character(int x, int y, int c,int mode = 0); + void character(int x, int y, int c); // void LayerCopy(void); void circle(int x0, int y0, int r, uint8_t color); void fillcircle(int x0, int y0, int r, uint8_t color); @@ -93,10 +93,20 @@ void fillrect(int x0, int y0, int x1, int y1, uint8_t color); void Symbol(unsigned int x, unsigned int y, unsigned char *symbol); void set_font(unsigned char* f); + unsigned char* font; + //ver2.0 void SetTransfermode(int transfermode); int* GetPixelValue(int x , int y , uint8_t* buff); + //ver3.0 + void set_FixedFontWidth( unsigned char width ); + void set_ActualFontWidth(void); + unsigned char get_Background(void); + int textout(int x,int y,char* text); + void oblique(int x, int y, int c); + int obliqueout(int x,int y,char* text); + protected: virtual int _putc(int value); virtual int _getc(); @@ -116,7 +126,11 @@ char _background; bool _ifMarge; char _if16; - + + //ver3.0 + //! Fixed Font width size if _FixedFontWidth==0, use actual Font width size. + unsigned char _FixedFontWidth; + #ifndef LINEBUFF_MODE //! frame buffer for display uint8_t _dispBUF[FRAME_SIZE];