Display text on LCD displays (even on multiple ones). Allow to create windows (frames) on display, and to combine them (split, add, duplicate, scroll). See http://mbed.org/users/hlipka/notebook/lcdwindow/ for more information.

Dependents:   Mbell

Files at this revision

API Documentation at this revision

Comitter:
hlipka
Date:
Tue Feb 22 22:57:44 2011 +0000
Parent:
8:ba176eea3e40
Commit message:
fixed semaphore handling - should now be really thread safe (can be called from interrupts)

Changed in this revision

dogm_spi.cpp Show annotated file Show diff for this revision Revisions of this file
hd44780_8bit.cpp Show annotated file Show diff for this revision Revisions of this file
ks0108_8bit.cpp Show annotated file Show diff for this revision Revisions of this file
sed1335text.cpp Show annotated file Show diff for this revision Revisions of this file
semaphore.cpp Show annotated file Show diff for this revision Revisions of this file
semaphore.h Show annotated file Show diff for this revision Revisions of this file
--- a/dogm_spi.cpp	Mon Jan 10 22:57:59 2011 +0000
+++ b/dogm_spi.cpp	Tue Feb 22 22:57:44 2011 +0000
@@ -50,7 +50,8 @@
 void DogmLCDSPI::character(int column, int row, int c)
 {
     int address=(row)*0x40+(column);
-    _guard->take();
+    if (!_guard->take())
+        return;
     sendCmd((char)address|0x80);
     wait_ms(1);
     sendData(c);
@@ -61,7 +62,8 @@
 void DogmLCDSPI::writeText(const unsigned int column, const unsigned int row, const char text[])
 {
     int address=(row)*0x40+(column);
-    _guard->take();
+    if (!_guard->take())
+        return;
     sendCmd((char)address|0x80);
     wait_ms(1);
     
@@ -77,7 +79,8 @@
 
 void DogmLCDSPI::clear()
 {
-    _guard->take();
+    if (!_guard->take())
+        return;
     sendCmd(1);
     _guard->release();
 }
--- a/hd44780_8bit.cpp	Mon Jan 10 22:57:59 2011 +0000
+++ b/hd44780_8bit.cpp	Tue Feb 22 22:57:44 2011 +0000
@@ -30,7 +30,8 @@
 void HD44780LCD8bit::character(int column, int row, int c)
 {
     int address=(row)*0x40+(column);
-    _guard->take();
+    if (!_guard->take())
+        return;
     sendCmd((unsigned char)address|0x80);
     wait_us(30);
     sendData(c);
@@ -42,7 +43,8 @@
 void HD44780LCD8bit::writeText(const unsigned int column, const unsigned int row, const char text[]) {
 //    printf("print to %d,%d {%s}\n",line,pos,text);
     int address=row*0x40+column;
-    _guard->take();
+    if (!_guard->take())
+        return;
     sendCmd((unsigned char)address|0x80);
     wait_us(30);
 
@@ -56,7 +58,8 @@
 }
 
 void HD44780LCD8bit::clear() {
-    _guard->take();
+    if (!_guard->take())
+        return;
     sendCmd(1);
     _guard->release();
 }
--- a/ks0108_8bit.cpp	Mon Jan 10 22:57:59 2011 +0000
+++ b/ks0108_8bit.cpp	Tue Feb 22 22:57:44 2011 +0000
@@ -39,7 +39,8 @@
 }
 
 void KS0108LCD8bit::clear() {
-    _guard->take();
+    if (!_guard->take())
+        return;
     clearHalf(_left);
     if (NULL!=_right)
         clearHalf(_right);
@@ -76,7 +77,8 @@
     if (NULL==cs)
         return;
     
-    _guard->take();
+    if (!_guard->take())
+        return;
     sendCmd(0xb8|row,cs); // set x page    
 
     unsigned int y=icolumn*8;
--- a/sed1335text.cpp	Mon Jan 10 22:57:59 2011 +0000
+++ b/sed1335text.cpp	Tue Feb 22 22:57:44 2011 +0000
@@ -38,6 +38,9 @@
     int i=0;
     
     int pos=row*getColumns()+column;
+
+    if (!_guard->take())
+        return;
     
     sendCmd(0x46); // set cursor addr
     sendData(LOW(pos)); 
@@ -48,6 +51,7 @@
         sendData(text[i]);
         i++;
     }
+    _guard->release();
 }
 
 void SED1335TextLCD::clearBank(int start, int size, int data) {
--- a/semaphore.cpp	Mon Jan 10 22:57:59 2011 +0000
+++ b/semaphore.cpp	Tue Feb 22 22:57:44 2011 +0000
@@ -5,35 +5,33 @@
 
 #include "semaphore.h"
 
-  Semaphore::Semaphore(): s(SemFree) {};
-  
-  bool Semaphore::take(bool block)
-  {
+Semaphore::Semaphore(): s(SemFree) {};
+bool Semaphore::_abort=false;
+
+bool Semaphore::take(bool block) {
+    if (_abort)
+        block=false;
     int oldval;
 #if defined(TARGET_LPC1768) // on Cortex-M3 we can use ldrex/strex
     do {
-      // read the semaphore value
-      oldval = __ldrex(&s);
-      // loop again if it is locked and we are blocking
-      // or setting it with strex failed
-    }
-    while ( (block && oldval == SemTaken) || __strex(SemTaken, &s) != 0 );
+        // read the semaphore value
+        oldval = __ldrex(&s);
+        // loop again if it is locked and we are blocking
+        // or setting it with strex failed
+    } while ( (block && oldval == SemTaken) || __strex(SemTaken, &s) != 0 );
     if ( !block ) __clrex(); // clear exclusive lock set by ldrex
 #else // on arm7 there's only swp
     do {
-      // swp sets the pointed data to the given value and returns the previous one
-      oldval = __swp(SemTaken, &s);
-      // if blocking, loop until the previous value becomes 0
-      // which would mean we have successfully taken the lock
-    }
-    while (block && oldval == SemTaken);
+        // swp sets the pointed data to the given value and returns the previous one
+        oldval = __swp(SemTaken, &s);
+        // if blocking, loop until the previous value becomes 0
+        // which would mean we have successfully taken the lock
+    } while (block && oldval == SemTaken);
 #endif
     return oldval == SemFree;
-  }
-  
-  // release the semaphore
-  void Semaphore::release()
-  {
+}
+
+// release the semaphore
+void Semaphore::release() {
     s = SemFree;
-  }
-  
\ No newline at end of file
+}
--- a/semaphore.h	Mon Jan 10 22:57:59 2011 +0000
+++ b/semaphore.h	Tue Feb 22 22:57:44 2011 +0000
@@ -18,10 +18,13 @@
   // release the semaphore
   void release();
   
+  static void setAbort(bool abort){_abort=abort;};
+  
  private:
    enum { SemFree, SemTaken };
   // semaphore value
   int s;  
+  static bool _abort;
 
 };