for CountupNumber_sample3

MIP8F_SPI_Ver7.0

Ver7.0 Addtional function is SpeedMeter Sample for 4.4" MIP8F Display (Japan Display Inc)

Files at this revision

API Documentation at this revision

Comitter:
JDI_Mbed_Team
Date:
Wed Jan 09 01:20:53 2019 +0000
Parent:
5:8cc8e00fed46
Commit message:
MIP8F_SPI_Ver70

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
--- a/MIP8F_SPI.cpp	Mon Nov 12 05:08:34 2018 +0000
+++ b/MIP8F_SPI.cpp	Wed Jan 09 01:20:53 2019 +0000
@@ -29,7 +29,7 @@
 #include "MIP8F_SPI.h"
 
 // for debug
-//Serial pc2(USBTX, USBRX); // tx, rx
+Serial pc2(USBTX, USBRX); // tx, rx
 
 memLCD8::memLCD8(PinName mosi,PinName miso,PinName sclk,PinName cs,PinName disp,PinName power)
     : _spi(mosi, miso, sclk),_cs(cs),_disp(disp),_power(power)
@@ -51,6 +51,12 @@
         _cs  = 0;
     */
     _FixedFontWidth=0;//setting:actual font width display  if _FixedFontWidth !=1: font fixed witdh
+#if MOVIEBUFF_MODE    
+    //movie_height = 80;
+    //movie_width = 80;
+    _height = 240;
+    _width = 400;
+#endif
 }
 
 /**
@@ -402,6 +408,29 @@
 }
 
 /**
+* @brief  display the oblique text.
+* @param[in] int x : horizontal allocation , up-left of text
+* @param[in] int y : vertical allocation , bottom-right of text
+* @param[in] char* text : strings
+* @param[in] int rx : a horizontal multiple numbler
+* @param[in] int ry : a vertical multiple numbler
+*/
+int memLCD8::obliqueout_multi(int x,int y,char* text,int rx,int ry)
+{
+    int i=0;
+    char_x = x;
+    char_y = y;
+
+    while(text[i] != 0x00 )
+    {
+       oblique_multi(char_x, char_y, text[i],rx,ry);
+       i++;
+    }
+    return text[i];
+}
+
+
+/**
 * @brief  dispay a character by bog font. big font is that "char data" byte size is over 0xff.
 * @param[in] int x : horizontal allocation , up-left of text
 * @param[in] int y : vertical allocation , bottom-right of text
@@ -497,6 +526,76 @@
     if ((w + 2) < hor) char_x += w + 2;                  // x offset to next char
     else               char_x += hor;
 }
+/**
+* @brief  dispay a oblique typte character by big font. 
+* @param[in] int x : horizontal allocation , up-left of text
+* @param[in] int y : vertical allocation , bottom-right of text
+* @param[in] char c : a charactor.
+* @param[in] int rx : a horizontal multiple numbler
+* @param[in] int ry : a vertical multiple numbler
+*/
+void memLCD8::oblique_multi(int x, int y, int c,int rx,int ry)
+{
+    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 k,l;
+    
+    if ((c < 32) || (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]-30;      // 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*rx+shift_x-(j*ry/shift_y)  ,y+j*ry  ,_foreground);
+                  //pixel(x+i*rx+shift_x-(j*ry/shift_y)+1,y+j*ry  ,_foreground);
+                  //pixel(x+i*rx+shift_x-(j*ry/shift_y)  ,y+j*ry+1,_foreground);
+                  //pixel(x+i*rx+shift_x-(j*ry/shift_y)+1,y+j*ry+1,_foreground);
+                  for(l=0;l<ry;l++)
+                  {
+                    for(k=0;k<rx;k++)
+                    {
+                      pixel(x+i*rx+shift_x-(j*ry/shift_y)+k  ,y+j*ry+l  ,_foreground);
+                    }
+                }
+                  
+            }
+            else if (_ifMarge == 0){
+                  pixel(x+i*rx+shift_x-(j*ry/shift_y)  ,y+j*ry  ,_background);
+                  pixel(x+i*rx+shift_x-(j*ry/shift_y)+1,y+j*ry  ,_background);
+                  pixel(x+i*rx+shift_x-(j*ry/shift_y)  ,y+j*ry+1,_background);
+                  pixel(x+i*rx+shift_x-(j*ry/shift_y)+1,y+j*ry+1,_background);
+            }
+
+        }
+    }
+    if ((w + 2) < hor) char_x += w*rx + 2;                  // x offset to next char
+    else               char_x += hor*rx;
+}
 
 /**
 * @brief  dispay the image from symbol data
@@ -713,7 +812,7 @@
     {
     case 0x90: //TrBIT4:
         // buffer 2pixel/1byte => 2pixel/1byte  buffe 2byte毎進める。
-        TrValue[0] = _dispBUF[_y* _width/2 + _x];
+        TrValue[0] = buff[_y* _width/2 + _x];
         break;
     case 0x80://TrBIT3:
         // buffer 2pixel/1byte => 3pixel-1subpixel/1bye (24 pixel/3byte) buffer 3byte毎進める。
@@ -723,27 +822,27 @@
             //4 bit RGBN(Nは予備) => 3bit RGB
             if( _width/2 > _x )
             {
-                TrValue[0] = TrValue[0] | ( ( (_dispBUF[_y* _width/2 + _x    ]&0xE0) ) );
-                TrValue[0] = TrValue[0] | ( ( (_dispBUF[_y* _width/2 + _x    ]&0x0E) ) << 1);
+                TrValue[0] = TrValue[0] | ( ( (buff[_y* _width/2 + _x    ]&0xE0) ) );
+                TrValue[0] = TrValue[0] | ( ( (buff[_y* _width/2 + _x    ]&0x0E) ) << 1);
             }
             if( _width/2 > _x + 1 )
             {
-                TrValue[0] = TrValue[0] | ( ( (_dispBUF[_y* _width/2 + _x + 1]&0xC0) ) >> 6);
+                TrValue[0] = TrValue[0] | ( ( (buff[_y* _width/2 + _x + 1]&0xC0) ) >> 6);
 
-                TrValue[1] = TrValue[1] | ( ( (_dispBUF[_y* _width/2 + _x + 1]&0x20) ) << 2);
-                TrValue[1] = TrValue[1] | ( ( (_dispBUF[_y* _width/2 + _x + 1]&0x0E) ) << 3);
+                TrValue[1] = TrValue[1] | ( ( (buff[_y* _width/2 + _x + 1]&0x20) ) << 2);
+                TrValue[1] = TrValue[1] | ( ( (buff[_y* _width/2 + _x + 1]&0x0E) ) << 3);
             }
             if( _width/2 > _x + 2 )
             {
-                TrValue[1] = TrValue[1] | ( ( (_dispBUF[_y* _width/2 + _x + 2]&0xE0) ) >> 4);
-                TrValue[1] = TrValue[1] | ( ( (_dispBUF[_y* _width/2 + _x + 2]&0x08) ) >> 3);
+                TrValue[1] = TrValue[1] | ( ( (buff[_y* _width/2 + _x + 2]&0xE0) ) >> 4);
+                TrValue[1] = TrValue[1] | ( ( (buff[_y* _width/2 + _x + 2]&0x08) ) >> 3);
 
-                TrValue[2] = TrValue[2] | ( ( (_dispBUF[_y* _width/2 + _x + 2]&0x06) ) << 5);
+                TrValue[2] = TrValue[2] | ( ( (buff[_y* _width/2 + _x + 2]&0x06) ) << 5);
             }
             if( _width/2 > _x + 3 )
             {
-                TrValue[2] = TrValue[2] | ( ( (_dispBUF[_y* _width/2 + _x + 3]&0xE0) ) >> 2);
-                TrValue[2] = TrValue[2] | ( ( (_dispBUF[_y* _width/2 + _x + 3]&0x0E) ) >> 1);
+                TrValue[2] = TrValue[2] | ( ( (buff[_y* _width/2 + _x + 3]&0xE0) ) >> 2);
+                TrValue[2] = TrValue[2] | ( ( (buff[_y* _width/2 + _x + 3]&0x0E) ) >> 1);
             }    
         }
         break;
@@ -755,8 +854,8 @@
             //Green bit => monochrome bit
             if( _width/2 > _x + i )
             {
-                TrValue[0] = TrValue[0] | ( ( (_dispBUF[_y* _width/2 + _x + i]&0x40) == 0 ? 0 : 1 ) << (7-i*2)   );
-                TrValue[0] = TrValue[0] | ( ( (_dispBUF[_y* _width/2 + _x + i]&0x04) == 0 ? 0 : 1 ) << (7-i*2)-1 );
+                TrValue[0] = TrValue[0] | ( ( (buff[_y* _width/2 + _x + i]&0x40) == 0 ? 0 : 1 ) << (7-i*2)   );
+                TrValue[0] = TrValue[0] | ( ( (buff[_y* _width/2 + _x + i]&0x04) == 0 ? 0 : 1 ) << (7-i*2)-1 );
                 //pc2.printf("[%d+%d][%d]<0x%x>\n",_x,i,_y,_dispBUF[_y* _width/2 + _x + i]);
             }
         }
@@ -819,6 +918,9 @@
     
     // frame
     for (int i=startline; i<=endline; i++) {
+        if( i >= _height ) continue;
+        if( i <0   ) continue;
+        
         // line
         wait_us(6);
         _cs  = 1;
@@ -887,5 +989,149 @@
         }
     }
 }
+#if MOVIEBUFF_MODE
+/**
+* @brief  Transfer One Pixel Data with x,y allocation to Animation buffer
+* @param[in] int x : horizontal allocation left to right
+* @param[in] int y : vertival allocation top to bottom
+* @param[in] uint8_t color : the color data for Drawing  0x0X  x is color data(RGBC) C is not used
+* @param[in] int memnu : animation buffer number.
+*/
+void memLCD8::movie_pixel(int x, int y, uint8_t color,int memnum)
+{
+    //pc2.printf("movie_pixel[%d][%d]col[%d]\n",x,y,color);
+    if(!(x % 2)) _dispMOVIEBUF[memnum][y*MOVIE_HORI_SIZE/2+x/2] =  _dispMOVIEBUF[memnum][y*MOVIE_HORI_SIZE/2+x/2]&0x0F  |  (color << 4)&0xF0 ;   //MASK 0000 1111
+    else         _dispMOVIEBUF[memnum][y*MOVIE_HORI_SIZE/2+x/2] =  _dispMOVIEBUF[memnum][y*MOVIE_HORI_SIZE/2+x/2]&0xF0  |  (color     )&0x0F ;   //MASK 1111 0000
+}
+
+/**
+* @brief  Transfer Pixel Data of Animation buffer with x,y allocation to frame buffer.
+* @param[in] int sx : horizontal start allocation left to right
+* @param[in] int sy : vertival start allocation top to bottom
+* @param[in] int memnu : animation buffer number.
+*/
+void memLCD8::makeMovieFrame(int sx , int sy, int memnum)
+{
+    int x,y;
+    //pc2.printf("1<%d,%d>\n",_width,_height);
+    for(y = 0; y < MOVIE_VERT_SIZE;y++)
+    {
+        for(x = 0; x < MOVIE_HORI_SIZE ;x+=2)
+        {
+                if( (sx + x) >= _width ) continue;
+                if( (sx + x) < 0 ) continue;
+                if( (sy + y) >= _height ) continue;
+                if( (sy + y) < 0 ) continue;
+                
+                _dispBACKUPBUF[y*MOVIE_HORI_SIZE/2+x/2] = _dispBUF[(sy+y)*(_width)/2+(sx+x)/2];
+
+                if( (_dispMOVIEBUF[memnum][y*MOVIE_HORI_SIZE/2+x/2]&0xF0) != 0 )
+                    _dispBUF[(sy+y)*(_width)/2+(sx+x)/2] = _dispBUF[(sy+y)*(_width)/2+(sx+x)/2]&0x0F | _dispMOVIEBUF[memnum][y*MOVIE_HORI_SIZE/2+x/2]&0xF0;   //MASK 0000 1111
+
+                if( (_dispMOVIEBUF[memnum][y*MOVIE_HORI_SIZE/2+x/2]&0x0F) != 0 )
+                    _dispBUF[(sy+y)*(_width)/2+(sx+x)/2] =  _dispBUF[(sy+y)*(_width)/2+(sx+x)/2]&0xF0 | _dispMOVIEBUF[memnum][y*MOVIE_HORI_SIZE/2+x/2]&0x0F;   //MASK 0000 1111
+        
+            //pc2.printf("dispMOVIEBUF[%d][%d] = %d\n",x,y,_dispMOVIEBUF[memnum][y*MOVIE_HORI_SIZE/2+x/2]);
+           //_dispBUF[(sy+y)*(_width)/2+(sx+x)/2] = _dispMOVIEBUF[memnum][y*MOVIE_HORI_SIZE/2+x/2];
+        }
+    }
+    //pc2.printf("memnum=%d,x=%d,y=%d>sx=%d,sy=%d\n",memnum,sx,sy,(sx+x)-1,(sy+y)-1);
+
+}
+/**
+* @brief  Transfer Pixel Data of Animation buffer with x,y allocation to frame buffer.  animation data read right to left.
+* @param[in] int sx : horizontal start allocation left to right
+* @param[in] int sy : vertival start allocation top to bottom
+* @param[in] int memnu : animation buffer number.
+*/
+void memLCD8::makeMovieFrame_Reverse(int sx , int sy, int memnum)
+{
+    int x,y;
+    //pc2.printf("1<%d,%d>\n",_width,_height);
+    for(y = 0; y < MOVIE_VERT_SIZE ;y++)
+    {
+        for(x = 0; x < MOVIE_HORI_SIZE  ;x+=2)
+        {
+                if( (sx + x) >= _width ) continue;
+                if( (sx + x) < 0 ) continue;
+                if( (sy + y) >= _height ) continue;
+                if( (sy + y) < 0 ) continue;
+                
+                _dispBACKUPBUF[y*MOVIE_HORI_SIZE/2+x/2] = _dispBUF[(sy+y)*(_width)/2+(sx+x)/2];
+
+                if( (_dispMOVIEBUF[memnum][y*MOVIE_HORI_SIZE/2+(MOVIE_HORI_SIZE-2-x)/2]&0xF0) != 0 )
+                    _dispBUF[(sy+y)*(_width)/2+(sx+x)/2] = _dispBUF[(sy+y)*(_width)/2+(sx+x)/2]&0x0F | _dispMOVIEBUF[memnum][y*MOVIE_HORI_SIZE/2+(MOVIE_HORI_SIZE-2-x)/2]&0xF0;   //MASK 0000 1111
+
+                if( (_dispMOVIEBUF[memnum][y*MOVIE_HORI_SIZE/2+(MOVIE_HORI_SIZE-2-x)/2]&0x0F) != 0 )
+                    _dispBUF[(sy+y)*(_width)/2+(sx+x)/2] = _dispBUF[(sy+y)*(_width)/2+(sx+x)/2]&0xF0 | _dispMOVIEBUF[memnum][y*MOVIE_HORI_SIZE/2+(MOVIE_HORI_SIZE-2-x)/2]&0x0F;   //MASK 0000 1111
+        
+            //pc2.printf("dispMOVIEBUF[%d][%d] = %d\n",x,y,_dispMOVIEBUF[memnum][y*MOVIE_HORI_SIZE/2+x/2]);
+           //_dispBUF[(sy+y)*(_width)/2+(sx+x)/2] = _dispMOVIEBUF[memnum][y*MOVIE_HORI_SIZE/2+x/2];
+        }
+    }
+    //pc2.printf("memnum=%d,x=%d,y=%d>sx=%d,sy=%d\n",memnum,sx,sy,(sx+x)-1,(sy+y)-1);
+
+}
+/**
+* @brief  Transfer Pixel Data of Animation buffer with x,y allocation to frame buffer.  animation data bottom to top.
+* @param[in] int sx : horizontal start allocation left to right
+* @param[in] int sy : vertival start allocation top to bottom
+* @param[in] int memnu : animation buffer number.
+*/
+void memLCD8::makeMovieFrame_Updown(int sx , int sy, int memnum)
+{
+    int x,y;
+    //pc2.printf("1<%d,%d>\n",_width,_height);
+    for(y = 0; y < MOVIE_VERT_SIZE ;y++)
+    {
+        for(x = 0; x < MOVIE_HORI_SIZE  ;x+=2)
+        {
+                if( (sx + x) >= _width ) continue;
+                if( (sx + x) < 0 ) continue;
+                if( (sy + y) >= _height ) continue;
+                if( (sy + y) < 0 ) continue;
+                
+                _dispBACKUPBUF[y*MOVIE_HORI_SIZE/2+x/2] = _dispBUF[(sy+y)*(_width)/2+(sx+x)/2];
+
+                if( (_dispMOVIEBUF[memnum][(MOVIE_VERT_SIZE-1-y)*MOVIE_HORI_SIZE/2+x/2]&0xF0) != 0 )
+                    _dispBUF[(sy+y)*(_width)/2+(sx+x)/2] = _dispBUF[(sy+y)*(_width)/2+(sx+x)/2]&0x0F | _dispMOVIEBUF[memnum][(MOVIE_VERT_SIZE-1-y)*MOVIE_HORI_SIZE/2+x/2]&0xF0;   //MASK 0000 1111
+
+                if( (_dispMOVIEBUF[memnum][(MOVIE_VERT_SIZE-1-y)*MOVIE_HORI_SIZE/2+x/2]&0x0F) != 0 )
+                    _dispBUF[(sy+y)*(_width)/2+(sx+x)/2] = _dispBUF[(sy+y)*(_width)/2+(sx+x)/2]&0xF0 | _dispMOVIEBUF[memnum][(MOVIE_VERT_SIZE-1-y)*MOVIE_HORI_SIZE/2+x/2]&0x0F;   //MASK 0000 1111
+        
+            //pc2.printf("dispMOVIEBUF[%d][%d] = %d\n",x,y,_dispMOVIEBUF[memnum][y*MOVIE_HORI_SIZE/2+x/2]);
+           //_dispBUF[(sy+y)*(_width)/2+(sx+x)/2] = _dispMOVIEBUF[memnum][y*MOVIE_HORI_SIZE/2+x/2];
+        }
+    }
+    //pc2.printf("memnum=%d,x=%d,y=%d>sx=%d,sy=%d\n",memnum,sx,sy,(sx+x)-1,(sy+y)-1);
+
+}
+/**
+* @brief  Transfer  Pixel Data of backuped original frame buffer with x,y allocation to frame buffer.
+* @param[in] int sx : horizontal start allocation left to right
+* @param[in] int sy : vertival start allocation top to bottom
+* @param[in] int memnu : animation buffer number.
+*/
+void memLCD8::RestoreMovieFrame(int sx , int sy, int memnum)
+{
+    int x,y;
+    //pc2.printf("1<%d,%d>\n",_width,_height);
+    for(y = 0; y < MOVIE_VERT_SIZE;y++)
+    {
+        for(x = 0; x < MOVIE_HORI_SIZE ;x++)
+        {
+           if( (sx + x) >= _width ) continue;
+           if( (sx + x) < 0 ) continue;
+           if( (sy + y) >= _height ) continue;
+           if( (sy + y) < 0 ) continue;
+           _dispBUF[(sy+y)*(_width)/2+(sx+x)/2]=_dispBACKUPBUF[y*MOVIE_HORI_SIZE/2+x/2];
+        }
+    }
+    //pc2.printf("memnum=%d,x=%d,y=%d>sx=%d,sy=%d\n",memnum,sx,sy,(sx+x)-1,(sy+y)-1);
+
+}
+//end MOVIEBUFF_MODE
+#endif
+//end FRAMEBUFF_MODE
 #endif
 
--- a/MIP8F_SPI.h	Mon Nov 12 05:08:34 2018 +0000
+++ b/MIP8F_SPI.h	Wed Jan 09 01:20:53 2019 +0000
@@ -33,6 +33,8 @@
 * @brief If you will use a Frame Buffer mode,you must define LINEBUFF_MODE 1
 */
 #define FRAMEBUFF_MODE 1
+
+#define MOVIEBUFF_MODE 1
 /*****************************************
 ******************************************/
 #if LINEBUFF_MODE
@@ -43,6 +45,12 @@
     //#define FRAME_SIZE 9328  //1flame = 212dot X 88dot  1dot = 4bit
     #define FRAME_SIZE  153600  //  153600 640 x 480        103600  400dot x 200dot    1dot = 4bit
 #endif
+#if MOVIEBUFF_MODE
+    #define MOVIE_SIZE  3200  //  80x80/2
+    #define MOVIE_NUM   10
+    #define MOVIE_VERT_SIZE 80
+    #define MOVIE_HORI_SIZE 80
+#endif
 
 // RGB color definitions       /*  R, G, B  */
 #define Black           0x00    /*  0  0  0  */
@@ -123,7 +131,18 @@
     int  textout(int x,int y,char* text);
     void oblique(int x, int y, int c);
     int  obliqueout(int x,int y,char* text);
+    int  obliqueout_multi(int x,int y,char* text,int rx,int ry);
+    void oblique_multi(int x, int y, int c,int rx,int ry);
 #endif
+#if MOVIEBUFF_MODE
+    void movie_pixel(int x, int y, uint8_t color,int memnum);
+    void makeMovieFrame(int sx , int sy, int memnum);
+    void makeMovieFrame_Reverse(int sx , int sy, int memnum);
+    void makeMovieFrame_Updown(int sx , int sy, int memnum);
+    void RestoreMovieFrame(int sx , int sy, int memnum);
+#endif
+
+
 
 protected:
     virtual int _putc(int value);
@@ -159,13 +178,19 @@
     //! line buffer for display
     uint8_t _dispLINEBUF[LINE_SIZE];
 #endif
-
     //! height,diplay pixel size 
     int _height;
     //! width,diplay pixel size 
     int _width;
     unsigned int char_x;
     unsigned int char_y;
+
+#if MOVIEBUFF_MODE
+    uint8_t _dispMOVIEBUF[MOVIE_NUM][MOVIE_SIZE];
+    //int movie_height;
+    //int movie_width;
+    uint8_t _dispBACKUPBUF[MOVIE_SIZE];
+#endif
     
     //ver2.0
     //! SPI transfer mode command to MIP8 diplay