Macro keypad::keypad_struct[][src]

macro_rules! keypad_struct {
    (
      $visibility:vis struct $struct_name:ident {
            rows: ( $($row_type:ty),* $(,)* ),
            columns: ( $($col_type:ty),* $(,)* ),
        }
    ) => { ... };
    (@array2d_type ($($row:ty),*) ($($col:ty),*) ) => { ... };
    (@array1d_type ($($col:ty),*)) => { ... };
    (@element_type ) => { ... };
    (@count $($token_trees:tt)*) => { ... };
    (@replace $_t:tt $sub:expr) => { ... };
    (@underscore $unused:tt) => { ... };
    (@destructure_ref $tuple:expr, ($($repeat_n:ty),*)) => { ... };
    (@tuple_helper $tuple:expr, ($head:ty), ($($result:expr),*  $(,)*)) => { ... };
    (@tuple_helper $tuple:expr, ($head:ty $(,$repeats:ty)* $(,)*),  ($($result:expr),*  $(,)*)) => { ... };
    (@tuple $tuple:expr, ($($repeats:ty),*)) => { ... };
}

Define a new struct representing your keypad matrix circuit.

Every pin has a unique type, depending on its pin number and its current mode. This struct is where you specify which pin types will be used in the rows and columns of the keypad matrix. All the row pins must implement the InputPin trait, and the column pins must implement the OutputPin trait.

You can specify the visibility of the struct (eg. pub) as usual.

This macro will implement the decompose() and release() methods for your struct. To view documentation for those methods, see the example crate.

Example

#[macro_use]
extern crate keypad;
use keypad::mock_hal::{self, Input, Output, PullUp, OpenDrain};

keypad_struct!{
    struct MyKeypad {
        rows: (
            mock_hal::gpioa::PA0<Input<PullUp>>,
            mock_hal::gpioa::PA1<Input<PullUp>>,
        ),
        columns: (
            mock_hal::gpioa::PA2<Output<OpenDrain>>,
            mock_hal::gpioa::PA3<Output<OpenDrain>>,
            mock_hal::gpioa::PA4<Output<OpenDrain>>,
        ),
    }
}

Safety

This macro uses unsafe to create an array with uninitialized memory, which is then immediately initialized in a loop. This is fine as long as there is not a bug in how the macro calculates the dimensions of the array.