Paint for the FRDM-KL25Z

Dependents:   Paint_9341 IUT-BED2021

Revision:
10:a02d649ea00e
Parent:
8:32bf76e1ec9f
--- a/SPI_TFT_ILI9341.cpp	Tue May 06 18:09:00 2014 +0000
+++ b/SPI_TFT_ILI9341.cpp	Thu Jan 10 01:14:10 2019 +0000
@@ -645,14 +645,14 @@
 
 
 
-void SPI_TFT_ILI9341::Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h,unsigned char *bitmap)
+void SPI_TFT_ILI9341::Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h,unsigned const char *bitmap)
 {
     unsigned int  j;
     int padd;
     unsigned short *bitmap_ptr = (unsigned short *)bitmap;
-    #if defined TARGET_KL25Z  // 8 Bit SPI
+    //#if defined TARGET_KL25Z  // 8 Bit SPI
         unsigned short pix_temp;
-    #endif
+    //#endif
     
     unsigned int i;
     
@@ -664,34 +664,34 @@
     window(x, y, w, h);
     bitmap_ptr += ((h - 1)* (w + padd));
     wr_cmd(0x2C);  // send pixel
-    #ifndef TARGET_KL25Z  // 16 Bit SPI 
-    _spi.format(16,3);
-    #endif                            // switch to 16 bit Mode 3
+    //#ifndef TARGET_KL25Z  // 16 Bit SPI 
+    //_spi.format(16,3);
+    #//endif                            // switch to 16 bit Mode 3
     for (j = 0; j < h; j++) {         //Lines
         for (i = 0; i < w; i++) {     // one line
-            #if defined TARGET_KL25Z  // 8 Bit SPI
+            //#if defined TARGET_KL25Z  // 8 Bit SPI
                 pix_temp = *bitmap_ptr;
                 _spi.write(pix_temp >> 8);
                 _spi.write(pix_temp);
                 bitmap_ptr++;
-            #else
-                _spi.write(*bitmap_ptr);    // one line
-                bitmap_ptr++;
-            #endif
+            //#else
+                //_spi.write(*bitmap_ptr);    // one line
+                //bitmap_ptr++;
+            //#endif
         }
         bitmap_ptr -= 2*w;
         bitmap_ptr -= padd;
     }
     _cs = 1;
-    #ifndef TARGET_KL25Z  // 16 Bit SPI 
-    _spi.format(8,3);
-    #endif
+    //#ifndef TARGET_KL25Z  // 16 Bit SPI 
+    //_spi.format(8,3);
+    //#endif
     WindowMax();
 }
 
 
 // local filesystem is not implemented in kinetis board
-#if DEVICE_LOCALFILESYSTEM
+//#if DEVICE_LOCALFILESYSTEM
 
 int SPI_TFT_ILI9341::BMP_16(unsigned int x, unsigned int y, const char *Name_BMP)
 {
@@ -710,17 +710,7 @@
     int padd,j;
     unsigned short *line;
 
-    // get the filename
-    LocalFileSystem local("local");
-    sprintf(&filename[0],"/local/");
-    i=7;
-    while (*Name_BMP!='\0') {
-        filename[i++]=*Name_BMP++;
-    }
-
-    fprintf(stderr, "filename : %s \n\r",filename);
-
-    FILE *Image = fopen((const char *)&filename[0], "rb");  // open the bmp file
+    FILE *Image = fopen("/local/bmp/trapattack.bmp", "rb");  // open the bmp file
     if (!Image) {
         return(0);      // error file not found !
     }
@@ -744,38 +734,36 @@
         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 (2 * PixelWidth); // we need a buffer for a line
     if (line == NULL) {
         return(-4);         // error no memory
     }
-
-    // the bmp lines are padded to multiple of 4 bytes
-    padd = -1;
-    do {
-        padd ++;
-    } while ((PixelWidth * 2 + padd)%4 != 0);
-
-
-//fseek(Image, 70 ,SEEK_SET);
+ 
+// the bmp lines are padded to multiple of 4 bytes
+     padd = -1;
+     _spi.format(8,3);
+     do {
+         padd ++;
+     //} while ((PixelWidth * 2 + padd)%4 != 0);
+     } while (2*(PixelWidth + padd)%4 != 0);
     window(x, y,PixelWidth ,PixelHeigh);
-    wr_cmd(0x2C);  // send pixel 
-    _spi.format(16,3);                            // 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
-            _spi.write(line[i]);                  // one 16 bit pixel
-        } 
+    wr_cmd(0x2C);  // send pixel
+    
+     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 
+            _spi.write(line[i] >> 8);
+            _spi.write(line[i]);
+         } 
      }
-    _cs = 1;
-    _spi.format(8,3);
-    free (line);
-    fclose(Image);
-    WindowMax();
-    return(1);
-}
-#endif
\ No newline at end of file
+     _cs = 1;
+     free (line);
+     fclose(Image);
+     WindowMax();
+     return(1);
+}
\ No newline at end of file