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

Files at this revision

API Documentation at this revision

Comitter:
displaymodule
Date:
Mon Jul 07 11:43:01 2014 +0000
Parent:
2:a77053c4f5cc
Child:
4:93ca338876e2
Commit message:
Updated library dependencies. Added basic clipping of BMP files.

Changed in this revision

DmDrawBmpBase.cpp Show annotated file Show diff for this revision Revisions of this file
DmTftLibrary.lib Show annotated file Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- 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);
 }
-
--- a/DmTftLibrary.lib	Fri Jul 04 10:36:42 2014 +0000
+++ b/DmTftLibrary.lib	Mon Jul 07 11:43:01 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/displaymodule/code/DmTftLibrary/#6cd8c36cbdb3
+http://mbed.org/users/displaymodule/code/DmTftLibrary/#b24f01d148c4
--- a/SDFileSystem.lib	Fri Jul 04 10:36:42 2014 +0000
+++ b/SDFileSystem.lib	Mon Jul 07 11:43:01 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/SDFileSystem/#7b35d1709458
+http://mbed.org/users/displaymodule/code/SDFileSystem/#4e415ec868b5
--- a/main.cpp	Fri Jul 04 10:36:42 2014 +0000
+++ b/main.cpp	Mon Jul 07 11:43:01 2014 +0000
@@ -33,8 +33,8 @@
    use the same pins for USBRX/USBTX and display control. Printing will
    cause the display to not work. Read more about this on the display's notebook
    page. */
-//#define log(...) printf(__VA_ARGS__)
-#define log(...)
+#define log(...) printf(__VA_ARGS__)
+//#define log(...)
 
 #define DM_PIN_SPI_MOSI   D11
 #define DM_PIN_SPI_MISO   D12