vial: support retrieving keyboard ID and protocol version

This commit is contained in:
Ilya Zhuravlev 2020-10-18 14:36:45 -04:00
parent 9791507fae
commit 2a9405a5a8
3 changed files with 30 additions and 0 deletions

View File

@ -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,
};
@ -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);

View File

@ -16,4 +16,8 @@
#pragma once
#include <inttypes.h>
#define VIAL_PROTOCOL_VERSION 0x00000000
void vial_handle_cmd(uint8_t *data, uint8_t length);

View File

@ -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()