Re: imt/hidmt: tests with "Windows Precision Touchpads" needed

2017-09-25 Thread Remi Locherer
On Tue, Sep 19, 2017 at 09:43:37PM +0200, Ulf Brosziewski wrote:
> This patch adapts hidmt - which is used by imt(4) - to the multitouch
> interface of wsmouse, and it adds the compat-mode configuration required
> by the wsmouse-internal touchpad input driver.
> 
> Tests with both the synaptics driver and the internal driver would be
> appreciated (see https://marc.info/?l=openbsd-misc=150153498920367=2).
> 
> If you have a custom configuration for synaptics, it might be necessary to
> adjust it, it seems that the current version does not handle the dimensions
> correctly.

I tested this patch with my Dell XPS13 9343 (applied after a cvs up on
September 24th).

mouse.type=elantech
mouse.rawmode=0
mouse.scale=0,1216,0,680,0,12,12
mouse.tp.tapping=1
mouse.tp.scaling=0.660
mouse.tp.swapsides=0
mouse.tp.disable=0

With the synaptics driver I successfully tested the following things:
- regular pointer movements
- scrolling with 2 fingers
- tap-and-drag with one and two fingers
- soft buttons 1, 2 and 3 (as defined in my xorg.conf)

xinput -list
⎡ Virtual core pointer  id=2[master pointer  (3)]
⎜   ↳ Virtual core XTEST pointerid=4[slave  pointer  (2)]
⎜   ↳ clickpad  id=6[slave  pointer  (2)]
⎜   ↳ /dev/wsmouse  id=8[slave  pointer  (2)]
⎣ Virtual core keyboard id=3[master keyboard (2)]
↳ Virtual core XTEST keyboard   id=5[slave  keyboard (3)]
↳ /dev/wskbdid=7[slave  keyboard (3)]

Also with the ws driver it works nice. In addition to the actions I tested
with synaptics I verified that these things work:
- two finger tapping (right button)
- three finger tapping (middle button)
- the soft button 2 (middle) is in the middle but a bit thin.

xinput -list
⎡ Virtual core pointer  id=2[master pointer  (3)]
⎜   ↳ Virtual core XTEST pointerid=4[slave  pointer  (2)]
⎜   ↳ /dev/wsmouse0 id=7[slave  pointer  (2)]
⎜   ↳ /dev/wsmouse  id=8[slave  pointer  (2)]
⎣ Virtual core keyboard id=3[master keyboard (2)]
↳ Virtual core XTEST keyboard   id=5[slave  keyboard (3)]
↳ /dev/wskbdid=6[slave  keyboard (3)]


Remi


OpenBSD 6.2-beta (GENERIC.MP) #85: Sun Sep 24 17:24:53 CEST 2017
r...@mistral.relo.ch:/usr/src/sys/arch/amd64/compile/GENERIC.MP
real mem = 8473636864 (8081MB)
avail mem = 8209813504 (7829MB)
mpath0 at root
scsibus0 at mpath0: 256 targets
mainbus0 at root
bios0 at mainbus0: SMBIOS rev. 2.8 @ 0xed7d0 (84 entries)
bios0: vendor Dell Inc. version "A12" date 05/09/2017
bios0: Dell Inc. XPS 13 9343
acpi0 at bios0: rev 2
acpi0: sleep states S0 S3 S4 S5
acpi0: tables DSDT FACP APIC FPDT FIDT MCFG HPET SSDT UEFI SSDT ASF! SSDT SSDT 
SSDT SSDT PCCT SSDT SSDT SSDT SLIC MSDM DMAR CSRT BGRT
acpi0: wakeup devices PEGP(S4) PEG0(S4) PEGP(S4) PEG1(S4) PEGP(S4) PEG2(S4) 
PXSX(S4) RP01(S4) PXSX(S4) RP02(S4) PXSX(S4) RP03(S4) PXSX(S4) RP04(S4) 
PXSX(S4) RP05(S4) [...]
acpitimer0 at acpi0: 3579545 Hz, 24 bits
acpimadt0 at acpi0 addr 0xfee0: PC-AT compat
cpu0 at mainbus0: apid 0 (boot processor)
cpu0: Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz, 2195.19 MHz
cpu0: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,SDBG,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,3DNOWP,PERF,ITSC,FSGSBASE,BMI1,AVX2,SMEP,BMI2,ERMS,INVPCID,RDSEED,ADX,SMAP,PT,SENSOR,ARAT
cpu0: 256KB 64b/line 8-way L2 cache
cpu0: TSC frequency 2195187520 Hz
cpu0: smt 0, core 0, package 0
mtrr: Pentium Pro MTRR support, 10 var ranges, 88 fixed ranges
cpu0: apic clock running at 99MHz
cpu0: mwait min=64, max=64, C-substates=0.2.1.2.4.1.1.1, IBE
cpu1 at mainbus0: apid 2 (application processor)
cpu1: Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz, 2194.92 MHz
cpu1: 
FPU,VME,DE,PSE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MTRR,PGE,MCA,CMOV,PAT,PSE36,CFLUSH,DS,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT,TM,PBE,SSE3,PCLMUL,DTES64,MWAIT,DS-CPL,VMX,EST,TM2,SSSE3,SDBG,FMA3,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,DEADLINE,AES,XSAVE,AVX,F16C,RDRAND,NXE,PAGE1GB,RDTSCP,LONG,LAHF,ABM,3DNOWP,PERF,ITSC,FSGSBASE,BMI1,AVX2,SMEP,BMI2,ERMS,INVPCID,RDSEED,ADX,SMAP,PT,SENSOR,ARAT
cpu1: 256KB 64b/line 8-way L2 cache
cpu1: smt 0, core 1, package 0
cpu2 at mainbus0: apid 1 (application processor)
cpu2: Intel(R) Core(TM) i5-5200U CPU @ 2.20GHz, 2194.92 MHz
cpu2: 

imt/hidmt: tests with "Windows Precision Touchpads" needed

2017-09-19 Thread Ulf Brosziewski
This patch adapts hidmt - which is used by imt(4) - to the multitouch
interface of wsmouse, and it adds the compat-mode configuration required
by the wsmouse-internal touchpad input driver.

Tests with both the synaptics driver and the internal driver would be
appreciated (see https://marc.info/?l=openbsd-misc=150153498920367=2).

If you have a custom configuration for synaptics, it might be necessary to
adjust it, it seems that the current version does not handle the dimensions
correctly.


Index: dev/hid/hidmt.c
===
RCS file: /cvs/src/sys/dev/hid/hidmt.c,v
retrieving revision 1.2
diff -u -p -r1.2 hidmt.c
--- dev/hid/hidmt.c 30 Mar 2016 23:34:12 -  1.2
+++ dev/hid/hidmt.c 19 Sep 2017 19:17:23 -
@@ -41,6 +41,70 @@
 #define DPRINTF(x)
 #endif
 
+#define HID_UNIT_CM0x11
+#define HID_UNIT_INCH  0x13
+
+/*
+ * Calculate the horizontal or vertical resolution, in device units per
+ * millimeter.
+ *
+ * With the length unit specified by the descriptor (centimeter or inch),
+ * the result is:
+ * (logical_maximum - logical_minimum) / ((physical_maximum -
+ * physical_minimum) * 10^unit_exponent)
+ *
+ * The descriptors should encode the unit exponent as a signed half-byte.
+ * However, this function accepts the values from -8 to -1 in both the
+ * 4-bit format and the usual encoding.  Other values beyond the 4-bit
+ * range are treated as undefined.  Possibly a misinterpretation of
+ * section 6.2.2.7 of the HID specification (v1.11) has been turned into
+ * a standard here, see (from www.usb.org)
+ * HUTRR39: "HID Sensor Usage Tables", sect. 3.9, 3.10, 4.2.1
+ * for an official exegesis and
+ * https://patchwork.kernel.org/patch/3033191
+ * for details and a different view.
+ */
+int
+hidmt_get_resolution(struct hid_item *h)
+{
+   int log_extent, phy_extent, exponent;
+
+   if (h->unit != HID_UNIT_CM && h->unit != HID_UNIT_INCH)
+   return (0);
+
+   log_extent = h->logical_maximum - h->logical_minimum;
+   phy_extent = h->physical_maximum - h->physical_minimum;
+   if (log_extent <= 0 || phy_extent <= 0)
+   return (0);
+
+   exponent = h->unit_exponent;
+   if (exponent < -8 || exponent > 15) /* See above. */
+   return (0);
+   if (exponent > 7)
+   exponent -= 16;
+
+   for (; exponent < 0 && log_extent <= INT_MAX / 10; exponent++)
+   log_extent *= 10;
+   for (; exponent > 0 && phy_extent <= INT_MAX / 10; exponent--)
+   phy_extent *= 10;
+   if (exponent != 0)
+   return (0);
+
+   if (h->unit == HID_UNIT_INCH) { /* Map inches to mm. */
+   if ((phy_extent > INT_MAX / 254)
+   || (log_extent > INT_MAX / 10))
+   return (0);
+   log_extent *= 10;
+   phy_extent *= 254;
+   } else {/* Map cm to mm. */
+   if (phy_extent > INT_MAX / 10)
+   return (0);
+   phy_extent *= 10;
+   }
+
+   return (log_extent / phy_extent);
+}
+
 int
 hidmt_setup(struct device *self, struct hidmt *mt, void *desc, int dlen)
 {
@@ -111,18 +175,18 @@ hidmt_setup(struct device *self, struct 
switch (h.usage) {
/* contact level usages */
case HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_X):
-   if (h.physical_minimum < mt->sc_minx)
-   mt->sc_minx = h.physical_minimum;
-   if (h.physical_maximum > mt->sc_maxx)
-   mt->sc_maxx = h.physical_maximum;
-
+   if (h.logical_maximum - h.logical_minimum) {
+   mt->sc_minx = h.logical_minimum;
+   mt->sc_maxx = h.logical_maximum;
+   mt->sc_resx = hidmt_get_resolution();
+   }
break;
case HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Y):
-   if (h.physical_minimum < mt->sc_miny)
-   mt->sc_miny = h.physical_minimum;
-   if (h.physical_maximum > mt->sc_maxy)
-   mt->sc_maxy = h.physical_maximum;
-
+   if (h.logical_maximum - h.logical_minimum) {
+   mt->sc_miny = h.logical_minimum;
+   mt->sc_maxy = h.logical_maximum;
+   mt->sc_resy = hidmt_get_resolution();
+   }
break;
case HID_USAGE2(HUP_DIGITIZERS, HUD_TIP_SWITCH):
case HID_USAGE2(HUP_DIGITIZERS, HUD_CONFIDENCE):
@@ -162,6 +226,29 @@ hidmt_setup(struct device *self, struct 
 }
 
 void
+hidmt_configure(struct hidmt *mt)
+{
+   struct wsmousehw *hw;
+
+