Skip to content

Instantly share code, notes, and snippets.

@thalesfragoso
Created June 7, 2020 00:00
Show Gist options
  • Save thalesfragoso/701cd875a0229e98d87ab627e8549469 to your computer and use it in GitHub Desktop.
Save thalesfragoso/701cd875a0229e98d87ab627e8549469 to your computer and use it in GitHub Desktop.
PPI macro
macro_rules! ppi {
(
not_fixed: [ $(
$(#[$attr:meta])?
($ppix:ident, $PpixType:ident, $ch:expr),)+
],
fixed: [$(($ppix_fixed:ident, $PpixTypeFixed:ident, $ch_fixed:expr),)+],
) => {
$(
$(#[$attrs])?
pub struct $PpixType {
_private: (),
}
$(#[$attrs])?
impl Channel for $PpixType {
const CH: usize = $ch;
}
$(#[$attrs])?
impl NotFixed for $PpixType {}
)+
$(
pub struct $PpixTypeFixed {
_private: (),
}
impl Channel for $PpixTypeFixed {
const CH: usize = $ch_fixed;
}
)+
pub struct Parts {
$(
$(#[$attrs])?
pub $ppix: $PpixType,
)+
$(
pub $ppix_fixed: $PpixTypeFixed,
)+
}
impl Parts {
pub fn new(_regs: PPI) -> Self {
Self {
$(
$(#[$attrs])?
$ppix: $PpixType {
_private: (),
},
)+
$(
$ppix_fixed: $PpixTypeFixed {
_private: (),
},
)+
}
}
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment