-
I'm using a board based on ESP32 that has a display interface, touch interface and sd-card, all on SPI but each on different pins (sck, miso, mosi, cs).
Let's say I can switch among them and not use all at the same time, for example start with the sd-card for initialization and then switch to use touch interface, my challenge becomes rust - how can I reuse a Spi, let's say SPI2, and change its pins after I used it for the sd-card. When I try to reuse SPI2 with different pins for the touch, I get a compilation error that
|
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 8 replies
-
Sounds like an interesting design choice of that board to me. Are there schematics available for that board? When you create the SPI driver you can pass the peripheral and the pins as But usually there are multiple devices connected to the same SPI bus and the device to talk to is selected by its CS line |
Beta Was this translation helpful? Give feedback.
-
There's a repo dedicated to that board (but doesn't cover rust) - https://github.com/witnessmenow/ESP32-Cheap-Yellow-Display Specific pointers to relevant technical information there:
Thanks, that worked. It was enough to just pass |
Beta Was this translation helpful? Give feedback.
-
Good to hear you made some progress. Let me know if it really works for you in the end |
Beta Was this translation helpful? Give feedback.
-
Great! Closing for now ... feel free to re-open when needed |
Beta Was this translation helpful? Give feedback.
-
In theory the hardware would support reconfiguring the pins but the driver won't let you do it (since we could not guarantee safe usage and I currently don't see a way to create a safe API for this) One thing you could do today is to pass the pins and the peripheral as |
Beta Was this translation helpful? Give feedback.
-
You could try to disconnect / connect the pins yourself to the peripheral - e.g. the code which currently does it in the driver is here: esp-hal/esp-hal-common/src/spi/master.rs Lines 405 to 435 in dfad09d |
Beta Was this translation helpful? Give feedback.
-
Yes, that's changed API on current |
Beta Was this translation helpful? Give feedback.
Sounds like an interesting design choice of that board to me. Are there schematics available for that board?
When you create the SPI driver you can pass the peripheral and the pins as
&mut
references instead of moving them into the driver. Then when you drop the driver you can recreate itBut usually there are multiple devices connected to the same SPI bus and the device to talk to is selected by its CS line