-
-
Notifications
You must be signed in to change notification settings - Fork 40k
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
Chibios SPI driver: allow some SPI pins to be left unassigned #20315
Chibios SPI driver: allow some SPI pins to be left unassigned #20315
Conversation
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.
I had some different ideas in mind when suggesting to add the NO_PIN
support to the SPI driver; the suggested changes are mostly about that (except one block that might fix the formatting issues).
#if SPI_SELECT_MODE != SPI_SELECT_MODE_NONE | ||
# if defined(K20x) || defined(KL2x) || defined(RP2040) | ||
static SPIConfig spiConfig = {NULL, 0, 0, 0}; | ||
#else | ||
# else | ||
static SPIConfig spiConfig = {false, NULL, 0, 0, 0, 0}; | ||
# endif | ||
#else | ||
# if defined(K20x) || defined(KL2x) || defined(RP2040) | ||
static SPIConfig spiConfig = {NULL, 0}; | ||
# else | ||
static SPIConfig spiConfig = {false, NULL, 0, 0}; | ||
# endif | ||
#endif |
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.
Can we just rely on the default zero initialization for static
variables here?
static SPIConfig spiConfig;
(GitHub does not allow adding a proper suggestion for this code block.)
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.
DONE
Co-authored-by: Sergey Vlasov <[email protected]>
…s, and simplify code
@sigprof I applied all your suggestions and rerun with my keyboard and things work. |
Im no big expert but i would get rid of
PS: This addition is great, thx. It should be used by #20258 if it gets somewhere. Since CS could be a "virtual pin" (instead of completely unused), ChibiOS wouldn't be able to control it, so we would want:
|
@elpekenin I don't think ChibiOS currently supports configuring some SPI buses with SPI_SELECT_MODE_NONE and some others with SPI_SELECT_MODE_PAD, correct me if I'm wrong. So not sure what advantage it would have to move those checks to runtime. However if this changes in the future then absolutely yes. I don't think the current PR implementation would prevent it from working with 20258. |
Indeed, it isnt an option currently, as
It wouldnt, in fact it helps (in case someone tries to use virtual pins for MISO/MOSI, we can ignore those as it makes no sense... and virtual CS could be used thanks to the manual control of the pin over letting ChibiOS handle that) |
I like the idea of having this all be runtime selected if that becomes an option in the future in Chibios upstream. But i guess I don't see the point in writing code for it now, since we don't even know if it's ever gonna happen, and we don't know what it's gonna look like. If it becomes possible we can always switch to runtime later as a response to the upstream change. And just going from #if SPI_SELECT_MODE == SPI_SELECT_MODE_PAD
spiConfig.ssport = PAL_PORT(slavePin);
spiConfig.sspad = PAL_PAD(slavePin); |
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.
The ChibiOS code looks like it should work.
One potential issue is that the AVR SPI driver might eventually need a similar change to make it accept NO_PIN
, but I'm not sure about any actual users for that feature.
This has a merge conflict that needs resolving. |
Thank you for your contribution! |
Thank you for your contribution! |
…to_not_be_assigned
) Co-authored-by: Sergey Vlasov <[email protected]> Co-authored-by: Nick Brassel <[email protected]>
) Co-authored-by: Sergey Vlasov <[email protected]> Co-authored-by: Nick Brassel <[email protected]>
) Co-authored-by: Sergey Vlasov <[email protected]> Co-authored-by: Nick Brassel <[email protected]>
) Co-authored-by: Sergey Vlasov <[email protected]> Co-authored-by: Nick Brassel <[email protected]>
Description
Types of Changes
Issues Fixed or Closed by This PR
Checklist