summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--skey.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/skey.c b/skey.c
index 834a6fe..d9bdef9 100644
--- a/skey.c
+++ b/skey.c
@@ -17,12 +17,31 @@ static __initdata char * rlabels[3] = {"R0", "R1", "R2"};
* timer period in ms and timer struct
*/
static struct timer_list update_timer;
-static int update_period = 5000;
+static int update_period = 5;
/*
*This function is called every timer-period to actually read the keyboard
*/
static void skey_update (unsigned long unused) {
printk(KERN_INFO "skey: updated keyboard\n");
+ //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++;
+ }
+ //sets the row pin low
+ gpio_set_value(column_pins[column_index],0);
+ column_index++;
+ }
+ //updates the timer
mod_timer(&update_timer, jiffies + msecs_to_jiffies(update_period));
}
/*
@@ -40,7 +59,7 @@ static int __init skey_init (void) {
return -EINVAL;
}
//requests access of the GPIO
- if (gpio_request_one(column_pins[i], GPIOF_DIR_IN ,clabels[i])) {
+ 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;
}
@@ -55,7 +74,7 @@ static int __init skey_init (void) {
return -EINVAL;
}
//requests access of the GPIO
- if (gpio_request_one(row_pins[j], GPIOF_OUT_INIT_LOW ,rlabels[j])) {
+ 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;
}