-
Notifications
You must be signed in to change notification settings - Fork 208
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
Remove EspWifiInitFor
& more granular init/deinit per driver
#2301
Conversation
df63636
to
5f16e35
Compare
Nearly done updating the examples. esp-now is causing me a considerable headache right now as it can be initialized on its own or from an existing wifi driver (ish). This makes it a bit tricky to reason about when to deinit wifi - will need a bit longer to figure this out. |
ef966f2
to
c845caa
Compare
CI is green(ish), this is now ready for another review round. |
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.
Looks good and works fine - happy to see that awkward EspWifiInitialization
and EspWifiInitFor
go away
c845caa
to
78cf67c
Compare
@@ -361,7 +385,7 @@ impl EspWifiTimerSource for TimeBase { | |||
/// ``` | |||
pub fn init<'d, T: EspWifiTimerSource>( | |||
timer: impl Peripheral<P = T> + 'd, | |||
_rng: hal::rng::Rng, | |||
_rng: impl EspWifiRngSource, |
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 could be impl Peripheral<P = RNG>
if Trng implements Peripheral<P = RNG>
without any additional traits.
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 could be, but the problem is that we don't want to completely own the Rng or Trng here, users will still want to use it in their own applications see: #2372
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.
And how does this (a trait that requires passing by value) help in not completely owning the rng?
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.
Rng
driver is clone
, Trng
might be clone soon. RNG
(the raw peripheral) will take exclusive access whether its via &mut Self
or Self
and not allow any other part of the system to use Rng
.
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.
I think you misunderstand what I want. I'm not proposing requiring using the raw peripheral. I'm proposing accepting drivers that work with the peripheral. Making Rng
and Trng
implement Peripheral
allows us to pass both of those, or a mutable reference to them (or just the RNG peripheral directly) and esp-wifi wouldn't know the difference.
I.e. I'm suggesting that instead of a custom trait we have:
impl Peripheral for Rng {
type P = RNG;
...
}
impl Peripheral for Trng {
type P = RNG;
...
}
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.
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.
In that case we may still go this way, just using Peripheral<P = Rng>
. But I'll not force the issue.
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.
With Trng
also impl Peripheral<P = Rng>
? That could work. Just wondering if there a case where someone might need to write Peripheral<P = Trng>
, because they wouldn't be able to in this case.
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.
Peripheral<P = Trng>
That is an interesting question, drivers absolutely requiring true randomness. I'm not sure, but we're not supporting it right now, either.
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.
The "funny" thing is that RNG will give true random numbers when the RF peripherals are enabled (but we still need #2443)
@@ -287,7 +288,7 @@ impl<'d> Drop for EspWifiController<'d> { | |||
/// | |||
/// This trait is meant to be used only for the `init` function. | |||
/// Calling `timers()` multiple times may panic. | |||
pub trait EspWifiTimerSource { | |||
pub trait EspWifiTimerSource: private::Sealed { |
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.
Isn't this a bit of an overkill?
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.
Maybe, but is there a down side to doing it?
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.
More code :)
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.
I suppose, but I can't see a reason to keep this trait open of downstream crates to impl.
I'm happy to remove it, but I'd like a more compelling argument than removing a few lines of hidden boiler plate impls.
Skip changelog for esp-hal changes, this is now ready for another round of review. |
- Rework EspWifiInit - No longer require EspWifiInitFor - Add Drop impls for each driver, and add Drop for EspWifiController to fully deinit the stack
6bbca3e
to
8edb88a
Compare
Thank you for your contribution!
We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:
Submission Checklist 📝
cargo xtask fmt-packages
command to ensure that all changed code is formatted correctly.CHANGELOG.md
in the proper section.Extra:
Pull Request Details 📖
Description
EspWifiInit
toEspWifiController
- bikeshedding welcomeinitialize
deinit
no longer returns the used resources, instead the peripheral ref pattern will take care of thisI haven't updated all the examples yet, I'll do so after a bit of review.
Testing
Try this modified wifi_dhcp example: https://gist.github.com/MabezDev/78aac5133c482a56db9600697c179650