Shows how to use a display, the onboard SD Card and the onboard SPI Flash. Requires a display module with direct Arduino pinning

Dependencies:   DmTftLibrary SDFileSystem mbed

Revision:
3:e1e1053e286f
Parent:
0:3ecd25651727
Child:
4:93ca338876e2
--- a/DmDrawBmpBase.cpp	Fri Jul 04 10:36:42 2014 +0000
+++ b/DmDrawBmpBase.cpp	Mon Jul 07 11:43:01 2014 +0000
@@ -30,25 +30,29 @@
 
 bool DmDrawBmpBase::draw888Bitmap(DmTftBase& tft, uint16_t x, uint16_t y) {
   const uint8_t bytesPerPixel = 3;
-  uint32_t filePosition = _bitmapOffset; 
+  uint32_t _bitmapOffset; 
   uint8_t red, green, blue;
   uint16_t row, column;
   uint16_t bytesPerRow = (bytesPerPixel*_width + 3) & ~3;
   uint8_t buff[20*bytesPerPixel];
   uint8_t buffPos = sizeof(buff);
-  
+  uint16_t clipX = _width;
+  uint16_t clipY = _height;
+
+  //make sure image fits
+  if ((x + clipX) > tft.width()) {
+    clipX = tft.width() - x;
+  }
+  if ((y + clipY) > tft.height()) {
+    clipY = tft.height() - y;
+  }
+    
   tft.select();
-  tft.setAddress(x, y, x+_width-1, y+_height-1);
+  tft.setAddress(x, y, x+clipX-1, y+clipY-1);
   tft.unSelect();
   
   for(row=0; row<_height; row++) {
-    _readPos = filePosition = _bitmapOffset + (_height - 1 -row ) * bytesPerRow;
-//    if(_imageFile.position() != filePosition) {
-//      tft.unSelect();
-//      _imageFile.seek(filePosition);
-//      tft.select();
-//      buffPos = sizeof(buff);
-//    }
+    _readPos = _bitmapOffset + (_height - 1 -row ) * bytesPerRow;
     buffPos = sizeof(buff);
     
     for(column=0; column<_width; column++) { 
@@ -56,7 +60,6 @@
         tft.unSelect();
         _readFunc(_userData, buff, _readPos, sizeof(buff));
         _readPos += sizeof(buff);
-//        _imageFile.read(buff, sizeof(buff));
         tft.select();
         buffPos = 0;
       }
@@ -65,7 +68,9 @@
       green = buff[buffPos++];
       red = buff[buffPos++];
 
-      tft.sendData(Convert888to565(red, green, blue));
+      if (row < clipY && column < clipX) {
+        tft.sendData(Convert888to565(red, green, blue));
+      }
     }
   }
   tft.unSelect();
@@ -81,12 +86,22 @@
   uint16_t height = -_height; // Change if load bottom-top
   uint16_t pixel;
   uint16_t row, column;
+  uint16_t clipX = _width;
+  uint16_t clipY = height;
   _readPos = _bitmapOffset;
   
   //_imageFile.seek(_bitmapOffset);
     
+  //make sure image fits
+  if ((x + clipX) > tft.width()) {
+    clipX = tft.width() - x;
+  }
+  if ((y + clipY) > tft.height()) {
+    clipY = tft.height() - y;
+  }
+    
   tft.select();
-  tft.setAddress(x, y, x+_width-1, y+height-1);
+  tft.setAddress(x, y, x+clipX-1, y+clipY-1);
   tft.unSelect();
 
   for(row=0; row<height; row++) {
@@ -101,7 +116,9 @@
       }
       pixel = buff[buffPos++] & 0xFF;
       pixel |= buff[buffPos++] << 8;
-      tft.sendData(pixel);
+      if (row < clipY && column < clipX) {
+        tft.sendData(pixel);
+      }
     }
 
     if ( paddingSize > 0 ) { // Check if there is padding in the file     
@@ -249,4 +266,3 @@
 uint16_t DmDrawBmpBase::Convert888to565(uint8_t red, uint8_t green, uint8_t blue){
   return ((red & 0xF8) << 8) | ((green & 0xFC) << 3) | (blue >> 3);
 }
-