into hidmt.
The HID code uses hid_feature, hid_input, and hid_output constants
to refer to report types internally that then need to be converted
to their bus-level counterparts before actually getting sent out (so
hid_feature becomes UHID_FEATURE_REPORT for USB,
I2C_HID_REPORT_TYPE_FEATURE for i2c).
This conversion was hard-coded in ihidev but ihidev_[gs]et_report
should assume the type passed is already an i2c-level define, not a
hid one. This is how uhidev does it.
Add a conversion routine callback that any hidmt callers need to set
so that hidmt can convert hid constants to the bus-level versions.
Also add a similar conversion function to uhidev.
ok deraadt
-/* $OpenBSD: hidmt.c,v 1.7 2018/07/30 15:56:30 jcs Exp $ */
+/* $OpenBSD: hidmt.c,v 1.8 2018/08/25 18:32:05 jcs Exp $ */
/*
* HID multitouch driver for devices conforming to Windows Precision Touchpad
* standard
capsize = hid_report_size(desc, dlen, hid_feature, mt->sc_rep_cap);
rep = malloc(capsize, M_DEVBUF, M_NOWAIT | M_ZERO);
- if (mt->hidev_get_report(mt->sc_device, hid_feature, mt->sc_rep_cap,
+ if (mt->hidev_report_type_conv == NULL)
+ panic("no report type conversion function");
+
+ if (mt->hidev_get_report(mt->sc_device,
+ mt->hidev_report_type_conv(hid_feature), mt->sc_rep_cap,
rep, capsize)) {
printf("\n%s: failed getting capability report\n",
self->dv_xname);
int
hidmt_set_input_mode(struct hidmt *mt, uint16_t mode)
{
- return mt->hidev_set_report(mt->sc_device, hid_feature,
- mt->sc_rep_config, &mode, 2);
+ if (mt->hidev_report_type_conv == NULL)
+ panic("no report type conversion function");
+
+ return mt->hidev_set_report(mt->sc_device,
+ mt->hidev_report_type_conv(hid_feature),
+ mt->sc_rep_config, &mode, sizeof(mode));
}
void
-/* $OpenBSD: hidmtvar.h,v 1.5 2017/10/10 20:31:50 jcs Exp $ */
+/* $OpenBSD: hidmtvar.h,v 1.6 2018/08/25 18:32:05 jcs Exp $ */
/*
* Copyright (c) 2016 joshua stein <jcs@openbsd.org>
*
#define HIDMT_REVY 0x0001 /* Y-axis is reversed ("natural" scrolling) */
struct device *sc_device;
+ int (*hidev_report_type_conv)(int);
int (*hidev_get_report)(struct device *, int, int, void *,
int);
int (*hidev_set_report)(struct device *, int, int, void *,
-/* $OpenBSD: ihidev.c,v 1.16 2018/01/12 08:11:47 mlarkin Exp $ */
+/* $OpenBSD: ihidev.c,v 1.17 2018/08/25 18:32:05 jcs Exp $ */
/*
* HID-over-i2c driver
*
*size = sc->sc_reportlen;
}
-/* convert hid_* constants used throughout HID code to i2c HID equivalents */
int
ihidev_report_type_conv(int hid_type_id)
{
{
struct ihidev_softc *sc = (struct ihidev_softc *)dev;
struct i2c_hid_report_request rreq;
- int ctype;
- if ((ctype = ihidev_report_type_conv(type)) < 0)
- return (1);
-
- rreq.type = ctype;
+ rreq.type = type;
rreq.id = id;
rreq.data = data;
rreq.len = len;
{
struct ihidev_softc *sc = (struct ihidev_softc *)dev;
struct i2c_hid_report_request rreq;
- int ctype;
-
- if ((ctype = ihidev_report_type_conv(type)) < 0)
- return (1);
- rreq.type = ctype;
+ rreq.type = type;
rreq.id = id;
rreq.data = data;
rreq.len = len;
-/* $OpenBSD: ihidev.h,v 1.5 2017/11/29 02:48:16 jcs Exp $ */
+/* $OpenBSD: ihidev.h,v 1.6 2018/08/25 18:32:05 jcs Exp $ */
/*
* HID-over-i2c driver
*
void ihidev_close(struct ihidev *);
int ihidev_ioctl(struct ihidev *, u_long, caddr_t, int, struct proc *);
+int ihidev_report_type_conv(int);
int ihidev_set_report(struct device *, int, int, void *, int);
int ihidev_get_report(struct device *, int, int, void *, int);
-/* $OpenBSD: imt.c,v 1.2 2017/07/23 22:39:11 jcs Exp $ */
+/* $OpenBSD: imt.c,v 1.3 2018/08/25 18:32:05 jcs Exp $ */
/*
* HID-over-i2c multitouch trackpad driver for devices conforming to
* Windows Precision Touchpad standard
/* assume everything has "natural scrolling" where Y axis is reversed */
mt->sc_flags = HIDMT_REVY;
+ mt->hidev_report_type_conv = ihidev_report_type_conv;
mt->hidev_get_report = imt_hidev_get_report;
mt->hidev_set_report = imt_hidev_set_report;
mt->sc_rep_input = sc->sc_rep_input;
-/* $OpenBSD: uhidev.c,v 1.75 2017/04/08 02:57:25 deraadt Exp $ */
+/* $OpenBSD: uhidev.c,v 1.76 2018/08/25 18:32:05 jcs Exp $ */
/* $NetBSD: uhidev.c,v 1.14 2003/03/11 16:44:00 augustss Exp $ */
/*
}
}
+int
+uhidev_report_type_conv(int hid_type_id)
+{
+ switch (hid_type_id) {
+ case hid_input:
+ return UHID_INPUT_REPORT;
+ case hid_output:
+ return UHID_OUTPUT_REPORT;
+ case hid_feature:
+ return UHID_FEATURE_REPORT;
+ default:
+ return -1;
+ }
+}
+
int
uhidev_set_report(struct uhidev_softc *sc, int type, int id, void *data,
int len)
-/* $OpenBSD: uhidev.h,v 1.24 2016/01/09 02:01:06 jcs Exp $ */
+/* $OpenBSD: uhidev.h,v 1.25 2018/08/25 18:32:05 jcs Exp $ */
/* $NetBSD: uhidev.h,v 1.3 2002/10/08 09:56:17 dan Exp $ */
/*
#define UHIDEV_CLAIM_ALLREPORTID 255
};
+int uhidev_report_type_conv(int);
void uhidev_get_report_desc(struct uhidev_softc *, void **, int *);
int uhidev_open(struct uhidev *);
void uhidev_close(struct uhidev *);