Skip to content

Commit

Permalink
cleanup and force max multiplier to simplify (multiplier can be adjus…
Browse files Browse the repository at this point in the history
…ted at runtime)
  • Loading branch information
Alabastard-64 committed Jan 22, 2023
1 parent 22170a6 commit d04dbd9
Show file tree
Hide file tree
Showing 8 changed files with 227 additions and 243 deletions.
10 changes: 4 additions & 6 deletions quantum/pointing_device/pointing_device_modes.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,19 +366,17 @@ static report_mouse_t process_pointing_mode(pointing_mode_t pointing_mode, repor
{
uint8_t cur_divisor = pointing_mode.divisor;
if (IS_HIRES_H_ACTIVE) {
int16_t drag_multiplier = MOUSE_SCROLL_MULTIPLIER_H / cur_divisor;
if(!(drag_multiplier >> 1)) drag_multiplier |= 0x0001;
pointing_mode.x *= drag_multiplier;
uint8_t drag_multiplier = MAX(MOUSE_SCROLL_MULTIPLIER_H / cur_divisor, 1);
pointing_mode.x *= (int16_t)drag_multiplier;
pointing_mode.divisor = 1;
}
# endif
mouse_report.h = pointing_device_hv_clamp(pointing_mode.x / (int16_t)pointing_mode.divisor);
pointing_mode.x -= (int16_t)mouse_report.h * (int16_t)pointing_mode.divisor;
# ifdef MOUSE_SCROLL_HIRES_ENABLE
if (IS_HIRES_V_ACTIVE) {
int16_t drag_multiplier = MOUSE_SCROLL_MULTIPLIER_V / cur_divisor;
if(!(drag_multiplier >> 1)) drag_multiplier |= 0x0001;
pointing_mode.y *= drag_multiplier;
uint8_t drag_multiplier = MAX(MOUSE_SCROLL_MULTIPLIER_V / cur_divisor, 1);
pointing_mode.y *= (int16_t)drag_multiplier;
pointing_mode.divisor = 1;
} else {
pointing_mode.divisor = cur_divisor;
Expand Down
97 changes: 48 additions & 49 deletions tmk_core/protocol/chibios/usb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,11 +552,11 @@ static void usb_event_cb(USBDriver *usbp, usbevent_t event) {
/* Disconnection event on suspend.*/
qmkusbSuspendHookI(&drivers.array[i].driver);
chSysUnlockFromISR();
}
}
#ifdef MOUSE_SCROLL_HIRES_ENABLE
/* Reset multiplier on reset */
resolution_multiplier_reset();
#endif
#endif
return;

case USB_EVENT_WAKEUP:
Expand Down Expand Up @@ -614,7 +614,7 @@ static void set_led_transfer_cb(USBDriver *usbp) {
#ifdef MOUSE_SCROLL_HIRES_ENABLE
static void set_multiplier_cb(USBDriver *usbp) {
if (usbp->setup[6] == 2 && set_report_buf[0] == REPORT_ID_MULTIPLIER) {
mouse_scroll_res_report.multiplier = set_report_buf[1];
mouse_scroll_res_report.data = set_report_buf[1];
}
}
#endif
Expand Down Expand Up @@ -650,7 +650,7 @@ static bool usb_request_hook_cb(USBDriver *usbp) {
return TRUE;
break;
# else
switch(usbp->setup[2]) {
switch (usbp->setup[2]) {
case REPORT_ID_MOUSE:
usbSetupTransfer(usbp, (uint8_t *)&mouse_report_sent, sizeof(mouse_report_sent), NULL);
return TRUE;
Expand All @@ -664,7 +664,7 @@ static bool usb_request_hook_cb(USBDriver *usbp) {
#endif
#ifdef SHARED_EP_ENABLE
case SHARED_INTERFACE:
switch(usbp->setup[2]) {
switch (usbp->setup[2]) {
# ifdef KEYBOARD_SHARED_EP
case REPORT_ID_KEYBOARD:
usbSetupTransfer(usbp, (uint8_t *)&keyboard_report_sent, KEYBOARD_REPORT_SIZE, NULL);
Expand Down Expand Up @@ -717,34 +717,33 @@ static bool usb_request_hook_cb(USBDriver *usbp) {
#endif
#if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
case MOUSE_INTERFACE:
#ifndef MOUSE_SCROLL_HIRES_ENABLE
# ifndef MOUSE_SCROLL_HIRES_ENABLE
usbSetupTransfer(usbp, set_report_buf, sizeof(set_report_buf), set_led_transfer_cb);
return TRUE;
break;
#else
switch(usbp->setup[2]) {
# else
switch (usbp->setup[2]) {
case REPORT_ID_KEYBOARD:
usbSetupTransfer(usbp, set_report_buf, sizeof(set_report_buf), set_led_transfer_cb);
return TRUE;
break;
case REPORT_ID_MULTIPLIER:
if(usbp->setup[3] == 0x03)
usbSetupTransfer(usbp, set_report_buf, sizeof(set_report_buf), set_multiplier_cb);
if (usbp->setup[3] == 0x03) usbSetupTransfer(usbp, set_report_buf, sizeof(set_report_buf), set_multiplier_cb);
return TRUE;
break;
}
#endif
# endif
}
break;

case HID_SET_PROTOCOL:
if ((usbp->setup[4] == KEYBOARD_INTERFACE) && (usbp->setup[5] == 0)) { /* wIndex */
keyboard_protocol = ((usbp->setup[2]) != 0x00); /* LSB(wValue) */
#ifdef NKRO_ENABLE
# ifdef NKRO_ENABLE
if (!keyboard_protocol && keyboard_idle) {
#else /* NKRO_ENABLE */
# else /* NKRO_ENABLE */
if (keyboard_idle) {
#endif /* NKRO_ENABLE */
# endif /* NKRO_ENABLE */
/* arm the idle timer if boot protocol & idle */
osalSysLockFromISR();
chVTSetI(&keyboard_idle_timer, 4 * TIME_MS2I(keyboard_idle), keyboard_idle_timer_cb, (void *)usbp);
Expand All @@ -758,11 +757,11 @@ static bool usb_request_hook_cb(USBDriver *usbp) {
case HID_SET_IDLE:
keyboard_idle = usbp->setup[3]; /* MSB(wValue) */
/* arm the timer */
#ifdef NKRO_ENABLE
# ifdef NKRO_ENABLE
if (!keymap_config.nkro && keyboard_idle) {
#else /* NKRO_ENABLE */
# else /* NKRO_ENABLE */
if (keyboard_idle) {
#endif /* NKRO_ENABLE */
# endif /* NKRO_ENABLE */
osalSysLockFromISR();
chVTSetI(&keyboard_idle_timer, 4 * TIME_MS2I(keyboard_idle), keyboard_idle_timer_cb, (void *)usbp);
osalSysUnlockFromISR();
Expand Down Expand Up @@ -813,23 +812,23 @@ static const USBConfig usbcfg = {
/*
* Initialize the USB driver
*/
void init_usb_driver(USBDriver *usbp) {
void init_usb_driver(USBDriver *usbp) {
for (int i = 0; i < NUM_USB_DRIVERS; i++) {
#ifdef USB_ENDPOINTS_ARE_REORDERABLE
# ifdef USB_ENDPOINTS_ARE_REORDERABLE
QMKUSBDriver *driver = &drivers.array[i].driver;
drivers.array[i].inout_ep_config.in_state = &drivers.array[i].in_ep_state;
drivers.array[i].inout_ep_config.out_state = &drivers.array[i].out_ep_state;
drivers.array[i].int_ep_config.in_state = &drivers.array[i].int_ep_state;
qmkusbObjectInit(driver, &drivers.array[i].config);
qmkusbStart(driver, &drivers.array[i].config);
#else
QMKUSBDriver *driver = &drivers.array[i].driver;
drivers.array[i].in_ep_config.in_state = &drivers.array[i].in_ep_state;
# else
QMKUSBDriver *driver = &drivers.array[i].driver;
drivers.array[i].in_ep_config.in_state = &drivers.array[i].in_ep_state;
drivers.array[i].out_ep_config.out_state = &drivers.array[i].out_ep_state;
drivers.array[i].int_ep_config.in_state = &drivers.array[i].int_ep_state;
drivers.array[i].int_ep_config.in_state = &drivers.array[i].int_ep_state;
qmkusbObjectInit(driver, &drivers.array[i].config);
qmkusbStart(driver, &drivers.array[i].config);
#endif
# endif
}

/*
Expand All @@ -850,15 +849,15 @@ __attribute__((weak)) void restart_usb_driver(USBDriver *usbp) {
usbDisconnectBus(usbp);
usbStop(usbp);

#if USB_SUSPEND_WAKEUP_DELAY > 0
# if USB_SUSPEND_WAKEUP_DELAY > 0
// Some hubs, kvm switches, and monitors do
// weird things, with USB device state bouncing
// around wildly on wakeup, yielding race
// conditions that can corrupt the keyboard state.
//
// Pause for a while to let things settle...
wait_ms(USB_SUSPEND_WAKEUP_DELAY);
#endif
# endif

usbStart(usbp, &usbcfg);
usbConnectBus(usbp);
Expand All @@ -884,11 +883,11 @@ static void keyboard_idle_timer_cb(struct ch_virtual_timer *timer, void *arg) {
return;
}

#ifdef NKRO_ENABLE
# ifdef NKRO_ENABLE
if (!keymap_config.nkro && keyboard_idle && keyboard_protocol) {
#else /* NKRO_ENABLE */
# else /* NKRO_ENABLE */
if (keyboard_idle && keyboard_protocol) {
#endif /* NKRO_ENABLE */
# endif /* NKRO_ENABLE */
/* TODO: are we sure we want the KBD_ENDPOINT? */
if (!usbGetTransmitStatusI(usbp, KEYBOARD_IN_EPNUM)) {
usbStartTransmitI(usbp, KEYBOARD_IN_EPNUM, (uint8_t *)&keyboard_report_sent, KEYBOARD_EPSIZE);
Expand Down Expand Up @@ -938,12 +937,12 @@ void send_keyboard(report_keyboard_t *report) {
if (!keyboard_protocol) {
send_report(ep, &report->mods, 8);
} else {
#ifdef NKRO_ENABLE
# ifdef NKRO_ENABLE
if (keymap_config.nkro) {
ep = SHARED_IN_EPNUM;
size = sizeof(struct nkro_report);
}
#endif
# endif

send_report(ep, report, size);
}
Expand All @@ -957,11 +956,11 @@ void send_keyboard(report_keyboard_t *report) {
*/

void send_mouse(report_mouse_t *report) {
#ifdef MOUSE_ENABLE
# ifdef MOUSE_ENABLE
send_report(MOUSE_IN_EPNUM, report, sizeof(report_mouse_t));
mouse_report_sent = *report;
osalSysUnlock();
#endif
# endif
}

/* ---------------------------------------------------------
Expand All @@ -970,35 +969,35 @@ void send_mouse(report_mouse_t *report) {
*/

void send_extra(report_extra_t *report) {
#ifdef EXTRAKEY_ENABLE
# ifdef EXTRAKEY_ENABLE
send_report(SHARED_IN_EPNUM, report, sizeof(report_extra_t));
#endif
# endif
}

void send_programmable_button(report_programmable_button_t *report) {
#ifdef PROGRAMMABLE_BUTTON_ENABLE
# ifdef PROGRAMMABLE_BUTTON_ENABLE
send_report(SHARED_IN_EPNUM, report, sizeof(report_programmable_button_t));
#endif
# endif
}

void send_joystick(report_joystick_t *report) {
#ifdef JOYSTICK_ENABLE
# ifdef JOYSTICK_ENABLE
send_report(JOYSTICK_IN_EPNUM, report, sizeof(report_joystick_t));
#endif
# endif
}

void send_digitizer(report_digitizer_t *report) {
#ifdef DIGITIZER_ENABLE
# ifdef DIGITIZER_ENABLE
send_report(DIGITIZER_IN_EPNUM, report, sizeof(report_digitizer_t));
#endif
# endif
}

/* ---------------------------------------------------------
* Console functions
* ---------------------------------------------------------
*/

#ifdef CONSOLE_ENABLE
# ifdef CONSOLE_ENABLE

int8_t sendchar(uint8_t c) {
static bool timed_out = false;
Expand Down Expand Up @@ -1047,9 +1046,9 @@ void console_task(void) {
} while (size > 0);
}

#endif /* CONSOLE_ENABLE */
# endif /* CONSOLE_ENABLE */

#ifdef RAW_ENABLE
# ifdef RAW_ENABLE
void raw_hid_send(uint8_t *data, uint8_t length) {
// TODO: implement variable size packet
if (length != RAW_EPSIZE) {
Expand All @@ -1075,9 +1074,9 @@ void raw_hid_task(void) {
} while (size > 0);
}

#endif
# endif

#ifdef MIDI_ENABLE
# ifdef MIDI_ENABLE

void send_midi_packet(MIDI_EventPacket_t *event) {
chnWrite(&drivers.midi_driver.driver, (uint8_t *)event, sizeof(MIDI_EventPacket_t));
Expand All @@ -1098,9 +1097,9 @@ void midi_ep_task(void) {
}
} while (size > 0);
}
#endif
# endif

#ifdef VIRTSER_ENABLE
# ifdef VIRTSER_ENABLE

void virtser_init(void) {}

Expand All @@ -1123,4 +1122,4 @@ void virtser_task(void) {
} while (numBytesReceived > 0);
}

#endif
# endif
Loading

0 comments on commit d04dbd9

Please sign in to comment.