Modifié pour fonctionner avec les écran arduino. Ecran surplaque blanche, dos bleu, au dimensions de l'arduino esplora

Dependencies:   ST7735_TFT

Dependents:   Arduino_screen

Fork of ST7735_TFT by Jonne Valola

Files at this revision

API Documentation at this revision

Comitter:
alex_asi_elec
Date:
Fri Dec 06 21:39:29 2013 +0000
Parent:
1:967235e6fd48
Commit message:
Fonctionne sur ?cran arduino (adafruit)

Changed in this revision

ST7735_TFT.cpp Show annotated file Show diff for this revision Revisions of this file
ST7735_TFT.h Show annotated file Show diff for this revision Revisions of this file
ST7735_TFT.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 967235e6fd48 -r b9c08958fef9 ST7735_TFT.cpp
--- a/ST7735_TFT.cpp	Sun Dec 11 21:18:21 2011 +0000
+++ b/ST7735_TFT.cpp	Fri Dec 06 21:39:29 2013 +0000
@@ -21,25 +21,168 @@
 #include "ST7735_TFT.h"
 #include "mbed.h"
 
-#define BPP         16                  // Bits per pixel                
+#define BPP         16                  // Bits per pixel   
+#define DELAY       0x80             
 
 ST7735_TFT::ST7735_TFT(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName rs, PinName reset, const char *name)
         : _spi(mosi, miso, sclk), _cs(cs), _rs(rs), _reset(reset),GraphicsDisplay(name) {
-    tft_reset();
+    Gtft_reset();
     orientation = 2;
     char_x = 0;
 }
 
+void ST7735_TFT::Gtft_reset() {
+    static unsigned short driverCode;
+    
+    // init SPI
+    _spi.format(8,3);                 // 8 bit spi mode 3
+    _spi.frequency(4000000);         // 16Mhz SPI clock ... 15Mhz is maximum for display, but it seems to work
+    
+    // reset exactly like in Arduino version
+    _cs = 0;
+    _reset = 1;                       // reset
+    wait_ms(500);
+    _reset = 0;                       // reset
+    wait_ms(500);
+    _reset = 1;                       // reset
+    wait_ms(500);
+    
+    /* Start Initial Sequence ----------------------------------------------------*/
+    wr_cmd(ST7735_SWRESET);                         /* SW Reset                       */
+    wait_ms(150);
+    wr_cmd(ST7735_SLPOUT);                         /* Out of sleepmode               */
+    wait_ms(500);
+    
+    wr_cmd(ST7735_FRMCTR1);                         /* Frame rate in normal mode            */
+   // wr_dat(0x02);                              
+    wr_dat(0x0B);
+    wr_dat(0x14);
+    
+    wr_cmd(0xC0);                         /* VRH1           */
+   // wr_dat(0x02);                              
+    wr_dat(0x08);
+    wr_dat(0x00);
+
+    wr_cmd(0xC1);                         /* BT           */
+    //wr_dat(0x01);                              
+    wr_dat(0x05);
+    
+    wr_cmd(0xC5);                           /* VHM          */
+    //wr_dat(0x02);                               
+    wr_dat(0x41);
+    wr_dat(0x30);
+    
+    wr_cmd(0xC7);   // lcd mode
+    //wr_dat(0x01);   
+    wr_dat(0x0C1);
+    
+    wr_cmd(0xEC);   // POWER CONTROL 1   
+   //wr_dat(0x01); 
+    wr_dat(0x1B);           
+    
+    wr_cmd(0x3A);   // color format  
+    //wr_dat(0x01 + DELAY);          
+    wr_dat(0x55);
+    wait_ms(100);
+    
+    wr_cmd(0x2A);   // colonne addr 
+   // wr_dat(0x04); 
+    wr_dat(0x00); 
+    wr_dat(0x00); 
+    wr_dat(0x00); 
+    wr_dat(0x7F);  
+    
+    wr_cmd(0x2B);   // page addr 
+   // wr_dat(0x04); 
+    wr_dat(0x00); 
+    wr_dat(0x00); 
+    wr_dat(0x00); 
+    wr_dat(0x9F);  
+    
+    wr_cmd(0x36);   // scanning direction  
+    //wr_dat(0x01); 
+    wr_dat(0xC8);  
+    
+    wr_cmd(0xB7);   // source output direction  
+   // wr_dat(0x01);          
+    wr_dat(0x00);
+    
+    wr_cmd(0xF2);   // enable gama bit
+   // wr_dat(0x01);          
+    wr_dat(0x00);
+    
+    wr_cmd(0xE0);   // magic
+   // wr_dat(0x15 + DELAY); 
+    wr_dat(0x28); 
+    wr_dat(0x24); 
+    wr_dat(0x22); 
+    wr_dat(0x31);  
+    wr_dat(0x2B); 
+    wr_dat(0x0E); 
+    wr_dat(0x53); 
+    wr_dat(0xA5);
+    wr_dat(0x42); 
+    wr_dat(0x16); 
+    wr_dat(0x18); 
+    wr_dat(0x12);
+    wr_dat(0x1A); 
+    wr_dat(0x14); 
+    wr_dat(0x03); 
+    wait_ms(50);  
+    
+    wr_cmd(0xE1);   // more magic
+   // wr_dat(0x15 + DELAY); 
+    wr_dat(0x17); 
+    wr_dat(0x1B); 
+    wr_dat(0x1D); 
+    wr_dat(0x0E);  
+    wr_dat(0x14); 
+    wr_dat(0x11); 
+    wr_dat(0x2C); 
+    wr_dat(0xA5);
+    wr_dat(0x3D); 
+    wr_dat(0x09); 
+    wr_dat(0x27); 
+    wr_dat(0x2D);
+    wr_dat(0x25); 
+    wr_dat(0x2B); 
+    wr_dat(0x3C); 
+    wait_ms(50);  
+    
+    wr_cmd(ST7735_NORON);   // Normal ON
+    wr_dat(DELAY);
+    wait_ms(10);  
+    
+    wr_cmd(ST7735_DISPON);   // Main screen ON
+    wr_dat(DELAY);
+    wait_ms(500);  
+  
+  switch (orientation) {
+        case 0:
+            wr_reg(0xC8, 0x0008);
+            break;
+        case 1:
+            wr_reg(0xC8, 0x0068);
+            break;
+        case 2:
+            wr_reg(0xC8, 0x00C8);
+            break;
+        case 3:
+            wr_reg(0xC8, 0x00A8);
+            break;
+    }
+    WindowMax ();
+}
 
 int ST7735_TFT::width() {
-    if (orientation == 0 || orientation == 2) return 128;
-    else return 160; 
+    if (orientation == 0 || orientation == 2) return 250;//128
+    else return 250; 
 }
 
 
 int ST7735_TFT::height() {
-    if (orientation == 0 || orientation == 2) return 160;
-    else return 128; 
+    if (orientation == 0 || orientation == 2) return 250;
+    else return 250; 
 }
 
 
@@ -249,7 +392,7 @@
     wr_dat(0x00);   //
     wr_dat(0x00);   // xstart = 0
     wr_dat(0x00);   //
-    wr_dat(0x7F);   // xend = 127
+    wr_dat(0x7F);   // xend = 127 7F
     
     wr_cmd(ST7735_RASET);   // ROW ADDR SET   
     wr_dat(0x00);   //
@@ -319,7 +462,7 @@
 
 
 void ST7735_TFT::pixel(int x, int y, int color) {
-  if ((x >= width()) || (y >= height())) return;
+  //if ((x >= width()) || (y >= height())) return;******************************************!!!!!!!!!!!!!*****
 
   window(x,y,x+1,y+1);
   
diff -r 967235e6fd48 -r b9c08958fef9 ST7735_TFT.h
--- a/ST7735_TFT.h	Sun Dec 11 21:18:21 2011 +0000
+++ b/ST7735_TFT.h	Fri Dec 06 21:39:29 2013 +0000
@@ -26,6 +26,12 @@
 #define RGB(r,g,b)  (((r&0xF8)<<8)|((g&0xFC)<<3)|((b&0xF8)>>3)) //5 red | 6 green | 5 blue
 
 /*define ST7735 Commands */
+#define INITR_GREENTAB 0x0
+#define INITR_REDTAB   0x1
+#define INITR_BLACKTAB   0x2
+
+#define ST7735_TFTWIDTH  128
+#define ST7735_TFTHEIGHT 160
 
 #define ST7735_NOP 0x0
 #define ST7735_SWRESET 0x01
@@ -348,6 +354,11 @@
    *
    */    
   void tft_reset();
+  
+  /** Init the ST7735 controller TOO BUT BETTER!
+   *
+   */    
+  void Gtft_reset();
     
    /** Write data to the LCD controller
    *
diff -r 967235e6fd48 -r b9c08958fef9 ST7735_TFT.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ST7735_TFT.lib	Fri Dec 06 21:39:29 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/smultron1977/code/ST7735_TFT/#967235e6fd48