Mark Peter Vargha / SPI_TFT_ILI9341

Fork of SPI_TFT_ILI9341 by Peter Drescher

Files at this revision

API Documentation at this revision

Comitter:
vargham
Date:
Sat Feb 11 18:56:31 2017 +0000
Parent:
13:b2b3e5430f81
Child:
15:b7848705d2ab
Commit message:
Added Discovery F429ZI 8 bit SPI support.; Added helper methods to locate chars.

Changed in this revision

GraphicsDisplay.cpp Show annotated file Show diff for this revision Revisions of this file
GraphicsDisplay.h Show annotated file Show diff for this revision Revisions of this file
SPI_TFT_ILI9341.cpp Show annotated file Show diff for this revision Revisions of this file
SPI_TFT_ILI9341.h Show annotated file Show diff for this revision Revisions of this file
SPI_TFT_ILI9341_NUCLEO.cpp Show annotated file Show diff for this revision Revisions of this file
SPI_TFT_ILI9341_NXP.cpp Show annotated file Show diff for this revision Revisions of this file
TextDisplay.cpp Show annotated file Show diff for this revision Revisions of this file
TextDisplay.h Show annotated file Show diff for this revision Revisions of this file
--- a/GraphicsDisplay.cpp	Wed Jun 25 16:51:27 2014 +0000
+++ b/GraphicsDisplay.cpp	Sat Feb 11 18:56:31 2017 +0000
@@ -174,3 +174,4 @@
     return height() / 8; 
 }
 
+
--- a/GraphicsDisplay.h	Wed Jun 25 16:51:27 2014 +0000
+++ b/GraphicsDisplay.h	Sat Feb 11 18:56:31 2017 +0000
@@ -6,7 +6,7 @@
  * To port a new display, derive from this class and implement
  * the constructor (setup the display), pixel (put a pixel
  * at a location), width and height functions. Everything else
- * (locate, printf, putc, cls, window, putp, fill, blit, blitbit) 
+ * (locate, printf, putc, cls, window, putp, fill, blit, blitbit)
  * will come for free. You can also provide a specialised implementation
  * of window and putp to speed up the results
  */
@@ -18,32 +18,32 @@
 
 class GraphicsDisplay : public TextDisplay {
 
-public:         
-          
+public:
+
     GraphicsDisplay(const char* name);
-     
+
     virtual void pixel(int x, int y, int colour) = 0;
     virtual int width() = 0;
     virtual int height() = 0;
-        
-    virtual void window(unsigned int x,unsigned int y,unsigned int w,unsigned int h);
+
+    virtual void window(unsigned int x, unsigned int y, unsigned int w, unsigned int h);
     virtual void putp(int colour);
-    
+
     virtual void cls();
     virtual void fill(int x, int y, int w, int h, int colour);
-    virtual void blit(int x, int y, int w, int h, const int *colour);    
+    virtual void blit(int x, int y, int w, int h, const int *colour);
     virtual void blitbit(int x, int y, int w, int h, const char* colour);
-    
+
     virtual void character(int column, int row, int value);
     virtual int columns();
     virtual int rows();
-    
+
 protected:
 
     // pixel location
     short _x;
     short _y;
-    
+
     // window location
     short _x1;
     short _x2;
@@ -53,3 +53,4 @@
 };
 
 #endif
+
--- a/SPI_TFT_ILI9341.cpp	Wed Jun 25 16:51:27 2014 +0000
+++ b/SPI_TFT_ILI9341.cpp	Sat Feb 11 18:56:31 2017 +0000
@@ -9,13 +9,13 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
- 
+
 // 12.06.13 fork from SPI_TFT code because controller is different ...
-// 14.07.13 Test with real display and bugfix 
+// 14.07.13 Test with real display and bugfix
 // 18.10.13 Better Circle function from Michael Ammann
 // 22.10.13 Fixes for Kinetis Board - 8 bit spi
 // 26.01.14 Change interface for BMP_16 to also use SD-cards
-// 23.06.14 switch back to old Version - fork for L152 
+// 23.06.14 switch back to old Version - fork for L152
 // 24.06.14 Add compiler flag for optimized L152 version
 // 25.06.14 Add optimized F103 version
 
@@ -27,19 +27,19 @@
 #include "SPI_TFT_ILI9341.h"
 #include "mbed.h"
 
-#define BPP         16                  // Bits per pixel    
-         
+#define BPP         16                  // Bits per pixel
+
 //extern Serial pc;
 //extern DigitalOut xx;     // debug !!
 
 SPI_TFT_ILI9341::SPI_TFT_ILI9341(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset, PinName dc, const char *name)
     : GraphicsDisplay(name), SPI(mosi, miso, sclk,NC), _cs(cs), _reset(reset), _dc(dc)
 {
-    
+
     orientation = 0;
     char_x = 0;
     SPI::format(8,3);                  // 8 bit spi mode 3
-    SPI::frequency(10000000);          // 10 Mhz SPI clock
+    SPI::frequency(50000000);          // 10 Mhz SPI clock
     tft_reset();
 }
 
@@ -75,9 +75,9 @@
             SPI::write(0xE8);
             break;
     }
-    _cs = 1; 
+    _cs = 1;
     WindowMax();
-} 
+}
 
 
 // write command to tft register
@@ -99,7 +99,7 @@
 
 
 
-// the ILI9341 can read 
+// the ILI9341 can read
 
 char SPI_TFT_ILI9341::rd_byte(unsigned char cmd)
 {
@@ -109,7 +109,7 @@
     SPI::write(cmd);      // mbed lib
     _cs = 1;
     r = SPI::write(0xff);
-    _cs = 1;    
+    _cs = 1;
     return(r);
 }
 
@@ -124,7 +124,7 @@
     d = d << 1;
     SPI::format(9,3);    // we have to add a dummy clock cycle
     SPI::write(d);
-    SPI::format(8,3);   
+    SPI::format(8,3);
     _dc = 1;
     r = SPI::write(0xff);
     d = r;
@@ -134,7 +134,7 @@
     d = (d << 8) | r;
     r = SPI::write(0xff);
     d = (d << 8) | r;
-    _cs = 1;    
+    _cs = 1;
     return(d);
 }
 
@@ -153,157 +153,157 @@
 void SPI_TFT_ILI9341::tft_reset()
 {
     _cs = 1;                           // cs high
-    _dc = 1;                           // dc high 
+    _dc = 1;                           // dc high
     _reset = 0;                        // display reset
 
     wait_us(50);
     _reset = 1;                       // end hardware reset
     wait_ms(5);
-     
-    wr_cmd(0x01);                     // SW reset  
+
+    wr_cmd(0x01);                     // SW reset
     wait_ms(5);
-    wr_cmd(0x28);                     // display off  
+    wr_cmd(0x28);                     // display off
 
     /* Start Initial Sequence ----------------------------------------------------*/
-     wr_cmd(0xCF);                     
+     wr_cmd(0xCF);
      SPI::write(0x00);
      SPI::write(0x83);
      SPI::write(0x30);
      _cs = 1;
-     
-     wr_cmd(0xED);                     
+
+     wr_cmd(0xED);
      SPI::write(0x64);
      SPI::write(0x03);
      SPI::write(0x12);
      SPI::write(0x81);
      _cs = 1;
-     
-     wr_cmd(0xE8);                     
+
+     wr_cmd(0xE8);
      SPI::write(0x85);
      SPI::write(0x01);
      SPI::write(0x79);
      _cs = 1;
-     
-     wr_cmd(0xCB);                     
+
+     wr_cmd(0xCB);
      SPI::write(0x39);
      SPI::write(0x2C);
      SPI::write(0x00);
      SPI::write(0x34);
      SPI::write(0x02);
      _cs = 1;
-           
-     wr_cmd(0xF7);                     
+
+     wr_cmd(0xF7);
      SPI::write(0x20);
      _cs = 1;
-           
-     wr_cmd(0xEA);                     
+
+     wr_cmd(0xEA);
      SPI::write(0x00);
      SPI::write(0x00);
      _cs = 1;
-     
+
      wr_cmd(0xC0);                     // POWER_CONTROL_1
      SPI::write(0x26);
      _cs = 1;
- 
+
      wr_cmd(0xC1);                     // POWER_CONTROL_2
      SPI::write(0x11);
      _cs = 1;
-     
+
      wr_cmd(0xC5);                     // VCOM_CONTROL_1
      SPI::write(0x35);
      SPI::write(0x3E);
      _cs = 1;
-     
+
      wr_cmd(0xC7);                     // VCOM_CONTROL_2
      SPI::write(0xBE);
-     _cs = 1; 
-     
+     _cs = 1;
+
      wr_cmd(0x36);                     // MEMORY_ACCESS_CONTROL
      SPI::write(0x48);
-     _cs = 1; 
-     
+     _cs = 1;
+
      wr_cmd(0x3A);                     // COLMOD_PIXEL_FORMAT_SET
-     SPI::write(0x55);                 // 16 bit pixel 
+     SPI::write(0x55);                 // 16 bit pixel
      _cs = 1;
-     
+
      wr_cmd(0xB1);                     // Frame Rate
      SPI::write(0x00);
-     SPI::write(0x1B);               
+     SPI::write(0x1B);
      _cs = 1;
-     
+
      wr_cmd(0xF2);                     // Gamma Function Disable
      SPI::write(0x08);
-     _cs = 1; 
-     
-     wr_cmd(0x26);                     
+     _cs = 1;
+
+     wr_cmd(0x26);
      SPI::write(0x01);                 // gamma set for curve 01/2/04/08
-     _cs = 1; 
-     
+     _cs = 1;
+
      wr_cmd(0xE0);                     // positive gamma correction
-     SPI::write(0x1F); 
-     SPI::write(0x1A); 
-     SPI::write(0x18); 
-     SPI::write(0x0A); 
-     SPI::write(0x0F); 
-     SPI::write(0x06); 
-     SPI::write(0x45); 
-     SPI::write(0x87); 
-     SPI::write(0x32); 
-     SPI::write(0x0A); 
-     SPI::write(0x07); 
-     SPI::write(0x02); 
+     SPI::write(0x1F);
+     SPI::write(0x1A);
+     SPI::write(0x18);
+     SPI::write(0x0A);
+     SPI::write(0x0F);
+     SPI::write(0x06);
+     SPI::write(0x45);
+     SPI::write(0x87);
+     SPI::write(0x32);
+     SPI::write(0x0A);
      SPI::write(0x07);
-     SPI::write(0x05); 
+     SPI::write(0x02);
+     SPI::write(0x07);
+     SPI::write(0x05);
      SPI::write(0x00);
      _cs = 1;
-     
+
      wr_cmd(0xE1);                     // negativ gamma correction
-     SPI::write(0x00); 
-     SPI::write(0x25); 
-     SPI::write(0x27); 
-     SPI::write(0x05); 
-     SPI::write(0x10); 
-     SPI::write(0x09); 
-     SPI::write(0x3A); 
-     SPI::write(0x78); 
-     SPI::write(0x4D); 
-     SPI::write(0x05); 
-     SPI::write(0x18); 
-     SPI::write(0x0D); 
+     SPI::write(0x00);
+     SPI::write(0x25);
+     SPI::write(0x27);
+     SPI::write(0x05);
+     SPI::write(0x10);
+     SPI::write(0x09);
+     SPI::write(0x3A);
+     SPI::write(0x78);
+     SPI::write(0x4D);
+     SPI::write(0x05);
+     SPI::write(0x18);
+     SPI::write(0x0D);
      SPI::write(0x38);
-     SPI::write(0x3A); 
+     SPI::write(0x3A);
      SPI::write(0x1F);
      _cs = 1;
-     
+
      WindowMax ();
-     
+
      //wr_cmd(0x34);                     // tearing effect off
      //_cs = 1;
-     
+
      //wr_cmd(0x35);                     // tearing effect on
      //_cs = 1;
-      
+
      wr_cmd(0xB7);                       // entry mode
      SPI::write(0x07);
      _cs = 1;
-     
+
      wr_cmd(0xB6);                       // display function control
      SPI::write(0x0A);
      SPI::write(0x82);
      SPI::write(0x27);
      SPI::write(0x00);
      _cs = 1;
-     
+
      wr_cmd(0x11);                     // sleep out
      _cs = 1;
-     
+
      wait_ms(100);
-     
+
      wr_cmd(0x29);                     // display on
      _cs = 1;
-     
+
      wait_ms(100);
-     
+
  }
 
 
@@ -318,10 +318,10 @@
     SPI::write(y);
     _cs = 1;
     wr_cmd(0x2C);  // send pixel
-    #if defined TARGET_KL25Z  // 8 Bit SPI
+    #if defined TARGET_KL25Z || defined TARGET_DISCO_F429ZI // 8 Bit SPI
     SPI::write(color >> 8);
     SPI::write(color & 0xff);
-    #else 
+    #else
     SPI::format(16,3);                            // switch to 16 bit Mode 3
     SPI::write(color);                              // Write D0..D15
     SPI::format(8,3);
@@ -337,7 +337,7 @@
     SPI::write(x);
     SPI::write((x+w-1) >> 8);
     SPI::write(x+w-1);
-    
+
     _cs = 1;
     wr_cmd(0x2B);
     SPI::write(y >> 8);
@@ -357,7 +357,7 @@
 
 void SPI_TFT_ILI9341::cls (void)
 {
-   // we can use the fillrect function 
+   // we can use the fillrect function
    fillrect(0,0,width()-1,height()-1,_background);
 }
 
@@ -403,13 +403,13 @@
     w = x1 - x0 + 1;
     window(x0,y,w,1);
     wr_cmd(0x2C);  // send pixel
-    #if defined TARGET_KL25Z  // 8 Bit SPI
+    #if defined TARGET_KL25Z  || defined TARGET_DISCO_F429ZI // 8 Bit SPI
     int j;
     for (j=0; j<w; j++) {
         SPI::write(color >> 8);
         SPI::write(color & 0xff);
-    } 
-    #else 
+    }
+    #else
     SPI::format(16,3);                            // switch to 16 bit Mode 3
     int j;
     for (j=0; j<w; j++) {
@@ -428,12 +428,12 @@
     h = y1 - y0 + 1;
     window(x,y0,1,h);
     wr_cmd(0x2C);  // send pixel
-    #if defined TARGET_KL25Z  // 8 Bit SPI
+    #if defined TARGET_KL25Z  || defined TARGET_DISCO_F429ZI // 8 Bit SPI
     for (int y=0; y<h; y++) {
         SPI::write(color >> 8);
         SPI::write(color & 0xff);
-    } 
-    #else 
+    }
+    #else
     SPI::format(16,3);                            // switch to 16 bit Mode 3
     for (int y=0; y<h; y++) {
         SPI::write(color);
@@ -546,8 +546,8 @@
     int w = x1 - x0 + 1;
     int pixel = h * w;
     window(x0,y0,w,h);
-    wr_cmd(0x2C);  // send pixel 
-    #if defined TARGET_KL25Z  // 8 Bit SPI
+    wr_cmd(0x2C);  // send pixel
+    #if defined TARGET_KL25Z  || defined TARGET_DISCO_F429ZI // 8 Bit SPI
     for (int p=0; p<pixel; p++) {
         SPI::write(color >> 8);
         SPI::write(color & 0xff);
@@ -575,14 +575,14 @@
 
 int SPI_TFT_ILI9341::columns()
 {
-    return width() / font[1];
+    return width() / font[FONT_WIDTH_INDEX];
 }
 
 
 
 int SPI_TFT_ILI9341::rows()
 {
-    return height() / font[2];
+    return height() / font[FONT_HEIGHT_INDEX];
 }
 
 
@@ -591,8 +591,8 @@
 {
     if (value == '\n') {    // new line
         char_x = 0;
-        char_y = char_y + font[2];
-        if (char_y >= height() - font[2]) {
+        char_y = char_y + font[FONT_HEIGHT_INDEX];
+        if (char_y >= height() - font[FONT_HEIGHT_INDEX]) {
             char_y = 0;
         }
     } else {
@@ -604,29 +604,29 @@
 
 void SPI_TFT_ILI9341::character(int x, int y, int c)
 {
-    unsigned int hor,vert,offset,bpl,j,i,b;
+    unsigned int hor, vert, offset, bpl, j, i, b;
     unsigned char* zeichen;
-    unsigned char z,w;
+    unsigned char z, w;
 
     if ((c < 31) || (c > 127)) return;   // test char range
 
     // read font parameter from start of array
-    offset = font[0];                    // bytes / char
-    hor = font[1];                       // get hor size of font
-    vert = font[2];                      // get vert size of font
-    bpl = font[3];                       // bytes per line
+    offset = font[FONT_OFFSET_INDEX];                    // bytes / char
+    hor = font[FONT_WIDTH_INDEX];                       // get hor size of font
+    vert = font[FONT_HEIGHT_INDEX];                      // get vert size of font
+    bpl = font[FONT_BSP_INDEX];                       // bytes per line
 
     if (char_x + hor > width()) {
         char_x = 0;
         char_y = char_y + vert;
-        if (char_y >= height() - font[2]) {
+        if (char_y >= height() - font[FONT_HEIGHT_INDEX]) {
             char_y = 0;
         }
     }
     window(char_x, char_y,hor,vert); // char box
     wr_cmd(0x2C);  // send pixel
-    #ifndef TARGET_KL25Z  // 16 Bit SPI 
-    SPI::format(16,3);   
+    #if ! defined TARGET_KL25Z && ! defined TARGET_DISCO_F429ZI  // 16 Bit SPI
+    SPI::format(16,3);
     #endif                         // switch to 16 bit Mode 3
     zeichen = &font[((c -32) * offset) + 4]; // start of char bitmap
     w = zeichen[0];                          // width of actual char
@@ -635,14 +635,14 @@
             z =  zeichen[bpl * i + ((j & 0xF8) >> 3)+1];
             b = 1 << (j & 0x07);
             if (( z & b ) == 0x00) {
-               #ifndef TARGET_KL25Z  // 16 Bit SPI 
+                #if ! defined TARGET_KL25Z && ! defined TARGET_DISCO_F429ZI  // 16 Bit SPI
                 SPI::write(_background);
-               #else
+                #else
                 SPI::write(_background >> 8);
                 SPI::write(_background & 0xff);
                 #endif
             } else {
-                #ifndef TARGET_KL25Z  // 16 Bit SPI
+                #if ! defined TARGET_KL25Z && ! defined TARGET_DISCO_F429ZI  // 16 Bit SPI
                 SPI::write(_foreground);
                 #else
                 SPI::write(_foreground >> 8);
@@ -652,7 +652,7 @@
         }
     }
     _cs = 1;
-    #ifndef TARGET_KL25Z  // 16 Bit SPI
+    #if ! defined TARGET_KL25Z && ! defined TARGET_DISCO_F429ZI  // 16 Bit SPI
     SPI::format(8,3);
     #endif
     WindowMax();
@@ -674,12 +674,12 @@
     unsigned int  j;
     int padd;
     unsigned short *bitmap_ptr = (unsigned short *)bitmap;
-    #if defined TARGET_KL25Z  // 8 Bit SPI
+    #if defined TARGET_KL25Z || defined TARGET_DISCO_F429ZI // 8 Bit SPI
         unsigned short pix_temp;
     #endif
-    
+
     unsigned int i;
-    
+
     // the lines are padded to multiple of 4 bytes in a bitmap
     padd = -1;
     do {
@@ -688,7 +688,7 @@
     window(x, y, w, h);
     bitmap_ptr += ((h - 1)* (w + padd));
     wr_cmd(0x2C);  // send pixel
-    #ifndef TARGET_KL25Z  // 16 Bit SPI 
+    #if ! defined TARGET_KL25Z && ! defined TARGET_DISCO_F429ZI // 16 Bit SPI
     SPI::format(16,3);
     #endif                            // switch to 16 bit Mode 3
     for (j = 0; j < h; j++) {         //Lines
@@ -707,7 +707,7 @@
         bitmap_ptr -= padd;
     }
     _cs = 1;
-    #ifndef TARGET_KL25Z  // 16 Bit SPI 
+    #if ! defined TARGET_KL25Z && ! defined TARGET_DISCO_F429ZI
     SPI::format(8,3);
     #endif
     WindowMax();
@@ -738,8 +738,8 @@
     while (*Name_BMP!='\0') {
         filename[i++]=*Name_BMP++;
     }
-    filename[i] = 0;  
-    
+    filename[i] = 0;
+
     FILE *Image = fopen((const char *)&filename[0], "rb");  // open the bmp file
     if (!Image) {
         return(0);      // error file not found !
@@ -780,21 +780,21 @@
 
     window(x, y,PixelWidth ,PixelHeigh);
     wr_cmd(0x2C);  // send pixel
-    #ifndef TARGET_KL25Z // only 8 Bit SPI 
-    SPI::format(16,3);  
+    #ifndef TARGET_KL25Z // only 8 Bit SPI
+    SPI::format(16,3);
     #endif                          // 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 
+        fread(line,1,PixelWidth * 2,Image);       // read a line - slow
         for (i = 0; i < PixelWidth; i++) {        // copy pixel data to TFT
         #ifndef TARGET_KL25Z // only 8 Bit SPI
             SPI::write(line[i]);                  // one 16 bit pixel
-        #else  
+        #else
             SPI::write(line[i] >> 8);
             SPI::write(line[i]);
-        #endif    
-        } 
+        #endif
+        }
      }
     _cs = 1;
     SPI::format(8,3);
@@ -804,4 +804,30 @@
     return(1);
 }
 
-#endif
\ No newline at end of file
+void SPI_TFT_ILI9341::locateChar(uint16_t row, uint16_t column)
+{
+    locate(getCharLeft(column), getCharTop(row));
+}
+
+uint16_t SPI_TFT_ILI9341::getCharLeft(uint16_t column)
+{
+    return font[FONT_WIDTH_INDEX] * column;
+}
+
+uint16_t SPI_TFT_ILI9341::getCharTop(uint16_t row)
+{
+    return font[FONT_HEIGHT_INDEX] * row;
+}
+
+uint16_t SPI_TFT_ILI9341::getCharBottom(uint16_t row)
+{
+    return font[FONT_HEIGHT_INDEX] * (row + 1) - 1;
+}
+
+uint16_t SPI_TFT_ILI9341::getCharRight(uint16_t column)
+{
+    return font[FONT_WIDTH_INDEX] * (column + 1) - 1;
+}
+
+#endif
+
--- a/SPI_TFT_ILI9341.h	Wed Jun 25 16:51:27 2014 +0000
+++ b/SPI_TFT_ILI9341.h	Sat Feb 11 18:56:31 2017 +0000
@@ -9,10 +9,10 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
- 
- /* change the char position handling
-  * use pixel (x,y) instadt of colum row */
- 
+
+/* change the char position handling
+ * use pixel (x,y) instadt of colum row */
+
 #ifndef MBED_SPI_TFT_ILI9341_H
 #define MBED_SPI_TFT_ILI9341_H
 
@@ -42,6 +42,10 @@
 #define Orange          0xFD20      /* 255, 165,   0 */
 #define GreenYellow     0xAFE5      /* 173, 255,  47 */
 
+#define FONT_OFFSET_INDEX 0
+#define FONT_WIDTH_INDEX 1
+#define FONT_HEIGHT_INDEX 2
+#define FONT_BSP_INDEX 3
 
 /** Display control class, based on GraphicsDisplay and TextDisplay
  *
@@ -53,22 +57,22 @@
  * #include "string"
  * #include "Arial12x12.h"
  * #include "Arial24x23.h"
- * 
+ *
  *
  *
  * // the TFT is connected to SPI pin 5-7 and IO's 8-10
  * SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p9, p10,"TFT"); // mosi, miso, sclk, cs, reset, dc
- * If your display need a signal for switch the backlight use a aditional IO pin in your program 
+ * If your display need a signal for switch the backlight use a aditional IO pin in your program
  *
  * int main() {
- *     TFT.claim(stdout);      // send stdout to the TFT display 
+ *     TFT.claim(stdout);      // send stdout to the TFT display
  *     //TFT.claim(stderr);      // send stderr to the TFT display
  *
  *     TFT.background(Black);    // set background to black
  *     TFT.foreground(White);    // set chars to white
  *     TFT.cls();                // clear the screen
  *     TFT.set_font((unsigned char*) Arial12x12);  // select the font
- *     
+ *
  *     TFT.set_orientation(0);
  *     printf("  Hello Mbed 0");
  *     TFT.set_font((unsigned char*) Arial24x23);  // select font 2
@@ -77,334 +81,375 @@
  *  }
  * @endcode
  */
- class SPI_TFT_ILI9341 : public GraphicsDisplay , public SPI {
- public:
+class SPI_TFT_ILI9341 : public GraphicsDisplay , public SPI
+{
+public:
+
+    /** Create a SPI_TFT object connected to SPI and three pins
+     *
+     * @param mosi pin connected to SDO of display
+     * @param miso pin connected to SDI of display
+     * @param sclk pin connected to RS of display
+     * @param cs pin connected to CS of display
+     * @param reset pin connected to RESET of display
+     * @param dc pin connected to WR of display
+     * the IM pins have to be set to 1110 (3-0)
+     */
+    SPI_TFT_ILI9341(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset, PinName dc, const char* name ="TFT");
+
+    /** Get the width of the screen in pixel
+     *
+     * @returns width of screen in pixel
+     *
+     */
+    virtual int width();
+
+    /** Get the height of the screen in pixel
+     *
+     * @returns height of screen in pixel
+     *
+     */
+    virtual int height();
+
+    /** Draw a pixel at x,y with color
+     *
+     * @param x horizontal position
+     * @param y vertical position
+     * @param color 16 bit pixel color
+     */
+    virtual void pixel(int x, int y, int colour);
+
+    /** draw a circle
+     *
+     * @param x,y center
+     * @param r radius
+     * @param color 16 bit color                                                                 *
+     *
+     */
+    void circle(int x, int y, int r, int colour);
+
+    /** draw a filled circle
+     *
+     * @param x,y center
+     * @param r radius
+     * @param color 16 bit color                                                                 *
+     */
+    void fillcircle(int x, int y, int r, int colour);
+
 
-  /** Create a SPI_TFT object connected to SPI and three pins
-   *
-   * @param mosi pin connected to SDO of display
-   * @param miso pin connected to SDI of display
-   * @param sclk pin connected to RS of display 
-   * @param cs pin connected to CS of display
-   * @param reset pin connected to RESET of display
-   * @param dc pin connected to WR of display
-   * the IM pins have to be set to 1110 (3-0) 
-   */ 
-  SPI_TFT_ILI9341(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset, PinName dc, const char* name ="TFT");
-    
-  /** Get the width of the screen in pixel
-   *
-   * @returns width of screen in pixel
-   *
-   */    
-  virtual int width();
+    /** draw a 1 pixel line
+     *
+     * @param x0,y0 start point
+     * @param x1,y1 stop point
+     * @param color 16 bit color
+     *
+     */
+    void line(int x0, int y0, int x1, int y1, int colour);
+
+    /** draw a rect
+     *
+     * @param x0,y0 top left corner
+     * @param x1,y1 down right corner
+     * @param color 16 bit color
+     *                                                   *
+     */
+    void rect(int x0, int y0, int x1, int y1, int colour);
+
+    /** draw a filled rect
+     *
+     * @param x0,y0 top left corner
+     * @param x1,y1 down right corner
+     * @param color 16 bit color
+     *
+     */
+    void fillrect(int x0, int y0, int x1, int y1, int colour);
+
+    /** setup cursor position
+     *
+     * @param x x-position (top left)
+     * @param y y-position
+     */
+    virtual void locate(int x, int y);
+
+    /** Fill the screen with _backgroun color
+     *
+     */
+    virtual void cls(void);
+
+    /** calculate the max number of char in a line
+     *
+     * @returns max columns
+     * depends on actual font size
+     *
+     */
+    virtual int columns(void);
+
+    /** calculate the max number of columns
+     *
+     * @returns max column
+     * depends on actual font size
+     *
+     */
+    virtual int rows(void);
+
+    /** put a char on the screen
+     *
+     * @param value char to print
+     * @returns printed char
+     *
+     */
+    virtual int _putc(int value);
 
-  /** Get the height of the screen in pixel
-   *
-   * @returns height of screen in pixel 
-   *
-   */     
-  virtual int height();
-    
-  /** Draw a pixel at x,y with color 
-   *  
-   * @param x horizontal position
-   * @param y vertical position
-   * @param color 16 bit pixel color
-   */    
-  virtual void pixel(int x, int y,int colour);
-    
-  /** draw a circle
-   *
-   * @param x0,y0 center
-   * @param r radius
-   * @param color 16 bit color                                                                 *
-   *
-   */    
-  void circle(int x, int y, int r, int colour); 
-  
-  /** draw a filled circle
-   *
-   * @param x0,y0 center
-   * @param r radius
-   * @param color 16 bit color                                                                 *
-   */    
-  void fillcircle(int x, int y, int r, int colour); 
- 
-    
-  /** draw a 1 pixel line
-   *
-   * @param x0,y0 start point
-   * @param x1,y1 stop point
-   * @param color 16 bit color
-   *
-   */    
-  void line(int x0, int y0, int x1, int y1, int colour);
-    
-  /** draw a rect
-   *
-   * @param x0,y0 top left corner
-   * @param x1,y1 down right corner
-   * @param color 16 bit color
-   *                                                   *
-   */    
-  void rect(int x0, int y0, int x1, int y1, int colour);
-    
-  /** draw a filled rect
-   *
-   * @param x0,y0 top left corner
-   * @param x1,y1 down right corner
-   * @param color 16 bit color
-   *
-   */    
-  void fillrect(int x0, int y0, int x1, int y1, int colour);
-    
-  /** setup cursor position
-   *
-   * @param x x-position (top left)
-   * @param y y-position 
-   */   
-  virtual void locate(int x, int y);
-    
-  /** Fill the screen with _backgroun color
-   *
-   */   
-  virtual void cls (void);   
-    
-  /** calculate the max number of char in a line
-   *
-   * @returns max columns
-   * depends on actual font size
-   *
-   */    
-  virtual int columns(void);
-    
-  /** calculate the max number of columns
-   *
-   * @returns max column
-   * depends on actual font size
-   *
-   */   
-  virtual int rows(void);
-    
-  /** put a char on the screen
-   *
-   * @param value char to print
-   * @returns printed char
-   *
-   */
-  virtual int _putc(int value);
-    
-  /** draw a character on given position out of the active font to the TFT
-   *
-   * @param x x-position of char (top left) 
-   * @param y y-position
-   * @param c char to print
-   *
-   */    
-  virtual void character(int x, int y, int c);
-    
-  /** paint a bitmap on the TFT 
-   *
-   * @param x,y : upper left corner 
-   * @param w width of bitmap
-   * @param h high of bitmap
-   * @param *bitmap pointer to the bitmap data
-   *
-   *   bitmap format: 16 bit R5 G6 B5
-   * 
-   *   use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5            
-   *   use winhex to load this file and mark data stating at offset 0x46 to end
-   *   use edit -> copy block -> C Source to export C array
-   *   paste this array into your program
-   * 
-   *   define the array as static const unsigned char to put it into flash memory
-   *   cast the pointer to (unsigned char *) :
-   *   tft.Bitmap(10,40,309,50,(unsigned char *)scala);
-   */    
-  void Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h,unsigned char *bitmap);
-    
-    
-   /** paint a 16 bit BMP from filesytem on the TFT (slow) 
-   *
-   * @param x,y : position of upper left corner 
-   * @param *Name_BMP name of the BMP file with drive: "/local/test.bmp"
-   *
-   * @returns 1 if bmp file was found and painted
-   * @returns  0 if bmp file was found not found
-   * @returns -1 if file is no bmp
-   * @returns -2 if bmp file is no 16 bit bmp
-   * @returns -3 if bmp file is to big for screen 
-   * @returns -4 if buffer malloc go wrong
-   *
-   *   bitmap format: 16 bit R5 G6 B5
-   * 
-   *   use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5
-   *   copy to internal file system or SD card           
-   */      
-    
-  int BMP_16(unsigned int x, unsigned int y, const char *Name_BMP);  
-    
-    
-    
-  /** select the font to use
-   *
-   * @param f pointer to font array 
-   *                                                                              
-   *   font array can created with GLCD Font Creator from http://www.mikroe.com
-   *   you have to add 4 parameter at the beginning of the font array to use: 
-   *   - the number of byte / char
-   *   - the vertial size in pixel
-   *   - the horizontal size in pixel
-   *   - the number of byte per vertical line
-   *   you also have to change the array to char[]
-   *
-   */  
-  void set_font(unsigned char* f);
-   
-  /** Set the orientation of the screen
-   *  x,y: 0,0 is always top left 
-   *
-   * @param o direction to use the screen (0-3)  
-   *
-   */  
-  void set_orientation(unsigned int o);
-  
-  
-  /** read out the manufacturer ID of the LCD
-   *  can used for checking the connection to the display
-   *  @returns ID
-   */ 
-  int Read_ID(void);
-  
-  DigitalOut _cs; 
-  DigitalOut _reset;
-  DigitalOut _dc;
-  unsigned char* font;
-  
-  
-  
-   
+    /** draw a character on given position out of the active font to the TFT
+     *
+     * @param x x-position of char (top left)
+     * @param y y-position
+     * @param c char to print
+     *
+     */
+    virtual void character(int x, int y, int c);
+
+    /** paint a bitmap on the TFT
+     *
+     * @param x,y : upper left corner
+     * @param w width of bitmap
+     * @param h high of bitmap
+     * @param *bitmap pointer to the bitmap data
+     *
+     *   bitmap format: 16 bit R5 G6 B5
+     *
+     *   use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5
+     *   use winhex to load this file and mark data stating at offset 0x46 to end
+     *   use edit -> copy block -> C Source to export C array
+     *   paste this array into your program
+     *
+     *   define the array as static const unsigned char to put it into flash memory
+     *   cast the pointer to (unsigned char *) :
+     *   tft.Bitmap(10,40,309,50,(unsigned char *)scala);
+     */
+    void Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *bitmap);
+
+
+    /** paint a 16 bit BMP from filesytem on the TFT (slow)
+    *
+    * @param x,y : position of upper left corner
+    * @param *Name_BMP name of the BMP file with drive: "/local/test.bmp"
+    *
+    * @returns 1 if bmp file was found and painted
+    * @returns  0 if bmp file was found not found
+    * @returns -1 if file is no bmp
+    * @returns -2 if bmp file is no 16 bit bmp
+    * @returns -3 if bmp file is to big for screen
+    * @returns -4 if buffer malloc go wrong
+    *
+    *   bitmap format: 16 bit R5 G6 B5
+    *
+    *   use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5
+    *   copy to internal file system or SD card
+    */
+
+    int BMP_16(unsigned int x, unsigned int y, const char *Name_BMP);
+
+
+
+    /** select the font to use
+     *
+     * @param f pointer to font array
+     *
+     *   font array can created with GLCD Font Creator from http://www.mikroe.com
+     *   you have to add 4 parameter at the beginning of the font array to use:
+     *   - the number of byte / char
+     *   - the vertial size in pixel
+     *   - the horizontal size in pixel
+     *   - the number of byte per vertical line
+     *   you also have to change the array to char[]
+     *
+     */
+    void set_font(unsigned char* f);
+
+    /** Set the orientation of the screen
+     *  x,y: 0,0 is always top left
+     *
+     * @param o direction to use the screen (0-3)
+     *
+     */
+    void set_orientation(unsigned int o);
+
+
+    /** read out the manufacturer ID of the LCD
+     *  can used for checking the connection to the display
+     *  @returns ID
+     */
+    int Read_ID(void);
+
+    /** Setup character cursor position, calculated from current font size.
+     *
+     * @param row
+     * @param column
+     */
+    void locateChar(uint16_t row, uint16_t column);
+
+    /** Calculates character's left coordinate in pixels.
+     *
+     * @param column The character's display column
+     * @returns the x coordinate in pixels
+     *
+     */
+    uint16_t getCharLeft(uint16_t column);
+
+    /** Calculates character's top coordinate in pixels.
+     *
+     * @param row The character's display row
+     * @returns the y coordinate in pixels
+     *
+     */
+    uint16_t getCharTop(uint16_t row);
+
+    /** Calculates character's bottom coordinate in pixels.
+     *
+     * @param row The character's display row
+     * @returns the y coordinate in pixels
+     *
+     */
+    uint16_t getCharBottom(uint16_t row);
+
+    /** Calculates character's right coordinate in pixel.
+     *
+     * @param column The character's display column
+     * @returns the x coordinate in pixels
+     *
+     */
+    uint16_t getCharRight(uint16_t column);
+
+    DigitalOut _cs;
+    DigitalOut _reset;
+    DigitalOut _dc;
+    unsigned char* font;
+
+
+
+
 protected:
 
-  /** Set draw window region to whole screen
-   *
-   */  
-  void WindowMax (void);
+    /** Set draw window region to whole screen
+     *
+     */
+    void WindowMax (void);
+
+
+    /** draw a horizontal line
+     *
+     * @param x0 horizontal start
+     * @param x1 horizontal stop
+     * @param y vertical position
+     * @param color 16 bit color
+     *
+     */
+    void hline(int x0, int x1, int y, int colour);
+
+    /** draw a vertical line
+     *
+     * @param x horizontal position
+     * @param y0 vertical start
+     * @param y1 vertical stop
+     * @param color 16 bit color
+     */
+    void vline(int y0, int y1, int x, int colour);
+
+    /** Set draw window region
+     *
+     * @param x horizontal position
+     * @param y vertical position
+     * @param w window width in pixel
+     * @param h window height in pixels
+     */
+    virtual void window (unsigned int x, unsigned int y, unsigned int w, unsigned int h);
+
 
 
-  /** draw a horizontal line
-   *
-   * @param x0 horizontal start
-   * @param x1 horizontal stop
-   * @param y vertical position
-   * @param color 16 bit color                                               
-   *
-   */
-  void hline(int x0, int x1, int y, int colour);
-    
-  /** draw a vertical line
-   *
-   * @param x horizontal position
-   * @param y0 vertical start 
-   * @param y1 vertical stop
-   * @param color 16 bit color
-   */
-  void vline(int y0, int y1, int x, int colour);
-    
-  /** Set draw window region
-   *
-   * @param x horizontal position
-   * @param y vertical position
-   * @param w window width in pixel
-   * @param h window height in pixels
-   */    
-  virtual void window (unsigned int x,unsigned int y, unsigned int w, unsigned int h);
-    
- 
-    
-  /** Init the ILI9341 controller 
-   *
-   */    
-  void tft_reset();
-    
-   /** Write data to the LCD controller
-   *
-   * @param dat data written to LCD controller
-   * 
-   */   
-  //void wr_dat(unsigned int value);
-  void wr_dat(unsigned char value);
-    
-  /** Write a command the LCD controller 
-   *
-   * @param cmd: command to be written   
-   *
-   */   
-  void wr_cmd(unsigned char value);
-    
-   /** Start data sequence to the LCD controller
-   * 
-   */   
-  //void wr_dat_start();
-    
-  /** Stop of data writing to the LCD controller
-   *   
-   */  
-  //void wr_dat_stop();
-    
-  /** write data to the LCD controller
-   *
-   * @param data to be written 
-   *                                           *
-   */    
-  //void wr_dat_only(unsigned short dat);
-    
-  /** Read byte from the LCD controller
-   *
-   * @param cmd comand to controller
-   * @returns data from LCD controller
-   *  
-   */    
-   char rd_byte(unsigned char cmd);
-    
-  
-  int rd_32(unsigned char cmd);  
-    
-    
-  /** Write a value to the to a LCD register
-   *
-   * @param reg register to be written
-   * @param val data to be written
-   */   
-  //void wr_reg (unsigned char reg, unsigned char val);
-    
-  /** Read a LCD register
-   *
-   * @param reg register to be read
-   * @returns value of the register 
-   */    
-  //unsigned short rd_reg (unsigned char reg);
-    
-  #if defined TARGET_NUCLEO_L152RE || defined TARGET_NUCLEO_F103RB || defined TARGET_LPC1768
-  /** fast SPI write function for optimized versions 
-   *
-   * @param data  data written to SPI
-   *
-   */
-  virtual void f_write(int data);
-  virtual void spi_bsy(void);
-  virtual void spi_16(bool s);
-  
-  #endif  
-    
-  unsigned char spi_port; 
-  unsigned int orientation;
-  unsigned int char_x;
-  unsigned int char_y;
-  unsigned char spi_num;
-  
-    
+    /** Init the ILI9341 controller
+     *
+     */
+    void tft_reset();
+
+    /** Write data to the LCD controller
+    *
+    * @param dat data written to LCD controller
+    *
+    */
+    //void wr_dat(unsigned int value);
+    void wr_dat(unsigned char value);
+
+    /** Write a command the LCD controller
+     *
+     * @param cmd: command to be written
+     *
+     */
+    void wr_cmd(unsigned char value);
+
+    /** Start data sequence to the LCD controller
+    *
+    */
+    //void wr_dat_start();
+
+    /** Stop of data writing to the LCD controller
+     *
+     */
+    //void wr_dat_stop();
+
+    /** write data to the LCD controller
+     *
+     * @param data to be written
+     *                                           *
+     */
+    //void wr_dat_only(unsigned short dat);
+
+    /** Read byte from the LCD controller
+     *
+     * @param cmd comand to controller
+     * @returns data from LCD controller
+     *
+     */
+    char rd_byte(unsigned char cmd);
+
+
+    int rd_32(unsigned char cmd);
+
+
+    /** Write a value to the to a LCD register
+     *
+     * @param reg register to be written
+     * @param val data to be written
+     */
+    //void wr_reg (unsigned char reg, unsigned char val);
+
+    /** Read a LCD register
+     *
+     * @param reg register to be read
+     * @returns value of the register
+     */
+    //unsigned short rd_reg (unsigned char reg);
+
+#if defined TARGET_NUCLEO_L152RE || defined TARGET_NUCLEO_F103RB || defined TARGET_LPC1768
+    /** fast SPI write function for optimized versions
+     *
+     * @param data  data written to SPI
+     *
+     */
+    virtual void f_write(int data);
+    virtual void spi_bsy(void);
+    virtual void spi_16(bool s);
+
+#endif
+
+    unsigned char spi_port;
+    unsigned int orientation;
+    unsigned int char_x;
+    unsigned int char_y;
+    unsigned char spi_num;
+
+
 };
 
 #endif
+
--- a/SPI_TFT_ILI9341_NUCLEO.cpp	Wed Jun 25 16:51:27 2014 +0000
+++ b/SPI_TFT_ILI9341_NUCLEO.cpp	Sat Feb 11 18:56:31 2017 +0000
@@ -12,9 +12,9 @@
  */
 
  // 24.06.14   initial version
- // 25.06.14   add Nucleo F103RB 
+ // 25.06.14   add Nucleo F103RB
 
-// only include this file if target is L152 or F103RB : 
+// only include this file if target is L152 or F103RB :
 #if defined TARGET_NUCLEO_L152RE || defined TARGET_NUCLEO_F103RB
 
 #include "SPI_TFT_ILI9341.h"
@@ -34,7 +34,7 @@
 //extern Serial pc;
 //extern DigitalOut xx;     // debug !!
 
-DMA_InitTypeDef DMA_InitStructure; 
+DMA_InitTypeDef DMA_InitStructure;
 
 
 SPI_TFT_ILI9341::SPI_TFT_ILI9341(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset, PinName dc, const char *name)
@@ -98,7 +98,7 @@
 #define bit_SPI2_bsy  *((volatile unsigned int *)0x4207011C)
 #define bit_SPI3_bsy  *((volatile unsigned int *)0x4207811C)
 
-void inline SPI_TFT_ILI9341::spi_bsy(void){    
+void inline SPI_TFT_ILI9341::spi_bsy(void){
 switch(spi_num){        // decide which SPI is to use
 case (1):
     while(bit_SPI1_bsy == 1);   // SPI1->SR bit 7
@@ -481,9 +481,9 @@
 // use DMA to transfer pixel data to the screen
 void SPI_TFT_ILI9341::cls (void)
 {
-    // we can use the fillrect function 
+    // we can use the fillrect function
    fillrect(0,0,width()-1,height()-1,_background);
-}    
+}
 
 void SPI_TFT_ILI9341::circle(int x0, int y0, int r, int color)
 {
@@ -892,7 +892,7 @@
         free ((uint16_t *) buffer);
         spi_16(0);
     }
-    
+
     else{
         #endif
         zeichen = &font[((c -32) * offset) + 4]; // start of char bitmap
@@ -911,9 +911,9 @@
         spi_bsy();
         _cs = 1;
         spi_16(0);
-    #ifdef use_ram   
+    #ifdef use_ram
     }
-    #endif    
+    #endif
     _cs = 1;
     WindowMax();
     if ((w + 2) < hor) {                   // x offset to next char
@@ -1046,3 +1046,4 @@
 
 #endif
 
+
--- a/SPI_TFT_ILI9341_NXP.cpp	Wed Jun 25 16:51:27 2014 +0000
+++ b/SPI_TFT_ILI9341_NXP.cpp	Sat Feb 11 18:56:31 2017 +0000
@@ -912,3 +912,4 @@
 
 #endif
 
+
--- a/TextDisplay.cpp	Wed Jun 25 16:51:27 2014 +0000
+++ b/TextDisplay.cpp	Sat Feb 11 18:56:31 2017 +0000
@@ -75,3 +75,4 @@
     setvbuf(stdout, NULL, _IOLBF, columns());
     return true;
 } 
+
--- a/TextDisplay.h	Wed Jun 25 16:51:27 2014 +0000
+++ b/TextDisplay.h	Sat Feb 11 18:56:31 2017 +0000
@@ -78,3 +78,4 @@
 };
 
 #endif
+