commit 4b34a38020addfa101c26c01f95a8de8f31b4aa8
parent 970efabd484c55770934d60607047b615f6957d8
Author: Lukas F. Hartmann <lukas@mntre.com>
Date: Sun, 25 Jul 2021 16:00:15 +0200
add horizontal wheel (pan) and hi res scrolling
Diffstat:
3 files changed, 67 insertions(+), 6 deletions(-)
diff --git a/reform2-trackball-fw/Descriptors.c b/reform2-trackball-fw/Descriptors.c
@@ -58,6 +58,7 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport[] =
HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */
HID_RI_USAGE(8, 0x02), /* Mouse */
HID_RI_COLLECTION(8, 0x01), /* Application */
+ HID_RI_REPORT_ID(8, 0x01),
HID_RI_USAGE(8, 0x01), /* Pointer */
HID_RI_COLLECTION(8, 0x00), /* Physical */
HID_RI_USAGE_PAGE(8, 0x09), /* Button */
@@ -68,9 +69,11 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport[] =
HID_RI_REPORT_COUNT(8, 0x03),
HID_RI_REPORT_SIZE(8, 0x01),
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
+
HID_RI_REPORT_COUNT(8, 0x01), // 5 bits padding
HID_RI_REPORT_SIZE(8, 0x05),
HID_RI_INPUT(8, HID_IOF_CONSTANT),
+
HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */
HID_RI_USAGE(8, 0x30), /* Usage X */
HID_RI_USAGE(8, 0x31), /* Usage Y */
@@ -81,17 +84,45 @@ const USB_Descriptor_HIDReport_Datatype_t PROGMEM MouseReport[] =
HID_RI_REPORT_COUNT(8, 0x02),
HID_RI_REPORT_SIZE(8, 0x08),
HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
+
+ HID_RI_COLLECTION(8, 0x02), /* Logical */
+ // ---
+ HID_RI_REPORT_ID(8, 0x02),
+ HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */
+ HID_RI_USAGE(8, 0x48), /* Usage Resolution Multiplier */
+ HID_RI_LOGICAL_MINIMUM(8, 0),
+ HID_RI_LOGICAL_MAXIMUM(8, 1),
+ HID_RI_PHYSICAL_MINIMUM(8, 1),
+ HID_RI_PHYSICAL_MAXIMUM(8, 16),
+ HID_RI_REPORT_COUNT(8, 0x01),
+ HID_RI_REPORT_SIZE(8, 0x08),
+ HID_RI_FEATURE(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_ABSOLUTE),
// ---
+ // ---
+ HID_RI_REPORT_ID(8, 0x01),
HID_RI_USAGE_PAGE(8, 0x01), /* Generic Desktop */
HID_RI_USAGE(8, 0x38), /* Usage Wheel */
HID_RI_LOGICAL_MINIMUM(8, -127),
HID_RI_LOGICAL_MAXIMUM(8, 127),
- HID_RI_PHYSICAL_MINIMUM(8, -127),
- HID_RI_PHYSICAL_MAXIMUM(8, 127),
+ HID_RI_PHYSICAL_MINIMUM(8, 0),
+ HID_RI_PHYSICAL_MAXIMUM(8, 0),
+ HID_RI_REPORT_COUNT(8, 0x01),
+ HID_RI_REPORT_SIZE(8, 0x08),
+ HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
+ // ---
+ // ---
+ HID_RI_REPORT_ID(8, 0x01),
+ HID_RI_USAGE_PAGE(8, 0x0c), /* Consumer */
+ HID_RI_USAGE(16, 0x238), /* Usage AC Pan, Linear Control */
+ HID_RI_LOGICAL_MINIMUM(8, -127),
+ HID_RI_LOGICAL_MAXIMUM(8, 127),
+ HID_RI_PHYSICAL_MINIMUM(8, -127),
+ HID_RI_PHYSICAL_MAXIMUM(8, 127),
HID_RI_REPORT_COUNT(8, 0x01),
- HID_RI_REPORT_SIZE(8, 0x08),
- HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
+ HID_RI_REPORT_SIZE(8, 0x08),
+ HID_RI_INPUT(8, HID_IOF_DATA | HID_IOF_VARIABLE | HID_IOF_RELATIVE),
// ---
+ HID_RI_END_COLLECTION(0),
HID_RI_END_COLLECTION(0),
HID_RI_END_COLLECTION(0),
};
diff --git a/reform2-trackball-fw/Descriptors.h b/reform2-trackball-fw/Descriptors.h
@@ -95,6 +95,12 @@ typedef struct
int8_t X;
int8_t Y;
int8_t Wheel;
+ int8_t Pan;
} ATTR_PACKED USB_WheelMouseReport_Data_t;
+typedef struct
+{
+ int8_t Multiplier;
+} ATTR_PACKED USB_WheelMouseFeatureReport_Data_t;
+
#endif
diff --git a/reform2-trackball-fw/Mouse.c b/reform2-trackball-fw/Mouse.c
@@ -250,7 +250,29 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
void* ReportData,
uint16_t* const ReportSize)
{
- if (ReportType==HID_REPORT_ITEM_Feature) return false;
+ if (ReportType==HID_REPORT_ITEM_Feature) {
+ if (*ReportID==0) {
+ *ReportID=2;
+ }
+
+ if (*ReportID==2) {
+ USB_WheelMouseFeatureReport_Data_t* FeatureReport = (USB_WheelMouseFeatureReport_Data_t*)ReportData;
+ FeatureReport->Multiplier = 2;
+ *ReportSize = sizeof(USB_WheelMouseFeatureReport_Data_t);
+ return true;
+ } else {
+ led_set(0x2);
+ return false;
+ }
+ }
+
+ if (*ReportID==0) {
+ *ReportID=1;
+ }
+ if (*ReportID!=1) {
+ led_set(0x1);
+ return false;
+ }
int8_t nx = 0;
int8_t ny = 0;
@@ -285,10 +307,12 @@ bool CALLBACK_HID_Device_CreateHIDReport(USB_ClassInfo_HID_Device_t* const HIDIn
}
MouseReport->Wheel = 0;
+ MouseReport->Pan = 0;
if (!(PIND&1) || !(PIND&(1<<2))) {
// wheel
- MouseReport->Wheel = -ny;
+ MouseReport->Pan = 2*nx;
+ MouseReport->Wheel = 2*-ny;
} else {
MouseReport->X = 2*abs(nx)*nx;
MouseReport->Y = 2*abs(ny)*ny;