I have two device drivers that need to use the SPI bus.
Fortunately the one that wants to "own" it, uses a trait, and I can interpose my own implementation.
If this were regular Rust an Arc<Mutex<SPI>> would be sufficient, but I am encountering challenges.
extern crate alloc;
use alloc::sync::Arc;
use avr_hal_generic::avr_device::interrupt::{CriticalSection, Mutex};
...
let spi = Arc::new(Mutex::new(spi));
let device_interface = SpiWorkaround::new(spi.clone(), cs, dc);
When I try to compile this in a project based off the https://github.com/Rahix/avr-hal-template I get
error[E0463]: can't find crate for `alloc`
--> src/main.rs:5:1
|
5 | extern crate alloc;
| ^^^^^^^^^^^^^^^^^^^ can't find crate
If I add alloc="*" to the Cargo.toml I get
error: no matching package named `alloc` found
location searched: registry `crates-io`
I was able to get past these using cargo build --release -Z build-std=core,alloc (is there a way to put that in the Cargo.toml?) and got this error:
error[E0432]: unresolved import `alloc::sync`
--> src/main.rs:7:12
|
7 | use alloc::sync::Arc;
| ^^^^ could not find `sync` in `alloc`
What is the proper technique for letting two data structures take turns using an object in the no_std AVR environment?