@@ -122,21 +122,18 @@ func rxHandler(b []byte) {
122
122
123
123
func rxHandler2 (b []byte ) bool {
124
124
switch b [0 ] {
125
- //case 0x12, 0x0E :
125
+ //case viaCommandDynamicKeymapGetBuffer, viaCommandDynamicKeymapMacroGetBuffer :
126
126
default :
127
127
//fmt.Printf("RxHandler % X\n", b)
128
128
}
129
129
130
130
copy (txb [:32 ], b )
131
131
switch b [0 ] {
132
- case 0x01 :
133
- // GetProtocolVersionCount
132
+ case viaCommandGetProtocolVersion :
134
133
txb [2 ] = 0x09
135
- case 0x11 :
136
- // DynamicKeymapGetLayerCountCommand
134
+ case viaCommandDynamicKeymapGetLayerCount :
137
135
txb [1 ] = 0x06
138
- case 0x12 :
139
- // DynamicKeymapReadBufferCommand
136
+ case viaCommandDynamicKeymapGetBuffer :
140
137
offset := (uint16 (b [1 ]) << 8 ) + uint16 (b [2 ])
141
138
sz := b [3 ]
142
139
//fmt.Printf(" offset : %04X + %d\n", offset, sz)
@@ -156,27 +153,22 @@ func rxHandler2(b []byte) bool {
156
153
txb [4 + 2 * i + 0 ] = uint8 (kc >> 8 )
157
154
}
158
155
159
- case 0x0D :
160
- // DynamicKeymapMacroGetBufferSizeCommand
156
+ case viaCommandDynamicKeymapMacroGetBufferSize :
161
157
sz := len (device .Macros )
162
158
txb [1 ] = byte (sz >> 8 )
163
159
txb [2 ] = byte (sz )
164
- case 0x0C :
165
- // DynamicKeymapMacroGetCountCommand
160
+ case viaCommandDynamicKeymapMacroGetCount :
166
161
txb [1 ] = 0x10
167
- case 0x0E :
168
- // DynamicKeymapMacroGetBufferCommand
162
+ case viaCommandDynamicKeymapMacroGetBuffer :
169
163
offset := (uint16 (b [1 ]) << 8 ) + uint16 (b [2 ])
170
164
sz := b [3 ]
171
165
copy (txb [4 :4 + sz ], device .Macros [offset :])
172
- case 0x0F :
173
- // CMD_VIA_MACRO_SET_BUFFER
166
+ case viaCommandDynamicKeymapMacroSetBuffer :
174
167
offset := (uint16 (b [1 ]) << 8 ) + uint16 (b [2 ])
175
168
sz := b [3 ]
176
169
copy (device .Macros [offset :], txb [4 :4 + sz ])
177
170
device .flashCh <- true
178
- case 0x02 :
179
- // id_get_keyboard_value
171
+ case viaCommandGetKeyboardValue :
180
172
Changed = false
181
173
Changed2 = false
182
174
switch txb [1 ] {
@@ -189,19 +181,18 @@ func rxHandler2(b []byte) bool {
189
181
txb [idx ] |= byte (1 << (col % 8 ))
190
182
}
191
183
}
192
- case 0x05 :
184
+ case viaCommandDynamicKeymapSetKeycode :
193
185
//fmt.Printf("XXXXXXXXX % X\n", b)
194
186
//Keys[b[1]][b[2]][b[3]] = Keycode((uint16(b[4]) << 8) + uint16(b[5]))
195
187
device .SetKeycodeVia (int (b [1 ]), int (b [2 ]), int (b [3 ]), Keycode ((uint16 (b [4 ])<< 8 )+ uint16 (b [5 ])))
196
188
device .flashCh <- true
197
189
//Changed = true
198
- case 0x08 :
199
- // id_lighting_get_value
190
+ case viaCommandLightingGetValue :
200
191
txb [1 ] = 0x00
201
192
txb [2 ] = 0x00
202
- case 0xFE : // vial
193
+ case viaCommandVialPrefix : // vial
203
194
switch b [1 ] {
204
- case 0x00 :
195
+ case vialGetKeyboardId :
205
196
// Get keyboard ID and Vial protocol version
206
197
const vialProtocolVersion = 0x00000006
207
198
txb [0 ] = vialProtocolVersion
@@ -216,14 +207,14 @@ func rxHandler2(b []byte) bool {
216
207
txb [9 ] = 0xF3
217
208
txb [10 ] = 0x54
218
209
txb [11 ] = 0xE2
219
- case 0x01 :
210
+ case vialGetSize :
220
211
// Retrieve keyboard definition size
221
212
size := len (KeyboardDef )
222
213
txb [0 ] = uint8 (size )
223
214
txb [1 ] = uint8 (size >> 8 )
224
215
txb [2 ] = uint8 (size >> 16 )
225
216
txb [3 ] = uint8 (size >> 24 )
226
- case 0x02 :
217
+ case vialGetDef :
227
218
// Retrieve 32-bytes block of the definition, page ID encoded within 2 bytes
228
219
page := uint16 (b [2 ]) + (uint16 (b [3 ]) << 8 )
229
220
start := page * 32
@@ -236,22 +227,18 @@ func rxHandler2(b []byte) bool {
236
227
}
237
228
//fmt.Printf("vial_get_def : page=%04X start=%04X end=%04X\n", page, start, end)
238
229
copy (txb [:32 ], KeyboardDef [start :end ])
239
- case 0x09 :
240
- // vial_qmk_settings_query
241
- // 未対応
230
+ case vialQmkSettingsQuery :
231
+ // not impl
242
232
for i := range txb [:32 ] {
243
233
txb [i ] = 0xFF
244
234
}
245
- case 0x0D :
246
- // vial_dynamic_entry_op
235
+ case vialDynamicEntryOp :
247
236
switch b [2 ] {
248
- case 0x00 :
249
- // DYNAMIC_VIAL_GET_NUMBER_OF_ENTRIES
237
+ case dynamicVialGetNumberOfEntries :
250
238
txb [0 ] = 0x00
251
239
txb [1 ] = 0x20 // combos
252
240
txb [2 ] = 0x00
253
- case 0x03 :
254
- // DYNAMIC_VIAL_COMBO_GET
241
+ case dynamicVialComboGet :
255
242
txb [0 ] = 0x00
256
243
idx := b [3 ]
257
244
txb [1 ] = byte (device .Combos [idx ][0 ])
@@ -266,8 +253,7 @@ func rxHandler2(b []byte) bool {
266
253
txb [10 ] = byte (device .Combos [idx ][4 ] >> 8 )
267
254
// 00 0400 0500 0000 0000 0700 000000000000000000000000000000000000000000
268
255
// 0 1 3 5 7 9
269
- case 0x04 :
270
- // DYNAMIC_VIAL_COMBO_SET
256
+ case dynamicVialComboSet :
271
257
txb [0 ] = 0x00
272
258
idx := b [3 ]
273
259
// fe0d04 00 0400 0500 0000 0000 0700 000000000000000000000000000000000000
@@ -283,8 +269,7 @@ func rxHandler2(b []byte) bool {
283
269
txb [1 ] = 0x00
284
270
txb [2 ] = 0x00
285
271
}
286
- case 0x05 :
287
- // vial_get_unlock_status
272
+ case vialGetUnlockStatus :
288
273
txb [0 ] = 1 // unlocked
289
274
txb [1 ] = 0 // unlock_in_progress
290
275
@@ -368,3 +353,57 @@ func setupHandler(setup usb.Setup) bool {
368
353
}
369
354
return ok
370
355
}
356
+
357
+ // https://github.com/vial-kb/vial-qmk/quantum/via.h
358
+ const (
359
+ viaCommandGetProtocolVersion = 0x01 // always 0x01
360
+ viaCommandGetKeyboardValue = 0x02
361
+ viaCommandSetKeyboardValue = 0x03
362
+ viaCommandDynamicKeymapGetKeycode = 0x04
363
+ viaCommandDynamicKeymapSetKeycode = 0x05
364
+ viaCommandDynamicKeymapReset = 0x06
365
+ viaCommandCustomSetValue = 0x07
366
+ viaCommandCustomGetValue = 0x08
367
+ viaCommandCustomSave = 0x09
368
+ viaCommandLightingSetValue = 0x07
369
+ viaCommandLightingGetValue = 0x08
370
+ viaCommandLightingSave = 0x09
371
+ viaCommandEepromReset = 0x0A
372
+ viaCommandBootloaderJump = 0x0B
373
+ viaCommandDynamicKeymapMacroGetCount = 0x0C
374
+ viaCommandDynamicKeymapMacroGetBufferSize = 0x0D
375
+ viaCommandDynamicKeymapMacroGetBuffer = 0x0E
376
+ viaCommandDynamicKeymapMacroSetBuffer = 0x0F
377
+ viaCommandDynamicKeymapMacroReset = 0x10
378
+ viaCommandDynamicKeymapGetLayerCount = 0x11
379
+ viaCommandDynamicKeymapGetBuffer = 0x12
380
+ viaCommandDynamicKeymapSetBuffer = 0x13
381
+ viaCommandVialPrefix = 0xFE
382
+ viaCommandUnhandled = 0xFF
383
+ )
384
+
385
+ // https://github.com/vial-kb/vial-qmk/quantum/vial.h
386
+ const (
387
+ vialGetKeyboardId = 0x00
388
+ vialGetSize = 0x01
389
+ vialGetDef = 0x02
390
+ vialGetEncoder = 0x03
391
+ vialSetEncoder = 0x04
392
+ vialGetUnlockStatus = 0x05
393
+ vialUnlockStart = 0x06
394
+ vialUnlockPoll = 0x07
395
+ vialLock = 0x08
396
+ vialQmkSettingsQuery = 0x09
397
+ vialQmkSettingsGet = 0x0A
398
+ vialQmkSettingsSet = 0x0B
399
+ vialQmkSettingsReset = 0x0C
400
+ vialDynamicEntryOp = 0x0D /* operate on tapdance, combos, etc */
401
+
402
+ dynamicVialGetNumberOfEntries = 0x00
403
+ dynamicVialTapDanceGet = 0x01
404
+ dynamicVialTapDanceSet = 0x02
405
+ dynamicVialComboGet = 0x03
406
+ dynamicVialComboSet = 0x04
407
+ dynamicVialKeyOverrideGet = 0x05
408
+ dynamicVialKeyOverrideSet = 0x06
409
+ )
0 commit comments