-
Notifications
You must be signed in to change notification settings - Fork 152
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
Add steal() for each peripheral. #723
Conversation
steal()
for each peripheral.
steal()
for each peripheral.
Is it sufficient to jus tcall the existing I'm not sure I'd want to make it easier to steal peripherals, because a stolen peripheral bypasses the ownership system ( |
@thejpster Indeed, a stolen peripheral bypasses the ownership system. So I implemented the I believe that anyone who uses unsafe methods should take responsibility for their choices. And it can be challenging without these unsafe methods when working on low-level MCU development. |
0708f6c
to
20a581a
Compare
But you don't have a If a HAL wishes to unsafely access the peripherals without using the PAC's sense of ownership, it can do that by creating its own types which are Copy or Clone. How it chooses to ensure that a read-modify-write cannot happen concurrently from multiple threads (or interrupts) is then a problem for the HAL author to solve. But I'm still not sure the PAC needs to make it easier for HAL authors to do this, because it's outside the normal pattern of operation. |
We discussed this PR a bit more in today's meeting, I think it's fair to say there is interest in merging it but we're not sure yet, and in particular wonder if the new function would need to set the global flag that |
No need to set the global flag, because before calling the |
Given the peripherals are already stolen/taken, maybe this should be named something like |
@reitermarkus
@thejpster pub trait UartReg {
fn ptr() -> *mut Self;
// or
unsafe fn mut_ref() -> &'static mut Self;
// or
unsafe fn steal_mut(&self) -> &'static mut Self;
}
impl UartReg for USART1 {
fn ptr() -> *mut Self {
(1_usize as *mut Self)
}
//...
}
impl UartReg for UART4 { //... } fn foo<U: UartReg>() {
let u = unsafe { &(*U::ptr()) };
} They are very useful. However, they are also weird because the pointer points to an invalid address. So I think adding an unsafe clone method to each peripheral would be a more elegant solution. |
Thanks for the PR! We discussed it again in today's meeting and we think it might be best if these new methods were associated functions (i.e., like They'd still be unsafe and do the same thing, but you don't need to already have the peripheral before you can make a new copy. With an associated What do you think? |
It is sufficient for me. |
I think this is ready to merge, @rust-embedded/tools any last thoughts? |
Won't clippy complain if an |
@adamgreig Maybe you fix docs yourself? |
cc @thejpster |
Sorry I'm on vacation at the moment. |
This is more convenient than the
Peripherals::steal()