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;
10
11#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, FromRepr)]
13#[repr(u8)]
14pub enum ViaCommand {
15 GetProtocolVersion = 0x01, GetKeyboardValue = 0x02,
17 SetKeyboardValue = 0x03,
18 DynamicKeymapGetKeyCode = 0x04,
19 DynamicKeymapSetKeyCode = 0x05,
20 DynamicKeymapReset = 0x06,
21 CustomSetValue = 0x07,
22 CustomGetValue = 0x08,
23 CustomSave = 0x09,
24 EepromReset = 0x0A,
25 BootloaderJump = 0x0B,
26 DynamicKeymapMacroGetCount = 0x0C,
27 DynamicKeymapMacroGetBufferSize = 0x0D,
28 DynamicKeymapMacroGetBuffer = 0x0E,
29 DynamicKeymapMacroSetBuffer = 0x0F,
30 DynamicKeymapMacroReset = 0x10,
31 DynamicKeymapGetLayerCount = 0x11,
32 DynamicKeymapGetBuffer = 0x12,
33 DynamicKeymapSetBuffer = 0x13,
34 DynamicKeymapGetEncoder = 0x14,
35 DynamicKeymapSetEncoder = 0x15,
36 Vial = 0xFE,
37 Unhandled = 0xFF,
38}
39
40impl From<u8> for ViaCommand {
41 fn from(value: u8) -> Self {
42 Self::from_repr(value).unwrap_or(Self::Unhandled)
43 }
44}
45
46#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, FromRepr)]
48#[repr(u8)]
49pub enum ViaKeyboardInfo {
50 Uptime = 0x01,
51 LayoutOptions = 0x02,
52 SwitchMatrixState = 0x03,
53 FirmwareVersion = 0x04,
54 DeviceIndication = 0x05,
55}
56
57impl TryFrom<u8> for ViaKeyboardInfo {
58 type Error = u8;
59
60 fn try_from(value: u8) -> Result<Self, Self::Error> {
61 Self::from_repr(value).ok_or(value)
63 }
64}
65
66#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, FromRepr)]
68#[cfg_attr(feature = "defmt", derive(defmt::Format))]
69#[repr(u8)]
70pub enum VialCommand {
71 GetKeyboardId = 0x00,
72 GetSize = 0x01,
73 GetKeyboardDef = 0x02,
74 GetEncoder = 0x03,
75 SetEncoder = 0x04,
76 GetUnlockStatus = 0x05,
77 UnlockStart = 0x06,
78 UnlockPoll = 0x07,
79 Lock = 0x08,
80 BehaviorSettingQuery = 0x09,
81 GetBehaviorSetting = 0x0A,
82 SetBehaviorSetting = 0x0B,
83 QmkSettingsReset = 0x0C,
84 DynamicEntryOp = 0x0D,
86 Unhandled = 0xFF,
87}
88
89impl From<u8> for VialCommand {
90 fn from(value: u8) -> Self {
91 Self::from_repr(value).unwrap_or(Self::Unhandled)
92 }
93}
94
95#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, FromRepr)]
96#[cfg_attr(feature = "defmt", derive(defmt::Format))]
97#[repr(u16)]
98pub enum SettingKey {
99 None,
100 ComboTimeout = 0x02,
101 OneShotTimeout = 0x06,
102 MorseTimeout = 0x07,
103 TapInterval = 0x12,
104 TapCapslockInterval = 0x13,
105 PermissiveHold = 0x16,
106 HoldOnOtherKeyPress = 0x17,
107 QuickTapTerm = 0x19,
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}