Chinese module HY-1.8 SPI TFT lcd Display library.

Dependencies:   BurstSPI

Dependents:   KL25Z_DCF77_HY-1_8LCD

Fork of HY-1_8TFT_ST7735 by Paul Staron

Files at this revision

API Documentation at this revision

Comitter:
star297
Date:
Sun Oct 11 21:30:26 2015 +0000
Parent:
1:ef70eaf15b18
Commit message:
updated BurstSPI

Changed in this revision

BurstSPI.lib Show annotated file Show diff for this revision Revisions of this file
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
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
diff -r ef70eaf15b18 -r 26149011665e BurstSPI.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BurstSPI.lib	Sun Oct 11 21:30:26 2015 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/Sissors/code/BurstSPI/#bc069279eb37
diff -r ef70eaf15b18 -r 26149011665e GraphicsDisplay.cpp
--- a/GraphicsDisplay.cpp	Fri Apr 19 20:46:47 2013 +0000
+++ b/GraphicsDisplay.cpp	Sun Oct 11 21:30:26 2015 +0000
@@ -110,7 +110,7 @@
     blitbit(column * 8, row * 8, 8, 8, (char*)&(FONT8x8[value - 0x1F][0]));
 }
 
-void GraphicsDisplay::window(int x, int y, int w, int h) {
+void GraphicsDisplay::gwindow(int x, int y, int w, int h) {
     // current pixel location
     _x = x;
     _y = y;
@@ -136,7 +136,7 @@
 }
 
 void GraphicsDisplay::fill(int x, int y, int w, int h, int colour) { 
-    window(x, y, w, h);
+    gwindow(x, y, w, h);
     for(int i=0; i<w*h; i++) {
         putp(colour);
     }
@@ -147,14 +147,14 @@
 }
     
 void GraphicsDisplay::blit(int x, int y, int w, int h, const int *colour) { 
-    window(x, y, w, h);
+    gwindow(x, y, w, h);
     for(int i=0; i<w*h; i++) {
         putp(colour[i]);
     }
 }
     
 void GraphicsDisplay::blitbit(int x, int y, int w, int h, const char* colour) {
-    window(x, y, w, h);
+    gwindow(x, y, w, h);
     for(int i = 0; i < w*h; i++) {
         char byte = colour[i >> 3];
         int offset = i & 0x7;
diff -r ef70eaf15b18 -r 26149011665e GraphicsDisplay.h
--- a/GraphicsDisplay.h	Fri Apr 19 20:46:47 2013 +0000
+++ b/GraphicsDisplay.h	Sun Oct 11 21:30:26 2015 +0000
@@ -15,7 +15,7 @@
     virtual int width() = 0;
     virtual int height() = 0;
         
-    virtual void window(int x, int y, int w, int h);
+    virtual void gwindow(int x, int y, int w, int h);
     virtual void putp(int colour);
     
     virtual void cls();
diff -r ef70eaf15b18 -r 26149011665e ST7735_TFT.cpp
--- a/ST7735_TFT.cpp	Fri Apr 19 20:46:47 2013 +0000
+++ b/ST7735_TFT.cpp	Sun Oct 11 21:30:26 2015 +0000
@@ -4,10 +4,10 @@
 #include "ST7735_TFT.h"
 #include "mbed.h"
 
-#define BPP         8                  // Bits per pixel                
+#define BPP         16                  // Bits per pixel                
 
 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)
+        : GraphicsDisplay(name),_spi(mosi, miso, sclk), _cs(cs), _rs(rs), _reset(reset)
          {
     tft_reset();
     orientation = 2;
@@ -128,7 +128,7 @@
 void ST7735_TFT::tft_reset() {
      // init SPI
     _spi.format(8,3);                 // 8 bit spi mode 3
-    _spi.frequency(16000000);         // 16Mhz SPI clock ... 15Mhz is maximum for display, but it seems to work
+    _spi.frequency(15000000);         // 16Mhz SPI clock ... 15Mhz is maximum for display, but it seems to work
     _cs = 0;
     _reset = 1;                       // reset
     wait_ms(10);
@@ -272,8 +272,8 @@
    _rs = 1; 
    _cs = 0;
    _spi.write(color);
-  _spi.write(color>>8);       
-  _cs = 1;
+   _spi.write(color>>8);       
+   _cs = 1;
 }
 void ST7735_TFT::window (unsigned int x, unsigned int y, unsigned int w, unsigned int h) {
   wr_cmd(ST7735_CASET);  // column addr set
@@ -297,9 +297,15 @@
     WindowMax();
     wr_dat_start();    
     for (i = 0; i < ( (width()) * (height())); i++) {
-        _spi.write(_background);
-        _spi.write(_background>>8);    
+        
+        //_spi.write(_background>>8);
+        //_spi.write(_background); 
+        
+        _spi.fastWrite(_background>>8);
+        _spi.fastWrite(_background);
+                   
     }
+    _spi.clearRX();
     wr_dat_stop();   
 }
 void ST7735_TFT::circle(int x0, int y0, int r, int color) {
@@ -408,9 +414,12 @@
     wr_cmd(0x2C);
     wr_dat_start();
     for (int x=0; x<w; x++) {
-        _spi.write(color);
-        _spi.write(color >> 8);
+        //_spi.write(color);
+        //_spi.write(color >> 8);
+        _spi.fastWrite(color>>8);
+        _spi.fastWrite(color);
     }
+    _spi.clearRX();
     wr_dat_stop();
     return;
 }
@@ -421,9 +430,12 @@
     wr_cmd(0x2C);
     wr_dat_start();
     for (int y=0; y<h; y++) {
-        _spi.write(color);
-        _spi.write(color >> 8);
+        //_spi.write(color);
+        //_spi.write(color >> 8);
+        _spi.fastWrite(color>>8);
+        _spi.fastWrite(color);
     }
+    _spi.clearRX();
     wr_dat_stop();
     return;
 }
@@ -509,9 +521,14 @@
     wr_cmd(0x2C);
     wr_dat_start();
     for (int p=0; p<pixel; p++) {
-        _spi.write(color);
-        _spi.write(color >> 8);
+        //_spi.write(color);
+        //_spi.write(color >> 8);
+        _spi.fastWrite(color>>8);
+        _spi.fastWrite(color);
+        
+        
     }
+    _spi.clearRX();
     wr_dat_stop();
     return;
 }
@@ -563,15 +580,22 @@
         for (i=0; i<hor; i++) {   //  horz line
             z =  sign[bpl * i + ((j & 0xF8) >> 3)+1];
             b = 1 << (j & 0x07);
-            if (( z & b ) == 0x00) {
-                _spi.write(_background);     
-                _spi.write(_background>>8);  
-            } else {
-                _spi.write(_foreground);     
-                _spi.write(_foreground>>8);  
+            if (( z & b ) == 0x00) {                  
+                //_spi.write(_background>>8);
+                //_spi.write(_background); 
+                _spi.fastWrite(_background>>8);
+                _spi.fastWrite(_background);                              
+                  
+            } else {                     
+               // _spi.write(_foreground>>8);
+               // _spi.write(_foreground); 
+                _spi.fastWrite(_foreground>>8); 
+                _spi.fastWrite(_foreground);     
+                                 
             }
         }
     }
+    _spi.clearRX();
     wr_dat_stop();
     if ((w + 2) < hor) {                   // x offset to next char
         char_x += w + 2;
@@ -588,11 +612,14 @@
     wr_dat_start();
     for (j = 0; j < h; j++) {        //Lines
         for (i = 0; i < w; i++) {     // copy pixel data to TFT
-            _spi.write(*bitmap_ptr);    // one line
-            _spi.write(*bitmap_ptr >> 8);  
+            //_spi.write(*bitmap_ptr);    // one line
+            //_spi.write(*bitmap_ptr >> 8);
+            _spi.fastWrite(*bitmap_ptr);
+            _spi.fastWrite(*bitmap_ptr >> 8);  
             bitmap_ptr++;
         }
     }
+    _spi.clearRX();
     wr_dat_stop();
 }
 int ST7735_TFT::BMP_16(unsigned int x, unsigned int y, const char *Name_BMP) {
@@ -657,10 +684,13 @@
         fseek(Image, off ,SEEK_SET);
         fread(line,1,PixelWidth * 2,Image);       // read a line - slow !
         for (i = 0; i < PixelWidth; i++) {        // copy pixel data to TFT
-            _spi.write(line[i]);                  // one 16 bit pixel
-            _spi.write(line[i]>>8);
+            //_spi.write(line[i]);                  // 2 x 8 bit pixel
+            //_spi.write(line[i]>>8);
+            _spi.fastWrite(line[i]);
+            _spi.fastWrite(line[i]>>8);
         } 
     }
+    _spi.clearRX();
     wr_dat_stop();
     free (line);
     fclose(Image);
diff -r ef70eaf15b18 -r 26149011665e ST7735_TFT.h
--- a/ST7735_TFT.h	Fri Apr 19 20:46:47 2013 +0000
+++ b/ST7735_TFT.h	Sun Oct 11 21:30:26 2015 +0000
@@ -5,6 +5,7 @@
 
 #include "mbed.h"
 #include "GraphicsDisplay.h"
+#include "BurstSPI.h"
 
 #define RGB(r,g,b)  (((r&0xF8)<<8)|((g&0xFC)<<3)|((b&0xF8)>>3)) //5 red | 6 green | 5 blue
 
@@ -56,27 +57,33 @@
 #define ST7735_GMCTRP1 0xE0
 #define ST7735_GMCTRN1 0xE1
 
-/* some RGB color definitions         RED  BLUE GREEN                           */
-#define Black           0x0000      /*   0,   0,   0 */
-#define Navy            0x000F      /*   0,   0, 128 */
-#define DarkGreen       0x03E0      /*   0, 128,   0 */
-#define DarkCyan        0x03EF      /*   0, 128, 128 */
-#define Maroon          0x7800      /* 128,   0,   0 */
-#define Purple          0x780F      /* 128,   0, 128 */
-#define Olive           0x7BE0      /* 128, 128,   0 */
-#define LightGrey       0xC618      /* 192, 192, 192 */
-#define DarkGrey        0x7BEF      /* 128, 128, 128 */
-#define Green           0x002F      /*   0,   0, 255 */
-#define Blue            0x07E0      /*   0, 255,   0 */
-#define Cyan            0x07FF      /*   0, 255, 255 */
-#define Red             0xFF00      /* 255,   0,   0 */
-#define Yellow          0xFF1F      /* 255,   0, 255 */
-#define Magenta         0xFFE0      /* 255, 255,   0 */
-#define White           0xFFFF      /* 255, 255, 255 */
-#define Orange          0xFD20      /* 255, 165,   0 */
-#define GreenYellow     0xAFE5      /* 173, 255,  47 */
-#define LightBlue       0x04FF
+// some RGB color definitions         RED GREEN BLUE                          
 
+#define Black           0x0000      //   0,   0,   0 
+#define Navy            0x8000      //   0,   0, 128 
+#define DarkGreen       0x0400      //   0, 128,   0 
+#define DarkCyan        0x8400      //   0, 128, 128 
+#define Maroon          0x0010      // 128,   0,   0 
+#define Purple          0x8010      // 128,   0, 128 
+#define Olive           0x0410      // 128, 128,   0 
+#define LightGrey       0xC618      // 192, 192, 192 
+#define DarkGrey        0x7BEF      // 128, 128, 128 
+#define Red             0x001F      // 255,   0,   0 
+#define Green           0x07E0      //   0, 255,   0 
+#define Yellow          0x07FF      // 255, 255,   0 
+#define Blue            0xF800      //   0,   0, 255 
+#define Magenta         0xF81F      // 255,   0, 255 
+#define Cyan            0xFFE0      //   0, 255, 255 
+#define White           0xFFFF      // 255, 255, 255 
+#define Orange          0x053F      // 255, 165,   0 
+#define GreenYellow     0x2FF5      // 173, 255,  47 
+
+    /*   Use this to Calculate and define any colour
+    
+         #define RGB565CONVERT(red, green, blue) (uint16_t)( (( blue   >> 3 ) << 11 ) | (( green >> 2 ) << 5  ) | ( red  >> 3 ))
+         lcd.printf("%4X  ",RGB565CONVERT(red value 0-255,green value 0-255,blue value 0-255));
+    */
+    
 class ST7735_TFT : public GraphicsDisplay {
  public:
 
@@ -288,7 +295,8 @@
    */  
   void set_orientation(unsigned int o);
     
-  SPI _spi;
+  //SPI _spi;
+  BurstSPI _spi;
   DigitalOut _cs;
   DigitalOut _rs;
   DigitalOut _reset;