pub struct Matrix<C: OutputPin, const CSIZE: usize, const MSIZE: usize, const INVERT_STROBE: bool> { /* private fields */ }
Expand description

Handles strobing the Hall Effect sensor matrix ADC reading is handled separately as the current embedded-hal doesn’t work well across oneshot, interrupt based and DMA ADC read methods. (usually requires quite a bit of MCU specific setup as well)

const CSIZE: usize = 18; // Number of columns
const RSIZE: usize = 6; // Number of rows
const MSIZE: usize = RSIZE * CSIZE; // Total matrix size
const INVERT_STROBE: bool = true; // P-Channel MOSFETs have an inverted strobe
type Matrix = kiibohd_hall_effect_keyscanning::Matrix<PioX<Output<PushPull>>, CSIZE, MSIZE, INVERT_STROBE>; // atsam4-hal
let cols = [
    pins.strobe1.downgrade(),
    pins.strobe2.downgrade(),
    pins.strobe3.downgrade(),
    pins.strobe4.downgrade(),
    pins.strobe5.downgrade(),
    pins.strobe6.downgrade(),
    pins.strobe7.downgrade(),
    pins.strobe8.downgrade(),
    pins.strobe9.downgrade(),
    pins.strobe10.downgrade(),
    pins.strobe11.downgrade(),
    pins.strobe12.downgrade(),
    pins.strobe13.downgrade(),
    pins.strobe14.downgrade(),
    pins.strobe15.downgrade(),
    pins.strobe16.downgrade(),
    pins.strobe17.downgrade(),
    pins.strobe18.downgrade(),
];
let mut matrix = Matrix::new(cols).unwrap();

Implementations§

source§

impl<C: OutputPin, const CSIZE: usize, const MSIZE: usize, const INVERT_STROBE: bool> Matrix<C, CSIZE, MSIZE, INVERT_STROBE>

source

pub fn new( cols: [C; CSIZE], mode: SensorMode, activation: i16, deactivation: i16 ) -> Result<Self, SensorError>

source

pub fn clear<'a, E: 'a>(&'a mut self) -> Result<(), E>where C: OutputPin<Error = E>,

Clears strobes Resets strobe counter to the last element (so next_strobe starts at 0)

source

pub fn next_strobe<'a, E: 'a>(&'a mut self) -> Result<usize, E>where C: OutputPin<Error = E>,

Next strobe

source

pub fn strobe(&self) -> usize

Current strobe

source

pub fn record<const IDLE_LIMIT: usize>( &mut self, index: usize, value: u16 ) -> Result<Option<&SenseData>, SensorError>

Record ADC Hall Effect reading for the given the current row/sense index The sense index is usually 0-5, though it depends on the typical setup IDLE_LIMIT - Number of samples before considering the sensor idle (within the configured range)

source

pub fn state(&self, index: usize) -> Option<Result<&SenseData, SensorError>>

Return current SenseData for a given index

Auto Trait Implementations§

§

impl<C, const CSIZE: usize, const MSIZE: usize, const INVERT_STROBE: bool> RefUnwindSafe for Matrix<C, CSIZE, MSIZE, INVERT_STROBE>where C: RefUnwindSafe,

§

impl<C, const CSIZE: usize, const MSIZE: usize, const INVERT_STROBE: bool> Send for Matrix<C, CSIZE, MSIZE, INVERT_STROBE>where C: Send,

§

impl<C, const CSIZE: usize, const MSIZE: usize, const INVERT_STROBE: bool> Sync for Matrix<C, CSIZE, MSIZE, INVERT_STROBE>where C: Sync,

§

impl<C, const CSIZE: usize, const MSIZE: usize, const INVERT_STROBE: bool> Unpin for Matrix<C, CSIZE, MSIZE, INVERT_STROBE>where C: Unpin,

§

impl<C, const CSIZE: usize, const MSIZE: usize, const INVERT_STROBE: bool> UnwindSafe for Matrix<C, CSIZE, MSIZE, INVERT_STROBE>where C: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.