From owner-dev-commits-src-all@freebsd.org Mon Aug 16 21:02:52 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 211F46547C1; Mon, 16 Aug 2021 21:02:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GpRSq6xQ3z3QG1; Mon, 16 Aug 2021 21:02:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D2C3E1083E; Mon, 16 Aug 2021 21:02:51 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 17GL2ptb036954; Mon, 16 Aug 2021 21:02:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17GL2pjk036953; Mon, 16 Aug 2021 21:02:51 GMT (envelope-from git) Date: Mon, 16 Aug 2021 21:02:51 GMT Message-Id: <202108162102.17GL2pjk036953@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Vladimir Kondratyev Subject: git: 51b221611454 - main - hid: move proper hat switch handling from ps4dshock to hgame MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wulf X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 51b2216114546bb13b13002b29fb1263e600a0fc Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Aug 2021 21:02:52 -0000 The branch main has been updated by wulf: URL: https://cgit.FreeBSD.org/src/commit/?id=51b2216114546bb13b13002b29fb1263e600a0fc commit 51b2216114546bb13b13002b29fb1263e600a0fc Author: Greg V AuthorDate: 2021-08-16 20:18:09 +0000 Commit: Vladimir Kondratyev CommitDate: 2021-08-16 20:24:05 +0000 hid: move proper hat switch handling from ps4dshock to hgame Generic "DirectInput" HID gamepads need this handling too. Reviewed by: wulf MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D31398 --- sys/dev/hid/hgame.c | 34 +++++++++++++++++++++++++++++++++- sys/dev/hid/hgame.h | 1 + sys/dev/hid/ps4dshock.c | 35 +++-------------------------------- 3 files changed, 37 insertions(+), 33 deletions(-) diff --git a/sys/dev/hid/hgame.c b/sys/dev/hid/hgame.c index 545c72e76d93..97b1ac91960c 100644 --- a/sys/dev/hid/hgame.c +++ b/sys/dev/hid/hgame.c @@ -52,6 +52,8 @@ __FBSDID("$FreeBSD$"); { HIDMAP_KEY_RANGE(HUP_BUTTON, number_from, number_to, code) } #define HGAME_MAP_ABS(usage, code) \ { HIDMAP_ABS(HUP_GENERIC_DESKTOP, HUG_##usage, code) } +#define HGAME_MAP_GCB(usage, callback) \ + { HIDMAP_ANY_CB(HUP_GENERIC_DESKTOP, HUG_##usage, callback) } #define HGAME_MAP_CRG(usage_from, usage_to, callback) \ { HIDMAP_ANY_CB_RANGE(HUP_GENERIC_DESKTOP, \ HUG_##usage_from, HUG_##usage_to, callback) } @@ -66,7 +68,7 @@ static const struct hidmap_item hgame_map[] = { HGAME_MAP_ABS(RX, ABS_RX), HGAME_MAP_ABS(RY, ABS_RY), HGAME_MAP_ABS(RZ, ABS_RZ), - HGAME_MAP_ABS(HAT_SWITCH, ABS_HAT0X), + HGAME_MAP_GCB(HAT_SWITCH, hgame_hat_switch_cb), HGAME_MAP_CRG(D_PAD_UP, D_PAD_LEFT, hgame_dpad_cb), HGAME_MAP_BRG(17, 57, BTN_TRIGGER_HAPPY), HGAME_FINALCB( hgame_final_cb), @@ -79,6 +81,36 @@ static const struct hid_device_id hgame_devs[] = { HID_DRIVER_INFO(HUG_GAME_PAD) }, }; +int +hgame_hat_switch_cb(HIDMAP_CB_ARGS) +{ + static const struct { int32_t x; int32_t y; } hat_switch_map[] = { + {0, -1}, {1, -1}, {1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, + {-1, -1},{0, 0} + }; + struct evdev_dev *evdev = HIDMAP_CB_GET_EVDEV(); + u_int idx; + + switch (HIDMAP_CB_GET_STATE()) { + case HIDMAP_CB_IS_ATTACHING: + evdev_support_event(evdev, EV_ABS); + evdev_support_abs(evdev, ABS_HAT0X, -1, 1, 0, 0, 0); + evdev_support_abs(evdev, ABS_HAT0Y, -1, 1, 0, 0, 0); + break; + + case HIDMAP_CB_IS_RUNNING: + idx = MIN(nitems(hat_switch_map) - 1, (u_int)ctx.data); + evdev_push_abs(evdev, ABS_HAT0X, hat_switch_map[idx].x); + evdev_push_abs(evdev, ABS_HAT0Y, hat_switch_map[idx].y); + break; + + default: + break; + } + + return (0); +} + /* * Emulate the hat switch report via the D-pad usages * found on XInput/XBox style devices diff --git a/sys/dev/hid/hgame.h b/sys/dev/hid/hgame.h index 32086ec4923c..702c65a4a4c1 100644 --- a/sys/dev/hid/hgame.h +++ b/sys/dev/hid/hgame.h @@ -31,6 +31,7 @@ #include +hidmap_cb_t hgame_hat_switch_cb; hidmap_cb_t hgame_dpad_cb; hidmap_cb_t hgame_final_cb; diff --git a/sys/dev/hid/ps4dshock.c b/sys/dev/hid/ps4dshock.c index eec26f808997..a4afba254c03 100644 --- a/sys/dev/hid/ps4dshock.c +++ b/sys/dev/hid/ps4dshock.c @@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$"); #include #define HID_DEBUG_VAR ps4dshock_debug +#include #include #include #include @@ -588,7 +589,6 @@ static const uint8_t ps4dshock_rdesc[] = { #define PS4DS_OUTPUT_REPORT5_SIZE 32 #define PS4DS_OUTPUT_REPORT11_SIZE 78 -static hidmap_cb_t ps4dshock_hat_switch_cb; static hidmap_cb_t ps4dshock_final_cb; static hidmap_cb_t ps4dsacc_data_cb; static hidmap_cb_t ps4dsacc_tstamp_cb; @@ -743,7 +743,7 @@ static const struct hidmap_item ps4dshock_map[] = { PS4DS_MAP_BTN(13, BTN_MODE), /* Click button is handled by touchpad driver */ /* PS4DS_MAP_BTN(14, BTN_LEFT), */ - PS4DS_MAP_GCB(HAT_SWITCH, ps4dshock_hat_switch_cb), + PS4DS_MAP_GCB(HAT_SWITCH, hgame_hat_switch_cb), PS4DS_FINALCB( ps4dshock_final_cb), }; static const struct hidmap_item ps4dsacc_map[] = { @@ -787,36 +787,6 @@ static const struct hid_device_id ps4dsmtp_devs[] = { HID_TLC(HUP_DIGITIZERS, HUD_TOUCHPAD) }, }; -static int -ps4dshock_hat_switch_cb(HIDMAP_CB_ARGS) -{ - static const struct { int32_t x; int32_t y; } hat_switch_map[] = { - {0, -1}, {1, -1}, {1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, - {-1, -1},{0, 0} - }; - struct evdev_dev *evdev = HIDMAP_CB_GET_EVDEV(); - u_int idx; - - switch (HIDMAP_CB_GET_STATE()) { - case HIDMAP_CB_IS_ATTACHING: - evdev_support_event(evdev, EV_ABS); - evdev_support_abs(evdev, ABS_HAT0X, -1, 1, 0, 0, 0); - evdev_support_abs(evdev, ABS_HAT0Y, -1, 1, 0, 0, 0); - break; - - case HIDMAP_CB_IS_RUNNING: - idx = MIN(nitems(hat_switch_map) - 1, (u_int)ctx.data); - evdev_push_abs(evdev, ABS_HAT0X, hat_switch_map[idx].x); - evdev_push_abs(evdev, ABS_HAT0Y, hat_switch_map[idx].y); - break; - - default: - break; - } - - return (0); -} - static int ps4dshock_final_cb(HIDMAP_CB_ARGS) { @@ -1414,6 +1384,7 @@ DRIVER_MODULE(ps4dshock, hidbus, ps4dshock_driver, ps4dshock_devclass, NULL, 0); MODULE_DEPEND(ps4dshock, hid, 1, 1, 1); MODULE_DEPEND(ps4dshock, hidbus, 1, 1, 1); MODULE_DEPEND(ps4dshock, hidmap, 1, 1, 1); +MODULE_DEPEND(ps4dshock, hgame, 1, 1, 1); MODULE_DEPEND(ps4dshock, evdev, 1, 1, 1); MODULE_VERSION(ps4dshock, 1); HID_PNP_INFO(ps4dshock_devs);