vial: support retrieving keyboard ID and protocol version
This commit is contained in:
parent
9791507fae
commit
2a9405a5a8
@ -14,12 +14,15 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "vial.h"
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "protocol/usb_descriptor.h"
|
#include "protocol/usb_descriptor.h"
|
||||||
|
|
||||||
#include "vial_generated_keyboard_definition.h"
|
#include "vial_generated_keyboard_definition.h"
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
vial_get_keyboard_id = 0x00,
|
||||||
vial_get_size = 0x01,
|
vial_get_size = 0x01,
|
||||||
vial_get_def = 0x02,
|
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 */
|
/* msg[0] is 0xFE -- prefix vial magic */
|
||||||
switch (msg[1]) {
|
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 */
|
/* Retrieve keyboard definition size */
|
||||||
case vial_get_size: {
|
case vial_get_size: {
|
||||||
uint32_t sz = sizeof(keyboard_definition);
|
uint32_t sz = sizeof(keyboard_definition);
|
||||||
|
@ -16,4 +16,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
#define VIAL_PROTOCOL_VERSION 0x00000000
|
||||||
|
|
||||||
void vial_handle_cmd(uint8_t *data, uint8_t length);
|
void vial_handle_cmd(uint8_t *data, uint8_t length);
|
||||||
|
12
util/vial_generate_keyboard_uid.py
Executable file
12
util/vial_generate_keyboard_uid.py
Executable 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()
|
Loading…
Reference in New Issue
Block a user