1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| #include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/stm/pio.h>
#include <linux/kthread.h>
#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/interrupt.h>
MODULE_AUTHOR("khamouma ayman");
MODULE_DESCRIPTION("craddle detect");
MODULE_LICENSE("GPL");
#define BTN_NUM 8
unsigned pio[8];
int irq[8];
struct task_struct *th;
struct stpio_pin *bpin;
static irqreturn_t keyIRQ(int catch_irq, void *dev_id)
{
if(catch_irq == irq[0])
printk("state changed for RIGHT DOWN boutton, irq %d\n",catch_irq);
else if(catch_irq == irq[1])
printk("state changed for RIGHT RIGHT boutton, irq %d\n",catch_irq);
else if(catch_irq == irq[2])
printk("state changed for RIGHT LEFT boutton, irq %d\n",catch_irq);
else if(catch_irq == irq[3])
printk("state changed for RIGHT UP boutton, irq %d\n",catch_irq);
else if(catch_irq == irq[4])
printk("state changed for LEFT UP boutton, irq %d\n",catch_irq);
else if(catch_irq == irq[5])
printk("state changed for LEFT RIGHT boutton, irq %d\n",catch_irq);
else if(catch_irq == irq[6])
printk("state changed for LEFT LEFT boutton, irq %d\n",catch_irq);
else if(catch_irq == irq[7])
printk("state changed for LEFT DOWN boutton, irq %d\n",catch_irq);
else
printk("state changed for ?? boutton, irq %d\n",catch_irq);
return IRQ_HANDLED;
}
static void MTV7109KeyPad_cleanup_module(void)
{
unsigned char i;
for (i=0;i<BTN_NUM;i++)
{
printk(KERN_ALERT"irq[%d]=%d\n",i,irq[i]);
free_irq(irq[i], NULL );
}
}
static int MTV7109KeyPad_init_module(void){
unsigned char i;
for(i=0 ; i<BTN_NUM ; i++){
pio[i] = stpio_to_gpio(1,i);
gpio_direction_input(pio[i]);
irq[i] = gpio_to_irq(pio[i]);
if (request_irq(irq[i], keyIRQ,IRQ_TYPE_EDGE_BOTH , "keypad", NULL)) {
printk(KERN_ERR "keypad.c: Can't allocate irq %d\n",irq[i] );
return -EBUSY;
}
}
return 0;
}
module_init(MTV7109KeyPad_init_module);
module_exit(MTV7109KeyPad_cleanup_module); |
Partager