tr

Revision:
21:4cbdc20fea9f
Parent:
20:8db6aa25f55e
Child:
22:31c54fc61f12
--- a/N5110.cpp	Thu Jan 19 19:42:34 2017 +0000
+++ b/N5110.cpp	Sat Jan 28 20:25:43 2017 +0000
@@ -7,10 +7,11 @@
 #include "mbed.h"
 #include "N5110.h"
 
-
+// overloaded constructor includes power pin - LCD Vcc connected to GPIO pin
+// this constructor works fine with LPC1768 - enough current sourced from GPIO
+// to power LCD. Doesn't work well with K64F.
 N5110::N5110(PinName pwrPin, PinName scePin, PinName rstPin, PinName dcPin, PinName mosiPin, PinName sclkPin, PinName ledPin)
 {
-
     spi = new SPI(mosiPin,NC,sclkPin); // create new SPI instance and initialise
     initSPI();
 
@@ -23,6 +24,22 @@
 
 }
 
+// overloaded constructor does not include power pin - LCD Vcc must be tied to +3V3
+// Best to use this with K64F as the GPIO hasn't sufficient output current to reliably
+// drive the LCD.
+N5110::N5110(PinName scePin, PinName rstPin, PinName dcPin, PinName mosiPin, PinName sclkPin, PinName ledPin)
+{
+    spi = new SPI(mosiPin,NC,sclkPin); // create new SPI instance and initialise
+    initSPI();
+
+    // set up pins as required
+    led = new PwmOut(ledPin);
+    sce = new DigitalOut(scePin);
+    rst = new DigitalOut(rstPin);
+    dc = new DigitalOut(dcPin);
+
+}
+
 // initialise function - powers up and sends the initialisation commands
 void N5110::init()
 {
@@ -66,7 +83,12 @@
 {
     // set brightness of LED - 0.0 to 1.0 - default is 50%
     setBrightness(0.5);
-    pwr->write(1);  // apply power
+
+    // if we are powering the LCD using the GPIO then make it high to turn on
+    // DigitalOut pointer won't be NULL if we used the constructor with power pin
+    if (pwr != NULL) {
+        pwr->write(1);  // apply power
+    }
 }
 
 // function to power down LCD
@@ -82,7 +104,12 @@
     sendCommand(0x20 | CMD_FS_POWER_DOWN_MODE | CMD_FS_HORIZONTAL_MODE | CMD_FS_EXTENDED_MODE);
     // small delay and then turn off the power pin
     wait_ms(10);
-    pwr->write(0);
+    
+    // if we are powering the LCD using the GPIO then make it low to turn off
+    // DigitalOut pointer won't be NULL if we used the constructor with power pin
+    if (pwr != NULL) {
+        pwr->write(0);  // turn off power
+    }
 
 }
 
@@ -291,7 +318,7 @@
         // elements are normalised from 0.0 to 1.0, so multiply
         // by 47 to convert to pixel range, and subtract from 47
         // since top-left is 0,0 in the display geometry
-        setPixel(i,47 - int(array[i]*47.0));
+        setPixel(i,47 - int(array[i]*47.0f));
     }
 
     refresh();