This demo reads a bitmap from a FAT formatted SD-card, copies it to flash and displays it on the screen. The demo is based on the following project: https://os.mbed.com/users/DieterGraef/code/DISCO-F746NG_SDFileSystem/

Dependencies:   LCD_DISCO_F746NG TS_DISCO_F746NG mbed FATFileSystem

Fork of DISCO-F746NG_SDFileSystem by Dieter Graef

Revision:
4:95e30a911d97
Parent:
1:7f463f6f904e
--- a/main.cpp	Wed Apr 13 09:54:35 2016 +0000
+++ b/main.cpp	Thu Apr 19 19:59:54 2018 +0000
@@ -1,53 +1,70 @@
 #include "mbed.h"
 #include "SDFileSystem.h"
+#include "LCD_DISCO_F746NG.h"
+#include "TS_DISCO_F746NG.h"
 #include <stdio.h>
+#include <stdlib.h>
+#include <string>
 
+void drawImage(char * name, uint16_t x, uint16_t y);
+
+LCD_DISCO_F746NG lcd;
 DigitalOut myled(LED1);
 SDFileSystem sd("sd");
+TS_DISCO_F746NG ts;
 
-// trim '\n'
-void ntrim(char *str)
-{
-    int i;
-    for (i = 0; str[i] != 0; ++i);
+int main() { 
+  uint8_t TS_Status;
+
+    lcd.SetBackColor(LCD_COLOR_BLACK);
+
+    // In this example, the TS is initialized but not used.
 
-    if (i > 0 && str[i - 1] == '\n')
-        str[i - 1] = 0;
+    TS_Status = ts.Init(lcd.GetXSize(), lcd.GetYSize());
+    if (TS_Status != TS_OK) {
+        lcd.Clear(LCD_COLOR_RED);
+        lcd.SetBackColor(LCD_COLOR_RED);
+        lcd.SetTextColor(LCD_COLOR_WHITE);
+        lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT FAIL", CENTER_MODE);
+    } else {
+        lcd.Clear(LCD_COLOR_BLACK);
+        lcd.SetBackColor(LCD_COLOR_BLACK);
+        lcd.SetTextColor(LCD_COLOR_WHITE);
+        lcd.DisplayStringAt(0, LINE(5), (uint8_t *)"TOUCHSCREEN INIT OK", CENTER_MODE);
+    }
+
+    wait(1);
+    
+    //Mounting SD-based filesystem
+    sd.mount();              
+    
+    //Drawing BMP file from SD-card
+    drawImage("/sd/interface.bmp", 0, 0);
 }
 
 
-int main() { 
-    printf("Starting Filetest"); 
-    sd.mount();
-    FILE * fp;
-        fp = fopen("/sd/test.txt", "w");
-        if (fp == NULL)
-        {
-            printf("open error!!\r\n");
-            while(1);
-        }
-        fprintf(fp,"Writing to SD Card");
-        fclose (fp);       
-        fp = fopen("/sd/test.txt", "r");
-        if (fp == NULL)
-        {
-            printf("open error!!\r\n");
-            while(1);
-        }
-        // read text file
-        char buf[1024];
-        while (fgets(buf, sizeof(buf), fp) != NULL)
-        {
-            ntrim(buf);
-            printf("%s\r\n", buf);
-        }
+void drawImage(char * name, uint16_t x, uint16_t y){
+    int fileSize;
+    char * buffer;
+    FILE *Image = fopen(name, "rb");  // open the bmp file
+  
+    //obtain file size:
+    fseek (Image , 0 , SEEK_END);
+    fileSize = ftell (Image);
+    rewind (Image);
+    
+    // allocate memory to contain the whole file:
+    buffer = (char*) malloc (sizeof(char)*fileSize);
+    
+    // copy the file into the buffer:
+    fseek (Image, 0 , SEEK_SET );  
+    // set SD file data start position    
+    fread (buffer,1,fileSize,Image);
+    fclose (Image);
 
-        // file close
-        fclose(fp);
-    while(1) {
-        myled = 1; // LED is ON
-        wait(0.2); // 200 ms
-        myled = 0; // LED is OFF
-        wait(1.0); // 1 sec
-    }
-}
+    //Draw image
+    lcd.DrawBitmap(x,y,(uint8_t *)buffer);
+
+    //Free allocated memory
+    free (buffer);     
+}
\ No newline at end of file