diff --git a/sys/dev/hid/hidms.c b/sys/dev/hid/hidms.c index 5831b677200a..c0ddc3cbb007 100644 --- a/sys/dev/hid/hidms.c +++ b/sys/dev/hid/hidms.c @@ -1,4 +1,4 @@ -/* $NetBSD: hidms.c,v 1.2 2018/05/25 15:52:45 ryoon Exp $ */ +/* $NetBSD: hidms.c,v 1.3 2019/07/09 12:52:51 ryoon Exp $ */ /* * Copyright (c) 1998, 2017 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: hidms.c,v 1.2 2018/05/25 15:52:45 ryoon Exp $"); +__KERNEL_RCSID(0, "$NetBSD: hidms.c,v 1.3 2019/07/09 12:52:51 ryoon Exp $"); #include #include @@ -267,6 +267,7 @@ hidms_intr(struct hidms *ms, void *ibuf, u_int len) if (ms->flags & HIDMS_ABS) { flags |= (WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y); dy = hid_get_data(ibuf, &ms->hidms_loc_y); + tpcalib_trans(&ms->sc_tpcalib, dx, dy, &dx, &dy); } else dy = -hid_get_data(ibuf, &ms->hidms_loc_y); dz = hid_get_data(ibuf, &ms->hidms_loc_z); diff --git a/sys/dev/hid/hidms.h b/sys/dev/hid/hidms.h index 988f57b93678..81e6363ed452 100644 --- a/sys/dev/hid/hidms.h +++ b/sys/dev/hid/hidms.h @@ -1,4 +1,4 @@ -/* $NetBSD: hidms.h,v 1.1 2017/12/10 17:03:07 bouyer Exp $ */ +/* $NetBSD: hidms.h,v 1.2 2019/07/09 12:52:51 ryoon Exp $ */ /* * Copyright (c) 1998, 2017 The NetBSD Foundation, Inc. @@ -32,6 +32,7 @@ #include #include +#include #define MAX_BUTTONS 31 /* must not exceed size of sc_buttons */ @@ -55,6 +56,9 @@ struct hidms { uint32_t hidms_buttons; /* mouse button status */ device_t hidms_wsmousedev; + + struct tpcalib_softc sc_tpcalib; /* calibration */ + struct wsmouse_calibcoords sc_calibcoords; }; bool hidms_setup(device_t, struct hidms *, int, void *, int); diff --git a/sys/dev/i2c/ims.c b/sys/dev/i2c/ims.c index c6912264f001..b042de793780 100644 --- a/sys/dev/i2c/ims.c +++ b/sys/dev/i2c/ims.c @@ -1,4 +1,4 @@ -/* $NetBSD: ims.c,v 1.1 2017/12/10 17:05:54 bouyer Exp $ */ +/* $NetBSD: ims.c,v 1.2 2019/07/09 12:52:51 ryoon Exp $ */ /* $OpenBSD ims.c,v 1.1 2016/01/12 01:11:15 jcs Exp $ */ /* @@ -20,7 +20,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ims.c,v 1.1 2017/12/10 17:05:54 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ims.c,v 1.2 2019/07/09 12:52:51 ryoon Exp $"); #include #include @@ -92,6 +92,8 @@ ims_attach(device_t parent, device_t self, void *aux) struct ihidev_attach_arg *iha = (struct ihidev_attach_arg *)aux; int size, repid; void *desc; + struct hid_data * d __debugused; + struct hid_item item __debugused; sc->sc_hdev.sc_idev = self; sc->sc_hdev.sc_intr = ims_intr; @@ -110,6 +112,30 @@ ims_attach(device_t parent, device_t self, void *aux) if (!hidms_setup(self, ms, iha->reportid, desc, size) != 0) return; +#if defined(DEBUG) + /* calibrate the touchscreen */ + memset(&sc->sc_ms.sc_calibcoords, 0, sizeof(sc->sc_ms.sc_calibcoords)); + d = hid_start_parse(desc, size, hid_input); + if (d != NULL) { + while (hid_get_item(d, &item)) { + if (item.kind != hid_input + || HID_GET_USAGE_PAGE(item.usage) != HUP_GENERIC_DESKTOP + || item.report_ID != sc->sc_hdev.sc_report_id) + continue; + if (HID_GET_USAGE(item.usage) == HUG_X) { + aprint_normal("X range: %d - %d\n", item.logical_minimum, item.logical_maximum); + } + if (HID_GET_USAGE(item.usage) == HUG_Y) { + aprint_normal("Y range: %d - %d\n", item.logical_minimum, item.logical_maximum); + } + } + hid_end_parse(d); + } +#endif + tpcalib_init(&sc->sc_ms.sc_tpcalib); + tpcalib_ioctl(&sc->sc_ms.sc_tpcalib, WSMOUSEIO_SCALIBCOORDS, + (void *)&sc->sc_ms.sc_calibcoords, 0, 0); + hidms_attach(self, ms, &ims_accessops); } @@ -199,6 +225,9 @@ ims_ioctl(void *v, u_long cmd, void *data, int flag, struct lwp *l) *(u_int *)data = WSMOUSE_TYPE_USB; } return 0; + case WSMOUSEIO_SCALIBCOORDS: + case WSMOUSEIO_GCALIBCOORDS: + return tpcalib_ioctl(&sc->sc_ms.sc_tpcalib, cmd, data, flag, l); } return EPASSTHROUGH; }