#include <linux/device.h>
#include <linux/hid.h>
#include <linux/module.h>
#include "hid-ids.h"
struct pxrc_priv {
u8 slider;
u8 dial;
bool alternate;
};
static __u8 pxrc_rdesc_fixed[] = {
0x05, 0x01,
0x09, 0x04,
0xA1, 0x01,
0x09, 0x01,
0xA1, 0x00,
0x09, 0x30,
0x09, 0x36,
0x09, 0x31,
0x09, 0x32,
0x09, 0x33,
0x09, 0x34,
0x09, 0x35,
0x09, 0x37,
0x15, 0x00,
0x26, 0xFF, 0x00,
0x35, 0x00,
0x46, 0xFF, 0x00,
0x75, 0x08,
0x95, 0x08,
0x81, 0x02,
0xC0,
0xC0,
};
static __u8 *pxrc_report_fixup(struct hid_device *hdev, __u8 *rdesc,
unsigned int *rsize)
{
hid_info(hdev, "fixing up PXRC report descriptor\n");
*rsize = sizeof(pxrc_rdesc_fixed);
return pxrc_rdesc_fixed;
}
static int pxrc_raw_event(struct hid_device *hdev, struct hid_report *report,
u8 *data, int size)
{
struct pxrc_priv *priv = hid_get_drvdata(hdev);
if (priv->alternate)
priv->slider = data[7];
else
priv->dial = data[7];
data[1] = priv->slider;
data[7] = priv->dial;
priv->alternate = !priv->alternate;
return 0;
}
static int pxrc_probe(struct hid_device *hdev, const struct hid_device_id *id)
{
int ret;
struct pxrc_priv *priv;
priv = devm_kzalloc(&hdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
return -ENOMEM;
hid_set_drvdata(hdev, priv);
ret = hid_parse(hdev);
if (ret) {
hid_err(hdev, "parse failed\n");
return ret;
}
ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
if (ret) {
hid_err(hdev, "hw start failed\n");
return ret;
}
return 0;
}
static const struct hid_device_id pxrc_devices[] = {
{ HID_USB_DEVICE(USB_VENDOR_ID_MULTIPLE_1781, USB_DEVICE_ID_PHOENIXRC) },
{ }
};
MODULE_DEVICE_TABLE(hid, pxrc_devices);
static struct hid_driver pxrc_driver = {
.name = "hid-pxrc",
.id_table = pxrc_devices,
.report_fixup = pxrc_report_fixup,
.probe = pxrc_probe,
.raw_event = pxrc_raw_event,
};
module_hid_driver(pxrc_driver);
MODULE_AUTHOR("Marcus Folkesson <marcus.folkesson@gmail.com>");
MODULE_DESCRIPTION("HID driver for PXRC 8-axis flight controller");
MODULE_LICENSE("GPL"