diff options
author | knolax <1339802534.kk@gmail.com> | 2017-12-07 21:03:30 -0500 |
---|---|---|
committer | knolax <1339802534.kk@gmail.com> | 2017-12-07 21:03:30 -0500 |
commit | e673f16c5d15640dd01d4af5effb08c9e298a1bd (patch) | |
tree | 09060219676c505d345f09f60903dd04ef800e3a | |
parent | d3a09ff7f9a2fb497ba492398f4307c2df628a03 (diff) |
added basic keypress scanning functionality to the update function
-rw-r--r-- | skey.c | 25 |
1 files changed, 22 insertions, 3 deletions
@@ -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; } |