assign-resources
This crate contains a macro to help assign and split up resources from a
struct, such as the Peripherals
struct provided by embedded PACs and HALs,
into many smaller structs which can be passed to other tasks or functions.
It's best explained with the example below. Here we define new structs named
UsbResources
and LedResources
, each containing some IO pins and a
peripheral, and generate a new split_resources!()
macro. When called,
the split_resources!()
macro takes PA12
, PA11
, and USB
out of
p: Peripherals
and uses them to create the field usb: UsbResources
, and
similarly creates the field leds: LedResources
in the returned object. We can
then move these new structs into our tasks, which access the resources by name.
We can also label some resources with type aliases, so function signatures can refer to that type as well.
use peripherals;
assign_resources!
async
async
async
async
This has a few advantages: you only need to write the specific pin names like
PA12
in one place and can refer to them by name thereafter, you only have one
argument for each task instead of potentially very many, and you don't need
to write out lots of code to split the resources up. If you're targetting
multiple different hardware, you can use #[cfg]
to change pin allocations
in just one place.