SPI based library for the ST7735 LCD controller.

Dependents:   RayCastingEngine RETRO_LCD_PerformanceTest RETRO_loop_test RETRO_RickGame ... more

Revision:
5:21c987ee68d2
Parent:
4:88d22437119c
Child:
7:f39c980a589c
--- a/LCD_ST7735.h	Sun Sep 21 07:01:15 2014 +0000
+++ b/LCD_ST7735.h	Sun Oct 05 22:24:22 2014 +0000
@@ -200,10 +200,11 @@
     private:
         void initDisplay();
         void reset();
-        void write(uint8_t cmd);        
+        
+        void writeCommand(uint8_t cmd);
         void write(uint8_t cmd, uint8_t data[], int dataLen);
         void write(uint8_t cmd, uint16_t data);        
-        void writeData(uint8_t data);        
+        
         void beginBatchCommand(uint8_t cmd);
         void writeBatchData(uint8_t data);
         void writeBatchData(uint8_t dataHigh, uint8_t dataLow);
@@ -223,12 +224,50 @@
         uint8_t    _backgroundColorHigh;
         uint8_t    _backgroundColorLow;
         
+    private:
+        class LCDSPI : public SPI
+        {
+            public:
+                LCDSPI(PinName mosi, PinName miso, PinName sclk) :
+                    SPI(mosi, miso, sclk)
+                {
+                }
+                
+                void waitWhileBusy()
+                {
+                    #ifdef TARGET_LPC11U24
+                    while (((_spi.spi->SR) & 0x10) != 0);
+                    #endif
+                }
+                
+                void fastWrite(uint8_t data)
+                {                    
+                    #ifdef TARGET_LPC11U24
+                        while (((_spi.spi->SR) & 0x01) == 0);
+                        _spi.spi->DR = data;
+                    #else
+                        SPI::write(data);
+                    #endif 
+                }       
+                
+                void clearRx()
+                {
+                    #ifdef TARGET_LPC11U24
+                        while (((_spi.spi->SR) & 0x14) != 0)
+                        {
+                            while (((_spi.spi->SR) & 0x04) == 0);
+                            int data = _spi.spi->DR;
+                        }                                         
+                    #endif  
+                }            
+        };
+        
     private:        
         DigitalOut  _backlight;
         DigitalOut  _reset;
         DigitalOut  _ds;
         DigitalOut  _cs;
-        SPI         _spi;
+        LCDSPI      _spi;
         
     private:
         static const uint8_t CMD_SLPOUT     = 0x11;
@@ -255,7 +294,7 @@
         static const uint8_t CMD_GAMCTRP1   = 0xe0;
         static const uint8_t CMD_GAMCTRN1   = 0xe1;
         
-        static const uint8_t CMD_EXTCTRL    = 0xf0;
+        static const uint8_t CMD_EXTCTRL    = 0xf0;                
 };
 
 #endif // __LCD_ST7735__