use crate::macros::{pub_const_fn_new_zeroed, u16_bool_field};
use core::ops;
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct KeyInput(u16);
impl KeyInput {
pub const fn new() -> Self {
Self(0xFFFF)
}
u16_bool_field!(inverted 0, a, with_a);
u16_bool_field!(inverted 1, b, with_b);
u16_bool_field!(inverted 2, select, with_select);
u16_bool_field!(inverted 3, start, with_start);
u16_bool_field!(inverted 4, right, with_right);
u16_bool_field!(inverted 5, left, with_left);
u16_bool_field!(inverted 6, up, with_up);
u16_bool_field!(inverted 7, down, with_down);
u16_bool_field!(inverted 8, r, with_r);
u16_bool_field!(inverted 9, l, with_l);
#[inline]
#[must_use]
pub const fn to_u16(self) -> u16 {
self.0
}
}
impl From<KeyInput> for u16 {
#[inline]
#[must_use]
fn from(value: KeyInput) -> Self {
value.to_u16()
}
}
impl From<u16> for KeyInput {
#[inline]
#[must_use]
fn from(value: u16) -> Self {
Self(value)
}
}
impl ops::BitAnd for KeyInput {
type Output = Self;
fn bitand(self, other: Self) -> Self {
Self(!(!self.to_u16() & !other.to_u16()))
}
}
impl ops::BitAndAssign for KeyInput {
fn bitand_assign(&mut self, other: Self) {
*self = *self & other;
}
}
impl ops::BitOr for KeyInput {
type Output = Self;
fn bitor(self, other: Self) -> Self {
Self(!(!self.to_u16() | !other.to_u16()))
}
}
impl ops::BitOrAssign for KeyInput {
fn bitor_assign(&mut self, other: Self) {
*self = *self | other;
}
}
impl ops::BitXor for KeyInput {
type Output = Self;
fn bitxor(self, other: Self) -> Self {
Self(!(!self.to_u16() ^ !other.to_u16()))
}
}
impl ops::BitXorAssign for KeyInput {
fn bitxor_assign(&mut self, other: Self) {
*self = *self ^ other;
}
}
impl ops::Not for KeyInput {
type Output = Self;
fn not(self) -> Self {
Self(!self.to_u16())
}
}
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(transparent)]
pub struct KeyControl(u16);
impl KeyControl {
pub_const_fn_new_zeroed!();
u16_bool_field!(0, a, with_a);
u16_bool_field!(1, b, with_b);
u16_bool_field!(2, select, with_select);
u16_bool_field!(3, start, with_start);
u16_bool_field!(4, right, with_right);
u16_bool_field!(5, left, with_left);
u16_bool_field!(6, up, with_up);
u16_bool_field!(7, down, with_down);
u16_bool_field!(8, r, with_r);
u16_bool_field!(9, l, with_l);
u16_bool_field!(14, irq_enabled, with_irq_enabled);
u16_bool_field!(15, irq_all, with_irq_all);
}