pub struct Matrix<C, R, const CS: usize, const RS: usize, D>where
C: InputPin,
R: OutputPin,
D: DelayNs,{ /* private fields */ }
Expand description
Describes the hardware-level matrix of switches.
Generic parameters are in order: The type of column pins, the type of row pins, the number of columns and rows. NOTE: In order to be able to put different pin structs in an array they have to be downgraded (stripped of their numbers etc.). Most HAL-s have a method of downgrading pins to a common (erased) struct. (for example see stm32f0xx_hal::gpio::PA0::downgrade)
TIM5 is used to provide a delay during the matrix scanning.
Implementations§
Source§impl<C, R, const CS: usize, const RS: usize, D> Matrix<C, R, CS, RS, D>where
C: InputPin,
R: OutputPin,
D: DelayNs,
impl<C, R, const CS: usize, const RS: usize, D> Matrix<C, R, CS, RS, D>where
C: InputPin,
R: OutputPin,
D: DelayNs,
Sourcepub fn new<E>(
cols: [C; CS],
rows: [R; RS],
delay: D,
select_delay_us: u32,
unselect_delay_us: u32,
) -> Result<Self, E>where
C: InputPin<Error = E>,
R: OutputPin<Error = E>,
pub fn new<E>(
cols: [C; CS],
rows: [R; RS],
delay: D,
select_delay_us: u32,
unselect_delay_us: u32,
) -> Result<Self, E>where
C: InputPin<Error = E>,
R: OutputPin<Error = E>,
Creates a new Matrix.
Assumes columns are pull-up inputs, and rows are output pins which are set high when not being scanned.
Trait Implementations§
Source§impl<C, R, const CS: usize, const RS: usize, D, E: Debug> MatrixScanner<CS, RS, E> for Matrix<C, R, CS, RS, D>where
C: InputPin<Error = E>,
R: OutputPin<Error = E>,
D: DelayNs,
impl<C, R, const CS: usize, const RS: usize, D, E: Debug> MatrixScanner<CS, RS, E> for Matrix<C, R, CS, RS, D>where
C: InputPin<Error = E>,
R: OutputPin<Error = E>,
D: DelayNs,
Source§fn get(&mut self) -> Result<[[bool; CS]; RS], E>
fn get(&mut self) -> Result<[[bool; CS]; RS], E>
Scans the matrix and checks which keys are pressed.
Every row pin in order is pulled low, and then each column pin is tested; if it’s low, the key is marked as pressed.
Delays for a bit after setting each pin, and after clearing each pin.
Source§fn is_boot_key_pressed(&mut self) -> bool
fn is_boot_key_pressed(&mut self) -> bool
Auto Trait Implementations§
impl<C, R, const CS: usize, const RS: usize, D> Freeze for Matrix<C, R, CS, RS, D>
impl<C, R, const CS: usize, const RS: usize, D> RefUnwindSafe for Matrix<C, R, CS, RS, D>
impl<C, R, const CS: usize, const RS: usize, D> Send for Matrix<C, R, CS, RS, D>
impl<C, R, const CS: usize, const RS: usize, D> Sync for Matrix<C, R, CS, RS, D>
impl<C, R, const CS: usize, const RS: usize, D> Unpin for Matrix<C, R, CS, RS, D>
impl<C, R, const CS: usize, const RS: usize, D> UnwindSafe for Matrix<C, R, CS, RS, D>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more