From 831b938ee1148cf02b0be03e5d9514491a47898b Mon Sep 17 00:00:00 2001 From: knolax <1339802534.kk@gmail.com> Date: Fri, 8 Dec 2017 12:01:07 -0500 Subject: added code to register a device with input.h --- skey.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/skey.c b/skey.c index e252cec..de255ab 100644 --- a/skey.c +++ b/skey.c @@ -5,6 +5,7 @@ #include #include #include +#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; } -- cgit v1.1