⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 keydrv.h

📁 在UCLIINUX环境下开发的自定义4*4键盘驱动,象手机键盘那样实现键盘的基本功能
💻 H
字号:

#include <asm/irq.h>


#define MAX_KBD_BUF  16

// define the interrupt  number.
#define PIO_KEY_INT_IRQ        5


#define   KEYSTATUS_DOWNX      1   
#define   KEYSTATUS_UP         2
#define   KEYSTATUS_DOWN       3  
//#define   KEYSTATUS_REPEAT     4

// define CAP states
#define    CAP_ON              1
#define    CAP_OFF             0

// port address definition.
#define  KEY_PORT_ROWS       (*((volatile unsigned char *)0x00201290))       //  to read 
#define  KEY_PORT_COLS       (*((volatile unsigned char *)0x002012E0))       //  to write
//#define  KEY_PORT_DIR       (*(volatile unsigned char *)0x??)       //  if the i/0 direction wanted

#define  KEY_MAX_ROWS     4
#define  KEY_MAX_COLS     4

#define   KEY_UP          0x80      // just make a flag    

#define   KBD_TIMER_DELAY      (HZ/10)          //100ms
#define   KBD_TIMER_DELAY1     (HZ/100)         //10ms
#define   KBD_SWIFT_TIME     (HZ/4)           // just a expired time when swift the table index

//typedef unsigned char u_char;

typedef struct{

/* KEYSTATUS_UP KEYSTATUS_DOWN  AND KEYSTATUS_DOWNX */
        unsigned int kbdStatus;
        u_char buf[MAX_KBD_BUF];
        unsigned int head,tail;
        wait_queue_head_t wq;
}KBD_DEV;


#define BUF_HEAD   (kbddev.buf[kbddev.head])
#define BUF_TAIL   (kbddev.buf[kbddev.tail])
#define INCBUF(x,mod)   ((++(x))&((mod)-1))


//  i must find the #include <>   find better.!!!!

/* 
  void enable_irq(unsigned int irq)
    {
        setimr(1<<irq);
    }

  void disable_irq(unsigned int irq)
    {
        clrimr(~(1<<irq));
    }
*/




#define   KBD_CLOSE_INT()          disable_irq(PIO_KEY_INT_IRQ)
#define   KBD_OPEN_INT()           enable_irq(PIO_KEY_INT_IRQ)

#define   ISKBD_DOWN()             ( (KEY_PORT_ROWS && 0x0f ) != 0 ? 1:0 )             // just 4 bits effects

//#define   KeyGetCol()         ??     (~KEY_PORT_COL) 
//#define   KeySelRow(row)        ??   (KEY_PORT_ROW = ~(1<<row))   //  force desired row low.     

static int key_open(struct inode *,struct file *);
static int key_release(struct inode *,struct file *);
static ssize_t key_read(struct file *,char *,size_t ,loff_t *);

//static irqreturn_t  key_interrupt(int ,void *);            // ,struct pt_regs *);
static void kbd_timer_handler(unsigned long);
static void get_kbd(void);  //  really have a key pressed , then find the key and write buf and wake up ..
static u_char decode_key(void);      //read the key i/o port
static u_char readbuf(void);       // read the key data form buf
static void kbdEvent_raw(void);

//static KeySelRow(u_char);   

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -