summaryrefslogtreecommitdiff
path: root/skey.c
diff options
context:
space:
mode:
authorknolax <1339802534.kk@gmail.com>2017-12-08 12:01:07 -0500
committerknolax <1339802534.kk@gmail.com>2017-12-08 12:01:07 -0500
commit831b938ee1148cf02b0be03e5d9514491a47898b (patch)
tree30e2590472251cbcb078789086d5c2a48dfcb8f5 /skey.c
parent1e4d95bde0c17b5bd2b0dd997963c032ed7089e3 (diff)
added code to register a device with input.h
Diffstat (limited to 'skey.c')
-rw-r--r--skey.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/skey.c b/skey.c
index e252cec..de255ab 100644
--- a/skey.c
+++ b/skey.c
@@ -5,6 +5,7 @@
#include <linux/kthread.h>
#include <linux/delay.h>
#include <linux/sched.h>
+#include "keymap.h"
/*
* defines whether to access the gpios so other parts of the kernel module can
* be tested on systems w/o the prerequisite GPIOs
@@ -22,11 +23,16 @@ static __initdata unsigned int row_pins[3] = {3, 6, 5};
static __initdata char * clabels[10] = {"C0", "C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8", "C9",};
static __initdata char * rlabels[3] = {"R0", "R1", "R2"};
/*
- * variables for setting up the thread
+ * task struct for setting up the thread
*/
static struct task_struct *update_task;
/*
+ * input.h input device
+ */
+struct input_dev * skey_dev;
+
+/*
*This function is called every timer-period to actually read the keyboard
*/
int skey_update_thread (void *data) {
@@ -121,6 +127,23 @@ static int __init skey_init (void) {
} else {
printk(KERN_ALERT "skey: currently in test mode with gpio use disabled\n");
}
+ /*
+ * sets up input.h device
+ */
+ skey_dev = input_allocate_device();
+ if (!skey_dev) {
+ printk(KERN_ALERT "skey: unable to allocate input device\n");
+ return -ENOMEM;
+ }
+ // declares the event code and typesthe device emmits
+ set_bit(EV_KEY, skey_dev->evbit);
+ set_bit(EV_REL, skey_dev->evbit);
+ set_bit(KEY_A, skey_dev.keybit);
+ // registers the device
+ if (input_register_device(skey_dev)) {
+ input_free_device(skey_dev);
+ return -EINVAL;
+ }
//sets up update thread
printk("skey: setting up update thread...\n");
update_task = kthread_run(skey_update_thread, NULL, "skey_update_thread");
@@ -150,6 +173,8 @@ static void __exit skey_exit (void) {
}
//deletes the thread
kthread_stop(update_task);
+ //frees input device
+ input_free_device(skey_dev);
printk(KERN_INFO "skey: module exited\n");
return;
}