-
Notifications
You must be signed in to change notification settings - Fork 767
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
nrf: New API supporting borrowed peripherals #91
Conversation
132d845
to
72163c1
Compare
83a5607
to
e4e1495
Compare
I'm playing with this on my nrf-52832. You need the line
on line 10 of |
Also, I might be wrong but I think you should use You could do this by forwarding your |
Nice catch, added!
Yes, I'm aware of this but I'm not sure how to best solve it. Ideally I want to avoid the pac appearing in the public API at all, so we can bump the pac's major version (or switch to something completely different) without bumping embassy-nrf major version (ie the pac should just be an internal implementation detail on how we access registers). One problem is that PACs intentionally forbid linking multiple major versions at once (precisely so you can't take() the peripherals multiple times), so even if the PAC doesn't appear in the public API bumping it is a breaking change... The reasoning behind doing our own Peripherals is the PAC's Peripherals is autogenerated from SVDs, which is not ideal:
|
Maybe its better if I explain what I mean in code. I mean something like (in the Peripherals macro) impl Peripherals {
///Returns all the peripherals *once*
#[inline]
pub fn take() -> Option<Self> {
if pac::Peripherals::take().is_some() {
Some(unsafe { <Self as ::embassy::util::Steal>::steal() })
} else {
None
}
}
} Update: URGH, pac crates mark the peripherals as taken even if you steal them. This is disappointing! If that wasn't the case you could do what I suggest above. |
I've done some work on my local copy making nrf gpio match the PeripheralBorrow scheme, which you might as well copy/paste. Let me know if you want me to post it somewhere. |
@derekdreery Yes please, that'd be great! You can send a PR to this PR (target branch borrow-v3 instead of master) |
embassy-nrf/src/uarte.rs
Outdated
|
||
T::state().tx_done.signal(()); | ||
} | ||
// TX is stopped almost instantly, spinning is fine. |
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.
RX abort is slow, previously we used embassy_extras::low_power_wait_until()
to wait until it is over.
I had a look at the UARTE part, but I did not test on real hardware. Still I have few nits for the RX part:
|
Thanks for taking a look @timokroeger , very good points.
Yep, I'll bring that back. Requires some care with the new interrupt handling but I think it's doable.
I removed it because IMO the
I do agree it's a nice functionality to have. An alternative would be adding a
Oh, that's what RXTO is for 🤦 . I now understand why your impl was that complex, haha. Will fix. |
This is a lighter version of InterruptFuture.
The interrupt could fire between checking if sense=disabled and registering the waker, in which case the future would get stuck.
… stop is necessary on drop.
Yet another way... trying to workaround the type inference issues.
This adds the possibility of creating drivers with borrowed peripheral instances.
It's cool:
Spim<'_, SPIM3>
regardless whether it's owned or borrowedBorrow<'a, T>
struct.