Crates.io | kiibohd-hall-effect-keyscanning |
lib.rs | kiibohd-hall-effect-keyscanning |
version | 0.2.0 |
source | src |
created_at | 2022-04-30 03:48:39.499284 |
updated_at | 2023-05-19 05:39:14.640073 |
description | Hall Effect keyscanning for strobed matrices |
homepage | |
repository | https://github.com/kiibohd/kiibohd-core |
max_upload_size | |
id | 577979 |
size | 17,872 |
Keyscanning embedded-hal driver for kiibohd-hall-effect. Can be used with single-shot, interrupt or DMA-connected ADC drivers.
const ADC_SAMPLES: usize = 1;
const RSIZE: usize = 6; // Matrix rows
const CSIZE: usize = 12; // Matrix columns
const MSIZE: usize = RSIZE * CSIZE; // Total matrix size
type Matrix = kiibohd_hall_effect_keyscanning::Matrix<PioX<Output<PushPull>>, CSIZE, MSIZE>;
let mut matrix = Matrix::new(cols).unwrap();
matrix.next_strobe().unwrap(); // Strobe first column
// Retrieve adc sample and key index
let sample = read_adc();
let index = determine_key_index();
// Store the sample value at the specified index
// ADC_SAMPLES specifies how many samples are needed (averaged) until a processed sense value is returned
match matrix.record::<ADC_SAMPLES>(index, sample) {
Ok(val) => {
// If data bucket has accumulated enough samples, pass to the next stage
if let Some(sense) = val {
// Processed ADC data
}
}
Err(e) => {
// Usually this is an index error
defmt::error!("Sample record failed ({}, {}, {}):{} -> {}", i, strobe, index, sample, e);
}
cargo build
Licensed under either of
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.