Wrote MatrixConfig type
This commit is contained in:
parent
382a018b22
commit
597d2584b1
1 changed files with 43 additions and 0 deletions
43
src/lib.rs
43
src/lib.rs
|
|
@ -8,3 +8,46 @@ pub struct TCA8418<I2C> {
|
||||||
i2c: I2C,
|
i2c: I2C,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy)]
|
||||||
|
pub struct MatrixConfig {
|
||||||
|
rows: u8,
|
||||||
|
columns: u16,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MatrixConfig {
|
||||||
|
/// A new config where the matrix has no rows or columns and all of the pins are
|
||||||
|
/// allocated for GPIO.
|
||||||
|
pub const fn new_empty() -> Self {
|
||||||
|
MatrixConfig {
|
||||||
|
rows: 0,
|
||||||
|
columns: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Add a row to the keyboard matrix, meaning its pin will not be available for GPIO.
|
||||||
|
///
|
||||||
|
/// `row_number` must be in the range `0..=7`
|
||||||
|
pub const fn with_row(self, row_number: u8) -> Self {
|
||||||
|
if row_number >= 8 {
|
||||||
|
panic!("row_number out of bounds");
|
||||||
|
}
|
||||||
|
MatrixConfig {
|
||||||
|
rows: self.rows | (1 << row_number),
|
||||||
|
columns: self.columns,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Add a column to the keyboard matrix, meaning its pin will not be available for GPIO.
|
||||||
|
///
|
||||||
|
/// `column_number` must be in the range `0..=9`
|
||||||
|
pub const fn with_column(self, column_number: u8) -> Self {
|
||||||
|
if column_number >= 10 {
|
||||||
|
panic!("column_number out of bounds");
|
||||||
|
}
|
||||||
|
MatrixConfig {
|
||||||
|
rows: self.rows,
|
||||||
|
columns: self.columns | (1 << column_number),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue