forked from bkovac/adbkbd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadbkbd.c
57 lines (44 loc) · 1.21 KB
/
adbkbd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/jiffies.h>
#include <linux/delay.h>
#include "adb_lowlevel.h"
#include "adb_hid.h"
static struct workqueue_struct* adbkbd_wq;
static struct delayed_work adbkbd_dw;
static bool adbkbd_has_died = false;
static void adbkbd_worker(struct work_struct* work) {
adb_hid_poll();
if (!adbkbd_has_died) {
queue_delayed_work(adbkbd_wq, &adbkbd_dw, msecs_to_jiffies(15));
}
}
int __init adbkbd_init(void) {
int r;
r = adb_lowlevel_init();
if (r != 1) {
return -EAGAIN;
}
r = adb_hid_init(ADB_HID_ENABLE_KEYBOARD);
if (r != 1) {
return -EAGAIN;
}
adbkbd_wq = create_workqueue("adbkbd");
INIT_DELAYED_WORK(&adbkbd_dw, adbkbd_worker);
queue_delayed_work(adbkbd_wq, &adbkbd_dw, msecs_to_jiffies(15)); //Polling delay can be changed here
printk(KERN_INFO "adbkbd kernel module attached!\n");
return 0;
}
void __exit adb_exit(void) {
adbkbd_has_died = true;
cancel_delayed_work_sync(&adbkbd_dw);
flush_workqueue(adbkbd_wq);
destroy_workqueue(adbkbd_wq);
adb_lowlevel_exit();
adb_hid_exit();
printk(KERN_INFO "adbkbd kernel module detached!\n");
}
MODULE_LICENSE("GPL");
module_init(adbkbd_init);
module_exit(adb_exit);