Started KeySet type

This commit is contained in:
Zac Wilson 2025-12-22 17:19:51 +00:00
parent 2d11808a91
commit 95d5a18e99

View file

@ -82,6 +82,56 @@ impl InterruptConfig {
}
}
#[derive(Clone, Copy)]
pub struct KeySet(u128);
impl KeySet {
fn contains(&self, key_number: u8) -> bool {
(self.0 & (1 << key_number)) != 0
}
}
impl core::ops::Not for KeySet {
type Output = KeySet;
fn not(self) -> Self::Output {
KeySet(!self.0)
}
}
pub struct KeySetIter {
key_set: KeySet,
shift: u8,
}
impl core::iter::Iterator for KeySetIter {
type Item = u8;
fn next(&mut self) -> Option<Self::Item> {
let next_shift = self.key_set.0.trailing_zeros() as u8 + 1;
if next_shift >= 128 {
return None;
}
self.key_set.0 >>= next_shift;
self.shift += next_shift;
Some(self.shift - 1)
}
}
impl core::iter::IntoIterator for KeySet {
type Item = u8;
type IntoIter = KeySetIter;
fn into_iter(self) -> Self::IntoIter {
KeySetIter {
key_set: self,
shift: 0
}
}
}
impl<I2C: embedded_hal::i2c::I2c> TCA8418<I2C> {
pub fn new(