Skip to content

Commit

Permalink
vial: support retrieving keyboard ID and protocol version
Browse files Browse the repository at this point in the history
  • Loading branch information
xyzz committed Oct 18, 2020
1 parent 9791507 commit 2a9405a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
14 changes: 14 additions & 0 deletions quantum/vial.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include "vial.h"

#include <string.h>
#include "protocol/usb_descriptor.h"

#include "vial_generated_keyboard_definition.h"

enum {
vial_get_keyboard_id = 0x00,
vial_get_size = 0x01,
vial_get_def = 0x02,
};
Expand All @@ -31,6 +34,17 @@ void vial_handle_cmd(uint8_t *msg, uint8_t length) {

/* msg[0] is 0xFE -- prefix vial magic */
switch (msg[1]) {
/* Get keyboard ID and Vial protocol version */
case vial_get_keyboard_id: {
uint8_t keyboard_uid[] = VIAL_KEYBOARD_UID;

msg[0] = VIAL_PROTOCOL_VERSION & 0xFF;
msg[1] = (VIAL_PROTOCOL_VERSION >> 8) & 0xFF;
msg[2] = (VIAL_PROTOCOL_VERSION >> 16) & 0xFF;
msg[3] = (VIAL_PROTOCOL_VERSION >> 24) & 0xFF;
memcpy(&msg[4], keyboard_uid, 8);
break;
}
/* Retrieve keyboard definition size */
case vial_get_size: {
uint32_t sz = sizeof(keyboard_definition);
Expand Down
4 changes: 4 additions & 0 deletions quantum/vial.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@

#pragma once

#include <inttypes.h>

#define VIAL_PROTOCOL_VERSION 0x00000000

void vial_handle_cmd(uint8_t *data, uint8_t length);
12 changes: 12 additions & 0 deletions util/vial_generate_keyboard_uid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python3
import secrets


def main():
print("#define VIAL_KEYBOARD_UID {{{}}}".format(
", ".join(["0x{:02X}".format(x) for x in secrets.token_bytes(8)])
))


if __name__ == "__main__":
main()

0 comments on commit 2a9405a

Please sign in to comment.