Source

New LiquidCrystal / FastIO.cpp

The default branch has multiple heads

Diff from to

FastIO.cpp

 //
 // @author Florian Fida -
 //
+// 2012-03-16 bperrybap updated fio_shiftout() to be smaller & faster
+//
 // @todo:
 //  support chipkit:
 // (https://github.com/chipKIT32/chipKIT32-MAX/blob/master/hardware/pic32/
 // ---------------------------------------------------------------------------
 #include "FastIO.h"
 
+
 fio_register fio_pinToOutputRegister(uint8_t pin, uint8_t initial_state)
 {
 	pinMode(pin, OUTPUT);
 #endif
 }
 
+
 fio_register fio_pinToInputRegister(uint8_t pin)
 {
 	pinMode(pin, INPUT);
 #endif
 }
 
-uint8_t fio_pinToBit(uint8_t pin)
+
+fio_bit fio_pinToBit(uint8_t pin)
 {
 #ifdef FIO_FALLBACK
 	// (ab)use the bit variable to store the pin
 #endif
 }
 
-void fio_digitalWrite(fio_register pinRegister, uint8_t pinBit, uint8_t value) 
+
+void fio_digitalWrite(fio_register pinRegister, fio_bit pinBit, uint8_t value) 
 {
 #ifdef FIO_FALLBACK
 	digitalWrite(pinBit, value);
 	// # disable interrupts
 	int8_t i;
    
-   
-   for(i = 0; i < 8; i++)
-   {
-      if (bitOrder == LSBFIRST)
-      {
-         fio_digitalWrite(dataRegister, dataBit, !!(value & (1 << i)));
-      }
-      else
-      {
-         fio_digitalWrite(dataRegister, dataBit, !!(value & (1 << (7 - i))));
-      }
-      ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
-      {
-         fio_digitalWrite_HIGH (clockRegister, clockBit);
-         
-         // Switching is a little bit faster
-         fio_digitalWrite_SWITCH (clockRegister,clockBit);
-      } // end critical section
+	if(bitOrder == LSBFIRST)
+	{
+		for(i = 0; i < 8; i++)
+		{
+			ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
+			{
+				if(value & 1)
+            {
+               fio_digitalWrite_HIGH(dataRegister, dataBit);
+				}
+            else
+            {
+               fio_digitalWrite_LOW(dataRegister, dataBit);
+            }
+            value >>= 1;
+				fio_digitalWrite_HIGH (clockRegister, clockBit);
+				fio_digitalWrite_LOW (clockRegister,clockBit);
+			}
+		}
       
-   } 
+	}
+	else
+	{
+		for(i = 0; i < 8; i++)
+		{
+			ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
+			{
+				if(value & 0x80)
+            {
+               fio_digitalWrite_HIGH(dataRegister, dataBit);
+				}
+            else
+            {
+               fio_digitalWrite_LOW(dataRegister, dataBit);
+            }
+				value <<= 1;
+				fio_digitalWrite_HIGH (clockRegister, clockBit);
+				fio_digitalWrite_LOW (clockRegister,clockBit);
+			}
+		}
+	}
 }
 
-void fio_shiftOut(fio_register dataRegister, uint8_t dataBit, 
-                  fio_register clockRegister, uint8_t clockBit)
+
+void fio_shiftOut(fio_register dataRegister, fio_bit dataBit, 
+                  fio_register clockRegister, fio_bit clockBit)
 {
    ATOMIC_BLOCK(ATOMIC_RESTORESTATE)
    {
       }
    }
 }
+
+
 void fio_shiftOut1_init(uint8_t pin)
 {
 	fio_shiftOut1_init(fio_pinToOutputRegister(pin,HIGH),fio_pinToBit(pin));
 	fio_digitalWrite(shift1Register,shift1Bit,HIGH);
 	delayMicroseconds(300);
 }
+
+
 void fio_shiftOut1(fio_register shift1Register, fio_bit shift1Bit, uint8_t value, 
                    boolean noLatch)
 {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.