Fix SpiBus for use with Polarity::IdleHigh #76
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.
Instead of just storing the correct polarity, also set this polarity in the GPIO struct, so that changes that write to GPIOs (e.g. asserting CS) will maintain the correct idle level.
If this is not done, the FTDI will create invalid output with clock spikes.
I did now implement the version with the API change because this way we get very similar results independent of whether we first deassert CS or set the clock polarity. One could argue that there is one valid order here, but it feels safer/more intuitive this way (but for sure for you to decide what you want to go forward with).
With this example code:
We now get this on the logic analyzer:
w/o writing in `set_clock_polarity`
For completeness, if
set_clock_polarity
does not immediately change the state andset_high
andset_clock_polarity
in the above example are swapped then we get this:Where the polarity only get set the moment we select the chip - so we need to take care that there is a delay for most devices that mandate stable signals for a certain setup time before asserting CS. This difference only occurs then on the first CS...
Fixes #75