macro_rules! bsp_pins {
(
$(
$( #[$id_cfg:meta] )*
$Id:ident {
$( #[$name_doc:meta] )*
name: $name:ident $(,)?
$(
aliases: {
$(
$( #[$alias_cfg:meta] )*
$Function:ty, $PullType:ident: $Alias:ident
),+
}
)?
} $(,)?
)+
) => { ... };
( @aliases, $( $( $( #[$attr:meta] )* $Id:ident $Function:ident $PullType:ident $Alias:ident )+ )? ) => { ... };
}Expand description
Helper macro to give meaningful names to GPIO pins
The normal Pins struct names each Pin according to its PinId.
However, BSP authors would prefer to name each Pin according to its
function. This macro defines a new Pins struct with custom field names
for each Pin.
ยงExample
Calling the macro like this:
use rp235x_hal::bsp_pins;
bsp_pins! {
#[cfg(feature = "gpio")]
Gpio0 {
/// Doc gpio0
name: gpio0,
aliases: { FunctionPio0, PullNone: PioPin }
},
Gpio1 {
name: led,
aliases: { FunctionPwm, PullDown: LedPwm }
},
}Is roughly equivalent to the following source code (excluding the docs strings below):
use ::rp235x_hal as hal;
use hal::gpio;
pub struct Pins {
/// Doc gpio0
#[cfg(feature = "gpio")]
pub gpio0: gpio::Pin<
gpio::bank0::Gpio0,
<gpio::bank0::Gpio0 as gpio::DefaultTypeState>::Function,
<gpio::bank0::Gpio0 as gpio::DefaultTypeState>::PullType,
>,
pub led: gpio::Pin<
gpio::bank0::Gpio1,
<gpio::bank0::Gpio1 as gpio::DefaultTypeState>::Function,
<gpio::bank0::Gpio1 as gpio::DefaultTypeState>::PullType,
>,
}
impl Pins {
#[inline]
pub fn new(
io: hal::pac::IO_BANK0,
pads: hal::pac::PADS_BANK0,
sio: hal::sio::SioGpioBank0,
reset: &mut hal::pac::RESETS,
) -> Self {
let mut pins = gpio::Pins::new(io, pads, sio, reset);
Self {
#[cfg(feature = "gpio")]
gpio0: pins.gpio0,
led: pins.gpio1,
}
}
}
pub type PioPin = gpio::Pin<gpio::bank0::Gpio0, gpio::FunctionPio0, gpio::PullNone>;
pub type LedPwm = gpio::Pin<gpio::bank0::Gpio1, gpio::FunctionPwm, gpio::PullDown>;