Software SPI allows non-standard SPI pins to be used for interfacing with SPI devices

Fork of SWSPI by Dave Van Wagner

Files at this revision

API Documentation at this revision

Comitter:
lionello
Date:
Fri May 08 08:29:50 2015 +0000
Parent:
2:eafe3ec5fbf8
Commit message:
Use wait_us instead of wait(float)

Changed in this revision

SWSPI.cpp Show annotated file Show diff for this revision Revisions of this file
SWSPI.h Show annotated file Show diff for this revision Revisions of this file
diff -r eafe3ec5fbf8 -r 8c19911bdb58 SWSPI.cpp
--- a/SWSPI.cpp	Fri May 08 08:23:58 2015 +0000
+++ b/SWSPI.cpp	Fri May 08 08:29:50 2015 +0000
@@ -50,7 +50,7 @@
 void SWSPI::frequency(int hz)
 {
     // TODO: need wait_ns taking int
-    this->delay_s = 0.5f/hz;
+    this->delay_us = 500000/hz;
 }
 
 int SWSPI::write(int value)
@@ -63,22 +63,22 @@
         if (phase == 0)
         {
             if (miso && miso->read())
-                read |= (1 << bit);
+                read |= bit;
         }
 
         sclk.write(!polarity);
 
-        wait(delay_s);
+        if (delay_us) wait_us(delay_us);
 
         if (phase == 1)
         {
             if (miso && miso->read())
-                read |= (1 << bit);
+                read |= bit;
         }
 
         sclk.write(polarity);
 
-        wait(delay_s);
+        if (delay_us) wait_us(delay_us);
     }
     
     return read;
diff -r eafe3ec5fbf8 -r 8c19911bdb58 SWSPI.h
--- a/SWSPI.h	Fri May 08 08:23:58 2015 +0000
+++ b/SWSPI.h	Fri May 08 08:29:50 2015 +0000
@@ -55,7 +55,7 @@
     int8_t bits;
     int8_t polarity; // idle clock value
     int8_t phase; // 0=sample on leading (first) clock edge, 1=trailing (second)
-    float delay_s;
+    unsigned delay_us;
     
 public:
     /** Create SWSPI object