@@ -917,6 +917,8 @@ Tessel.SPI = function(params, port) {
917
917
918
918
this . chipSelectActive = params . chipSelectActive === 'high' || params . chipSelectActive === 1 ? 1 : 0 ;
919
919
920
+ this . chipSelectDelay = ( params . chipSelectDelayUs / 1e3 ) || 0 ;
921
+
920
922
if ( this . chipSelectActive ) {
921
923
// active high, pull low for now
922
924
this . chipSelect . low ( ) ;
@@ -969,11 +971,21 @@ Tessel.SPI = function(params, port) {
969
971
} ;
970
972
971
973
Tessel . SPI . prototype . send = function ( data , callback ) {
972
- this . _port . cork ( ) ;
974
+
973
975
this . chipSelect . low ( ) ;
974
- this . _port . _tx ( data , callback ) ;
975
- this . chipSelect . high ( ) ;
976
- this . _port . uncork ( ) ;
976
+
977
+ setTimeout ( ( ) => {
978
+ // Only cork if we have specified a target delay, otherwise delay increases
979
+ if ( this . chipSelectDelay > 0 ) {
980
+ this . _port . cork ( ) ;
981
+ }
982
+ this . _port . _tx ( data , callback ) ;
983
+ this . chipSelect . high ( ) ;
984
+ if ( this . chipSelectDelay > 0 ) {
985
+ this . _port . uncork ( ) ;
986
+ }
987
+ } , this . chipSelectDelay ) ;
988
+
977
989
} ;
978
990
979
991
Tessel . SPI . prototype . disable = function ( ) {
@@ -984,19 +996,36 @@ Tessel.SPI.prototype.disable = function() {
984
996
} ;
985
997
986
998
Tessel . SPI . prototype . receive = function ( data_len , callback ) {
987
- this . _port . cork ( ) ;
999
+
988
1000
this . chipSelect . low ( ) ;
989
- this . _port . _rx ( data_len , callback ) ;
990
- this . chipSelect . high ( ) ;
991
- this . _port . uncork ( ) ;
1001
+
1002
+ setTimeout ( ( ) => {
1003
+ // Only cork if we have specified a target delay, otherwise delay increases
1004
+ if ( this . chipSelectDelay > 0 ) {
1005
+ this . _port . cork ( ) ;
1006
+ }
1007
+ this . _port . _rx ( data_len , callback ) ;
1008
+ if ( this . chipSelectDelay > 0 ) {
1009
+ this . _port . uncork ( ) ;
1010
+ }
1011
+ } , this . chipSelectDelay ) ;
992
1012
} ;
993
1013
994
1014
Tessel . SPI . prototype . transfer = function ( data , callback ) {
995
- this . _port . cork ( ) ;
1015
+
996
1016
this . chipSelect . low ( ) ;
997
- this . _port . _txrx ( data , callback ) ;
998
- this . chipSelect . high ( ) ;
999
- this . _port . uncork ( ) ;
1017
+
1018
+ setTimeout ( ( ) => {
1019
+ // Only cork if we have specified a target delay, otherwise delay increases
1020
+ if ( this . chipSelectDelay > 0 ) {
1021
+ this . _port . cork ( ) ;
1022
+ }
1023
+ this . _port . _txrx ( data , callback ) ;
1024
+ this . chipSelect . high ( ) ;
1025
+ if ( this . chipSelectDelay > 0 ) {
1026
+ this . _port . uncork ( ) ;
1027
+ }
1028
+ } , this . chipSelectDelay ) ;
1000
1029
} ;
1001
1030
1002
1031
Tessel . UART = function ( port , options ) {
@@ -1509,7 +1538,7 @@ function getWifiInfo() {
1509
1538
if ( bcastMatches === null ) {
1510
1539
recursiveWifi ( network ) ;
1511
1540
} else {
1512
- // Successful matches will have a result that looks like:
1541
+ // Successful matches will have a result that looks like:
1513
1542
// ["Bcast:0.0.0.0", "Bcast", "0.0.0.0"]
1514
1543
if ( bcastMatches . length === 3 ) {
1515
1544
network . ip = bcastMatches [ 2 ] ;
0 commit comments