-
Notifications
You must be signed in to change notification settings - Fork 25
Borrow spi instead of owning #21
base: master
Are you sure you want to change the base?
Conversation
I agree that supporting this use case somehow is important, but I'm not sure this is the best way to do that. What do other driver crates do to handle this? If you use |
The other SPI peripheral I'm using, epd_waveshare uses mutable references in the functions, in a similar way to this. this module I found as the first entry on the awsome-embedded list for SPi takes the SPI periph back with a As far as I can tell, these are the two main approaches, but these are anecdotes. |
I'd prefer to add a We can also add a method that returns a mutable reference to the SPI, for temporary operations. |
I feel like free/consuming can get verbose if you're using more than one device on the perhiph, since you need to constantly free/consume, track state, and hope all crates using this pattern handle use-while-freed elegantly. Using a mutable reference requires passing the periph every time (eg adding So overall, I think the borrow mut approach is both less verbose (Despite appearing more so at first), and less error-prone. |
FYI I added enter and exit |
FWIW, I am also sharing SPI between |
#19
This implementation isn't the most elegant. It could be improved by storing the mutable reference in the structure, but I don't have the skill to do this. The cost of my approach is that both the internal code, and API calls require passing
&spi
each time. I still think it's worth it, since this allows you to use the same SPI peripherals for multiple devices, which is important.