Skip to content

Commit

Permalink
DeskHop v0.64 (Bugfixes)
Browse files Browse the repository at this point in the history
  - Caps lock / Num lock didn't correctly remember output B state
  - Windows relative mouse was jumping from secondary to primary
  - Fixed NKRO keyboards without report ID

  - IMPORTANT: moved config shortcut to LEFT CTRL + RIGHT SHIFT + C + O
               because users had issues with keyboards unable to send both
               shifts. Sorry for changing this.
  • Loading branch information
Hrvoje Cavrak committed Aug 24, 2024
1 parent a249aa5 commit 97a2cea
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 25 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.6)

set(VERSION_MAJOR 00)
set(VERSION_MINOR 156)
set(VERSION_MINOR 157)

set(PICO_SDK_FETCH_FROM_GIT off)
set(PICO_BOARD=pico)
Expand Down
8 changes: 6 additions & 2 deletions src/handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,12 @@ void handle_mouse_zoom_msg(uart_packet_t *packet, device_t *state) {

/* Process request to update keyboard LEDs */
void handle_set_report_msg(uart_packet_t *packet, device_t *state) {
state->keyboard_leds[BOARD_ROLE] = packet->data[0];
restore_leds(state);
/* We got this via serial, so it's stored to the opposite of our board role */
state->keyboard_leds[OTHER_ROLE] = packet->data[0];

/* If we have a keyboard we can control leds on, restore state if active */
if (global_state.keyboard_connected && !CURRENT_BOARD_IS_ACTIVE_OUTPUT)
restore_leds(state);
}

/* Process request to block mouse from switching, update internal state */
Expand Down
5 changes: 1 addition & 4 deletions src/hid_report.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ int32_t _extract_kbd_nkro(uint8_t *raw_report, int len, hid_interface_t *iface,

int32_t extract_kbd_data(
uint8_t *raw_report, int len, uint8_t itf, hid_interface_t *iface, hid_keyboard_report_t *report) {
int report_id = raw_report[0];

/* Clear the report to start fresh */
memset(report, 0, KBD_REPORT_LENGTH);
Expand All @@ -285,9 +284,7 @@ int32_t extract_kbd_data(
return _extract_kbd_boot(raw_report, len, report);

/* NKRO is a special case */
if (report_id > 0
&& report_id == iface->keyboard.nkro.report_id
&& iface->keyboard.is_nkro)
if (iface->keyboard.is_nkro)
return _extract_kbd_nkro(raw_report, len, iface, report);

/* If we're getting 8 bytes of report, it's safe to assume standard modifier + reserved + keys */
Expand Down
5 changes: 4 additions & 1 deletion src/include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@

#define ABSOLUTE 0
#define RELATIVE 1
#define TOUCH 2

#define MOUSE_BOOT_REPORT_LEN 4
#define MOUSE_ZOOM_SCALING_FACTOR 2
Expand Down Expand Up @@ -76,6 +77,7 @@
#define SERIAL_RX_PIN (global_state.board_role == OUTPUT_A ? BOARD_A_RX : BOARD_B_RX)

#define BOARD_ROLE (global_state.board_role)
#define OTHER_ROLE (BOARD_ROLE == OUTPUT_A ? OUTPUT_B : OUTPUT_A)

/********* Serial port definitions **********/
#define SERIAL_UART uart0
Expand Down Expand Up @@ -351,7 +353,7 @@ typedef struct TU_ATTR_PACKED {
multiple desktops (Windows/MacOS) */
typedef struct {
uint8_t tip_pressure;
uint8_t buttons; // Buttons
uint8_t buttons; // Digitizer buttons
uint16_t x; // X coordinate (0-32767)
uint16_t y; // Y coordinate (0-32767)
} touch_report_t;
Expand Down Expand Up @@ -423,6 +425,7 @@ typedef struct {
bool onboard_led_state; // True when LED is ON
bool relative_mouse; // True when relative mouse mode is used
bool config_mode_active; // True when config mode is active
bool digitizer_active; // True when digitizer Win/Mac workaround is active

/* Onboard LED blinky (provide feedback when e.g. mouse connected) */
int32_t blinks_left; // How many blink transitions are left
Expand Down
53 changes: 51 additions & 2 deletions src/include/usb_descriptors.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
#define REPORT_ID_SYSTEM 4

// Interface 1
#define REPORT_ID_RELMOUSE 5
#define REPORT_ID_RELMOUSE 5
#define REPORT_ID_DIGITIZER 7

// Interface 2
#define REPORT_ID_VENDOR 6
Expand Down Expand Up @@ -173,7 +174,7 @@ HID_COLLECTION_END \
HID_REPORT_SIZE ( 3 ) ,\
HID_INPUT ( HID_CONSTANT ) ,\
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
/* X, Y position [-127, 127] */ \
/* X, Y position [-32767, 32767] */ \
HID_USAGE ( HID_USAGE_DESKTOP_X ) ,\
HID_USAGE ( HID_USAGE_DESKTOP_Y ) ,\
HID_LOGICAL_MIN_N ( 0x8000, 2 ) ,\
Expand All @@ -195,4 +196,52 @@ HID_COLLECTION_END \
HID_COLLECTION_END , \
HID_COLLECTION_END \

#define HID_USAGE_DIGITIZER 0x01

#define TUD_HID_REPORT_DESC_DIGITIZER_PEN(...) \
HID_USAGE_PAGE ( HID_USAGE_PAGE_DIGITIZER ) ,\
HID_USAGE ( HID_USAGE_DIGITIZER ) ,\
HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
/* Report ID if any */\
__VA_ARGS__ \
HID_USAGE ( HID_USAGE_DIGITIZER ) ,\
HID_COLLECTION ( HID_COLLECTION_PHYSICAL ) ,\
HID_USAGE_PAGE ( HID_USAGE_PAGE_DIGITIZER ) ,\
/* Tip Pressure */\
HID_USAGE ( 0x30 ) ,\
HID_LOGICAL_MIN ( 0x00 ) ,\
HID_LOGICAL_MAX ( 0xff ) ,\
HID_REPORT_COUNT( 1 ) ,\
HID_REPORT_SIZE ( 8 ) ,\
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
\
HID_REPORT_COUNT( 5 ) ,\
HID_REPORT_SIZE ( 1 ) ,\
/* In range */\
HID_USAGE ( 0x32 ) ,\
/* Tip switch */\
HID_USAGE ( 0x42 ) ,\
/* Eraser */\
HID_USAGE ( 0x45 ) ,\
/* Barrel switch */\
HID_USAGE ( 0x44 ) ,\
/* Invert */\
HID_USAGE ( 0x3c ) ,\
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
\
HID_REPORT_COUNT( 3 ) ,\
HID_REPORT_SIZE ( 1 ) ,\
HID_INPUT ( HID_CONSTANT ) ,\
/* X and Y coordinates */\
HID_USAGE_PAGE ( HID_USAGE_PAGE_DESKTOP ) ,\
HID_USAGE ( HID_USAGE_DESKTOP_X ) ,\
HID_USAGE ( HID_USAGE_DESKTOP_Y ) ,\
HID_LOGICAL_MIN ( 0 ) ,\
HID_LOGICAL_MAX_N ( 32767, 2 ) ,\
HID_REPORT_SIZE ( 16 ) ,\
HID_REPORT_COUNT ( 2 ) ,\
HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE) ,\
HID_COLLECTION_END ,\
HID_COLLECTION_END

#endif /* USB_DESCRIPTORS_H_ */
4 changes: 2 additions & 2 deletions src/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ hotkey_combo_t hotkeys[] = {
.action_handler = &screenlock_hotkey_handler},

/* Toggle gaming mode */
{.modifier = KEYBOARD_MODIFIER_LEFTSHIFT | KEYBOARD_MODIFIER_RIGHTSHIFT,
{.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_RIGHTSHIFT,
.keys = {HID_KEY_G},
.key_count = 1,
.acknowledge = true,
Expand All @@ -73,7 +73,7 @@ hotkey_combo_t hotkeys[] = {
.action_handler = &screen_border_hotkey_handler},

/* Switch to configuration mode */
{.modifier = KEYBOARD_MODIFIER_RIGHTSHIFT | KEYBOARD_MODIFIER_LEFTSHIFT,
{.modifier = KEYBOARD_MODIFIER_LEFTCTRL | KEYBOARD_MODIFIER_RIGHTSHIFT,
.keys = {HID_KEY_C, HID_KEY_O},
.key_count = 2,
.acknowledge = true,
Expand Down
6 changes: 1 addition & 5 deletions src/mouse.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ void update_mouse_position(device_t *state, mouse_values_t *values) {
output_t *current = &state->config.output[state->active_output];
uint8_t reduce_speed = 0;

/* If relative mouse mode is active, just pass mouse movements and update nothing */
if (state->relative_mouse)
return;

/* Check if we are configured to move slowly */
if (state->mouse_zoom)
reduce_speed = MOUSE_ZOOM_SCALING_FACTOR;
Expand Down Expand Up @@ -299,7 +295,7 @@ void process_mouse_queue_task(device_t *state) {
if (!tud_hid_n_ready(ITF_NUM_HID))
return;

/* ... try sending it to the host, if it's successful */
/* Try sending it to the host, if it's successful */
bool succeeded = tud_mouse_report(report.mode, report.buttons, report.x, report.y, report.wheel);

/* ... then we can remove it from the queue */
Expand Down
19 changes: 11 additions & 8 deletions src/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ void tud_hid_set_report_cb(uint8_t instance,
leds |= KEYBOARD_LED_CAPSLOCK;
}

global_state.keyboard_leds[global_state.active_output] = leds;
global_state.keyboard_leds[BOARD_ROLE] = leds;

/* If the board doesn't have the keyboard hooked up directly, we need to relay this information
to the other one that has (and LEDs you can turn on). */
if (global_state.keyboard_connected)
/* If the board has a keyboard connected directly, restore those leds. */
if (global_state.keyboard_connected && CURRENT_BOARD_IS_ACTIVE_OUTPUT)
restore_leds(&global_state);
else
send_value(leds, KBD_SET_REPORT_MSG);

/* Always send to the other one, so it is aware of the change */
send_value(leds, KBD_SET_REPORT_MSG);
}

/* Invoked when device is mounted */
Expand Down Expand Up @@ -194,8 +194,11 @@ void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t cons
if (instance >= MAX_INTERFACES)
return;

if (iface->uses_report_id) {
uint8_t report_id = report[0];
if (itf_protocol == HID_ITF_PROTOCOL_NONE) {
uint8_t report_id = 0;

if (iface->uses_report_id)
report_id = report[0];

if (report_id < MAX_REPORTS) {
process_report_f receiver = iface->report_handler[report_id];
Expand Down

0 comments on commit 97a2cea

Please sign in to comment.