Skip to main content

ButtonMatrix

Struct ButtonMatrix 

Source
pub struct ButtonMatrix<ROW, COL, NAME, const ROWS: usize, const COLS: usize> { /* private fields */ }
Expand description

Debounced scanner for a rectangular button matrix.

ROWS input pins are read while each of the COLS output pins is selected one at a time. Each key has an independent debouncer, so multiple keys can be pressed and released during the same scan.

Implementations§

Source§

impl<ROW, COL, NAME, const ROWS: usize, const COLS: usize> ButtonMatrix<ROW, COL, NAME, ROWS, COLS>

Source

pub const fn new( rows: [ROW; ROWS], columns: [COL; COLS], names: [[NAME; COLS]; ROWS], ) -> Self

Creates a matrix using MatrixConfig::active_low.

Source

pub const fn with_config( rows: [ROW; ROWS], columns: [COL; COLS], names: [[NAME; COLS]; ROWS], config: MatrixConfig, ) -> Self

Creates a matrix with a custom configuration.

Source

pub const fn config(&self) -> MatrixConfig

Returns the current configuration.

Source

pub fn set_config(&mut self, config: MatrixConfig)

Replaces the whole configuration.

Source

pub const fn debounce_ms(&self) -> Millis

Returns the current debounce time.

Source

pub fn set_debounce_ms(&mut self, debounce_ms: Millis)

Sets the debounce time.

Source

pub const fn row_active_level(&self) -> ActiveLevel

Returns the current row active level.

Source

pub fn set_row_active_level(&mut self, row_active_level: ActiveLevel)

Sets the row active level.

Source

pub const fn column_drive(&self) -> ColumnDrive

Returns the current column drive polarity.

Source

pub fn set_column_drive(&mut self, column_drive: ColumnDrive)

Sets the column drive polarity.

Source

pub fn name(&self, row: usize, column: usize) -> Option<NAME>
where NAME: Copy,

Returns the name assigned to a key.

Source

pub fn state(&self, row: usize, column: usize) -> Option<ButtonState>

Returns the stable debounced state of a key.

Source

pub fn is_pressed(&self, row: usize, column: usize) -> bool

Returns true if the key is currently stably pressed.

Source

pub fn held_ms( &self, row: usize, column: usize, now_ms: Millis, ) -> Option<Millis>

Returns the current debounced hold time for a key, or None if the key is released or the indexes are out of range.

Source

pub const fn pressed_keys( &self, now_ms: Millis, ) -> PressedKeys<'_, ROW, COL, NAME, ROWS, COLS> ⓘ

Iterates over all keys that are currently stably pressed.

Source

pub fn rows_mut(&mut self) -> &mut [ROW; ROWS]

Returns mutable access to the row pins.

Source

pub fn columns_mut(&mut self) -> &mut [COL; COLS]

Returns mutable access to the column pins.

Source

pub fn into_parts(self) -> ([ROW; ROWS], [COL; COLS], [[NAME; COLS]; ROWS])

Returns the inner pins and the key-name matrix.

Source§

impl<ROW, COL, NAME, const ROWS: usize, const COLS: usize> ButtonMatrix<ROW, COL, NAME, ROWS, COLS>
where ROW: InputPin, COL: OutputPin, NAME: Copy,

Source

pub fn scan( &mut self, now_ms: Millis, ) -> Result<ButtonMatrixEvents<NAME, ROWS, COLS>, MatrixError<ROW::Error, COL::Error>>

Scans the whole matrix once and returns all debounced transition events.

The method drives one column active at a time, reads every row, updates independent debouncers for all keys, and then moves to the next column. It does not allocate and it does not wait internally.

Auto Trait Implementations§

§

impl<ROW, COL, NAME, const ROWS: usize, const COLS: usize> Forget for ButtonMatrix<ROW, COL, NAME, ROWS, COLS>

§

impl<ROW, COL, NAME, const ROWS: usize, const COLS: usize> Freeze for ButtonMatrix<ROW, COL, NAME, ROWS, COLS>

§

impl<ROW, COL, NAME, const ROWS: usize, const COLS: usize> Move for ButtonMatrix<ROW, COL, NAME, ROWS, COLS>

§

impl<ROW, COL, NAME, const ROWS: usize, const COLS: usize> RefUnwindSafe for ButtonMatrix<ROW, COL, NAME, ROWS, COLS>

§

impl<ROW, COL, NAME, const ROWS: usize, const COLS: usize> Send for ButtonMatrix<ROW, COL, NAME, ROWS, COLS>

§

impl<ROW, COL, NAME, const ROWS: usize, const COLS: usize> Sync for ButtonMatrix<ROW, COL, NAME, ROWS, COLS>

§

impl<ROW, COL, NAME, const ROWS: usize, const COLS: usize> Unpin for ButtonMatrix<ROW, COL, NAME, ROWS, COLS>

§

impl<ROW, COL, NAME, const ROWS: usize, const COLS: usize> UnsafeUnpin for ButtonMatrix<ROW, COL, NAME, ROWS, COLS>

§

impl<ROW, COL, NAME, const ROWS: usize, const COLS: usize> UnwindSafe for ButtonMatrix<ROW, COL, NAME, ROWS, COLS>

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.