Commits

F Malpartida committed 7091000

Added critical section to SR_LCD3 wire latching library.

Comments (0)

Files changed (3)

     */
    virtual void send(uint8_t value, uint8_t mode);
    
+   
+   /*!
+    @function
+    @abstract   Sets the pin to control the backlight.
+    @discussion Sets the pin in the device to control the backlight.
+    
+    @param      mode: backlight mode (HIGH|LOW)
+    */
+   void setBacklightPin ( uint8_t pin );
+   
    /*!
     @function
     @abstract   Switch-on/off the LCD backlight.
     */
    void setBacklight ( uint8_t mode );
    
-   /*!
-    @function
-    @abstract   Sets the pin to control the backlight.
-    @discussion Sets the pin in the device to control the backlight.
-    
-    @param      mode: backlight mode (HIGH|LOW)
-    */
-   void setBacklightPin ( uint8_t pin );
-   
-   
-   
 private:
    
    /*!
     * @abstract takes care of shifting and the enable pulse
     */
    void shiftIt (uint8_t val);
-
+   
    uint8_t _enable_pin;  // Enable Pin
    uint8_t _two_wire;    // two wire mode
-
+   
    fio_register _srDataRegister; // Serial Data pin
    fio_bit _srDataBit;
    fio_register _srClockRegister; // Clock Pin
    fio_bit _srClockBit;
    fio_register _srEnableRegister; // Enable Pin
    fio_bit _srEnableBit;
-
+   
 };
 
 #endif

LiquidCrystal_SR_LCD3.cpp

 #include <stdio.h>
 #include <string.h>
 #include <inttypes.h>
+#include <util/atomic.h> // for critical section management
 
 #if (ARDUINO <  100)
 #include <WProgram.h>
 // ---------------------------------------------------------------------------
 // Assuming 1 line 8 pixel high font
 LiquidCrystal_SR_LCD3::LiquidCrystal_SR_LCD3 ( uint8_t srdata, uint8_t srclock, 
-                                               uint8_t strobe )
+                                              uint8_t strobe )
 {
 	init ( srdata, srclock, strobe, 1, 0 );
 }
 //
 // init
 void LiquidCrystal_SR_LCD3::init( uint8_t srdata, uint8_t srclock, uint8_t strobe, 
-                                  uint8_t lines, uint8_t font )
+                                 uint8_t lines, uint8_t font )
 {
 	// Initialise private variables
 	// translate all pins to bits and registers
 	// pinMode to OUTPUT, Output LOW
-
+   
    _srdata_bit = fio_pinToBit(srdata);
    _srdata_register = fio_pinToOutputRegister(srdata);
    _srclock_bit = fio_pinToBit(srclock);
    
    // Little trick to force a pulse of the LCD enable bit and make sure it is
    // low before we start further writes since this is assumed.
-
+   
    write4bits(0);
    
    _displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x10DOTS;
    fio_shiftOut(_srdata_register, _srdata_bit, _srclock_register, _srclock_bit, nibble, LSBFIRST);
    
    // Make new data active.
-   fio_digitalWrite_HIGH(_strobe_register, _strobe_bit);
-   waitUsec( 1 ); // strobe pulse must be >450ns (old code had 10ms)
-   fio_digitalWrite_SWITCHTO(_strobe_register, _strobe_bit,LOW);
+   ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
+   {
+      fio_digitalWrite_HIGH(_strobe_register, _strobe_bit);
+      waitUsec( 1 ); // strobe pulse must be >450ns (old code had 10ms)
+      fio_digitalWrite_SWITCHTO(_strobe_register, _strobe_bit,LOW);
+   }
    waitUsec( 40 ); // commands need > 37us to settle
 }

LiquidCrystal_SR_LCD3.h

     */
    void write4bits ( uint8_t );
    void _pushOut ( uint8_t );
-
+   
    // Serial Data pin
    fio_bit _srdata_bit;
    fio_register _srdata_register;
-
+   
    // Clock Pin
    fio_bit _srclock_bit;
    fio_register _srclock_register;