Skip to content

Commit e06777a

Browse files
committed
Add horizontal scrolling support for HID mouse
PR #6172 <#6172>
1 parent a352372 commit e06777a

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

app/src/hid/hid_mouse.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#include <stdint.h>
44

55
// 1 byte for buttons + padding, 1 byte for X position, 1 byte for Y position,
6-
// 1 byte for wheel motion
7-
#define SC_HID_MOUSE_INPUT_SIZE 4
6+
// 1 byte for wheel motion, 1 byte for hozizontal scrolling
7+
#define SC_HID_MOUSE_INPUT_SIZE 5
88

99
/**
1010
* Mouse descriptor from the specification:
@@ -75,6 +75,21 @@ static const uint8_t SC_HID_MOUSE_REPORT_DESC[] = {
7575
// Input (Data, Variable, Relative): 3 position bytes (X, Y, Wheel)
7676
0x81, 0x06,
7777

78+
// Usage Page (Consumer Page)
79+
0x05, 0x0C,
80+
// Usage(AC Pan)
81+
0x0A, 0x38, 0x02,
82+
// Logical Minimum (-127)
83+
0x15, 0x81,
84+
// Logical Maximum (127)
85+
0x25, 0x7F,
86+
// Report Size (8)
87+
0x75, 0x08,
88+
// Report Count (1)
89+
0x95, 0x01,
90+
// Input (Data, Variable, Relative): 1 byte (AC Pan)
91+
0x81, 0x06,
92+
7893
// End Collection
7994
0xC0,
8095

@@ -160,7 +175,8 @@ sc_hid_mouse_generate_input_from_motion(struct sc_hid_input *hid_input,
160175
data[0] = sc_hid_buttons_from_buttons_state(event->buttons_state);
161176
data[1] = CLAMP(event->xrel, -127, 127);
162177
data[2] = CLAMP(event->yrel, -127, 127);
163-
data[3] = 0; // wheel coordinates only used for scrolling
178+
data[3] = 0; // no vertical scrolling
179+
data[4] = 0; // no horizontal scrolling
164180
}
165181

166182
void
@@ -172,13 +188,14 @@ sc_hid_mouse_generate_input_from_click(struct sc_hid_input *hid_input,
172188
data[0] = sc_hid_buttons_from_buttons_state(event->buttons_state);
173189
data[1] = 0; // no x motion
174190
data[2] = 0; // no y motion
175-
data[3] = 0; // wheel coordinates only used for scrolling
191+
data[3] = 0; // no vertical scrolling
192+
data[4] = 0; // no horizontal scrolling
176193
}
177194

178195
bool
179196
sc_hid_mouse_generate_input_from_scroll(struct sc_hid_input *hid_input,
180197
const struct sc_mouse_scroll_event *event) {
181-
if (!event->vscroll_int) {
198+
if (!event->vscroll_int && !event->hscroll_int) {
182199
// Need a full integral value for HID
183200
return false;
184201
}
@@ -190,7 +207,7 @@ sc_hid_mouse_generate_input_from_scroll(struct sc_hid_input *hid_input,
190207
data[1] = 0; // no x motion
191208
data[2] = 0; // no y motion
192209
data[3] = CLAMP(event->vscroll_int, -127, 127);
193-
// Horizontal scrolling ignored
210+
data[4] = CLAMP(event->hscroll_int, -127, 127);
194211
return true;
195212
}
196213

0 commit comments

Comments
 (0)