Macro shared_bus::new_std [−][src]
macro_rules! new_std { ($bus_type:ty = $bus:expr) => { ... }; }
Macro for creating a std
-based bus manager with 'static
lifetime.
This macro is a convenience helper for creating a bus manager that lives for the 'static
lifetime an thus can be safely shared across threads.
This macro is only available with the std
feature.
Syntax
ⓘ
let bus = shared_bus::new_std!(<Full Bus Type Signature> = <bus>).unwrap();
The macro returns an Option which will be Some(&'static bus_manager)
on the first run and
None
afterwards. This is necessary to uphold safety around the inner static
variable.
Example
// For example: // let i2c = I2c::i2c1(dp.I2C1, (scl, sda), 90.khz(), clocks, &mut rcc.apb1); // The bus is a 'static reference -> it lives forever and references can be // shared with other threads. let bus: &'static _ = shared_bus::new_std!(SomeI2cBus = i2c).unwrap(); let mut proxy1 = bus.acquire_i2c(); let mut my_device = MyDevice::new(bus.acquire_i2c()); // We can easily move a proxy to another thread: std::thread::spawn(move || { my_device.do_something_on_the_bus(); });