Macro define_peripherals
macro_rules! define_peripherals {
(
$(#[$outer:meta])*
$peripherals:ident {
$(
$(#[$inner:meta])*
$peripheral_name:ident : $peripheral_field:ident $(=$peripheral_alias:ident)?
),*
$(,)?
}
) => { ... };
}Expand description
This macro allows to obtain peripherals from the one listed in the peripherals module
exported by this crate.
It makes sense to use this macro multiple times, coupled with conditional compilation (using
the cfg
attribute),
to define different setups for different boards.
§Examples
Basic usage for defining a peripheral struct holding two LED pins:
ⓘ
ariel_os::hal::define_peripherals!(LedPeripherals {
led0: P0_13,
led1: P0_14,
});
#[ariel_os::task(autostart, peripherals)]
async fn blinky(peripherals: LedPeripherals) {
let led = Output::new(peripherals.led0, Level::Low);
// ...
}Using cfg attributes to define the same struct with a different pin on each board:
ⓘ
#[cfg(context = "nrf52840dk")]
ariel_os::hal::define_peripherals!(LedPeripherals { led: P0_13 });
#[cfg(context = "rpi-pico")]
ariel_os::hal::define_peripherals!(LedPeripherals { led: PIN_25 });Defining a LedPin type alias, so the type of the LED’s peripheral can be named
the same way on every board:
ⓘ
#[cfg(context = "nrf52840dk")]
ariel_os::hal::define_peripherals!(LedPeripherals { led: P0_13 = LedPin });
#[cfg(context = "rpi-pico")]
ariel_os::hal::define_peripherals!(LedPeripherals { led: PIN_25 = LedPin });