Rule out a bit-banged board without writing to it - #3
Merged
Merged
Conversation
The probe that identifies a board still wrote to one it must not write to. A bit-banged board was meant to give itself away by handing over bytes with nothing asked of it, but it only does that once something has read its FTDI chip, which nothing had. On a fresh port it stays silent for as long as it is listened to, so the probe went ahead and wrote: 'ask//' landed on the relays and left them holding a '/', and the bytes that came back were taken for a status reply, so an 8 relay board was reported as a type16 with sixteen relays that were not there. Read the chip's data lines first. That changes nothing on any board -- no byte is sent, no pin becomes an output -- but it wakes the read side of an FT245's FIFO, and the board then answers the port unprompted and is recognised before anything is written to it. Relays are left where they were, measured across three patterns. Without libftdi nothing can be told about the data lines, so the board falls through to the protocol probe as before; the worst that comes of it is a board that has to be named with --board.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #2, which claimed this was already handled. It was not.
What was wrong
#2 made a bit-banged board give itself away by handing over bytes with nothing
asked of it, and skipped the write when it did. That check passed in testing only
because a libftdi session had just run against the board — which is what wakes the
read side of an FT245's FIFO. On a fresh port the board stays silent for as long as
it is listened to (measured: nothing in 2 s), so the probe went ahead and wrote.
The result on
maintoday, with the relays at0x5a:ask//landed on the relays and left them holding a/(0x2f), and the bytes theFIFO handed back were taken for a status reply, so an 8 relay board was reported as a
type16with sixteen relays that are not there.The fix
Read the chip's data lines before anything else.
read_data_linesopens the chip inits ordinary serial mode and only reads: no byte is sent, no pin is switched to an
output, so it is safe to do to a board of any kind. But it wakes the FIFO, so a
bit-banged board then answers the port unprompted and is recognised before a single
byte is written to it.
Measured across three patterns —
0x5a,0xa5,0xf0— the auto-probe now leavesthe relays exactly where they were and asks for
--board type8instead of inventinga type16.
probe_board_typeandresolve_board_typetake theDevicerather than the portname, since the serial number is what finds the chip.
When libftdi is not there
Nothing can be told about the data lines, so the board falls through to the protocol
probe exactly as before. The worst that comes of it is a board that has to be named
with
--board, which is already the documented answer for these boards. There is atest for that path.
Testing
Against the 8 relay board (FT245) on macOS 26: the three-pattern probe check above,
and
on,toggle,offstill driving the board. 80 tests pass; the probe testsstub both the FTDI chip and the serial port, including the no-libftdi fallback.