#include <linux/module.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <plat/irqs.h>
#include <linux/errno.h>
#include <linux/input.h>
#include <linux/bitops.h>
#include <plat/regs-gpio.h>
#include <asm/io.h>
#include <plat/regs-timer.h>
#include <linux/cdev.h>
#include <linux/kdev_t.h>
#include <asm/uaccess.h>
#include <linux/fs.h>
#include <linux/semaphore.h>
#define NUM 19
#define LEN 32
#define HIGH_V 30
#define ALL_ONE LEN*50+278
static int started = 0;
static int count;
static int data[LEN+10];
static char keys[LEN/8];
static char kiss[2];//最终传输
struct semaphore sema;//信号量
static char my_key[NUM] = {
KEY_I,
KEY_E,
KEY_J,
KEY_B,
KEY_C,
KEY_D,
KEY_Q,
KEY_F,
KEY_P,
KEY_G,
KEY_A,
KEY_H,
KEY_LEFT,
KEY_UP,
KEY_RIGHT,
KEY_DOWN,
KEY_SPACE,
KEY_ESC,
};
static struct input_dev *my_dev;//为啥input_dev补不全
//////////////////////////////////////////////////////////
typedef struct {
u8 irqno;
u8 code;
}MYKEY_T;
static MYKEY_T keysss[5] = {{IRQ_EINT(0), KEY_UP},//六个按键
{IRQ_EINT(1), KEY_DOWN},
{IRQ_EINT(2), KEY_LEFT},
{IRQ_EINT(3), KEY_RIGHT},
{IRQ_EINT(4), KEY_ENTER},
};
irqreturn_t irq_key(int irqno, void *arg)//中断
{
int i = (int)arg;
if (i >= ARRAY_SIZE(keysss))//如果超过就丢弃防止越界
return IRQ_HANDLED;
printk("=====>%d",i);
if (ioread8(S3C64XX_GPNDAT) & (1 << i))
input_report_key(my_dev, keysss[i].code, 0); //released
else
input_report_key(my_dev, keysss[i].code, 1); //pressed
input_sync(my_dev);//同步,为必须
return IRQ_HANDLED;
}
///////////////////////////////////////////////////
void my_time_stop()
{
u32 va;
va = ioread32(S3C_TCON);
va &= ~1;
iowrite32(va, S3C_TCON);
}
void my_time_start()
{
u32 va;
va = ioread32(S3C_TCON);
va |= ((1<<3)|1);
iowrite32(va ,S3C_TCON);
}
void my_time_updata()
{
u32 va;
iowrite32(ALL_ONE,S3C_TCNTB(0));
va = ioread32(S3C_TCON);
va |= 1<<1;
iowrite32(va, S3C_TCON);
va &= ~(1<<1);
iowrite32(va, S3C_TCON);
}
void my_changge()
{
int i,j,tmp;
for(i = 0;i < LEN/8 ;i++)
{
tmp = 0;
for(j = 0;j <8; j++)
{
if(data[i*8+j+1] > HIGH_V)
tmp |= 1<<j;
}
keys[i] = tmp;
printk("before:%02x \n",keys[i]);
}
for(i=0;i < 2;i++)
{
keys[i] = keys[i+2];
printk("keys%02x \n",keys[i]);
kiss[i] = keys[i];//最终数据
printk("here:%02x \n",kiss[i]);
}
switch(kiss[0]){
case 0x45:
switch(kiss[1]){
case 0xba:
input_report_key(my_dev,my_key[0],1);//I
printk("-------->I!");
input_report_key(my_dev,my_key[0],0);
break;
}
break;
case 0x46:
switch(kiss[1]){
case 0xb9:
input_report_key(my_dev ,my_key[1] , 1);//E
printk("-------->E!");
input_report_key(my_dev,my_key[1] , 0);
break;
}
break;
case 0x47:
switch(kiss[1]){
case 0xb8:
input_report_key(my_dev ,my_key[2],1);//J
printk("-------->J!");
input_report_key(my_dev,my_key[2],0);
break;
}
break;
case 0x44:
switch(kiss[1]){
case 0xbb:
input_report_key(my_dev ,my_key[3],1);//B
printk("-------->rB!");
input_report_key(my_dev,my_key[3],0);
break;
}
break;
case 0x40:
switch(kiss[1]){
case 0xbf:
input_report_key(my_dev ,my_key[4],1);//C
printk("-------->C!");
input_report_key(my_dev,my_key[4],0);
break;
}
break;
case 0x43:
switch(kiss[1]){
case 0xbc:
input_report_key(my_dev ,my_key[5],1);//D
printk("-------->D!");
input_report_key(my_dev,my_key[5],0);
break;
}
break;
case 0x07:
switch(kiss[1]){
case 0xf8:
input_report_key(my_dev ,my_key[6],1);//Q
printk("-------->qqqq!");
input_report_key(my_dev,my_key[6],0);
break;
}
break;
case 0x15:
switch(kiss[1]){
case 0xea:
input_report_key(my_dev ,my_key[7],1);//F
printk("-------->FFF!");
input_report_key(my_dev,my_key[7],0);
break;
}
break;
case 0x09:
switch(kiss[1]){
case 0xf6:
input_report_key(my_dev ,my_key[8],1);//p
printk("-------->pp!");
input_report_key(my_dev,my_key[8],0);
break;
}
break;
case 0x16:
switch(kiss[1]){
case 0xe9:
input_report_key(my_dev ,my_key[9],1);//G
printk("-------->GGG!");
input_report_key(my_dev,my_key[9],0);
break;
}
break;
case 0x19:
switch(kiss[1]){
case 0xe6:
input_report_key(my_dev ,my_key[10],1);//A
printk("-------->AAA!");
input_report_key(my_dev,my_key[10],0);
break;
}
break;
case 0x0d:
switch(kiss[1]){
case 0xf2:
input_report_key(my_dev ,my_key[11],1);//H
printk("-------->HHH!");
input_report_key(my_dev,my_key[11],0);
break;
}
break;
/*
case 0x0c:
switch(kiss[1]){
case 0xf3:
input_report_key(my_dev ,my_key[7],1);//p
printk("-------->ppp!");
input_report_key(my_dev,my_key[7],0);
break;
}
break;
case 0x18:
switch(kiss[1]){
case 0xe7:
input_report_key(my_dev ,my_key[7],1);//p
printk("-------->ppp!");
input_report_key(my_dev,my_key[7],0);
break;
}
break;
case 0x5e:
switch(kiss[1]){
case 0xa1:
input_report_key(my_dev ,my_key[7],1);//p
printk("-------->ppp!");
input_report_key(my_dev,my_key[7],0);
break;
}
break;
*/
case 0x08:
switch(kiss[1]){
case 0xf7:
input_report_key(my_dev ,my_key[12],1);//LEFT
printk("-------->LEFT!");
input_report_key(my_dev,my_key[12],0);
break;
}
break;
case 0x1c:
switch(kiss[1]){
case 0xe3:
input_report_key(my_dev ,my_key[13],1);//UP
printk("-------->UP!");
input_report_key(my_dev,my_key[13],0);
break;
}
break;
case 0x5a:
switch(kiss[1]){
case 0xa5:
input_report_key(my_dev ,my_key[14],1);//RIGHT
printk("-------->RIGH!");
input_report_key(my_dev,my_key[14],0);
break;
}
break;
case 0x42:
switch(kiss[1]){
case 0xbd:
input_report_key(my_dev ,my_key[15],1);//SPACE
printk("-------->SACPE!");
input_report_key(my_dev,my_key[15],0);
break;
}
break;
case 0x52:
switch(kiss[1]){
case 0xad:
input_report_key(my_dev ,my_key[16],1);//DOWN
printk("-------->DOWN!");
input_report_key(my_dev,my_key[16],0);
break;
}
break;
case 0x4a:
switch(kiss[1]){
case 0xb5:
input_report_key(my_dev ,my_key[17],1);//ESC
printk("-------->ESC!");
input_report_key(my_dev,my_key[17],0);
break;
}
break;
//////////////////////////////////////////////////
}
input_sync(my_dev);
}
irqreturn_t my_func(int num, void *arg)//当有遥控信号时
{
static int a;
int last;
if(!started)
{
started = 1;
count = 0;
a = ALL_ONE;
my_time_updata();
my_time_start();
return IRQ_HANDLED;
}
if(count >LEN) return IRQ_HANDLED;
last = ioread32(S3C_TCNTO(0));//读定时器零剩下多少
data[count++] = a - last;
a = last;
return IRQ_HANDLED;
}
irqreturn_t my_time_func(int num, void * arg)//计时
{
my_time_stop();
my_changge();
started = 0;//restart
return IRQ_HANDLED;
}
int __init my_yaokong(void)
{
u