• «
  • 1
  • 2
  • »
  • Pages: 1/2     Go
主题 : wince6.0  4*5矩阵键盘 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 16436
精华: 0
发帖: 21
金钱: 105 两
威望: 21 点
贡献值: 0 点
综合积分: 42 分
注册时间: 2010-03-17
最后登录: 2013-03-30
楼主  发表于: 2010-07-23 16:44

 wince6.0  4*5矩阵键盘

4*5的矩阵键盘,就在友善之比wince6.0 的usekey修改而来,已测试通过
喜欢的可以看看,有疑问的请回个帖


#include <windows.h>
//#include <ceddk.h>
#include <nkintr.h>
//#include <oalintr.h>
#include <pm.h>
#include "pmplatform.h"
#include "Pkfuncs.h"
#include "s2440.h"


volatile IOPreg     *s2440IOP = (IOPreg *)IOP_BASE;
volatile INTreg     *s2440INT = (INTreg *)INT_BASE;
UINT32 g_KeySysIntr[6];
HANDLE KeyThread;
HANDLE KeyEvent;

BYTE Virtualkey;

void Virtual_Alloc();                        // Virtual allocation
DWORD UserKeyProcessThread(void);

const TCHAR szevtUserInput[] = L"FriendlyARM/ButtonEvent";

static void EINT_2_INPUT()
{
    s2440IOP->rGPGCON  = (s2440IOP->rGPGCON  & ~(0x3 << 0)) | (0x0 << 0);    // GPG0 == EINT8        
    
    s2440IOP->rGPGCON  = (s2440IOP->rGPGCON  & ~(0x3 << 6)) | (0x0 << 6);    // GPG3 == EINT11    

    s2440IOP->rGPGCON  = (s2440IOP->rGPGCON  & ~(0x3 << 10)) | (0x0 << 10);    // GPG5 == EINT13    

    s2440IOP->rGPGCON  = (s2440IOP->rGPGCON  & ~(0x3 << 12)) | (0x0 << 12);    // GPG6 == EINT14        
}

static void INPUT_2_EINT()
{
    s2440IOP->rGPGCON  = (s2440IOP->rGPGCON  & ~(0x3 << 0x0)) | (0x2 << 0x0);    // GPG0 == EINT8
    s2440IOP->rEXTINT1 = (s2440IOP->rEXTINT1 & ~(0x7<< 0)) | (0x6 << 0);        
    
    s2440IOP->rGPGCON  = (s2440IOP->rGPGCON  & ~(0x3 << 6)) | (0x2 << 6);    // GPG3 == EINT11
    s2440IOP->rEXTINT1 = (s2440IOP->rEXTINT1 & ~(0x7<< 12)) | (0x6 << 12);        

    s2440IOP->rGPGCON  = (s2440IOP->rGPGCON  & ~(0x3 << 10)) | (0x2 << 10);    // GPG5 == EINT13
    s2440IOP->rEXTINT1 = (s2440IOP->rEXTINT1 & ~(0x7<< 20)) | (0x6 << 20);        

    s2440IOP->rGPGCON  = (s2440IOP->rGPGCON  & ~(0x3 << 12)) | (0x2 << 12);    // GPG6 == EINT14
    s2440IOP->rEXTINT1 = (s2440IOP->rEXTINT1 & ~(0x7<< 24)) | (0x6 << 24);    
}


DWORD UserKeyProcessThread(void)
{

    HANDLE UserInputEvent = CreateEvent(NULL, FALSE, FALSE, szevtUserInput);
    UINT32 IRQ[4]={36,39,41,42};//IRQ_EINT8;IRQ_EINT11;IRQ_EINT13;IRQ_EINT14
    static int count=0;

    for(int i=0;i<4;i++)
    {
        if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &IRQ, sizeof(UINT32), &g_KeySysIntr, sizeof(UINT32), NULL))
        {
            RETAILMSG(1, (TEXT("ERROR: kEYBD: Failed to request sysintr value.\r\n")));
            return FALSE;
        }
        if (!InterruptInitialize(g_KeySysIntr, KeyEvent, NULL, 0))
        {
            RETAILMSG(1,(TEXT("Fail to initialize userkey interrupt event\r\n")));
            return FALSE;
        }
    }

    while(1)
    {
        WaitForSingleObject(KeyEvent, INFINITE);
        SetEvent(UserInputEvent);
        RETAILMSG(0,(L"EINTMASK=%X, rGPGCON=%X rGPGDAT=%X\r\n", s2440IOP->rEINTMASK, s2440IOP->rGPGCON, s2440IOP->rGPGDAT));
        EINT_2_INPUT();
        UINT32 Eint[4]={0x1<<8,0x1<<11,0x1<<13,0x1<<14};
        UINT32 Index_Get_Data[4] ={0x1<<0, 0x1<<3, 0x1<<5, 0x1<<6};
        UINT32 Output_data[5] ={0x1<<0, 0x1<<1, 0x1<<2, 0x1<<3, 0x1<<4};
        //EINT8 - K1
        for(int row=0;row<4;row++)
        {
            if(s2440IOP->rEINTMASK & Eint[row])
            {
                Sleep(3);
                if(s2440IOP->rGPGDAT & Index_Get_Data[row])
                {
                    keybd_event(Virtualkey,0, KEYEVENTF_EXTENDEDKEY|KEYEVENTF_KEYUP, 0);
                }
                else
                {
                    s2440IOP->rGPFDAT  |= (((0x1<<0)|(0x1<<1)|(0x1<<2)|(0x1<<3)|(0x1<<4)));
                    for(int array=0;array<5;array++)
                    {
                        s2440IOP->rGPFDAT &= (~ Output_data[array]);
                        Sleep(3);
                        while(!(s2440IOP->rGPGDAT & Index_Get_Data[row]))
                        {
                            Sleep(10);
                            if(count==0)
                            {
                                Virtualkey=0x41+5*row+array;
                                keybd_event(Virtualkey,0, KEYEVENTF_EXTENDEDKEY|0, 0);
                                count++;
                            }
                        }
                        count=0;
                        s2440IOP->rGPFDAT |= Output_data[array];
                    }
                    s2440IOP->rGPFDAT  &= (~((0x1<<0)|(0x1<<1)|(0x1<<2)|(0x1<<3)|(0x1<<4)));
                }
                InterruptDone(g_KeySysIntr[row]);
            }
        }
        INPUT_2_EINT();
    }
}



void Virtual_Alloc()
{

    // GPIO Virtual alloc
    s2440IOP = (volatile IOPreg *) VirtualAlloc(0,sizeof(IOPreg),MEM_RESERVE, PAGE_NOACCESS);
    if(s2440IOP == NULL) {
        RETAILMSG(1,(TEXT("For s2440IOP: VirtualAlloc failed!\r\n")));
    }
    else {
        if(!VirtualCopy((PVOID)s2440IOP,(PVOID)(IOP_BASE),sizeof(IOPreg),PAGE_READWRITE | PAGE_NOCACHE )) {
            RETAILMSG(1,(TEXT("For s2440IOP: VirtualCopy failed!\r\n")));
        }
    }


    // Interrupt Virtual alloc
    s2440INT = (volatile INTreg *) VirtualAlloc(0,sizeof(INTreg),MEM_RESERVE, PAGE_NOACCESS);
    if(s2440INT == NULL) {
        RETAILMSG(1,(TEXT("For s2440INT: VirtualAlloc failed!\r\n")));
    }
    else {
        if(!VirtualCopy((PVOID)s2440INT,(PVOID)(INT_BASE),sizeof(INTreg),PAGE_READWRITE | PAGE_NOCACHE )) {
            RETAILMSG(1,(TEXT("For s2440INT: VirtualCopy failed!\r\n")));
        }
    }
    
}


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 KEY_Deinit(DWORD hDeviceContext)
{
    BOOL bRet = TRUE;
    
    RETAILMSG(1,(TEXT("USERKEY: KEY_Deinit\r\n")));

    for (int i=0; i<6; i++)
        InterruptDisable(g_KeySysIntr);

    
    CloseHandle(KeyThread);
    CloseHandle(KeyEvent);
    VirtualFree((void*)s2440IOP, sizeof(IOPreg), MEM_RELEASE);
    VirtualFree((void*)s2440INT, sizeof(INTreg), MEM_RELEASE);

    return TRUE;
}






BOOL KeyGpioInit()
{
    RETAILMSG(1,(TEXT("Key_Gpio_Setting----\r\n")));
    //s2440IOP->rGPGUP   = 0xffff;
    s2440IOP->rGPGCON  = (s2440IOP->rGPGCON  & ~(0x3 << 0x0)) | (0x2 << 0x0);    // GPG0 == EINT8
    s2440IOP->rEXTINT1 = (s2440IOP->rEXTINT1 & ~(0x7<< 0)) | (0x6 << 0);        
    
    s2440IOP->rGPGCON  = (s2440IOP->rGPGCON  & ~(0x3 << 6)) | (0x2 << 6);    // GPG3 == EINT11
    s2440IOP->rEXTINT1 = (s2440IOP->rEXTINT1 & ~(0x7<< 12)) | (0x6 << 12);        

    s2440IOP->rGPGCON  = (s2440IOP->rGPGCON  & ~(0x3 << 10)) | (0x2 << 10);    // GPG5 == EINT13
    s2440IOP->rEXTINT1 = (s2440IOP->rEXTINT1 & ~(0x7<< 20)) | (0x6 << 20);        

    s2440IOP->rGPGCON  = (s2440IOP->rGPGCON  & ~(0x3 << 12)) | (0x2 << 12);    // GPG6 == EINT14
    s2440IOP->rEXTINT1 = (s2440IOP->rEXTINT1 & ~(0x7<< 24)) | (0x6 << 24);                
    
    s2440IOP->rGPFCON    = (s2440IOP->rGPFCON & ~(0x3 << 0)) | (0x1 << 0);               //F0--F4
    s2440IOP->rGPFCON    = (s2440IOP->rGPFCON & ~(0x3 << 2)) | (0x1 << 2);              
    s2440IOP->rGPFCON    = (s2440IOP->rGPFCON & ~(0x3 << 4)) | (0x1 << 4);                
    s2440IOP->rGPFCON    = (s2440IOP->rGPFCON & ~(0x3 << 6)) | (0x1 << 6);
    s2440IOP->rGPFCON    = (s2440IOP->rGPFCON & ~(0x3 << 8)) | (0x1 << 8);
    s2440IOP->rGPFDAT  &= (~((0x1<<0)|(0x1<<1)|(0x1<<2)|(0x1<<3)|(0x1<<4)));
    return TRUE;
}




DWORD KEY_Init(DWORD dwContext)
{
    DWORD       threadID;                         // thread ID
    RETAILMSG(1,(TEXT("KEY_Init----\r\n")));

    // 1. Virtual Alloc
    Virtual_Alloc();
    
    KeyGpioInit();

    KeyEvent = CreateEvent(NULL, FALSE, FALSE, NULL);    
    if (!KeyEvent)    {
        RETAILMSG(1, (TEXT("ERROR: kEYBD: Failed to create event.\r\n")));
        return FALSE;
    }

    KeyThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)UserKeyProcessThread,  0,  0, &threadID);
    
    if (NULL == KeyThread ) {
        RETAILMSG(1,(TEXT("ERROR: failed to Create Key Thread!\r\n")));
        return FALSE;
    }
    
    return TRUE;
}

//-----------------------------------------------------------------------------
DWORD KEY_Open(DWORD hDeviceContext, DWORD AccessCode, DWORD ShareMode)
{
    return 0;
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
BOOL KEY_Close(DWORD hOpenContext)
{
    RETAILMSG(1,(TEXT("USERKEY: KEY_Close\r\n")));
    return TRUE;
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void KEY_PowerDown(DWORD hDeviceContext)
{
    
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void KEY_PowerUp(DWORD hDeviceContext)
{
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
DWORD KEY_Read(DWORD hOpenContext, LPVOID pBuffer, DWORD Count)
{
    return 0;
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
DWORD KEY_Seek(DWORD hOpenContext, long Amount, DWORD Type)
{
    return 0;
}

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
DWORD KEY_Write(DWORD hOpenContext, LPCVOID pSourceBytes, DWORD NumberOfBytes)
{
    return 0;
}




级别: 新手上路
UID: 26144
精华: 0
发帖: 8
金钱: 40 两
威望: 8 点
贡献值: 0 点
综合积分: 16 分
注册时间: 2010-08-04
最后登录: 2011-03-06
1楼  发表于: 2010-08-14 23:38

 Re:wince6.0 4*5矩阵键盘

不错,受教了
只想要虚心的学些东西,希望大家多多帮助。
级别: 侠客
UID: 19481
精华: 0
发帖: 52
金钱: 260 两
威望: 52 点
贡献值: 0 点
综合积分: 104 分
注册时间: 2010-04-20
最后登录: 2012-05-09
2楼  发表于: 2011-06-14 10:41

 Re:wince6.0 4*5矩阵键盘

非常感谢楼主,哈哈~~~
级别: 新手上路
UID: 48484
精华: 0
发帖: 3
金钱: 15 两
威望: 3 点
贡献值: 0 点
综合积分: 6 分
注册时间: 2011-06-01
最后登录: 2011-07-11
3楼  发表于: 2011-06-16 15:23

 Re:wince6.0 4*5矩阵键盘

谢谢,楼主
只想要虚心的学些东西,希望大家多多帮助。
级别: 侠客
UID: 19481
精华: 0
发帖: 52
金钱: 260 两
威望: 52 点
贡献值: 0 点
综合积分: 104 分
注册时间: 2010-04-20
最后登录: 2012-05-09
4楼  发表于: 2011-07-12 09:44

 Re:wince6.0 4*5矩阵键盘

楼主啊,static void EINT_2_INPUT()函数中每一行后面的注释是不是有问题啊,应该不是EINT,而是INPUT吧。
我刚刚开始接触这些东西,猛的一看到这么多代码就蒙了,楼主可不可以做一下说明啊?
比如:
    1)矩阵键盘引脚数,引脚定义以及如何连接;
    2)模拟的这20个按键都是什么键。
还有就是,我不知道这个程序是属于驱动呢,还是应用呢?不知道如何使用。
因为我现在要在MINI2440上接出来一个键盘,20个按键应该足够了,我得写一下这个键盘的驱动,不知道从何下手呢~~~
所以,希望楼主能多给我讲讲~~~
只想要虚心的学些东西,希望大家多多帮助。
级别: 侠客
UID: 19481
精华: 0
发帖: 52
金钱: 260 两
威望: 52 点
贡献值: 0 点
综合积分: 104 分
注册时间: 2010-04-20
最后登录: 2012-05-09
5楼  发表于: 2011-07-12 09:46

 Re:wince6.0 4*5矩阵键盘

主要是看到你这个帖子很开心,想从你这个程序开始学起~~~
级别: 新手上路
UID: 60402
精华: 0
发帖: 14
金钱: 75 两
威望: 15 点
贡献值: 0 点
综合积分: 28 分
注册时间: 2011-12-09
最后登录: 2014-07-06
6楼  发表于: 2011-12-27 14:23

 Re:wince6.0 4*5矩阵键盘

LZ你代码应该有不少BUG!怪不得我觉得很多疑问~
级别: 新手上路
UID: 116126
精华: 0
发帖: 6
金钱: 30 两
威望: 6 点
贡献值: 0 点
综合积分: 12 分
注册时间: 2015-06-08
最后登录: 2015-09-17
7楼  发表于: 2015-06-25 14:56

 Re:wince6.0  4*5矩阵键盘

你好,我这边用那个VirtualCopy((PVOID)s2440IOP,(PVOID)(IOP_BASE),sizeof(IOPreg),PAGE_READWRITE | PAGE_NOCACHE ),这个函数虚拟不成功是怎么一回事,遇到过吗,求解答是不是我少添加了某个文件??
级别: 禁止发言
UID: 133549
精华: 0
发帖: 2701
金钱: 13505 两
威望: 2701 点
贡献值: 0 点
综合积分: 5402 分
注册时间: 2017-07-06
最后登录: 2017-07-08
8楼  发表于: 2017-07-06 23:14
用户被禁言,该主题自动屏蔽!
级别: 风云使者
UID: 133553
精华: 0
发帖: 2691
金钱: 13455 两
威望: 2691 点
贡献值: 0 点
综合积分: 5382 分
注册时间: 2017-07-06
最后登录: 2017-07-08
9楼  发表于: 2017-07-07 02:52

 Re:wince6.0 4*5矩阵键盘

勤奋真能造就财富吗?
  • «
  • 1
  • 2
  • »
  • Pages: 1/2     Go