Added methods and features

Fork of SPI_TFT_ILI9341 by Peter Drescher

Revision:
11:7aabc3810093
Parent:
10:2d505d14b7eb
--- a/SPI_TFT_ILI9341.cpp	Sat Apr 12 20:33:24 2014 +0000
+++ b/SPI_TFT_ILI9341.cpp	Tue Apr 22 19:10:47 2014 +0000
@@ -24,7 +24,6 @@
 //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)
-//WH    : _spi(mosi, miso, sclk), _cs(cs), _reset(reset), _dc(dc), GraphicsDisplay(name)
     : GraphicsDisplay(name), _spi(mosi, miso, sclk), _cs(cs), _dc(dc) 
 {
 
@@ -187,7 +186,10 @@
     _cs = 0;
     d = cmd;
     d = d << 1;
+
+//Note WH: the 9bit format is not supported for most mbed devices...This wont work.
     _spi.format(9,0);    // we have to add a dummy clock cycle
+     
     _spi.write(d);
     _spi.format(8,0);   
     _dc = 1;
@@ -218,7 +220,7 @@
 void SPI_TFT_ILI9341::tft_reset()
 {
 //WH    _spi.format(8,3);                  // 8 bit spi Mode 3
-    _spi.format(8,0);                  // 8 bit spi mode 0    
+    _spi.format(8,0);                  // 8 bit spi, mode 0    
     
 //    _spi.frequency(4000000);          // 4 Mhz SPI clock
 //    _spi.frequency(8000000);          // 8 Mhz SPI clock
@@ -229,22 +231,18 @@
 
     _hwreset();                        // HW reset 
          
-//WH    wr_cmd(0x01);                     // SW reset  
     wr_cmd(ILI9341_DISPLAY_RST);      // SW reset      
     wait_ms(5);
 
-//WH    wr_cmd(0x28);                     // display off  
     wr_cmd(ILI9341_DISPLAY_OFF);      // display off      
 
     /* Start Initial Sequence ----------------------------------------------------*/
-//     wr_cmd(0xCF);    
      wr_cmd(ILI9341_POWERB);    /* Power control B register */
      _spi.write(0x00);
      _spi.write(0x83);
      _spi.write(0x30);
      _cs = 1;
      
-//     wr_cmd(0xED);     
      wr_cmd(ILI9341_POWER_SEQ); /* Power on sequence register */
      _spi.write(0x64);
      _spi.write(0x03);
@@ -252,14 +250,12 @@
      _spi.write(0x81);
      _cs = 1;
      
-//     wr_cmd(0xE8);                     
      wr_cmd(ILI9341_DTCA);      /* Driver timing control A */                      
      _spi.write(0x85);
      _spi.write(0x01);
      _spi.write(0x79);
      _cs = 1;
      
-//     wr_cmd(0xCB);                     
      wr_cmd(ILI9341_POWERA);    /* Power control A register */                     
      _spi.write(0x39);
      _spi.write(0x2C);
@@ -268,65 +264,53 @@
      _spi.write(0x02);
      _cs = 1;
            
-//     wr_cmd(0xF7);                     
      wr_cmd(ILI9341_PRC);       /* Pump ratio control register */                   
      _spi.write(0x20);
      _cs = 1;
            
-//     wr_cmd(0xEA);                     
      wr_cmd(ILI9341_DTCB);      /* Driver timing control B */                          
      _spi.write(0x00);
      _spi.write(0x00);
      _cs = 1;
      
-//     wr_cmd(0xC0);                     // POWER_CONTROL_1
      wr_cmd(ILI9341_POWER1);    // POWER_CONTROL_1   
      _spi.write(0x26);
      _cs = 1;
  
-//     wr_cmd(0xC1);                     // POWER_CONTROL_2
      wr_cmd(ILI9341_POWER2);    // POWER_CONTROL_2
      _spi.write(0x11);
      _cs = 1;
      
-//     wr_cmd(0xC5);                     // VCOM_CONTROL_1
      wr_cmd(ILI9341_VCOM1);     // VCOM_CONTROL_1     
      _spi.write(0x35);
      _spi.write(0x3E);
      _cs = 1;
      
-//     wr_cmd(0xC7);                     // VCOM_CONTROL_2
      wr_cmd(ILI9341_VCOM2);     // VCOM_CONTROL_2     
      _spi.write(0xBE);
      _cs = 1; 
      
-//     wr_cmd(0x36);                     // MEMORY_ACCESS_CONTROL
      wr_cmd(ILI9341_MAC);       // MEMORY_ACCESS_CONTROL     
      _spi.write(0x48);            // my,mx,mv,ml,BGR,mh,0,0
      _cs = 1; 
      
-//     wr_cmd(0x3A);                     // COLMOD_PIXEL_FORMAT_SET
      wr_cmd(ILI9341_PIXEL_FORMAT); /* Pixel Format register */
      _spi.write(0x55);                 // 16 bit pixel 
      _cs = 1;
      
-//     wr_cmd(0xB1);                     // Frame Rate
      wr_cmd(ILI9341_FRC);          /* Frame Rate Control register */
      _spi.write(0x00);
      _spi.write(0x1B);               
      _cs = 1;
      
-//     wr_cmd(0xF2);                     // Gamma Function Disable
      wr_cmd(ILI9341_3GAMMA_EN);    /* 3 Gamma enable register */     
      _spi.write(0x08);             // Gamma Function Disable
      _cs = 1; 
      
-//     wr_cmd(0x26);                     
      wr_cmd(ILI9341_GAMMA);        /* Gamma register */
      _spi.write(0x01);                 // gamma set for curve 01/2/04/08
      _cs = 1; 
      
-//     wr_cmd(0xE0);                     // positive gamma correction
      wr_cmd(ILI9341_PGAMMA);       /* Positive Gamma Correction register*/     
      _spi.write(0x1F); 
      _spi.write(0x1A); 
@@ -345,7 +329,6 @@
      _spi.write(0x00);
      _cs = 1;
      
-//     wr_cmd(0xE1);                     // negativ gamma correction
      wr_cmd(ILI9341_NGAMMA);       /* Negative Gamma Correction register*/
      _spi.write(0x00); 
      _spi.write(0x25); 
@@ -372,12 +355,10 @@
      //wr_cmd(ILI9341_TEAR_ON);            // tearing effect on
      //_cs = 1;
       
-//WH     wr_cmd(0xB7);                       // entry mode
      wr_cmd(ILI9341_ENTRY_MODE);          // entry mode         
      _spi.write(0x07);
      _cs = 1;
      
-//     wr_cmd(0xB6);                       // display function control
      wr_cmd(ILI9341_DFC);                /* Display Function Control register*/     
      _spi.write(0x0A);
      _spi.write(0x82);
@@ -385,13 +366,11 @@
      _spi.write(0x00);
      _cs = 1;
      
-//     wr_cmd(0x11);                     // sleep out
      wr_cmd(ILI9341_SLEEP_OUT);          // sleep out     
      _cs = 1;
      
      wait_ms(100);
      
-//     wr_cmd(0x29);                     // display on
      wr_cmd(ILI9341_DISPLAY_ON); 
      _cs = 1;
      
@@ -413,7 +392,6 @@
 
 void SPI_TFT_ILI9341::pixel(int x, int y, int color)
 {
-//    wr_cmd(0x2A);
     wr_cmd(ILI9341_COLUMN_ADDR);
     _spi.write(x >> 8);
     _spi.write(x);
@@ -422,7 +400,6 @@
     
     _cs = 1;
     
-//    wr_cmd(0x2B);
     wr_cmd(ILI9341_PAGE_ADDR);
     _spi.write(y >> 8);
     _spi.write(y);
@@ -431,21 +408,8 @@
     
     _cs = 1;
 
-//    wr_cmd(0x2C);  // send pixel
     wr_cmd(ILI9341_GRAM);  // send pixel     
 
-//WH
-#if(0)
-    #if defined TARGET_KL25Z  // 8 Bit SPI
-    _spi.write(color >> 8);
-    _spi.write(color & 0xff);
-    #else 
-    _spi.format(16,0);                            // switch to 16 bit Mode 0
-    _spi.write(color);                              // Write D0..D15
-    _spi.format(8,0);
-    #endif
-#endif
-
 //    #if (SPI_16 == 1)
     #if(0)   // dont bother switching for only one pixel
     // 16 Bit SPI
@@ -465,7 +429,6 @@
 void SPI_TFT_ILI9341::window (unsigned int x, unsigned int y, unsigned int w, unsigned int h)
 {
 
-//    wr_cmd(0x2A);
     wr_cmd(ILI9341_COLUMN_ADDR);
     _spi.write(x >> 8);
     _spi.write(x);
@@ -473,7 +436,6 @@
     _spi.write(x+w-1);   
     _cs = 1;
 
-//    wr_cmd(0x2B);
     wr_cmd(ILI9341_PAGE_ADDR);  
     _spi.write(y >> 8);
     _spi.write(y);
@@ -489,30 +451,6 @@
 }
 
 
-//WH
-#if(0)
-void SPI_TFT_ILI9341::cls (void)
-{
-    int pixel = ( width() * height());
-    window_max();
-    wr_cmd(0x2C);  // send pixel
-    #if defined TARGET_KL25Z  // 8 Bit SPI
-    unsigned int i;
-    for (i = 0; i < ( width() * height()); i++){
-        _spi.write(_background >> 8);
-        _spi.write(_background & 0xff);
-        }
-    
-    #else 
-    _spi.format(16,0);                            // switch to 16 bit Mode 0
-    unsigned int i;
-    for (i = 0; i < ( width() * height()); i++)
-        _spi.write(_background);
-    _spi.format(8,0);    
-    #endif                         
-    _cs = 1; 
-}
-#else
 
 /** Fill the screen with _background color
   *  @param none
@@ -522,11 +460,9 @@
 {  
   fillrect(0, 0, width()-1, height()-1, _background);
 }    
-    
-#endif
 
 
-
+//WH test
 void SPI_TFT_ILI9341::newcls (void)
 {  
     int pixels = height() * width();
@@ -737,34 +673,6 @@
 } /* End filloval */
 
 
-
-//WH
-#if(0)
-void SPI_TFT_ILI9341::hline(int x0, int x1, int y, int color)
-{
-    int w;
-    w = x1 - x0 + 1;
-    window(x0,y,w,1);
-    wr_cmd(0x2C);  // send pixel
-    #if defined TARGET_KL25Z  // 8 Bit SPI
-    int j;
-    for (j=0; j<w; j++) {
-        _spi.write(color >> 8);
-        _spi.write(color & 0xff);
-    } 
-    #else 
-    _spi.format(16,0);                            // switch to 16 bit Mode 0
-    int j;
-    for (j=0; j<w; j++) {
-        _spi.write(color);
-    }
-    _spi.format(8,0);
-    #endif
-    _cs = 1;
-    window_max();
-    return;
-}
-#else
 void SPI_TFT_ILI9341::hline(int x0, int x1, int y, int color)
 {
     int i, w;
@@ -795,35 +703,9 @@
     _cs = 1;
     window_max();
 }
-#endif
 
 
 
-//WH
-#if(0)
-void SPI_TFT_ILI9341::vline(int x, int y0, int y1, int color)
-{
-    int h;
-    h = y1 - y0 + 1;
-    window(x,y0,1,h);
-    wr_cmd(0x2C);  // send pixel
-    #if defined TARGET_KL25Z  // 8 Bit SPI
-    for (int y=0; y<h; y++) {
-        _spi.write(color >> 8);
-        _spi.write(color & 0xff);
-    } 
-    #else 
-    _spi.format(16,0);                            // switch to 16 bit Mode 0
-    for (int y=0; y<h; y++) {
-        _spi.write(color);
-    }
-    _spi.format(8,0);
-    #endif
-    _cs = 1;
-    window_max();
-    return;
-}
-#else
 void SPI_TFT_ILI9341::vline(int x, int y0, int y1, int color)
 {
     int i, h;
@@ -855,7 +737,6 @@
     _cs = 1;
     window_max();
 }
-#endif
 
 void SPI_TFT_ILI9341::line(int x0, int y0, int x1, int y1, int color)
 {
@@ -948,34 +829,6 @@
 }
 
 
-//WH
-#if(0)
-void SPI_TFT_ILI9341::fillrect(int x0, int y0, int x1, int y1, int color)
-{
-    int h = y1 - y0 + 1;
-    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
-    for (int p=0; p<pixel; p++) {
-        _spi.write(color >> 8);
-        _spi.write(color & 0xff);
-    }
-   #else
-    _spi.format(16,0);                            // switch to 16 bit Mode 0
-    for (int p=0; p<pixel; p++) {
-        _spi.write(color);
-    }
-    _spi.format(8,0);
-    #endif
-    _cs = 1;
-    window_max();
-    return;
-}
-
-#else
-
 void SPI_TFT_ILI9341::fillrect(int x0, int y0, int x1, int y1, int color)
 {  
     //sanity check
@@ -1014,7 +867,7 @@
 
     _cs = 1; 
 }
-#endif
+
 
 void SPI_TFT_ILI9341::roundrect( int x1, int y1, int x2, int y2, int color )
 {
@@ -1298,8 +1151,6 @@
 }
 #endif
 
-
-
 #endif