summaryrefslogtreecommitdiff
path: root/skey.c
diff options
context:
space:
mode:
Diffstat (limited to 'skey.c')
-rw-r--r--skey.c136
1 files changed, 77 insertions, 59 deletions
diff --git a/skey.c b/skey.c
index 0457cb4..d08c140 100644
--- a/skey.c
+++ b/skey.c
@@ -6,6 +6,11 @@
#include <linux/delay.h>
#include <linux/sched.h>
/*
+ * defines whether to access the gpios so other parts of the kernel module can
+ * be tested on systems w/o the prerequisite GPIOs
+ */
+#define USE_GPIO 1
+/*
* Unsigned ints containing the BCM pin numbers for the pins used, __initdata
* helps with the loading and unloading of data in memory
*/
@@ -20,7 +25,7 @@ static __initdata char * rlabels[3] = {"R0", "R1", "R2"};
* variables for setting up the thread
*/
-struct task_struct *update_task;
+static struct task_struct *update_task;
/*
*This function is called every timer-period to actually read the keyboard
*/
@@ -30,24 +35,29 @@ int skey_update_thread (void *data) {
const struct sched_param PARAM = { .sched_priority = 45};
sched_setscheduler(current, SCHED_FIFO, &PARAM);
printk(KERN_INFO "skey: started update thread\n");
+
while (1) {
- //reads the keyboard
- int row_index = 0;
- int column_index = 0;
- while (column_index < 10) {
- //sets the column pin high for reading
- gpio_set_value(column_pins[column_index], 1);
- //reads with all the rows
- row_index = 0;
- while (row_index < 3) {
- if (gpio_get_value(row_pins[row_index])) {
- printk(KERN_INFO "skey: key pressed at column %d, row %d\n", column_index, row_index);
+ if (USE_GPIO) {
+ //reads the keyboard
+ int row_index = 0;
+ int column_index = 0;
+ while (column_index < 10) {
+ //sets the column pin high for reading
+ gpio_set_value(column_pins[column_index], 1);
+ //reads with all the rows
+ row_index = 0;
+ while (row_index < 3) {
+ if (gpio_get_value(row_pins[row_index])) {
+ printk(KERN_INFO "skey: key pressed at column %d, row %d\n", column_index, row_index);
+ }
+ row_index++;
}
- row_index++;
+ //sets the row pin low
+ gpio_set_value(column_pins[column_index], 0);
+ column_index++;
}
- //sets the row pin low
- gpio_set_value(column_pins[column_index], 0);
- column_index++;
+ } else {
+ printk(KERN_ALERT "skey: currently in test mode with gpio use disabled\n");
}
//sleep 2000us= 2ms = 0.002 seconds
usleep_range(2000, 2000);
@@ -64,41 +74,45 @@ int skey_update_thread (void *data) {
*/
static int __init skey_init (void) {
printk(KERN_INFO "skey: module initiating...\n");
- int i = 0;
- //claims the column pins
- while (i < 10) {
- //checks to see if the gpios are valid
- if (!gpio_is_valid(column_pins[i])) {
- printk(KERN_ALERT "skey: column_pins[%d], BCM %d request invalid\n", i, column_pins[i]);
- return -EINVAL;
- }
- //requests access of the GPIO
- if (gpio_request_one(column_pins[i], GPIOF_OUT_INIT_LOW ,clabels[i])) {
- printk(KERN_ALERT "skey: column_pins[%d], BCM %d request failed\n", i, column_pins[i]);
- return -EINVAL;
- }
- if (gpio_direction_output(column_pins[i], 0)) {
- printk(KERN_ALERT "skey: column_pins[%d], BCM %d, set output failed\n",i, column_pins[i]);
- }
- i++;
- }
- //ditto for row pins
- int j = 0;
- while (j < 3) {
- //checks to see if the gpios are valid
- if (!gpio_is_valid(row_pins[j])) {
- printk(KERN_ALERT "skey: row_pins[%d], BCM %d request invalid\n", j, row_pins[j]);
- return -EINVAL;
- }
- //requests access of the GPIO
- if (gpio_request_one(row_pins[j], GPIOF_DIR_IN ,rlabels[j])) {
- printk(KERN_ALERT "skey: row_pins[%d], BCM %d request failed\n", j, row_pins[j]);
- return -EINVAL;
+ if (USE_GPIO) {
+ int i = 0;
+ //claims the column pins
+ while (i < 10) {
+ //checks to see if the gpios are valid
+ if (!gpio_is_valid(column_pins[i])) {
+ printk(KERN_ALERT "skey: column_pins[%d], BCM %d request invalid\n", i, column_pins[i]);
+ return -EINVAL;
+ }
+ //requests access of the GPIO
+ if (gpio_request_one(column_pins[i], GPIOF_OUT_INIT_LOW ,clabels[i])) {
+ printk(KERN_ALERT "skey: column_pins[%d], BCM %d request failed\n", i, column_pins[i]);
+ return -EINVAL;
+ }
+ if (gpio_direction_output(column_pins[i], 0)) {
+ printk(KERN_ALERT "skey: column_pins[%d], BCM %d, set output failed\n",i, column_pins[i]);
+ }
+ i++;
}
- if (gpio_direction_input(row_pins[j])) {
- printk(KERN_ALERT "skey: row_pins[%d], BCM %d, set output failed\n",j, row_pins[j]);
+ //ditto for row pins
+ int j = 0;
+ while (j < 3) {
+ //checks to see if the gpios are valid
+ if (!gpio_is_valid(row_pins[j])) {
+ printk(KERN_ALERT "skey: row_pins[%d], BCM %d request invalid\n", j, row_pins[j]);
+ return -EINVAL;
+ }
+ //requests access of the GPIO
+ if (gpio_request_one(row_pins[j], GPIOF_DIR_IN ,rlabels[j])) {
+ printk(KERN_ALERT "skey: row_pins[%d], BCM %d request failed\n", j, row_pins[j]);
+ return -EINVAL;
+ }
+ if (gpio_direction_input(row_pins[j])) {
+ printk(KERN_ALERT "skey: row_pins[%d], BCM %d, set output failed\n",j, row_pins[j]);
+ }
+ j++;
}
- j++;
+ } else {
+ printk(KERN_ALERT "skey: currently in test mode with gpio use disabled\n");
}
//sets up update thread
printk("skey: setting up update thread...\n");
@@ -112,16 +126,20 @@ static int __init skey_init (void) {
*/
static void __exit skey_exit (void) {
printk(KERN_INFO "skey: module exiting...\n");
- //frees column and row pins
- int i = 0;
- while (i < 10) {
- gpio_free(column_pins[i]);
- i++;
- }
- int j = 0;
- while (j < 3) {
- gpio_free(row_pins[j]);
- j++;
+ if (USE_GPIO) {
+ //frees column and row pins
+ int i = 0;
+ while (i < 10) {
+ gpio_free(column_pins[i]);
+ i++;
+ }
+ int j = 0;
+ while (j < 3) {
+ gpio_free(row_pins[j]);
+ j++;
+ }
+ } else {
+ printk(KERN_ALERT "skey: currently in test mode with gpio use disabled\n");
}
//deletes the thread
kthread_stop(update_task);