lotus: Add WIP factory HID protocol
Use like:
```sh
./hidapitester --vidpid 32ac/0012 --usagePage 0xFF60 --usage 0x0061 -v \
--open -l32 --send-output 0,1 --read-input
./hidapitester --vidpid 32ac/0012 --usagePage 0xFF60 --usage 0x0061 -v \
--open -l32 --send-output 0,11,0
./hidapitester --vidpid 32ac/0012 --usagePage 0xFF60 --usage 0x0061 -v \
--open -l32 --send-output 0,11,1,4
./hidapitester --vidpid 32ac/0012 --usagePage 0xFF60 --usage 0x0061 -v \
--open -l32 --send-output 0,11,2,1
./hidapitester --vidpid 32ac/0012 --usagePage 0xFF60 --usage 0x0061 -v \
--open -l32 --send-output 0,11,2,0
```
Signed-off-by: Daniel Schaefer <git@danielschaefer.me>
This commit is contained in:
parent
e981025660
commit
c593ebe3bd
82
keyboards/lotus/factory.c
Normal file
82
keyboards/lotus/factory.c
Normal file
@ -0,0 +1,82 @@
|
||||
// Copyright 2022 Framework Computer
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
#include "quantum.h"
|
||||
#include "raw_hid.h"
|
||||
|
||||
enum factory_commands {
|
||||
f_bootloader = 0x00,
|
||||
f_emu_keypress = 0x01, // Next byte is keycode
|
||||
f_backlight = 0x02, // Next byte is on/off boolean
|
||||
};
|
||||
|
||||
void handle_factory_command(uint8_t *data) {
|
||||
uint8_t factory_command_id = data[0];
|
||||
uint8_t *command_data = &(data[1]);
|
||||
uprintf("handle_factory_command(command: %u)\n", factory_command_id);
|
||||
|
||||
switch (factory_command_id) {
|
||||
case f_bootloader:
|
||||
print("bootloader_jump\n");
|
||||
bootloader_jump();
|
||||
break;
|
||||
case f_emu_keypress:
|
||||
uprintf("Emulating keycode: %u\n", command_data[0]);
|
||||
tap_code(command_data[0]);
|
||||
break;
|
||||
case f_backlight:
|
||||
// Need a separate command because tap_code won't work for
|
||||
// commands larger than 1 byte. The extra byte in tap_code16
|
||||
// is just for modifiers.
|
||||
uprintf("backlight: %u\n", command_data[0]);
|
||||
if (command_data[0] == 0) {
|
||||
backlight_disable();
|
||||
} else {
|
||||
backlight_enable();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
uprintf("Unknown factory command: %u\n", factory_command_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool 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: %X, length: %d)\n", command_id, length);
|
||||
|
||||
switch (command_id) {
|
||||
case 0x01:
|
||||
print("protocol_ver\n");
|
||||
#ifndef VIA_ENABLE
|
||||
command_data[0] = 0x0B >> 8;
|
||||
command_data[1] = 0x0B & 0xFF;
|
||||
raw_hid_send(data, length);
|
||||
#endif
|
||||
break;
|
||||
case 0x0B:
|
||||
// Take over the bootloader jump command ID from via and use it for our purposes
|
||||
handle_factory_command(command_data);
|
||||
// Don't let VIA handle it
|
||||
return true;
|
||||
default:
|
||||
uprintf("Unrecognized command ID: %u\n", command_id);
|
||||
break;
|
||||
}
|
||||
// Continue with default HID handling
|
||||
return false;
|
||||
}
|
||||
|
||||
// Add hooks to handle raw HID commands.
|
||||
// Need add both functions to make it work when
|
||||
// either RAW_ENABLE or VIA_ENABLE are enabled.
|
||||
bool via_command_kb(uint8_t *data, uint8_t length) {
|
||||
return handle_hid(data, length);
|
||||
}
|
||||
#ifndef VIA_ENABLE
|
||||
bool raw_hid_receive(uint8_t *data, uint8_t length) {
|
||||
return handle_hid(data, length);
|
||||
}
|
||||
#endif
|
||||
@ -3,7 +3,6 @@
|
||||
|
||||
#include "quantum.h"
|
||||
#include "lotus.h"
|
||||
#include "raw_hid.h"
|
||||
|
||||
#define BOOT_DONE_GPIO GP5
|
||||
|
||||
@ -44,40 +43,3 @@ bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
|
||||
return true; // Process all other keycodes normally
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@ -14,4 +14,6 @@ BACKLIGHT_DRIVER = pwm
|
||||
CUSTOM_MATRIX = lite
|
||||
SRC += matrix.c
|
||||
|
||||
SRC += factory.c
|
||||
|
||||
DEFAULT_FOLDER = lotus/ansi
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user