1use strum::FromRepr;
4
5pub const VIA_PROTOCOL_VERSION: u16 = 0x0009;
6pub const VIA_FIRMWARE_VERSION: u32 = 0x0001;
7
8pub const VIAL_PROTOCOL_VERSION: u32 = 6;
9pub const VIAL_EP_SIZE: usize = 32;
10pub const VIAL_COMBO_MAX_LENGTH: usize = 4;
11
12#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, FromRepr)]
14#[repr(u8)]
15pub enum ViaCommand {
16 GetProtocolVersion = 0x01, GetKeyboardValue = 0x02,
18 SetKeyboardValue = 0x03,
19 DynamicKeymapGetKeyCode = 0x04,
20 DynamicKeymapSetKeyCode = 0x05,
21 DynamicKeymapReset = 0x06,
22 CustomSetValue = 0x07,
23 CustomGetValue = 0x08,
24 CustomSave = 0x09,
25 EepromReset = 0x0A,
26 BootloaderJump = 0x0B,
27 DynamicKeymapMacroGetCount = 0x0C,
28 DynamicKeymapMacroGetBufferSize = 0x0D,
29 DynamicKeymapMacroGetBuffer = 0x0E,
30 DynamicKeymapMacroSetBuffer = 0x0F,
31 DynamicKeymapMacroReset = 0x10,
32 DynamicKeymapGetLayerCount = 0x11,
33 DynamicKeymapGetBuffer = 0x12,
34 DynamicKeymapSetBuffer = 0x13,
35 DynamicKeymapGetEncoder = 0x14,
36 DynamicKeymapSetEncoder = 0x15,
37 Vial = 0xFE,
38 Unhandled = 0xFF,
39}
40
41impl From<u8> for ViaCommand {
42 fn from(value: u8) -> Self {
43 Self::from_repr(value).unwrap_or(Self::Unhandled)
44 }
45}
46
47#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, FromRepr)]
49#[repr(u8)]
50pub enum ViaKeyboardInfo {
51 Uptime = 0x01,
52 LayoutOptions = 0x02,
53 SwitchMatrixState = 0x03,
54 FirmwareVersion = 0x04,
55 DeviceIndication = 0x05,
56}
57
58impl TryFrom<u8> for ViaKeyboardInfo {
59 type Error = u8;
60
61 fn try_from(value: u8) -> Result<Self, Self::Error> {
62 Self::from_repr(value).ok_or(value)
64 }
65}
66
67#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, FromRepr)]
69#[cfg_attr(feature = "defmt", derive(defmt::Format))]
70#[repr(u8)]
71pub enum VialCommand {
72 GetKeyboardId = 0x00,
73 GetSize = 0x01,
74 GetKeyboardDef = 0x02,
75 GetEncoder = 0x03,
76 SetEncoder = 0x04,
77 GetUnlockStatus = 0x05,
78 UnlockStart = 0x06,
79 UnlockPoll = 0x07,
80 Lock = 0x08,
81 BehaviorSettingQuery = 0x09,
82 GetBehaviorSetting = 0x0A,
83 SetBehaviorSetting = 0x0B,
84 QmkSettingsReset = 0x0C,
85 DynamicEntryOp = 0x0D,
87 Unhandled = 0xFF,
88}
89
90impl From<u8> for VialCommand {
91 fn from(value: u8) -> Self {
92 Self::from_repr(value).unwrap_or(Self::Unhandled)
93 }
94}
95
96#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, FromRepr)]
97#[cfg_attr(feature = "defmt", derive(defmt::Format))]
98#[repr(u16)]
99pub enum SettingKey {
100 None,
101 ComboTimeout = 0x02,
102 OneShotTimeout = 0x06,
103 MorseTimeout = 0x07,
104 TapInterval = 0x12,
105 TapCapslockInterval = 0x13,
106 PermissiveHold = 0x16,
107 HoldOnOtherKeyPress = 0x17,
108 UnilateralTap = 0x1A,
109 PriorIdleTime = 0x1B,
110}
111
112impl From<u16> for SettingKey {
113 fn from(value: u16) -> Self {
114 Self::from_repr(value).unwrap_or(Self::None)
115 }
116}
117
118#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, FromRepr)]
120#[repr(u8)]
121pub enum VialDynamic {
122 DynamicVialGetNumberOfEntries = 0x00,
123 DynamicVialMorseGet = 0x01,
124 DynamicVialMorseSet = 0x02,
125 DynamicVialComboGet = 0x03,
126 DynamicVialComboSet = 0x04,
127 DynamicVialKeyOverrideGet = 0x05,
128 DynamicVialKeyOverrideSet = 0x06,
129 Unhandled = 0xFF,
130}
131
132impl From<u8> for VialDynamic {
133 fn from(value: u8) -> Self {
134 Self::from_repr(value).unwrap_or(Self::Unhandled)
135 }
136}