Skip to content

Commit

Permalink
major update/revision most issues fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Alabastard-64 committed Jan 21, 2023
1 parent 591cedb commit ec686da
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 73 deletions.
4 changes: 2 additions & 2 deletions quantum/pointing_device/pointing_device_modes.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,15 +366,15 @@ static report_mouse_t process_pointing_mode(pointing_mode_t pointing_mode, repor
{
uint8_t cur_divisor = pointing_mode.divisor;
uint8_t drag_multiplier = MAX(MOUSE_SCROLL_MULTIPLIER / cur_divisor, 1);
if (resolution_multiplier & 1 << 2) {
if (RESOLUTION_MULTIPLIER_H) {
pointing_mode.x *= 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 (resolution_multiplier & 1 << 0) {
if (RESOLUTION_MULTIPLIER_V) {
pointing_mode.y *= drag_multiplier;
pointing_mode.divisor = 1;
} else {
Expand Down
6 changes: 5 additions & 1 deletion quantum/pointing_device/pointing_device_modes.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@
# define POINTING_PRECISION_DIVISOR 2
#endif
#ifndef POINTING_DRAG_DIVISOR
# define POINTING_DRAG_DIVISOR 4
# ifdef MOUSE_SCROLL_HIRES_ENABLE
# define POINTING_DRAG_DIVISOR 8
# else
# define POINTING_DRAG_DIVISOR 4
# endif
#endif

/* error checking */
Expand Down
69 changes: 37 additions & 32 deletions tmk_core/protocol/chibios/usb_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ union {
#define HID_SET_REPORT 0x09
#define HID_SET_IDLE 0x0A
#define HID_SET_PROTOCOL 0x0B
#define HID_FEATURE_REPORT 0x03

/*
* Handles the GET_DESCRIPTOR callback
Expand Down Expand Up @@ -650,40 +651,40 @@ static bool usb_request_hook_cb(USBDriver *usbp) {
return TRUE;
break;
# else
if (usbp->setup[2] == REPORT_ID_MULTIPLIER) {
usbSetupTransfer(usbp, (uint8_t *)&resolution_multiplier, sizeof(resolution_multiplier), NULL);
return TRUE;
break;
} else {
usbSetupTransfer(usbp, (uint8_t *)&mouse_report_sent, sizeof(mouse_report_sent), NULL);
return TRUE;
break;
switch(usbp->setup[2]) {
case REPORT_ID_MOUSE:
usbSetupTransfer(usbp, (uint8_t *)&mouse_report_sent, sizeof(mouse_report_sent), NULL);
return TRUE;
break;
case REPORT_ID_MULTIPLIER:
usbSetupTransfer(usbp, (uint8_t *)&resolution_multiplier, sizeof(resolution_multiplier), NULL);
return TRUE;
break;
}
# endif
#endif
#ifdef SHARED_EP_ENABLE
case SHARED_INTERFACE:
switch(usbp->setup[2]) {
# ifdef KEYBOARD_SHARED_EP
if (usbp->setup[2] == REPORT_ID_KEYBOARD) {
usbSetupTransfer(usbp, (uint8_t *)&keyboard_report_sent, KEYBOARD_REPORT_SIZE, NULL);
return TRUE;
break;
}
case REPORT_ID_KEYBOARD:
usbSetupTransfer(usbp, (uint8_t *)&keyboard_report_sent, KEYBOARD_REPORT_SIZE, NULL);
return TRUE;
break;
# endif
# ifdef MOUSE_SHARED_EP
if (usbp->setup[2] == REPORT_ID_MOUSE) {
usbSetupTransfer(usbp, (uint8_t *)&mouse_report_sent, sizeof(mouse_report_sent), NULL);
return TRUE;
break;
}
case REPORT_ID_MOUSE:
usbSetupTransfer(usbp, (uint8_t *)&mouse_report_sent, sizeof(mouse_report_sent), NULL);
return TRUE;
break;
# ifdef MOUSE_SCROLL_HIRES_ENABLE
case REPORT_ID_MULTIPLIER:
usbSetupTransfer(usbp, (uint8_t *)&resolution_multiplier, sizeof(resolution_multiplier), NULL);
return TRUE;
break;
# endif
# endif
# ifdef MOUSE_SCROLL_HIRES_ENABLE
if (usbp->setup[2] == REPORT_ID_MULTIPLIER) {
usbSetupTransfer(usbp, (uint8_t *)&resolution_multiplier, sizeof(resolution_multiplier), NULL);
return TRUE;
break;
}
# endif
#endif /* SHARED_EP_ENABLE */
default:
universal_report_blank.report_id = usbp->setup[2];
Expand Down Expand Up @@ -715,19 +716,23 @@ static bool usb_request_hook_cb(USBDriver *usbp) {
#if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP)
case SHARED_INTERFACE:
#endif
#if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
case MOUSE_INTERFACE:
#ifndef MOUSE_SCROLL_HIRES_ENABLE
usbSetupTransfer(usbp, set_report_buf, sizeof(set_report_buf), set_led_transfer_cb);
return TRUE;
break;
#else
if (usbp->setup[2] == REPORT_ID_MULTIPLIER) {
usbSetupTransfer(usbp, set_report_buf, sizeof(set_report_buf), set_multiplier_cb);
return TRUE;
break;
} else {
usbSetupTransfer(usbp, set_report_buf, sizeof(set_report_buf), set_led_transfer_cb);
return TRUE;
break;
switch(usbp->setup[2]) {
case REPORT_ID_MOUSE:
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);
return TRUE;
break;
}
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion tmk_core/protocol/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void host_mouse_send(report_mouse_t *report) {
#endif

if (!driver) return;
#ifdef MOUSE_SHARED_EP
#if defined(MOUSE_SHARED_EP) || defined(MOUSE_SCROLL_HIRES_ENABLE)
report->report_id = REPORT_ID_MOUSE;
#endif
#ifdef MOUSE_EXTENDED_REPORT
Expand Down
42 changes: 30 additions & 12 deletions tmk_core/protocol/lufa/lufa.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,23 +450,43 @@ void EVENT_USB_Device_ControlRequest(void) {

// Interface
switch (USB_ControlRequest.wIndex) {
#ifndef KEYBOARD_SHARED_EP
case KEYBOARD_INTERFACE:
// TODO: test/check
ReportData = (uint8_t *)&keyboard_report_sent;
ReportSize = sizeof(keyboard_report_sent);
break;
#if defined(SHARED_EP_ENABLE) && defined(MOUSE_SHARED_EP)
case SHARED_INTERFACE:
#else
case MOUSE_INTERFACE:
#endif
#if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
case MOUSE_INTERFACE:
# ifdef MOUSE_SCROLL_HIRES_ENABLE
if (USB_ControlRequest.wValue == (0x0300 | REPORT_ID_MULTIPLIER)) {
if ((USB_ControlRequest.wValue & 0xff) == REPORT_ID_MULTIPLIER) {
ReportData = &resolution_multiplier;
ReportSize = sizeof(resolution_multiplier);
break;
}
# endif
break;
#endif
#ifdef SHARED_EP_ENABLE
case SHARED_INTERFACE:
{
uint8_t report_id = USB_ControlRequest.wValue & 0xff;
switch(report_id) {
# ifdef KEYBOARD_SHARED_EP
case REPORT_ID_KEYBOARD:
ReportData = (uint8_t *)&keyboard_report_sent;
ReportSize = sizeof(keyboard_report_sent);
break;
# endif
# if defined(MOUSE_ENABLE) && defined(MOUSE_SCROLL_HIRES_ENABLE) && defined(MOUSE_SHARED_EP)
case REPORT_ID_MULTIPLIER:
ReportData = &resolution_multiplier;
ReportSize = sizeof(resolution_multiplier);
break;
# endif
}
}
#endif
}
/* Write the report data to the control endpoint */
Endpoint_Write_Control_Stream_LE(ReportData, ReportSize);
Expand All @@ -480,7 +500,10 @@ void EVENT_USB_Device_ControlRequest(void) {
switch (USB_ControlRequest.wIndex) {
case KEYBOARD_INTERFACE:
#if defined(SHARED_EP_ENABLE) && !defined(KEYBOARD_SHARED_EP)
case SHARED_INTERFACE:
case SHARED_INTERFACE:
#endif
#if defined(MOUSE_ENABLE) && !defined(MOUSE_SHARED_EP)
case MOUSE_INTERFACE:
#endif
Endpoint_ClearSETUP();

Expand All @@ -504,7 +527,6 @@ void EVENT_USB_Device_ControlRequest(void) {
break;
#endif
}

Endpoint_ClearOUT();
Endpoint_ClearStatusStage();
break;
Expand Down Expand Up @@ -840,10 +862,6 @@ static void setup_usb(void) {
// Leonardo needs. Without this USB device is not recognized.
USB_Disable();

#ifdef MOUSE_SCROLL_HIRES_ENABLE
resolution_multiplier = 0;
#endif

USB_Init();

// for Console_Task
Expand Down
6 changes: 3 additions & 3 deletions tmk_core/protocol/report.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static int8_t cb_count = 0;
#endif

#ifdef MOUSE_SCROLL_HIRES_ENABLE
static uint8_t prev_resolution_multiplier = 0;
static uint8_t resolution_multiplier_stored = 0;
uint8_t resolution_multiplier = 0;
#endif

Expand Down Expand Up @@ -297,12 +297,12 @@ __attribute__((weak)) bool has_mouse_report_changed(report_mouse_t* new_report,
}

# ifdef MOUSE_SCROLL_HIRES_ENABLE
void hires_scroll_disable_next(hires_axis_t axis) {
void hires_scroll_disable_next(uint8_t axis) {
resolution_multiplier_stored |= resolution_multiplier;
resolution_multiplier &= ~(axis);
}
void hires_scroll_reset(void) {
resolution_multiplier |= prev_resolution_multiplier;
resolution_multiplier |= resolution_multiplier_stored;
}
# endif
#endif // MOUSE_ENABLE
20 changes: 10 additions & 10 deletions tmk_core/protocol/report.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
# elif (MOUSE_SCROLL_MULTIPLIER > 120 || MOUSE_SCROLL_MULTIPLIER < 1)
# error "MOUSE_SCROLL_MULTIPLIER out of bounds must be in range of 1-120"
# endif
# endif
enum {
HIRES_V = 0x0F,
HIRES_H = 0xF0,
HIRES_BOTH = HIRES_V | HIRES_H,
};
#endif

/* HID report IDs */
enum hid_report_ids {
Expand Down Expand Up @@ -224,12 +229,12 @@ typedef int8_t mouse_hv_report_t;

#ifdef MOUSE_SCROLL_HIRES_ENABLE
extern uint8_t resolution_multiplier;
# define IS_V_HIRES_ACTIVE (bool)(resolution_multiplier & (0x01 << 0))
# define IS_H_HIRES_ACTIVE (bool)(resolution_multiplier & (0x01 << 2))
# define RESOLUTION_MULTIPLIER_V (resolution_multiplier & HIRES_V)
# define RESOLUTION_MULTIPLIER_H (resolution_multiplier & HIRES_H)
#endif

typedef struct {
#if (defined(MOUSE_SHARED_EP) || defined(MOUSE_SCROLL_HIRES_ENABLE))
#if defined(MOUSE_SHARED_EP) || defined(MOUSE_SCROLL_HIRES_ENABLE)
uint8_t report_id;
#endif
uint8_t buttons;
Expand Down Expand Up @@ -364,12 +369,7 @@ bool has_mouse_report_changed(report_mouse_t* new_report, report_mouse_t* old_re
#endif

#ifdef MOUSE_SCROLL_HIRES_ENABLE
typedef enum {
HIRES_V = 1,
HIRES_H = 4,
HIRES_BOTH = 5,
} hires_axis_t;
void disable_hires_scroll_on_next(hires_axis_t axis);
void disable_hires_scroll_on_next(uint8_t axis);
void hires_scroll_reset(void);
#endif

Expand Down
20 changes: 8 additions & 12 deletions tmk_core/protocol/usb_descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
HID_RI_USAGE_PAGE(8, 0x01), // Generic Desktop
HID_RI_USAGE(8, 0x02), // Mouse
HID_RI_COLLECTION(8, 0x01), // Application
# if (defined(MOUSE_SHARED_EP) || defined(MOUSE_SCROLL_HIRES_ENABLE))
# if defined(MOUSE_SHARED_EP) || defined(MOUSE_SCROLL_HIRES_ENABLE)
HID_RI_REPORT_ID(8, REPORT_ID_MOUSE),
# endif
HID_RI_USAGE(8, 0x01), // Pointer
Expand Down Expand Up @@ -155,15 +155,15 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {

// Vertical/Horizontal Wheel (2 or 4 bytes)
# ifdef MOUSE_SCROLL_HIRES_ENABLE
HID_RI_COLLECTION(8, 0x02), // Logical collection
HID_RI_COLLECTION(8, 0x02), // Logical collection
// Resolution Multiplier (2 bits)
HID_RI_REPORT_ID(8, REPORT_ID_MULTIPLIER),
HID_RI_USAGE(8, 0x48), // Resolution Multiplier
HID_RI_USAGE(8, 0x48), // Resolution Multiplier
HID_RI_REPORT_COUNT(8, 0x01),
HID_RI_REPORT_SIZE(8, 0x02),
HID_RI_REPORT_SIZE(8, 0x04),
HID_RI_LOGICAL_MINIMUM(8, 0x00),
HID_RI_LOGICAL_MAXIMUM(8, 0x01),
HID_RI_PHYSICAL_MINIMUM(8, 0x01), // Min 1
HID_RI_LOGICAL_MAXIMUM(8, 0x0F),
HID_RI_PHYSICAL_MINIMUM(8, 0x01), // Min 1
HID_RI_PHYSICAL_MAXIMUM(8, MOUSE_SCROLL_MULTIPLIER), // Max 120
HID_RI_FEATURE(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),

Expand Down Expand Up @@ -197,16 +197,12 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM SharedReport[] = {
HID_RI_REPORT_ID(8, REPORT_ID_MULTIPLIER),
HID_RI_USAGE(8, 0x48), // Resolution Multiplier
HID_RI_REPORT_COUNT(8, 0x01),
HID_RI_REPORT_SIZE(8, 0x02),
HID_RI_REPORT_SIZE(8, 0x04),
HID_RI_LOGICAL_MINIMUM(8, 0x00),
HID_RI_LOGICAL_MAXIMUM(8, 0x01),
HID_RI_LOGICAL_MAXIMUM(8, 0x0F),
HID_RI_PHYSICAL_MINIMUM(8, 0x01), // Min 1
HID_RI_PHYSICAL_MAXIMUM(8, MOUSE_SCROLL_MULTIPLIER), // Max 120
HID_RI_FEATURE(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
// Padding 4 bits
HID_RI_REPORT_SIZE(8, 0x04),
HID_RI_REPORT_COUNT(8, 0x01),
HID_RI_FEATURE(8, HID_IOF_CONSTANT),

HID_RI_REPORT_ID(8, REPORT_ID_MOUSE),
# endif // MOUSE_SCROLL_HIRES_ENABLE
Expand Down

0 comments on commit ec686da

Please sign in to comment.