summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaditya Dhruv <[email protected]>2025-11-23 12:58:39 -0600
committerAaditya Dhruv <[email protected]>2025-11-23 17:20:08 -0600
commitf2e71b9fa6796022b85480ab9e57835ba9b64eda (patch)
tree672feac749a7ac282a2483e0fa65f130186c3587
parent0c24c3ad8a748c785d795449e043eb6d60fcd1db (diff)
wip
-rw-r--r--starbit.c91
-rw-r--r--startbit.h22
2 files changed, 100 insertions, 13 deletions
diff --git a/starbit.c b/starbit.c
index 91052de..44d5ae3 100644
--- a/starbit.c
+++ b/starbit.c
@@ -1,3 +1,5 @@
+#include "linux/input.h"
+#include "linux/kern_levels.h"
#include "linux/printk.h"
#include <linux/usb.h>
#include <linux/module.h>
@@ -5,32 +7,95 @@
#include <linux/init.h>
#include <linux/device.h>
#include <linux/hid.h>
+#include "startbit.h"
-struct wiimote_dev {
+struct wiimouse_dev {
+ struct hid_device* hdev;
+ struct input_dev* in_dev;
};
-static const struct hid_device_id wiimote_ids[] = {
- {HID_BLUETOOTH_DEVICE(0x057e, 0x0306)},
+static const struct hid_device_id wiimouse_ids[] = {
+ {HID_BLUETOOTH_DEVICE(NINTENDO_WIIMOTE_VENDOR_ID, NINTENDO_WIIMOTE_PRODUCT_ID)},
{}
};
-MODULE_DEVICE_TABLE(hid, wiimote_ids);
-static int wiimote_probe(struct hid_device *hdev, const struct hid_device_id *id)
+
+
+/*
+ * wiimote_init
+ * Initialize certain aspects of the wiimote such as the LEDs and sensors by
+ * sending appropriate HID reports to the device. Returns 0 on success, non-zero
+ * on error
+ * Details about the report details can be found in https://wiibrew.org/wiki/Wiimote
+ */
+static int wiimote_init(struct hid_device* hdev) {
+ int ret = 0;
+ __u8 rumble[2] = { HID_REPORT_ID_WIIMOTE_RUMBLE_ENABLE, HID_REPORT_DATA_WIIMOTE_RUMBLE_ENABLE };
+ if ((ret = hid_hw_output_report(hdev, (__u8*)rumble, 2)) < 0) return ret;
+ __u8 led_p1[2] = { HID_REPORT_ID_WIIMOTE_LED_ENABLE, HID_REPORT_DATA_WIIMOTE_LED_ENABLE_P1 };
+ if ((ret = hid_hw_output_report(hdev, (__u8*)led_p1, 2)) < 0) return ret;
+
+ __u8 enable_ir1[2] = { HID_REPORT_ID_WIIMOTE_IR1_ENABLE, HID_REPORT_DATA_WIIMOTE_IR1_ENABLE };
+ if ((ret = hid_hw_output_report(hdev, (__u8*)enable_ir1, 2)) < 0) return ret;
+ __u8 enable_ir2[2] = { HID_REPORT_ID_WIIMOTE_IR2_ENABLE, HID_REPORT_DATA_WIIMOTE_IR2_ENABLE };
+ if ((ret = hid_hw_output_report(hdev, (__u8*)enable_ir2, 2)) < 0) return ret;
+
+ return ret;
+}
+
+
+static int wiimote_event(struct hid_device* hdev, struct hid_report* report, u8 *data, int size) {
+ printk(KERN_DEBUG "Report ID: %02x | Buttons: %02x %02x %02x\n", report->id, data[0], data[1], data[2]);
+
+
+ if (data[2] & 0x08) {
+ printk(KERN_DEBUG "A button was pressed\n");
+ }
+ return 0;
+}
+
+MODULE_DEVICE_TABLE(hid, wiimouse_ids);
+static int wiimouse_probe(struct hid_device *hdev, const struct hid_device_id *id)
{
- printk(KERN_DEBUG "Hello I'm a wiimote mouse!");
+ int ret = 0;
+ struct wiimouse_dev* wdev;
+ wdev = devm_kzalloc(&hdev->dev, sizeof(struct wiimouse_dev), GFP_KERNEL);
+ wdev->hdev = hdev;
+ struct input_dev* in_dev = input_allocate_device();
+ if(in_dev == NULL) {
+ return -1;
+ }
+
+
+ printk(KERN_DEBUG "wiimouse-mouse: Starting parse");
+ /* Init hid device, setup input subsystem etc. */
+ ret = hid_parse(hdev);
+ if (ret) return ret;
+ ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
+ if (ret) return ret;
+
+ wiimote_init(hdev);
+ /* Init done, device ready to use */
+ printk(KERN_DEBUG "Hello I'm a wiimouse!");
+ return 0;
+}
+
- return 0;
+static void wiimote_report(struct hid_device *hdev, struct hid_report *report) {
+ printk(KERN_DEBUG "Report ID: %02x\n", report->id);
}
-static struct hid_driver wiimote_driver = {
- .name = "wiimote-mouse",
- .id_table = wiimote_ids,
- .probe = wiimote_probe,
+static struct hid_driver wiimouse_driver = {
+ .name = "wiimouse-mouse",
+ .id_table = wiimouse_ids,
+ .probe = wiimouse_probe,
+ .raw_event = wiimote_event,
+ .report = wiimote_report,
};
-module_hid_driver(wiimote_driver);
+module_hid_driver(wiimouse_driver);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Aaditya Dhruv");
-MODULE_DESCRIPTION("Test");
+MODULE_DESCRIPTION("Use your wiimote as a simple mouse");
diff --git a/startbit.h b/startbit.h
new file mode 100644
index 0000000..5547a15
--- /dev/null
+++ b/startbit.h
@@ -0,0 +1,22 @@
+#ifndef STARBIT_H_FILE
+#define STARBIT_H_FILE
+
+
+
+#define NINTENDO_WIIMOTE_VENDOR_ID 0x057e
+#define NINTENDO_WIIMOTE_PRODUCT_ID 0x0306
+
+#define HID_REPORT_ID_WIIMOTE_RUMBLE_ENABLE 0x10
+#define HID_REPORT_DATA_WIIMOTE_RUMBLE_ENABLE 0x10
+#define HID_REPORT_ID_WIIMOTE_LED_ENABLE 0x11
+#define HID_REPORT_DATA_WIIMOTE_LED_ENABLE_P1 0x10
+
+#define HID_REPORT_ID_WIIMOTE_IR1_ENABLE 0x13
+#define HID_REPORT_ID_WIIMOTE_IR2_ENABLE 0x1a
+
+
+#define HID_REPORT_DATA_WIIMOTE_IR1_ENABLE 0x04
+#define HID_REPORT_DATA_WIIMOTE_IR2_ENABLE 0x04
+
+
+#endif