Basically, this solution consists of 2 major elements.
-
I2cHandlerProxy
which pretends to be the embedded_hal's i2c implementation. It is supposed to be consumed by a driver object during init phase.- It spawns i2c-related task via RTIC's
Spawn
object.
- It spawns i2c-related task via RTIC's
-
ScopedTaskSpawnProvider
which creates something similar to scope.- On creation, it populates
I2cHandlerProxy
withSpawn
instance. - On drop, it sets
I2cHandlerProxy
Spawn
reference toNone
.- After drop, accessing i2c via
I2cHandlerProxy
causes panic.
- After drop, accessing i2c via
- On creation, it populates
I reworked it and now it is runnable in qemu-system-arm
with cargo run
.
STSP
accepts anySpawn
object (actually any object that implementsI2cHandlerCallable
)- Therefore, it will be transmuted into any other
I2cHandlerCallable
implementing type causing UB. - It is a result of struggles with lifetimes. More information in the code and comments.
- Therefore, it will be transmuted into any other
I2cCommand
holds references withstatic
lifetimes. Passing it to any spawned task with lower priority than i2c handler is a potentialuse-after-free
.