Closed adamgreig closed 1 year ago
Closing this. We discovered why this is present: frameworks like RTIC want to take()
the peripherals but know it cannot fail as they are running before any other code, so can use steal()
to avoid the overhead associated with unwrap()
while still setting the DEVICE_PERIPHERALS
flag to ensure subsequent user code cannot safely end up with duplicate peripherals.
We should add this to the documentation ideally, but it doesn't seem worth changing this behaviour. Instead we can add the new per-peripheral steal()
in #723 which needn't set DEVICE_PERIPHERALS
, and that can be the zero-overhead way of unsafely creating a peripheral for new code.
We've discussed this a bit in the weekly meetings, I propose removing setting
DEVICE_PERIPHERALS
fromsteal()
and leave it only intake()
. This shouldn't meaningfully change the safety conditions or the use of either API, but does make stealing zero-cost. It was always possible to unsafelytransmute()
to obtainPeripherals
without settingDEVICE_PERIPHERALS
, so I'm interested if anyone can remember why this existed in the first place or if it is indeed still needed.