Struct Matrix

Source
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,

Source

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,

Source§

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

Check whether SW_1_1 is pressed.

Auto Trait Implementations§

§

impl<C, R, const CS: usize, const RS: usize, D> Freeze for Matrix<C, R, CS, RS, D>
where D: Freeze, C: Freeze, R: Freeze,

§

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>
where D: Send, C: Send, R: Send,

§

impl<C, R, const CS: usize, const RS: usize, D> Sync for Matrix<C, R, CS, RS, D>
where D: Sync, C: Sync, R: Sync,

§

impl<C, R, const CS: usize, const RS: usize, D> Unpin for Matrix<C, R, CS, RS, D>
where D: Unpin, C: Unpin, R: Unpin,

§

impl<C, R, const CS: usize, const RS: usize, D> UnwindSafe for Matrix<C, R, CS, RS, D>
where D: UnwindSafe, C: UnwindSafe, R: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.