Commits

F Malpartida committed 3afcaba

Added conditional compilation of time to toggle LCD IOs depending on how optimized the digitalWrite operation is.
The current version uses FAST_MODE by default, assuming that it uses the Arduino's SDK digitalWrite.

Comments (0)

Files changed (4)

LiquidCrystal.cpp

 #endif
 #include <LiquidCrystal.h>
 
-// When the display powers up, it is configured as follows:
-//
-// 1. Display clear
-// 2. Function set: 
-//    DL = 1; 8-bit interface data 
-//    N = 0; 1-line display 
-//    F = 0; 5x8 dot character font 
-// 3. Display on/off control: 
-//    D = 0; Display off 
-//    C = 0; Cursor off 
-//    B = 0; Blinking off 
-// 4. Entry mode set: 
-//    I/D = 1; Increment by 1 
-//    S = 0; No shift 
-//
-// Note, however, that resetting the Arduino doesn't reset the LCD, so we
-// can't assume that its in that state when a sketch starts (and the
-// LiquidCrystal constructor is called).
-// A call to begin() will reinitialize the LCD.
-
+// STATIC helper routines
+// ---------------------------------------------------------------------------
+/*!
+    @function
+    @abstract   waits for a given time in microseconds (compilation dependent).
+    @discussion Waits for a given time defined in microseconds depending on
+    the FAST_MODE define. If the FAST_MODE is defined the call will return
+    inmediatelly.
+    @param      uSec[in] time in microseconds.
+    @result     None
+*/
+inline static void waitUsec ( uint16_t uSec )
+{
+#ifndef FAST_MODE
+   delayMicroseconds ( uSec );
+#endif // FAST_MODE
+}
 
 // CONSTRUCTORS
 // ---------------------------------------------------------------------------
 // PRIVATE METHODS
 // ---------------------------------------------------------------------------
 
+// When the display powers up, it is configured as follows:
+//
+// 1. Display clear
+// 2. Function set: 
+//    DL = 1; 8-bit interface data 
+//    N = 0; 1-line display 
+//    F = 0; 5x8 dot character font 
+// 3. Display on/off control: 
+//    D = 0; Display off 
+//    C = 0; Cursor off 
+//    B = 0; Blinking off 
+// 4. Entry mode set: 
+//    I/D = 1; Increment by 1 
+//    S = 0; No shift 
+//
+// Note, however, that resetting the Arduino doesn't reset the LCD, so we
+// can't assume that its in that state when a sketch starts (and the
+// LiquidCrystal constructor is called).
+// A call to begin() will reinitialize the LCD.
 //
 // init
 void LiquidCrystal::init(uint8_t fourbitmode, uint8_t rs, uint8_t rw, uint8_t enable,
    // There is no need for the delays, since the digitalWrite operation
    // takes longer.
    digitalWrite(_enable_pin, LOW);
-   //delayMicroseconds(1);
+   waitUsec(1);
    
    digitalWrite(_enable_pin, HIGH);
-   //delayMicroseconds(1);          // enable pulse must be > 450ns
+   waitUsec(1);          // enable pulse must be > 450ns
    
    digitalWrite(_enable_pin, LOW);
-   //delayMicroseconds(37);         // commands need > 37us to settle
+   waitUsec(37);         // commands need > 37us to settle
 }
 
 //
    {
       digitalWrite(_data_pins[i], (value >> i) & 0x01);
    }
-   
    pulseEnable();
 }
 
 #include <inttypes.h>
 #include <LCD.h>
 
+/*!
+    @defined 
+    @abstract   Enables disables fast waits for write operations for LCD
+    @discussion If defined, the library will avoid doing un-necessary waits.
+    this can be done, because the time taken by Arduino's slow digitalWrite
+    operations. If fast digitalIO operations, comment this line out or undefine
+    the mode.
+*/
+#define FAST_MODE
 
 class LiquidCrystal : public LCD
 {

LiquidCrystal_I2C.cpp

    {
       mode = _Rs;
    }
-      
+   
 	expanderWrite ( pinMapValue | mode );
 	pulseEnable ( pinMapValue | mode );
 }
    // No need to use the delay routines since the time taken to write takes
    // longer that what is needed.
 	expanderWrite (_data | _En);	// En HIGH
-	//delayMicroseconds(1);		   // enable pulse must be >450ns
    
-	expanderWrite(_data & ~_En);  // En low
+	expanderWrite(_data & ~_En);  // En LOW
 	//delayMicroseconds(50);		// commands need > 37us to settle
 } 
 

LiquidCrystal_SR.cpp

    digitalWrite( _enable_pin, HIGH );
    delayMicroseconds(1);                 // enable pulse must be >450ns
    digitalWrite( _enable_pin, LOW );
-   
    delayMicroseconds(40);                // commands need > 37us to settle
 }