Skip to content

Commit acc3e34

Browse files
marcusfolkessonbentiss
authored andcommitted
HID: Add driver for PhoenixRC Flight Controller
The PhoenixRC is a controller with 8 channels for use in flight simulators. Signed-off-by: Marcus Folkesson <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 2c5e8e6 commit acc3e34

File tree

5 files changed

+129
-0
lines changed

5 files changed

+129
-0
lines changed

MAINTAINERS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9053,6 +9053,12 @@ L: [email protected]
90539053
S: Supported
90549054
F: drivers/hid/hid-playstation.c
90559055

9056+
HID PHOENIX RC FLIGHT CONTROLLER
9057+
M: Marcus Folkesson <[email protected]>
9058+
9059+
S: Maintained
9060+
F: drivers/hid/hid-pxrc.c
9061+
90569062
HID SENSOR HUB DRIVERS
90579063
M: Jiri Kosina <[email protected]>
90589064
M: Jonathan Cameron <[email protected]>

drivers/hid/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -960,6 +960,15 @@ config PLAYSTATION_FF
960960
Say Y here if you would like to enable force feedback support for
961961
PlayStation game controllers.
962962

963+
config HID_PXRC
964+
tristate "PhoenixRC HID Flight Controller"
965+
depends on HID
966+
help
967+
Support for PhoenixRC HID Flight Controller, a 8-axis flight controller.
968+
969+
To compile this driver as a module, choose M here: the
970+
module will be called hid-pxrc.
971+
963972
config HID_RAZER
964973
tristate "Razer non-fully HID-compliant devices"
965974
depends on HID

drivers/hid/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ hid-picolcd-$(CONFIG_DEBUG_FS) += hid-picolcd_debugfs.o
101101
obj-$(CONFIG_HID_PLANTRONICS) += hid-plantronics.o
102102
obj-$(CONFIG_HID_PLAYSTATION) += hid-playstation.o
103103
obj-$(CONFIG_HID_PRIMAX) += hid-primax.o
104+
obj-$(CONFIG_HID_PXRC) += hid-pxrc.o
104105
obj-$(CONFIG_HID_RAZER) += hid-razer.o
105106
obj-$(CONFIG_HID_REDRAGON) += hid-redragon.o
106107
obj-$(CONFIG_HID_RETRODE) += hid-retrode.o

drivers/hid/hid-ids.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1386,6 +1386,7 @@
13861386

13871387
#define USB_VENDOR_ID_MULTIPLE_1781 0x1781
13881388
#define USB_DEVICE_ID_RAPHNET_4NES4SNES_OLD 0x0a9d
1389+
#define USB_DEVICE_ID_PHOENIXRC 0x0898
13891390

13901391
#define USB_VENDOR_ID_DRACAL_RAPHNET 0x289b
13911392
#define USB_DEVICE_ID_RAPHNET_2NES2SNES 0x0002

drivers/hid/hid-pxrc.c

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* HID driver for PhoenixRC 8-axis flight controller
4+
*
5+
* Copyright (C) 2022 Marcus Folkesson <[email protected]>
6+
*/
7+
8+
#include <linux/device.h>
9+
#include <linux/hid.h>
10+
#include <linux/module.h>
11+
12+
#include "hid-ids.h"
13+
14+
struct pxrc_priv {
15+
u8 slider;
16+
u8 dial;
17+
bool alternate;
18+
};
19+
20+
static __u8 pxrc_rdesc_fixed[] = {
21+
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
22+
0x09, 0x04, // Usage (Joystick)
23+
0xA1, 0x01, // Collection (Application)
24+
0x09, 0x01, // Usage (Pointer)
25+
0xA1, 0x00, // Collection (Physical)
26+
0x09, 0x30, // Usage (X)
27+
0x09, 0x36, // Usage (Slider)
28+
0x09, 0x31, // Usage (Y)
29+
0x09, 0x32, // Usage (Z)
30+
0x09, 0x33, // Usage (Rx)
31+
0x09, 0x34, // Usage (Ry)
32+
0x09, 0x35, // Usage (Rz)
33+
0x09, 0x37, // Usage (Dial)
34+
0x15, 0x00, // Logical Minimum (0)
35+
0x26, 0xFF, 0x00, // Logical Maximum (255)
36+
0x35, 0x00, // Physical Minimum (0)
37+
0x46, 0xFF, 0x00, // Physical Maximum (255)
38+
0x75, 0x08, // Report Size (8)
39+
0x95, 0x08, // Report Count (8)
40+
0x81, 0x02, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,No Null Position)
41+
0xC0, // End Collection
42+
0xC0, // End Collection
43+
};
44+
45+
static __u8 *pxrc_report_fixup(struct hid_device *hdev, __u8 *rdesc,
46+
unsigned int *rsize)
47+
{
48+
hid_info(hdev, "fixing up PXRC report descriptor\n");
49+
*rsize = sizeof(pxrc_rdesc_fixed);
50+
return pxrc_rdesc_fixed;
51+
}
52+
53+
static int pxrc_raw_event(struct hid_device *hdev, struct hid_report *report,
54+
u8 *data, int size)
55+
{
56+
struct pxrc_priv *priv = hid_get_drvdata(hdev);
57+
58+
if (priv->alternate)
59+
priv->slider = data[7];
60+
else
61+
priv->dial = data[7];
62+
63+
data[1] = priv->slider;
64+
data[7] = priv->dial;
65+
66+
priv->alternate = !priv->alternate;
67+
return 0;
68+
}
69+
70+
static int pxrc_probe(struct hid_device *hdev, const struct hid_device_id *id)
71+
{
72+
int ret;
73+
struct pxrc_priv *priv;
74+
75+
priv = devm_kzalloc(&hdev->dev, sizeof(*priv), GFP_KERNEL);
76+
if (!priv)
77+
return -ENOMEM;
78+
hid_set_drvdata(hdev, priv);
79+
80+
ret = hid_parse(hdev);
81+
if (ret) {
82+
hid_err(hdev, "parse failed\n");
83+
return ret;
84+
}
85+
86+
ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
87+
if (ret) {
88+
hid_err(hdev, "hw start failed\n");
89+
return ret;
90+
}
91+
92+
return 0;
93+
}
94+
95+
static const struct hid_device_id pxrc_devices[] = {
96+
{ HID_USB_DEVICE(USB_VENDOR_ID_MULTIPLE_1781, USB_DEVICE_ID_PHOENIXRC) },
97+
{ /* sentinel */ }
98+
};
99+
MODULE_DEVICE_TABLE(hid, pxrc_devices);
100+
101+
static struct hid_driver pxrc_driver = {
102+
.name = "hid-pxrc",
103+
.id_table = pxrc_devices,
104+
.report_fixup = pxrc_report_fixup,
105+
.probe = pxrc_probe,
106+
.raw_event = pxrc_raw_event,
107+
};
108+
module_hid_driver(pxrc_driver);
109+
110+
MODULE_AUTHOR("Marcus Folkesson <[email protected]>");
111+
MODULE_DESCRIPTION("HID driver for PXRC 8-axis flight controller");
112+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)