Added new and init functions for TCA8418
This commit is contained in:
parent
0e697b48f1
commit
2d11808a91
1 changed files with 25 additions and 0 deletions
25
src/lib.rs
25
src/lib.rs
|
|
@ -82,3 +82,28 @@ impl InterruptConfig {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl<I2C: embedded_hal::i2c::I2c> TCA8418<I2C> {
|
||||||
|
pub fn new(
|
||||||
|
i2c: I2C,
|
||||||
|
matrix_config: MatrixConfig,
|
||||||
|
interrupt_config: InterruptConfig,
|
||||||
|
) -> Self {
|
||||||
|
let mut self_ = Self { i2c };
|
||||||
|
self_.init(matrix_config, interrupt_config);
|
||||||
|
self_
|
||||||
|
}
|
||||||
|
|
||||||
|
fn init(&mut self, matrix_config: MatrixConfig, interrupt_config: InterruptConfig) {
|
||||||
|
self.i2c.write(I2C_ADDR, &[0x1D, matrix_config.rows]);
|
||||||
|
self.i2c
|
||||||
|
.write(I2C_ADDR, &[0x1E, matrix_config.columns as u8]);
|
||||||
|
self.i2c
|
||||||
|
.write(I2C_ADDR, &[0x1F, (matrix_config.columns >> 8) as u8]);
|
||||||
|
self.i2c.write(I2C_ADDR, &[0x01, interrupt_config.0]);
|
||||||
|
self.i2c.write(I2C_ADDR, &[0x0F, 0]);
|
||||||
|
self.i2c.write(I2C_ADDR, &[0x10, 0]);
|
||||||
|
self.i2c.write(I2C_ADDR, &[0x0E, 0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue