Driver Library for our displays

Dependents:   dm_bubbles dm_calc dm_paint dm_sdcard_with_adapter ... more

Revision:
14:2db7065edbec
Parent:
11:264e19992620
--- a/DmTftRa8875.cpp	Fri Sep 18 14:59:13 2015 +0000
+++ b/DmTftRa8875.cpp	Mon Oct 12 08:35:35 2015 +0000
@@ -13,23 +13,21 @@
 /*  Notice:
     The panel resolution should be config in DmTftRa8875::init() function.
     RA8875Size size = RA8875_480x272 or RA8875Size size = RA8875_800x480;
+    
+    Tested on NUCLEO-F401RE, LPCXpresso11U68, LPCXpresso824-MAX platform.
 */
 
 #include "DmTftRa8875.h"
 #if defined (DM_TOOLCHAIN_ARDUINO)
 DmTftRa8875::DmTftRa8875(uint8_t cs, uint8_t sel)
+: DmTftBase(480, 272)
 #elif defined (DM_TOOLCHAIN_MBED)
-DmTftRa8875::DmTftRa8875(uint8_t cs, uint8_t sel, uint8_t miso, uint8_t mosi, uint8_t clk)
+DmTftRa8875::DmTftRa8875(PinName cs, PinName sel, PinName mosi, PinName miso, PinName clk)
+: DmTftBase(480, 272), spi(mosi, miso, clk)
 #endif
-    : DmTftBase(480, 272)
 {
     _cs = cs;
     _sel = sel;
-#if defined (DM_TOOLCHAIN_MBED)
-    _miso = miso;
-    _mosi = mosi;
-    _clk = clk;
-#endif
 }
 
 DmTftRa8875::~DmTftRa8875()
@@ -37,11 +35,9 @@
 #if defined (DM_TOOLCHAIN_MBED)
     delete _pinCS;
     delete _pinSEL;
-    delete _spi;
 
     _pinCS = NULL;
     _pinSEL = NULL;
-    _spi = NULL;
 #endif
 }
 
@@ -62,7 +58,7 @@
     SPDR = data;                 // SPI Data Register
     while(!(SPSR & _BV(SPIF)));  // SPI Status Register Wait for transmission to finish
 #elif defined (DM_TOOLCHAIN_MBED)
-    _spi->write(data);
+    spi.write(data);
 #endif
 }
 
@@ -74,7 +70,7 @@
     while(!(SPSR & _BV(SPIF)));  // SPI Status Register Wait for transmission to finish
     return SPDR;
 #elif defined (DM_TOOLCHAIN_MBED)
-    return _spi->write(0x00); // dummy byte to read
+    return spi.write(0x00); // dummy byte to read
 #endif
 }
 
@@ -185,7 +181,7 @@
 void DmTftRa8875::init(void)
 {
     // DM_TFT43_108 = RA8875_480x272;  DM_TFT50_111 = RA8875_800x480
-    RA8875Size size = RA8875_800x480;
+    RA8875Size size = RA8875_480x272;
     
     setTextColor(BLACK, WHITE);
 #if defined (DM_TOOLCHAIN_ARDUINO)
@@ -205,15 +201,26 @@
     SPI.setDataMode(SPI_MODE0);
     _spiSettings = SPCR;
 #elif defined (DM_TOOLCHAIN_MBED)
-    _pinCS = new DigitalOut((PinName)_cs);
-    _pinSEL = new DigitalOut((PinName)_sel);
+    _pinCS = new DigitalOut(_cs);
+    _pinSEL = new DigitalOut(_sel);
     sbi(_pinSEL, _bitmaskSEL);  // w25 control by MCU
 
     sbi(_pinCS, _bitmaskCS);
 
-    _spi = new SPI((PinName)_mosi, (PinName)_miso, (PinName)_clk);
-    _spi->format(8,3);
-    _spi->frequency(2000000); // Max SPI speed for display is 10 and for 17 for LPC15xx
+
+#ifdef TARGET_LPC824        // for LPCXpresso824-MAX
+    spi.format(8,3);
+    spi.frequency(8000000); 
+#elif TARGET_LPC11U6X       // for LPCXpresso11U68
+    spi.format(8,3);
+    spi.frequency(2000000); 
+#elif TARGET_NUCLEO_F401RE  // for NUCLEO-F401RE
+    spi.format(8,0);
+    spi.frequency(8000000);     
+#else    
+    spi.format(8,3);
+    spi.frequency(2000000); // Max SPI speed for display is 10 and for 17 for LPC15xx    
+#endif
     softReset();
 #endif