-
Notifications
You must be signed in to change notification settings - Fork 249
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
Fix Spi for EH1 alpha #611
Conversation
I was getting an error. Not sure if these are the right changes but fixes the issue for me. ``` error[E0308]: mismatched types --> src/main.rs:72:9 | 68 | let mut spi = spi.init( | ---- arguments to this method are incorrect ... 72 | &embedded_hal::spi::MODE_0, | ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `embedded_hal::spi::Mode`, found `Mode` | = note: `Mode` and `embedded_hal::spi::Mode` have similar names, but are actually distinct types ```
0b44172
to
967340b
Compare
What is failing on CI here is not failing for me locally. Not sure what difference is causing it. |
It is failing because the examples always/only use embedded-hal 0.2.7. So the issue here is a bit unfortunate. I'd probably made the rp2040-hal's It's a bit convoluted but that's the most "seamless"/non-breaking I can think of for users. |
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.
This is a good catch! however, this solution isn't going to work very well.
I left another comment to explain a bit more what's happening and one way of working around that issue.
Thank you so much for figuring that out! Makes sense to me now.
I'll give it a go |
75da4b2
to
a7f4ab8
Compare
rp2040-hal/src/spi.rs
Outdated
@@ -165,14 +200,15 @@ impl<D: SpiDevice, const DS: u8> Spi<Disabled, D, DS> { | |||
} | |||
|
|||
/// Set format and datasize | |||
fn set_format(&mut self, data_bits: u8, mode: &Mode) { | |||
fn set_format<M: Into<Mode> + Clone>(&mut self, data_bits: u8, mode: &M) { | |||
let mode: Mode = (*mode).clone().into(); |
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.
Introduces a clone
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.
It would be a breaking change but 0.9.0 is planned to have loads anyway, so this can be made into:
fn set_format<M: Into<Mode>>(&mut self, data_bits: u8, mode: M) {
let mode: Mode = mode.into();
EDIT: actually we don't need the generic to go that deep in the API.
See the top level comment.
Re-exporting |
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.
This looks like a great step forward!
The bounds for copy and clone can be avoided by using From<&eh1::spi::Mode>
.
I don't know if that's a common/recommended practice.
Alternatively, the function may as well take the mode by value.
I prefer this but it'll be more of a breaking change.
I spoke too soon haha |
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.
Actually, all the private methods (set_format
, init_spi
) can take a plain rp2040_hal::spi::Mode
.
init
and init_slave
can take a generic M: Into<Mode>
by value and do the required mode.into()
as it calls the private method.
The Mode
type is always going to be a fairly small type (about 2 bytes) so according to the AAPCS (IIRC) such type can be passed in a single register, so it is the same price as passing a reference.
e4136a9
to
94d724e
Compare
I was getting an error. Not sure if these are the right changes but fixes the issue for me. Potentially the feature conditionals could be tidied up.