Basic library for SHARP LCD LS027B4DH01/LS027B7DH01

Dependents:   AkiSpiLcd_demo AkiSpiLcd_demo2 LCDRAM AkiSpiLcd_example

Files at this revision

API Documentation at this revision

Comitter:
k4zuki
Date:
Thu Aug 28 10:10:37 2014 +0000
Parent:
4:844693a617dc
Child:
6:e3ed7599692c
Commit message:
simplified code using Ser26K256 library

Changed in this revision

AkiSpiLcd.cpp Show annotated file Show diff for this revision Revisions of this file
AkiSpiLcd.h Show annotated file Show diff for this revision Revisions of this file
Ser23K256.lib Show annotated file Show diff for this revision Revisions of this file
--- a/AkiSpiLcd.cpp	Thu Aug 28 06:26:48 2014 +0000
+++ b/AkiSpiLcd.cpp	Thu Aug 28 10:10:37 2014 +0000
@@ -8,29 +8,28 @@
 AkiSpiLcd::AkiSpiLcd(PinName mosi, PinName miso, PinName sck, PinName csl, PinName csr)
     :_spi(mosi, miso, sck), _csl(csl), _csr(csr)
 {
+    _ram= new Ser23K256::Ser23K256(_spi,csr);
     _csl=0;
     _csr=1;
     _spi.format(8,0);
     _spi.frequency(2000000);
     comflag = modeflag = clearflag = 0;
-    _csr=0; //select VRAM
-    _spi.write(0x02);
-    _spi.write(0x60);
-    _spi.write(0x00);
-    for(int i=1;i<241;i++){
-        //write swapped i into RAM
-        _spi.write(
-        ( ( i & 0x01 ) << 7 )|
-        ( ( i & 0x02 ) << 5 )|
-        ( ( i & 0x04 ) << 3 )|
-        ( ( i & 0x08 ) << 1 )|
-        ( ( i & 0x10 ) >> 1 )|
-        ( ( i & 0x20 ) >> 3 )|
-        ( ( i & 0x40 ) >> 5 )|
-        ( ( i & 0x80 ) >> 7 )
-        );
-    _csr=1;
+
+    int data=0;
+    for(int i=0;i<240;i++){
+        data=( ( i & 0x01 ) << 7 )|
+            ( ( i & 0x02 ) << 5 )|
+            ( ( i & 0x04 ) << 3 )|
+            ( ( i & 0x08 ) << 1 )|
+            ( ( i & 0x10 ) >> 1 )|
+            ( ( i & 0x20 ) >> 3 )|
+            ( ( i & 0x40 ) >> 5 )|
+            ( ( i & 0x80 ) >> 7 );
+
+        _ram->write(RAMLINE_BASE+i,(uint8_t)data);
     }
+        _ram->write(RAMMODE_BASE,0x00000000);
+
 }
 
 void AkiSpiLcd::cls()
@@ -101,14 +100,14 @@
         for (int j=0; j<length; j++) {
             _spi.write( (modeflag << 7) | (comflag << 6) | (clearflag << 5) );
             _spi.write(
-                ( ( (line+1) & 0x01 ) << 7 )|
-                ( ( (line+1) & 0x02 ) << 5 )|
-                ( ( (line+1) & 0x04 ) << 3 )|
-                ( ( (line+1) & 0x08 ) << 1 )|
-                ( ( (line+1) & 0x10 ) >> 1 )|
-                ( ( (line+1) & 0x20 ) >> 3 )|
-                ( ( (line+1) & 0x40 ) >> 5 )|
-                ( ( (line+1) & 0x80 ) >> 7 )
+                ( ( (line) & 0x01 ) << 7 )|
+                ( ( (line) & 0x02 ) << 5 )|
+                ( ( (line) & 0x04 ) << 3 )|
+                ( ( (line) & 0x08 ) << 1 )|
+                ( ( (line) & 0x10 ) >> 1 )|
+                ( ( (line) & 0x20 ) >> 3 )|
+                ( ( (line) & 0x40 ) >> 5 )|
+                ( ( (line) & 0x80 ) >> 7 )
             );
 
             for(int i=0; i<50; i++) {
@@ -164,6 +163,8 @@
 //    uint8_t buffer[50];
     line*=50;
     int address=screen+line;
+    _ram->read(address,buffer,50);
+    /*
     _csr=0; //select VRAM
     _spi.write(0x03);
     _spi.write(address>>8);
@@ -172,6 +173,7 @@
         *(buffer+i)=_spi.write(0xaa);
     }
     _csr=1;
+    */
 //    return buffer;
 }
 
@@ -182,6 +184,10 @@
     screen<<=7;
     line*=50;
     int address=screen+line;
+//    for(int j=0;j<length;j++){
+    _ram->read(address,buffer,50*length);
+//    }
+    /*
     _csr=0; //select VRAM
     _spi.write(0x03);
     _spi.write(address>>8);
@@ -192,6 +198,7 @@
         }
     }
     _csr=1;
+    */
 //    return buffer;
 }
     
@@ -202,6 +209,8 @@
     screen<<=7;
     line*=50;
     int address=screen+line;
+    _ram->write(address,data,50);
+    
     _csr=0; //select VRAM
     _spi.write(0x02);
     _spi.write(address>>8);
@@ -220,7 +229,8 @@
     line*=50;
     
     int address=screen+line;
-    
+    _ram->write(address,data,50*length);
+    /*
     _csr=0; //select VRAM
     _spi.write(0x02);
     _spi.write(address>>8);
@@ -231,6 +241,7 @@
         }
     }
     _csr=1;
+    */
 }
 
     /** copies whole data in screen into LCD
@@ -240,21 +251,28 @@
     screen<<=7;
 
     int address=screen;
-    int dummy=0;
-    
-    _csl=1;
+    uint8_t* dummy;
+    /*
     _csr=0; //select VRAM
     _spi.write(0x03);
     _spi.write(address>>8);
     _spi.write(address&0xff);
+    */
     for(int j=0;j<240;j++){
+        _ram->write(RAMMODE_BASE,(modeflag << 7) | (comflag << 6) | (clearflag << 5));
+        _csl=1;
+        _ram->read(RAMMODE_BASE,dummy,2);
         for(int i=0;i<50;i++){
-            dummy=_spi.write(0xaa);
+            _ram->read(address,dummy,50);
+        }
+        _ram->read(RAMMODE_BASE+2,dummy,2);
+        wait_us(5);
+        _csl=0;
+        if(comflag == 0) {
+            comflag = 1;
+        } else {
+            comflag = 0;
         }
     }
-    _spi.write(0x00);
-    _spi.write(0x00);
-    _csr=1;
-    wait_us(5);
     _csl=0;
 }
--- a/AkiSpiLcd.h	Thu Aug 28 06:26:48 2014 +0000
+++ b/AkiSpiLcd.h	Thu Aug 28 10:10:37 2014 +0000
@@ -5,6 +5,8 @@
 #ifndef __AKISPILCD_H__
 #define __AKISPILCD_H
 
+#include "mbed.h"
+#include "Ser23K256.h"
 /** AkiSpiLcd
  * mbed library for SHARP LCD LS027B4DH01
  *
@@ -32,6 +34,11 @@
  * }
  * @endcode
  */
+#define RAMLINE_BASE 0x6000
+#define RAMMODE_BASE 0x6100
+#define SCREEN0_BASE 0x0000
+#define SCREEN1_BASE 0x3000
+ 
 class AkiSpiLcd
 {
 public:
@@ -92,6 +99,7 @@
 //    void dispOn(bool disp);
 
 private:
+    Ser23K256::Ser23K256 *_ram;
     int comflag;
     int modeflag;
     int clearflag;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Ser23K256.lib	Thu Aug 28 10:10:37 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/romilly/code/Ser23K256/#d52cc2db5bea