Skip to content
This repository has been archived by the owner on Oct 18, 2022. It is now read-only.

Don't consume SPI #19

Open
David-OConnor opened this issue May 30, 2020 · 3 comments
Open

Don't consume SPI #19

David-OConnor opened this issue May 30, 2020 · 3 comments

Comments

@David-OConnor
Copy link

AFAIK, you can't use this with any other SPI peripherals on the same SPI.

2 solns:

  • Mutably borrow the spi periph
  • Allow it to be freed.

I think the first is the better approach. Thoughts?

@jonas-schievink
Copy link
Owner

Hmm, why doesn't embedded-hal provide a blanket impl for the SPI trait for &mut T?

@jonas-schievink
Copy link
Owner

Mutably borrow the spi periph

One problem with this is that it forces users to use borrowing instead of ownership transfer, which is problematic when you don't need borrowing but want to store the flash object in something like an RTFM resource.

Allow it to be freed.

This should be done regardless, since I believe you just need to add a single method for this.

@David-OConnor
Copy link
Author

I suppose which approach is better depends on your code style. Eg allowing free accomodates programing styles that need storing, but generally borrowing allows simpler code, since you don't have to manage spi state - you just initialize the peripherals and forget about it.

Anecdotally, it seems like most of the crates I use (including the one I'm currently having a conflict here with) use the borrow approach.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants