Chinaunix首页 | 论坛 | 博客
  • 博客访问: 488827
  • 博文数量: 164
  • 博客积分: 4024
  • 博客等级: 上校
  • 技术积分: 1580
  • 用 户 组: 普通用户
  • 注册时间: 2009-10-10 16:27
文章分类

全部博文(164)

文章存档

2011年(1)

2010年(108)

2009年(55)

我的朋友

分类: 嵌入式

2010-05-05 09:24:51

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "BSP.h"
#include "pmplatform.h"
#include "Pkfuncs.h"
static volatile S3C2440A_IOPORT_REG* v_pIOPregs;
volatile S3C2440A_INTR_REG* v_pINTRregs;
static HANDLE  m_hMute;
static BYTE Virtualkey0=VK_NUMPAD0;
UINT32 g_KeySysIntr[5];
HANDLE IntThread;
HANDLE IntEvent;
DWORD IntProcessThread(void);
//int keyScan(UINT32 IODAT, int num);
void AllOutpinHigh();
void AllOutpinLow();
static DWORD KeyPadUnLock();
static DWORD KeyPadLock();
static DWORD KeyPadUnLock()  
{  
    DWORD dwStatus = ERROR_SUCCESS;  
    BOOL fOk;  
      
    fOk = ReleaseMutex(m_hMute);  
    if(!fOk) {  
        dwStatus = GetLastError();  
    }  
      
    return dwStatus;  
static DWORD KeyPadLock()  
{  
    DWORD dwStatus;  
    
    dwStatus = WaitForSingleObject(m_hMute, INFINITE);  
    if(dwStatus == WAIT_OBJECT_0) {  
        dwStatus = ERROR_SUCCESS;  
    } else {  
        dwStatus = GetLastError();  
    }  
      
    return dwStatus;  
}
 
DWORD IntProcessThread(void)
{
 UINT32 IRQ;
 //UINT32 IODAT;  
    BYTE i, pre, now;  
    //static int count=0;
 RETAILMSG(1, (TEXT("IntProcessThread start!!!!\r\n")));
 IntEvent = CreateEvent(NULL, FALSE, FALSE, NULL);   
 if (!IntEvent)
 {
  RETAILMSG(1, (TEXT("ERROR: kEYBD: Failed to create event.\r\n")));
  return FALSE;
 }
 //
 IRQ = IRQ_EINT3; //IRQ_EINT3;
 if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &IRQ, sizeof(UINT32),
   &g_KeySysIntr[0], sizeof(UINT32), NULL))
 {
  RETAILMSG(1,
   (TEXT("ERROR: kEYBD: Failed to request sysintr value.\r\n")));
  return FALSE;
 }
 IRQ = IRQ_EINT11; //IRQ_EINT11;
 if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &IRQ, sizeof(UINT32),
   &g_KeySysIntr[1], sizeof(UINT32), NULL))
 {
  RETAILMSG(1,
   (TEXT("ERROR: kEYBD: Failed to request sysintr value.\r\n")));
  return FALSE;
 }
 IRQ = IRQ_EINT13; //IRQ_EINT13;
 if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &IRQ, sizeof(UINT32),
   &g_KeySysIntr[2], sizeof(UINT32), NULL))
 {
  RETAILMSG(1,
   (TEXT("ERROR: kEYBD: Failed to request sysintr value.\r\n")));
  return FALSE;
 }
 IRQ = IRQ_EINT15; //IRQ_EINT15;
 if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &IRQ, sizeof(UINT32),
   &g_KeySysIntr[3], sizeof(UINT32), NULL))
 {
  RETAILMSG(1,
   (TEXT("ERROR: kEYBD: Failed to request sysintr value.\r\n")));
  return FALSE;
 }
 IRQ = IRQ_EINT9; //IRQ_EINT9;
 if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &IRQ, sizeof(UINT32),
   &g_KeySysIntr[4], sizeof(UINT32), NULL))
 {
  RETAILMSG(1,
   (TEXT("ERROR: kEYBD: Failed to request sysintr value.\r\n")));
  return FALSE;
 }
 if (!InterruptInitialize(g_KeySysIntr[0], IntEvent, NULL, 0))
 {
  RETAILMSG(1, (TEXT("Fail to initialize userkey interrupt event\r\n")));
  return FALSE;
 }
 if (!InterruptInitialize(g_KeySysIntr[1], IntEvent, NULL, 0))
 {
  RETAILMSG(1, (TEXT("Fail to initialize userkey interrupt event\r\n")));
  return FALSE;
 }
 if (!InterruptInitialize(g_KeySysIntr[2], IntEvent, NULL, 0))
 {
  RETAILMSG(1, (TEXT("Fail to initialize userkey interrupt event\r\n")));
  return FALSE;
 }
 if (!InterruptInitialize(g_KeySysIntr[3], IntEvent, NULL, 0))
 {
  RETAILMSG(1, (TEXT("Fail to initialize userkey interrupt event\r\n")));
  return FALSE;
 }
 if (!InterruptInitialize(g_KeySysIntr[4], IntEvent, NULL, 0))
 {
  RETAILMSG(1, (TEXT("Fail to initialize userkey interrupt event\r\n")));
  return FALSE;
 }

 while (1)
 {
  WaitForSingleObject(IntEvent, INFINITE);
  RETAILMSG(1,
   (L"INTMASK=%X, EINTMASK=%X, GPGCON=%X\r\n", v_pINTRregs->INTMSK,
   v_pIOPregs->EINTMASK, v_pIOPregs->GPFCON));
  //EINT3
  if (v_pINTRregs->INTMSK & (1 << IRQ_EINT3))   //INTMASK外部中断屏蔽寄存器
  {
   //判断中断输入脚是否稳定,消除按键抖动
   KeyPadLock();
   pre = (v_pIOPregs->GPFDAT & (0x1 << 3));
            for(i=0;i<3;i++)
   {
     Sleep(3);
     now = (v_pIOPregs->GPFDAT & (0x1 << 3));
     if (pre!=now)
     {
       KeyPadUnLock();
                InterruptDone(g_KeySysIntr[0]);
    break;
     }
   }
   KeyPadUnLock();
   if(v_pIOPregs->GPFDAT & (0x1 << 3))//键弹起
   {
     keybd_event(Virtualkey0, 0, KEYEVENTF_KEYUP, 0);
   }
   else
   {
     AllOutpinHigh();  //全部输出高,开始轮询
              //GPG2
           v_pIOPregs->GPGDAT &= ~(0x1 << 2);  //GPG2输出低
           Sleep(3);
           if ((v_pIOPregs->GPFDAT & (0x1 << 3))==0)
            {
             Virtualkey0 = 0x41;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
              v_pIOPregs->GPGDAT |= (0x1 << 2);  //GPG2输出高
 
             //GPG13
             v_pIOPregs->GPGDAT &= ~(0x1 << 13);  //GPG13输出低
             Sleep(3);
           if ((v_pIOPregs->GPFDAT & (0x1 << 3))==0)
            {
             Virtualkey0 = 0x42;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPGDAT |= (0x1 << 13);  //GPG13输出高
 
             //GPB7
              v_pIOPregs->GPBDAT &= ~(0x1 << 7);  //GPB7输出低
             Sleep(3);
              if ((v_pIOPregs->GPFDAT & (0x1 << 3))==0)
            {
             Virtualkey0 = 0x43;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
              v_pIOPregs->GPBDAT |= (0x1 << 7);  //GPB7输出高
 
             //GPB5
             v_pIOPregs->GPBDAT &= ~(0x1 << 5);  //GPB5输出低
             Sleep(3);
             if ((v_pIOPregs->GPFDAT & (0x1 << 3))==0)
            {
             Virtualkey0 = 0x44;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPBDAT |= (0x1 << 5);  //GPB5输出高
 
           //GPG14
           v_pIOPregs->GPGDAT &= ~(0x1 << 14);  //GPG14输出低
             Sleep(3);
             if ((v_pIOPregs->GPFDAT & (0x1 << 3))==0)
            {
             Virtualkey0 = 0x45;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPGDAT |= (0x1 << 14);  //GPG14输出高
 
           //GPB6
             v_pIOPregs->GPBDAT &= ~(0x1 << 6);  //GPB6输出低
             Sleep(3);
             if ((v_pIOPregs->GPFDAT & (0x1 << 3))==0)
            {
             Virtualkey0 = 0x46;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPBDAT |= (0x1 << 6);  //GPB6输出高
 
             //GPB8
             v_pIOPregs->GPBDAT &= ~(0x1 << 8);  //GPB8输出低
             Sleep(3);
             if ((v_pIOPregs->GPFDAT & (0x1 << 3))==0)
            {
             Virtualkey0 = 0x47;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPBDAT |= (0x1 << 8);  //GPB8输出高
 
             //GPE13
           v_pIOPregs->GPEDAT &= ~(0x1 << 13);  //GPE13输出低
           Sleep(3);
             if ((v_pIOPregs->GPFDAT & (0x1 << 3))==0)
            {
             Virtualkey0 = 0x48;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
           v_pIOPregs->GPEDAT |= (0x1 << 13);  //GPE13输出高
 
             AllOutpinLow();
   }
   InterruptDone(g_KeySysIntr[0]);
  }
  //EINT11
  if (v_pIOPregs->EINTMASK & (1 << 11))
  {
   //判断中断输入脚是否稳定,消除按键抖动
   KeyPadLock();
   pre = (v_pIOPregs->GPGDAT & (0x1 << 3));
            for(i=0;i<3;i++)
   {
     Sleep(3);
     now = (v_pIOPregs->GPGDAT & (0x1 << 3));
     if (pre!=now)
     {
       KeyPadUnLock();
                InterruptDone(g_KeySysIntr[1]);
    break;
     }
   }
   KeyPadUnLock();
   if(v_pIOPregs->GPGDAT & (0x1 << 3))
   {
     keybd_event(Virtualkey0, 0, KEYEVENTF_KEYUP, 0);
   }
   else
   {
     AllOutpinHigh();  //全部输出高,开始轮询
              //GPG2
           v_pIOPregs->GPGDAT &= ~(0x1 << 2);  //GPG2输出低
           Sleep(3);
           if ((v_pIOPregs->GPGDAT & (0x1 << 3))==0)
            {
             Virtualkey0 = 0x49;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
              v_pIOPregs->GPGDAT |= (0x1 << 2);  //GPG2输出高
 
             //GPG13
             v_pIOPregs->GPGDAT &= ~(0x1 << 13);  //GPG13输出低
             Sleep(3);
           if ((v_pIOPregs->GPGDAT & (0x1 << 3))==0)
            {
             Virtualkey0 = 0x4a;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPGDAT |= (0x1 << 13);  //GPG13输出高
 
             //GPB7
              v_pIOPregs->GPBDAT &= ~(0x1 << 7);  //GPB7输出低
             Sleep(3);
              if ((v_pIOPregs->GPGDAT & (0x1 << 3))==0)
            {
             Virtualkey0 = 0x4b;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
              v_pIOPregs->GPBDAT |= (0x1 << 7);  //GPB7输出高
 
             //GPB5
             v_pIOPregs->GPBDAT &= ~(0x1 << 5);  //GPB5输出低
             Sleep(3);
             if ((v_pIOPregs->GPGDAT & (0x1 << 3))==0)
            {
             Virtualkey0 = 0x4c;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPBDAT |= (0x1 << 5);  //GPB5输出高
 
           //GPG14
           v_pIOPregs->GPGDAT &= ~(0x1 << 14);  //GPG14输出低
             Sleep(3);
             if ((v_pIOPregs->GPGDAT & (0x1 << 3))==0)
            {
             Virtualkey0 = 0x4d;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPGDAT |= (0x1 << 14);  //GPG14输出高
 
           //GPB6
             v_pIOPregs->GPBDAT &= ~(0x1 << 6);  //GPB6输出低
             Sleep(3);
             if ((v_pIOPregs->GPGDAT & (0x1 << 3))==0)
            {
             Virtualkey0 = 0x4e;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPBDAT |= (0x1 << 6);  //GPB6输出高
 
             //GPB8
             v_pIOPregs->GPBDAT &= ~(0x1 << 8);  //GPB8输出低
             Sleep(3);
             if ((v_pIOPregs->GPGDAT & (0x1 << 3))==0)
            {
             Virtualkey0 = 0x4f;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPBDAT |= (0x1 << 8);  //GPB8输出高
 
             //GPE13
           v_pIOPregs->GPEDAT &= ~(0x1 << 13);  //GPE13输出低
           Sleep(3);
             if ((v_pIOPregs->GPGDAT & (0x1 << 3))==0)
            {
             Virtualkey0 = 0x50;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
           v_pIOPregs->GPEDAT |= (0x1 << 13);  //GPE13输出高
 
             AllOutpinLow();
   }
   InterruptDone(g_KeySysIntr[1]);
  }
  //EINT13
  if (v_pIOPregs->EINTMASK & (1 << 13))
  {
            //判断中断输入脚是否稳定,消除按键抖动
   KeyPadLock();
   pre = (v_pIOPregs->GPGDAT & (0x1 << 5));
            for(i=0;i<3;i++)
   {
     Sleep(3);
     now = (v_pIOPregs->GPGDAT & (0x1 << 5));
     if (pre!=now)
     {
       KeyPadUnLock();
                InterruptDone(g_KeySysIntr[2]);
    break;
     }
   }
   KeyPadUnLock();
   if(v_pIOPregs->GPGDAT & (0x1 << 5))
   {
     keybd_event(Virtualkey0, 0, KEYEVENTF_KEYUP, 0);
   }
   else
   {
     AllOutpinHigh();  //全部输出高,开始轮询
              //GPG2
           v_pIOPregs->GPGDAT &= ~(0x1 << 2);  //GPG2输出低
           Sleep(3);
           if ((v_pIOPregs->GPGDAT & (0x1 << 5))==0)
            {
             Virtualkey0 = 0x51;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
              v_pIOPregs->GPGDAT |= (0x1 << 2);  //GPG2输出高
 
             //GPG13
             v_pIOPregs->GPGDAT &= ~(0x1 << 13);  //GPG13输出低
             Sleep(3);
           if ((v_pIOPregs->GPGDAT & (0x1 << 5))==0)
            {
             Virtualkey0 = 0x52;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPGDAT |= (0x1 << 13);  //GPG13输出高
 
             //GPB7
              v_pIOPregs->GPBDAT &= ~(0x1 << 7);  //GPB7输出低
             Sleep(3);
              if ((v_pIOPregs->GPGDAT & (0x1 << 5))==0)
            {
             Virtualkey0 = 0x53;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
              v_pIOPregs->GPBDAT |= (0x1 << 7);  //GPB7输出高
 
             //GPB5
             v_pIOPregs->GPBDAT &= ~(0x1 << 5);  //GPB5输出低
             Sleep(3);
             if ((v_pIOPregs->GPGDAT & (0x1 << 5))==0)
            {
             Virtualkey0 = 0x54;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPBDAT |= (0x1 << 5);  //GPB5输出高
 
           //GPG14
           v_pIOPregs->GPGDAT &= ~(0x1 << 14);  //GPG14输出低
             Sleep(3);
             if ((v_pIOPregs->GPGDAT & (0x1 << 5))==0)
            {
             Virtualkey0 = 0x55;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPGDAT |= (0x1 << 14);  //GPG14输出高
 
           //GPB6
             v_pIOPregs->GPBDAT &= ~(0x1 << 6);  //GPB6输出低
             Sleep(3);
             if ((v_pIOPregs->GPGDAT & (0x1 << 5))==0)
            {
             Virtualkey0 = 0x56;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPBDAT |= (0x1 << 6);  //GPB6输出高
 
             //GPB8
             v_pIOPregs->GPBDAT &= ~(0x1 << 8);  //GPB8输出低
             Sleep(3);
             if ((v_pIOPregs->GPGDAT & (0x1 << 5))==0)
            {
             Virtualkey0 = 0x57;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPBDAT |= (0x1 << 8);  //GPB8输出高
 
             //GPE13
           v_pIOPregs->GPEDAT &= ~(0x1 << 13);  //GPE13输出低
           Sleep(3);
             if ((v_pIOPregs->GPGDAT & (0x1 << 5))==0)
            {
             Virtualkey0 = 0x58;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
           v_pIOPregs->GPEDAT |= (0x1 << 13);  //GPE13输出高
 
             AllOutpinLow();
   }
            InterruptDone(g_KeySysIntr[2]);
  }
  //EINT15
  if (v_pIOPregs->EINTMASK & (1 << 15))
  {
   //判断中断输入脚是否稳定,消除按键抖动
   KeyPadLock();
   pre = (v_pIOPregs->GPGDAT & (0x1 << 7));
            for(i=0;i<3;i++)
   {
     Sleep(3);
     now = (v_pIOPregs->GPGDAT & (0x1 << 7));
     if (pre!=now)
     {
       KeyPadUnLock();
                InterruptDone(g_KeySysIntr[3]);
    break;
     }
   }
   KeyPadUnLock();
   if(v_pIOPregs->GPGDAT & (0x1 << 7))
   {
     keybd_event(Virtualkey0, 0, KEYEVENTF_KEYUP, 0);
   }
   else
   {
     AllOutpinHigh();  //全部输出高,开始轮询
              //GPG2
           v_pIOPregs->GPGDAT &= ~(0x1 << 2);  //GPG2输出低
           Sleep(3);
           if ((v_pIOPregs->GPGDAT & (0x1 << 7))==0)
            {
             Virtualkey0 = 0x59;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
              v_pIOPregs->GPGDAT |= (0x1 << 2);  //GPG2输出高
 
             //GPG13
             v_pIOPregs->GPGDAT &= ~(0x1 << 13);  //GPG13输出低
             Sleep(3);
           if ((v_pIOPregs->GPGDAT & (0x1 << 7))==0)
            {
             Virtualkey0 = 0x5a;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPGDAT |= (0x1 << 13);  //GPG13输出高
 
             //GPB7
              v_pIOPregs->GPBDAT &= ~(0x1 << 7);  //GPB7输出低
             Sleep(3);
              if ((v_pIOPregs->GPGDAT & (0x1 << 7))==0)
            {
             Virtualkey0 = 0x31;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
              v_pIOPregs->GPBDAT |= (0x1 << 7);  //GPB7输出高
 
             //GPB5
             v_pIOPregs->GPBDAT &= ~(0x1 << 5);  //GPB5输出低
             Sleep(3);
             if ((v_pIOPregs->GPGDAT & (0x1 << 7))==0)
            {
             Virtualkey0 = 0x32;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPBDAT |= (0x1 << 5);  //GPB5输出高
 
           //GPG14
           v_pIOPregs->GPGDAT &= ~(0x1 << 14);  //GPG14输出低
             Sleep(3);
             if ((v_pIOPregs->GPGDAT & (0x1 << 7))==0)
            {
             Virtualkey0 = 0x33;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPGDAT |= (0x1 << 14);  //GPG14输出高
 
           //GPB6
             v_pIOPregs->GPBDAT &= ~(0x1 << 6);  //GPB6输出低
             Sleep(3);
             if ((v_pIOPregs->GPGDAT & (0x1 << 7))==0)
            {
             Virtualkey0 = 0x34;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPBDAT |= (0x1 << 6);  //GPB6输出高
 
             //GPB8
             v_pIOPregs->GPBDAT &= ~(0x1 << 8);  //GPB8输出低
             Sleep(3);
             if ((v_pIOPregs->GPGDAT & (0x1 << 7))==0)
            {
             Virtualkey0 = 0x35;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPBDAT |= (0x1 << 8);  //GPB8输出高
 
             //GPE13
           v_pIOPregs->GPEDAT &= ~(0x1 << 13);  //GPE13输出低
           Sleep(3);
             if ((v_pIOPregs->GPGDAT & (0x1 << 7))==0)
            {
             Virtualkey0 = 0x36;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
           v_pIOPregs->GPEDAT |= (0x1 << 13);  //GPE13输出高
 
             AllOutpinLow();
   }
            InterruptDone(g_KeySysIntr[3]);
  }
  //EINT9
  if (v_pIOPregs->EINTMASK & (1 << 9))
  {
   //判断中断输入脚是否稳定,消除按键抖动
   KeyPadLock();
   pre = (v_pIOPregs->GPGDAT & (0x1 << 1));
            for(i=0;i<3;i++)
   {
     Sleep(3);
     now = (v_pIOPregs->GPGDAT & (0x1 << 1));
     if (pre!=now)
     {
       KeyPadUnLock();
                InterruptDone(g_KeySysIntr[4]);
    break;
     }
   }
   KeyPadUnLock();
   if(v_pIOPregs->GPGDAT & (0x1 << 1))
   {
     keybd_event(Virtualkey0, 0, KEYEVENTF_KEYUP, 0);
   }
   else
   {
     AllOutpinHigh();  //全部输出高,开始轮询
              //GPG2
           v_pIOPregs->GPGDAT &= ~(0x1 << 2);  //GPG2输出低
           Sleep(3);
           if ((v_pIOPregs->GPGDAT & (0x1 << 1))==0)
            {
             Virtualkey0 = 0x37;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
              v_pIOPregs->GPGDAT |= (0x1 << 2);  //GPG2输出高
 
             //GPG13
             v_pIOPregs->GPGDAT &= ~(0x1 << 13);  //GPG13输出低
             Sleep(3);
           if ((v_pIOPregs->GPGDAT & (0x1 << 1))==0)
            {
             Virtualkey0 = 0x38;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPGDAT |= (0x1 << 13);  //GPG13输出高
 
             //GPB7
              v_pIOPregs->GPBDAT &= ~(0x1 << 7);  //GPB7输出低
             Sleep(3);
              if ((v_pIOPregs->GPGDAT & (0x1 << 1))==0)
            {
             Virtualkey0 = 0x39;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
              v_pIOPregs->GPBDAT |= (0x1 << 7);  //GPB7输出高
 
             //GPB5
             v_pIOPregs->GPBDAT &= ~(0x1 << 5);  //GPB5输出低
             Sleep(3);
             if ((v_pIOPregs->GPGDAT & (0x1 << 1))==0)
            {
             Virtualkey0 = 0xba;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPBDAT |= (0x1 << 5);  //GPB5输出高
 
           //GPG14
           v_pIOPregs->GPGDAT &= ~(0x1 << 14);  //GPG14输出低
             Sleep(3);
             if ((v_pIOPregs->GPGDAT & (0x1 << 1))==0)
            {
             Virtualkey0 = 0xbb;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPGDAT |= (0x1 << 14);  //GPG14输出高
 
           //GPB6
             v_pIOPregs->GPBDAT &= ~(0x1 << 6);  //GPB6输出低
             Sleep(3);
             if ((v_pIOPregs->GPGDAT & (0x1 << 1))==0)
            {
             Virtualkey0 = 0xbc;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPBDAT |= (0x1 << 6);  //GPB6输出高
 
             //GPB8
             v_pIOPregs->GPBDAT &= ~(0x1 << 8);  //GPB8输出低
             Sleep(3);
             if ((v_pIOPregs->GPGDAT & (0x1 << 1))==0)
            {
             Virtualkey0 = 0xbd;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
             v_pIOPregs->GPBDAT |= (0x1 << 8);  //GPB8输出高
 
             //GPE13
           v_pIOPregs->GPEDAT &= ~(0x1 << 13);  //GPE13输出低
           Sleep(3);
             if ((v_pIOPregs->GPGDAT & (0x1 << 1))==0)
            {
             Virtualkey0 = 0xbe;
                    keybd_event(Virtualkey0, 0, 0, 0);
             }
           v_pIOPregs->GPEDAT |= (0x1 << 13);  //GPE13输出高
 
             AllOutpinLow();
   }
            InterruptDone(g_KeySysIntr[4]);
  }
 }
}

BOOL WINAPI
DllEntry(HANDLE hinstDLL, DWORD dwReason,
 LPVOID  Reserved/* lpvReserved */)
{
 switch (dwReason)
 {
 case DLL_PROCESS_ATTACH:
  DEBUGREGISTER((HINSTANCE) hinstDLL);
  return TRUE;
 case DLL_THREAD_ATTACH:
  break;
 case DLL_THREAD_DETACH:
  break;
 case DLL_PROCESS_DETACH:
  break;
#ifdef UNDER_CE
 case DLL_PROCESS_EXITING:
  break;
 case DLL_SYSTEM_STARTED:
  break;
#endif
 }
 return TRUE;
}
BOOL MKB_Deinit(DWORD hDeviceContext)
{
 BOOL bRet = TRUE;
 RETAILMSG(1, (TEXT("USERKEY: MDD_Deinit\r\n")));
 for (int i = 0; i < 5; i++)
  InterruptDisable(g_KeySysIntr[i]);
 CloseHandle(IntThread);
 CloseHandle(IntEvent);
 VirtualFree((void *) v_pIOPregs, sizeof(S3C2440A_IOPORT_REG), MEM_RELEASE);
 VirtualFree((void *) v_pINTRregs, sizeof(S3C2440A_INTR_REG), MEM_RELEASE);
 return TRUE;
}
void AllOutpinHigh()
{
 v_pIOPregs->GPBDAT |= (0xf << 5);        /*将各Output端口输出高电平*/
 v_pIOPregs->GPEDAT |= (0x3 << 12);
 v_pIOPregs->GPGDAT |= (0x1 << 2);
 v_pIOPregs->GPGDAT |= (0x3 << 13);
 }
 
void AllOutpinLow()
{
 v_pIOPregs->GPBDAT &= ~(0xf << 5);       /*将各Output端口输出低电平*/
 v_pIOPregs->GPEDAT &= ~(0x3 << 12);
 v_pIOPregs->GPGDAT &= ~(0x1 << 2);
 v_pIOPregs->GPGDAT &= ~(0x3 << 13);
 }
BOOL Eint_GPIO_Init()
{
 RETAILMSG(1,
   (L"GPGCON=%X\r\n", v_pIOPregs->GPGCON));
 v_pIOPregs->GPFCON &= ~(0x3 << 6);    /* Set EINT3(GPF3) as EINT3       */
 v_pIOPregs->GPFCON |= (0x2 << 6);
 v_pIOPregs->GPGCON &= ~(0x3 << 6);   /* Set EINT11(GPG3) as EINEINT11      */
 v_pIOPregs->GPGCON |= (0x2 << 6);
 v_pIOPregs->GPGCON &= ~(0x3 << 10);   /* Set EINT13(GPG5) as EINT13     */
 v_pIOPregs->GPGCON |= (0x2 << 10);
 v_pIOPregs->GPGCON &= ~(0x3 << 14);   /* Set EINT15(GPG7) as EINT15    */
 v_pIOPregs->GPGCON |= (0x2 << 14);
 v_pIOPregs->GPGCON &= ~(0x3 << 2);   /* Set EINT9(GPG1) as EINT9      */
 v_pIOPregs->GPGCON |= (0x2 << 2);
 v_pIOPregs->EXTINT0 &= ~(0x7 << 12); /* Configure EINT3 as Falling Edge Mode    */
 v_pIOPregs->EXTINT0 |= (0x2 << 12);
 v_pIOPregs->EXTINT1 &= ~(0x7 << 12); /* Configure EINT11 as Falling Edge Mode    */
 v_pIOPregs->EXTINT1 |= (0x2 << 12);
 v_pIOPregs->EXTINT1 &= ~(0x7 << 20); /* Configure EINT13 as Falling Edge Mode    */
 v_pIOPregs->EXTINT1 |= (0x2 << 20);
 v_pIOPregs->EXTINT1 &= ~(0x7 << 28); /* Configure EINT15 as Falling Edge Mode    */
 v_pIOPregs->EXTINT1 |= (0x2 << 28);
 v_pIOPregs->EXTINT1 &= ~(0x7 << 4); /* Configure EINT9 as Falling Edge Mode    */
 v_pIOPregs->EXTINT1 |= (0x2 << 4);
 
 v_pIOPregs->GPBCON &= ~(0xff<< 10);   /*将各列对应IO口(GPB5-8,GPE12-13,GPG2、13、14)设置为Output*/  
 v_pIOPregs->GPBCON |= (0x55 << 10);
 
 v_pIOPregs->GPECON &= ~(0xf << 24);
 v_pIOPregs->GPECON |= (0x5 << 24);
    
 v_pIOPregs->GPGCON &= ~(0x3 << 4);
 v_pIOPregs->GPGCON |= (0x1 << 4);
 
 v_pIOPregs->GPGCON &= ~(0xf << 26);
 v_pIOPregs->GPGCON |= (0x5 << 26);
 
 AllOutpinLow();
 
 /*v_pIOPregs->GPBCON &= ~(0x3 << 10);
 v_pIOPregs->GPBCON |=  (0x1 << 10);
 v_pIOPregs->GPBCON &= ~(0x3 << 12);
 v_pIOPregs->GPBCON |=  (0x1 << 12);
 v_pIOPregs->GPBCON &= ~(0x3 << 14);
 v_pIOPregs->GPBCON |=  (0x1 << 14);
 v_pIOPregs->GPBCON &= ~(0x3 << 16);
 v_pIOPregs->GPBCON |=  (0x1 << 16);
 //v_pIOPregs->GPBDAT &= ~(0xF<<5);
    //v_pIOPregs->GPBCON &= ~(0xff << 10);        //设置为input*/
 RETAILMSG(1,
   (L"GPGCON=%X\r\n", v_pIOPregs->GPGCON));
 return TRUE;
}
DWORD MKB_Init(LPCTSTR pContext)
{
 DWORD isSuccess=1; //assume success
 DWORD error=0; //接受出错码
 DWORD threadID;       // thread ID
  RETAILMSG(1,(TEXT("GPI_init\r\n")));

  ///////////////////////////////////
  //为v_pIOPregs 变量分配虚拟空间
  ///////////////////////////////////
 
  v_pIOPregs = (volatile S3C2440A_IOPORT_REG *)VirtualAlloc(0,
                sizeof(S3C2440A_IOPORT_REG), MEM_RESERVE,PAGE_NOACCESS);
  if (v_pIOPregs == NULL) //分配虚拟空间不成功
  {
     ERRORMSG(1,(TEXT("For IOPregs : VirtualAlloc failed!\r\n")));
     error=GetLastError(); //获得出错码
     printf("For IOPregs : VirtualAlloc failed!%d\r\n",error);
     isSuccess = 0;
  }
  else
  {/*把v_pIOPregs 虚拟空间映射到物理内存*/
    if(!VirtualCopy((PVOID)v_pIOPregs,
       (PVOID)(S3C2440A_BASE_REG_PA_IOPORT>>8) , sizeof(S3C2440A_IOPORT_REG),
       PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE))
 {
       ERRORMSG(1,(TEXT("For IOPregs: VirtualCopy failed!\r\n")));
       isSuccess = 0;
 }
  }
  if (!isSuccess) /*分配虚拟空间或映射到物理内存失败*/
  {
 if (v_pIOPregs) /* 如果v_pIOPregs 变量非无效*/
 {
       VirtualFree((PVOID) v_pIOPregs, 0, MEM_RELEASE); /*释放虚拟空间*/
 }
    v_pIOPregs = NULL;
  }
    ///////////////////////////////////
    //为v_pINTRregs 变量分配虚拟空间
    ///////////////////////////////////
   
  v_pINTRregs = (volatile S3C2440A_INTR_REG *)VirtualAlloc(0,
                sizeof(S3C2440A_INTR_REG), MEM_RESERVE,PAGE_NOACCESS);
  if (v_pINTRregs == NULL) //分配虚拟空间不成功
  {
     ERRORMSG(1,(TEXT("For INPregs : VirtualAlloc failed!\r\n")));
     error=GetLastError(); //获得出错码
     printf("For INPregs : VirtualAlloc failed!%d\r\n",error);
     isSuccess = 0;
  }
  else
  {/*把v_pINTRregs 虚拟空间映射到物理内存*/
    if(!VirtualCopy((PVOID)v_pINTRregs,
       (PVOID)(S3C2440A_BASE_REG_PA_INTR>>8) , sizeof(S3C2440A_INTR_REG),
       PAGE_PHYSICAL | PAGE_READWRITE | PAGE_NOCACHE))
 {
       ERRORMSG(1,(TEXT("For INPregs: VirtualCopy failed!\r\n")));
       isSuccess = 0;
 }
  }
  if (!isSuccess) /*分配虚拟空间或映射到物理内存失败*/
  {
 if (v_pINTRregs) /* 如果v_pINTRregs 变量非无效*/
 {
       VirtualFree((PVOID) v_pINTRregs, 0, MEM_RELEASE); /*释放虚拟空间*/
 }
    v_pINTRregs = NULL;
  }
 
  Eint_GPIO_Init();
 
  IntThread = CreateThread(NULL, 0,
     (LPTHREAD_START_ROUTINE) IntProcessThread, 0, 0, &threadID);
 if (NULL == IntThread)
 {
  RETAILMSG(1, (TEXT("ERROR: failed to Create Key Thread!\r\n")));
  return FALSE;
 }
  return (isSuccess);
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
BOOL MKB_IOControl(DWORD hOpenContext, DWORD dwCode, PBYTE pBufIn,
 DWORD dwLenIn, PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut)
{
 return TRUE;
}
DWORD MKB_Open(DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode)
{
 return TRUE;
}
BOOL MKB_Close(DWORD hOpenContext)
{
 return TRUE;
}
DWORD MKB_Read(DWORD hOpenContext, LPVOID pBuffer, DWORD Count)
{
 RETAILMSG(1, (TEXT("USERKEY: MDD_Read\r\n")));
 return TRUE;
}
DWORD MKB_Seek(DWORD hOpenContext, long Amount, DWORD Type)
{
 return 0;
}
DWORD MKB_Write(DWORD hOpenContext, LPCVOID pSourceBytes, DWORD NumberOfBytes)
{
 return 0;
}
阅读(1221) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-05-17 21:56:25

你好,请问您这是什么板子的?

chinaunix网友2010-05-10 12:53:10

有全的代码吗?我现在正在做一个5X6的键盘驱动,以前没做过,需要你的参考一下,谢谢了!我的邮箱:ly_xia@yeah.net