-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
ports/rp2: Optional spi_id and optional disabling of MISO pin #16922
Closed
Gadgetoid
wants to merge
2
commits into
micropython:master
from
pimoroni:patch-rp2-machine-spi-optional-id-miso
Closed
ports/rp2: Optional spi_id and optional disabling of MISO pin #16922
Gadgetoid
wants to merge
2
commits into
micropython:master
from
pimoroni:patch-rp2-machine-spi-optional-id-miso
Conversation
This file contains 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
Code size report:
|
dpgeorge
reviewed
Mar 13, 2025
dpgeorge
reviewed
Mar 13, 2025
50968d4
to
8975d9e
Compare
dpgeorge
reviewed
Mar 13, 2025
If the "spi_id" arg is not supplied and then the board default specified by PICO_DEFAULT_SPI will be used. If this is not set, it's defaulted to 0. Note: spi_id is still required when MICROPY_HW_SPI_NO_DEFAULT_PINS is set. Signed-off-by: Phil Howard <[email protected]>
8975d9e
to
1183bd0
Compare
dpgeorge
reviewed
Mar 25, 2025
It's common with write-only SPI displays for MISO to be repurposed as a register select or data/command pin. While that was possible by setting up the pin after a call to `machine.SPI()` this change makes `machine.SPI(miso=None)` explicit. Signed-off-by: Phil Howard <[email protected]>
1183bd0
to
6d66eef
Compare
dpgeorge
approved these changes
Mar 26, 2025
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.
Summary
This PR includes two changes:
machine.SPI()
into parity withmachine.I2C()
, selecting the default instance where none is specified. See: feature/optional_i2c_bus #16671machine.SPI(mosi=None)
explicitly disable MISO, for configurations which use this as a register-select or data/command pin (very common for write-only LCDs). See: When miso=None is set, the default miso pin changed state. #16912I avoided making this change for all pins, since it rarely makes sense for MOSI or SCLK to be disabled.
Testing
Tested various invocations of
machine.SPI()
on a Pico 2 W.Notably this change introduces a difference in behaviour that always resets MISO back to the default unless it's specified or set to
None
. Eg:This is materially different from, for example, mosi where it's impossible to implicitly set a pin back to its default value:
🤔 Maybe this changeset should also require that a pin is specified or that it is otherwise always set back to its default value.
Trade-offs and Alternatives
The latter change is more about explicit vs implicit. It's possibly just to set upt he MISO pin after setting up SPI and it will work as expected. A documentation change establishing this as the accepted pattern might be an alternative... though it might not be possible in all cases for the pin setup to happen before SPI.
Consider the following very crude example driver pattern where a user wishes to save a pin (normally eaten by SPI) and reuse it for register select:
However because the pin is constructed before it's passed into the driver class, its mux will be overwritten by
machine.SPI()
With this change, a driver author could use:
And SPI would no longer trample the "rs" pin config by setting it up as MISO.