-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds chip select delay option #209
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -917,6 +917,8 @@ Tessel.SPI = function(params, port) { | |
|
||
this.chipSelectActive = params.chipSelectActive === 'high' || params.chipSelectActive === 1 ? 1 : 0; | ||
|
||
this.chipSelectDelay = (params.chipSelectDelayUs/1e3) || 0; | ||
|
||
if (this.chipSelectActive) { | ||
// active high, pull low for now | ||
this.chipSelect.low(); | ||
|
@@ -969,11 +971,21 @@ Tessel.SPI = function(params, port) { | |
}; | ||
|
||
Tessel.SPI.prototype.send = function(data, callback) { | ||
this._port.cork(); | ||
|
||
this.chipSelect.low(); | ||
this._port._tx(data, callback); | ||
this.chipSelect.high(); | ||
this._port.uncork(); | ||
|
||
setTimeout(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ideally you would only uncork if you wanted a delay, otherwise you're going to get 100us-1ms of delay whether you like it or not. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your change isn't quite what I meant. In the case where you don't add a delay, you want to leave the entire transaction in one |
||
// Only cork if we have specified a target delay, otherwise delay increases | ||
if (this.chipSelectDelay > 0) { | ||
this._port.cork(); | ||
} | ||
this._port._tx(data, callback); | ||
this.chipSelect.high(); | ||
if (this.chipSelectDelay > 0) { | ||
this._port.uncork(); | ||
} | ||
}, this.chipSelectDelay); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my comment above https://github.com/tessel/t2-firmware/pull/209/files#r78751516 |
||
|
||
}; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did the |
||
Tessel.SPI.prototype.disable = function() { | ||
|
@@ -984,19 +996,36 @@ Tessel.SPI.prototype.disable = function() { | |
}; | ||
|
||
Tessel.SPI.prototype.receive = function(data_len, callback) { | ||
this._port.cork(); | ||
|
||
this.chipSelect.low(); | ||
this._port._rx(data_len, callback); | ||
this.chipSelect.high(); | ||
this._port.uncork(); | ||
|
||
setTimeout(() => { | ||
// Only cork if we have specified a target delay, otherwise delay increases | ||
if (this.chipSelectDelay > 0) { | ||
this._port.cork(); | ||
} | ||
this._port._rx(data_len, callback); | ||
if (this.chipSelectDelay > 0) { | ||
this._port.uncork(); | ||
} | ||
}, this.chipSelectDelay); | ||
}; | ||
|
||
Tessel.SPI.prototype.transfer = function(data, callback) { | ||
this._port.cork(); | ||
|
||
this.chipSelect.low(); | ||
this._port._txrx(data, callback); | ||
this.chipSelect.high(); | ||
this._port.uncork(); | ||
|
||
setTimeout(() => { | ||
// Only cork if we have specified a target delay, otherwise delay increases | ||
if (this.chipSelectDelay > 0) { | ||
this._port.cork(); | ||
} | ||
this._port._txrx(data, callback); | ||
this.chipSelect.high(); | ||
if (this.chipSelectDelay > 0) { | ||
this._port.uncork(); | ||
} | ||
}, this.chipSelectDelay); | ||
}; | ||
|
||
Tessel.UART = function(port, options) { | ||
|
@@ -1509,7 +1538,7 @@ function getWifiInfo() { | |
if (bcastMatches === null) { | ||
recursiveWifi(network); | ||
} else { | ||
// Successful matches will have a result that looks like: | ||
// Successful matches will have a result that looks like: | ||
// ["Bcast:0.0.0.0", "Bcast", "0.0.0.0"] | ||
if (bcastMatches.length === 3) { | ||
network.ip = bcastMatches[2]; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1e3
is only 1 character shorter than1000
:PIdeally,
this.chipSelectDelay
andparams.chipSelectDelayUs
would have the same name and value (instead of ms and μs)A sub-millisecond parameter to
setTimeout
is impossible: https://nodejs.org/docs/latest/api/timers.html#timers_setinterval_callback_delay_arg