From 6dcfb422aa876f2ea445a918d57911e97dc3a798 Mon Sep 17 00:00:00 2001 From: Daniel Schaefer Date: Thu, 29 Dec 2022 21:05:35 +0800 Subject: [PATCH] lotus: Jump to bootloader via raw HID Signed-off-by: Daniel Schaefer --- keyboards/lotus/lotus.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/keyboards/lotus/lotus.c b/keyboards/lotus/lotus.c index f0d6de513e..662427f55f 100644 --- a/keyboards/lotus/lotus.c +++ b/keyboards/lotus/lotus.c @@ -2,6 +2,7 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "lotus.h" +#include "raw_hid.h" #define BOOT_DONE_GPIO GP5 @@ -41,4 +42,41 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) { default: return true; // Process all other keycodes normally } -} \ No newline at end of file +} + +void handle_hid(uint8_t *data, uint8_t length) { + uint8_t command_id = data[0]; + uint8_t *command_data = &(data[1]); + + uprintf("raw_hid_receive(command: %u, length: %d)\n", command_id, length); + + switch (command_id) { + case 0x01: + print("protocol_ver\n"); + command_data[0] = 0x0B >> 8; + command_data[1] = 0x0B & 0xFF; +#ifndef VIA_ENABLE + raw_hid_send(data, length); +#endif + break; + case 0x0B: + print("bootloader_jump\n"); + bootloader_jump(); + break; + default: + print("Unrecognized command ID\n"); + break; + } +} + +// Add hooks to handle raw HID commands. +// Need add both functions to make it work when +// either RAW_ENABLE or VIA_ENABLE are enabled. +void via_command_kb(uint8_t *data, uint8_t length) { + handle_hid(data, length); +} +#ifndef VIA_ENABLE +void raw_hid_receive(uint8_t *data, uint8_t length) { + handle_hid(data, length); +} +#endif