Skip to content
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

Make embedded-hal 0.2 optional #435

Merged
merged 11 commits into from
Apr 8, 2024
Merged

Make embedded-hal 0.2 optional #435

merged 11 commits into from
Apr 8, 2024

Conversation

qwandor
Copy link
Member

@qwandor qwandor commented Mar 6, 2024

This required some refactoring as some of the embedded-hal 1.0 implementations depended on the embedded-hal 0.2 implementations.

@qwandor qwandor force-pushed the embedded-hal branch 8 times, most recently from c70e147 to f330108 Compare March 6, 2024 18:58
@qwandor qwandor changed the base branch from master to embedded-hal-examples March 6, 2024 19:23
Base automatically changed from embedded-hal-examples to master March 10, 2024 17:38
embedded-hal 0.2 support will be kept for now for compatibility, but
users should migrate to embedded-hal 1.0 traits where possible so the
old traits shouldn't be in the prelude.
@qwandor qwandor marked this pull request as ready for review March 10, 2024 18:39
@qwandor qwandor requested a review from BartMassey March 10, 2024 18:39
Copy link
Contributor

@ia0 ia0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a thorough review (in particular given I'm not familiar with the code) but ideally could help move forward.

self,
initial_output: Level,
drive: DriveConfig,
) -> Pin<Output<PushPull>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi: There's no diff here except fixing formatting. Maybe there should be a format check in CI?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, added.

13 => self.0.ch[0].pselp.write(|w| w.pselp().vddhdiv5()),
// This can never happen the only analog pins have already been defined
// PAY CLOSE ATTENTION TO ANY CHANGES TO THIS IMPL OR THE `channel_mappings!` MACRO
_ => unsafe { unreachable_unchecked() },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Channel trait seems to be public and safe, which means its channel() function cannot be assumed to be correct. It could either be make an unsafe trait or it could be sealed. But maybe I'm missing some constraint that make it impossible to implement and use a bad Channel.

(Reading the rest of the diff, I can see this code was simply moved. So probably not an issue for this PR.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. This isn't new code, but returning an error seems like a better option than causing undefined behaviour.

rt = ["nrf52811-pac/rt"]
default = ["rt"]
default = ["rt", "embedded-hal-02"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess embedded-hal-02 is added as a default feature to avoid breaking change. But what about users that disable default features? I'm not sure what the Cargo Book recommends in those cases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will be breaking changes in this release anyway, so I'm not really worried about that. I've included it by default just to make life easier for new users who might be using device drivers that depend on the embedded-hal 0.2 traits. People who care about binary size and build time can disable default features.

&toml_path,
"--target",
target,
//"--no-default-features",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a leftover?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, well spotted. Uncommented.

Return an error if Channel::channel() is invalid rather than causing
undefined behaviour. The Channel trait is not sealed, so we can't rely
on the implementation being correct.
@qwandor qwandor merged commit 1a15fb2 into master Apr 8, 2024
5 checks passed
@qwandor qwandor deleted the embedded-hal branch April 8, 2024 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants