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

📄 keybdpdd.cpp

📁 EP9315的BSP包(WINCE下的BSP,内有各种驱动的详细的代码)
💻 CPP
📖 第 1 页 / 共 2 页
字号:

        //
        // Clear any overrun condition if it exists.
        //
        // *SPI_ICR= 0;
    
        //
        // If we have one character in the array, do the following.
        //
        if(ulNum ==1 )
        {
            //
            // If it is a simple key without the extended scan code perform 
            // following.
            //
            if(ucKScan[0] < KSCAN_TABLE_SIZE)
            {
                uiVKey = KScanCodeToVKeyTable[ucKScan[0]];

                //
                // If the Parity bit is invalid lets through the key away.
                //
                if(uiVKey != VK_NONE )
                {
                    VirtualKeys[iVKeysReturned] = uiVKey;
                    KeyEvents[iVKeysReturned]   = KeyStateDownFlag;
                    iVKeysReturned++;
                }                    
                ulNum           = 0;
            }            
            //
            // I don't know what type of character this is so erase the 
            // keys stored in the buffer and continue.
            //
            else if((ucKScan[0] !=0xF0) && (ucKScan[0] !=0xE0))
            {
                ulNum           = 0;
            }
        }
        else if(ulNum == 2)
        {
            //
            // 0xF0 means that a key has been released.
            //
            if(ucKScan[0] == 0xF0)
            {
                //
                // If it is a simple key without the extended scan code 
                // perform the following.
                //
                if(ucKScan[1] < KSCAN_TABLE_SIZE)
                {
                    uiVKey = KScanCodeToVKeyTable[ucKScan[1]];
                    if(uiVKey != VK_NONE)
                    {
                        VirtualKeys[iVKeysReturned] = uiVKey;
                        KeyEvents[iVKeysReturned]   = 0;
                        iVKeysReturned++;
                    }                    
                    ulNum           = 0;
                }            
                //
                // If it a extended kscan continue to get the next byte.
                //
                else if(ucKScan[1] !=0xE0)
                {
                    ulNum           = 0;
                }
            }                                    
            //
            // Find out what extended code it is.
            //
            else if(ucKScan[0] == 0xE0 && ucKScan[1] != 0xF0)
            {
                uiVKey = ExtendedKscanVirtualKey(ucKScan[1]);
                if(uiVKey!= VK_NONE)
                {
                    VirtualKeys[iVKeysReturned] = uiVKey;
                    KeyEvents[iVKeysReturned]   = KeyStateDownFlag;
                    iVKeysReturned++;
                }            
                ulNum = 0;
            }
        }
        //
        // This means that an extended code key has been released.
        //
        else if (ulNum == 3)
        {
            //
            // 0xF0 means that a key has been released.
            //
            if(ucKScan[0] == 0xE0 && ucKScan[1] == 0xF0)
            {
                uiVKey = ExtendedKscanVirtualKey(ucKScan[2]);
                if(uiVKey!= VK_NONE)
                {
                    VirtualKeys[iVKeysReturned] = uiVKey;
                    KeyEvents[iVKeysReturned]   = 0;
                    iVKeysReturned++;
                }            
            }
            ulNum = 0;
        }

        //
        // I am not going to worry about break and pause keys right know.
        // There is little use for this in Windows CE.
        //
        
    }

    //
    // Disable and enable the SPI port
    //
    *SPI_CR1        = SPICR1_MS | SPICR1_RIE;
    *SPI_ICR        = 0;
    *SPI_CR1        = SPICR1_MS | SPICR1_RIE | SPICR1_SSE;  

    //
    // Clear GPIO pin 14 to enable the keyboard again.  This allows
    // the keyboard to send keys.
    //
    HalWriteCommonReg(GPIO_PBDR, 0x40, 0x0);
    // DEBUGMSG(1,(L"GetEvent_Exit\n"));


    return (iVKeysReturned);
}    

//****************************************************************************
// KeybdPdd_GetEventEx2
//****************************************************************************
//  Called by the MDD to retrieve keyboard events after SYSINTR_KEYBD is 
//  signalled.
//
UINT WINAPI KeybdPdd_GetEventEx2
(
    UINT    uiPddId,
    UINT32  rguiScanCode[16],
    BOOL    rgfKeyUp[16]
)
{
    UINT32 VirtualKeys[16];            //  @parm Buffer to put virtual keys which were detected.
    KEY_STATE_FLAGS KeyEvents[16];     //  @parm Buffer to put key state flags.
    static  unsigned char   ucKScan[4] = {0,0,0,0};
    //static    unsigned char   bParity[4] = {0,0,0,0};
    static  unsigned int    ulNum = 0;
    INT     iVKeysReturned = 0;
    UINT32  uiVKey;
    ULONG   ulTemp;
    BOOL    bParityValid;
    

    //
    // Set GPIO pins 14 high.  This causes spiclk to be low and prevent the keyboard from sending keys.
    // The keyboard is disabled while reading in the keys.
    //
    // DEBUGMSG(1,(L"GetEvent_Enter\n"));
    HalWriteCommonReg(GPIO_PBDR, 0x40, 0x40);


    while((*SPI_SR & SPISR_RNE ) &&  iVKeysReturned<16)
    {
        ulTemp = *SPI_DR;

        //
        // Read in the value from the SPI controller.
        //
        ucKScan[ulNum++] = SPI2KScan(ulTemp, &bParityValid);


        // DEBUGMSG(1,(L"0x%3x 0x%01x\n",ulTemp, bParityValid));

        //
        // Reset the SPI device and break.
        //
        if(!bParityValid)
        {
            ulNum = 0;
            break;
        }

        //
        // Clear any overrun condition if it exists.
        //
        // *SPI_ICR= 0;
    
        //
        // If we have one character in the array, do the following.
        //
        if(ulNum ==1 )
        {
            //
            // If it is a simple key without the extended scan code perform 
            // following.
            //
            if(ucKScan[0] < KSCAN_TABLE_SIZE)
            {
                uiVKey = KScanCodeToVKeyTable[ucKScan[0]];

                //
                // If the Parity bit is invalid lets through the key away.
                //
                if(uiVKey != VK_NONE )
                {
                    VirtualKeys[iVKeysReturned]     = uiVKey;
                    KeyEvents[iVKeysReturned]       = KeyStateDownFlag;

                    rguiScanCode[iVKeysReturned]    = ucKScan[0];
                    rgfKeyUp[iVKeysReturned]        = FALSE;
                    iVKeysReturned++;
                }                    
                ulNum           = 0;
            }            
            //
            // I don't know what type of character this is so erase the 
            // keys stored in the buffer and continue.
            //
            else if((ucKScan[0] !=0xF0) && (ucKScan[0] !=0xE0))
            {
                ulNum           = 0;
            }
        }
        else if(ulNum == 2)
        {
            //
            // 0xF0 means that a key has been released.
            //
            if(ucKScan[0] == 0xF0)
            {
                //
                // If it is a simple key without the extended scan code 
                // perform the following.
                //
                if(ucKScan[1] < KSCAN_TABLE_SIZE)
                {
                    uiVKey = KScanCodeToVKeyTable[ucKScan[1]];
                    if(uiVKey != VK_NONE)
                    {
                        VirtualKeys[iVKeysReturned]     = uiVKey;
                        KeyEvents[iVKeysReturned]       = 0;

                        rguiScanCode[iVKeysReturned]    = ucKScan[1];
                        rgfKeyUp[iVKeysReturned]        = TRUE;
                        iVKeysReturned++;
                    }                    
                    ulNum           = 0;
                }            
                //
                // If it a extended kscan continue to get the next byte.
                //
                else if(ucKScan[1] !=0xE0)
                {
                    ulNum           = 0;
                }
            }                                    
            //
            // Find out what extended code it is.
            //
            else if(ucKScan[0] == 0xE0 && ucKScan[1] != 0xF0)
            {
                uiVKey = ExtendedKscanVirtualKey(ucKScan[1]);
                if(uiVKey!= VK_NONE)
                {
                    VirtualKeys[iVKeysReturned]     = uiVKey;
                    KeyEvents[iVKeysReturned]       = KeyStateDownFlag;

                    rguiScanCode[iVKeysReturned]    = (ucKScan[0]<<8) + ucKScan[1];
                    rgfKeyUp[iVKeysReturned]        = FALSE;
                    iVKeysReturned++;
                }            
                ulNum = 0;
            }
        }
        //
        // This means that an extended code key has been released.
        //
        else if (ulNum == 3)
        {
            //
            // 0xF0 means that a key has been released.
            //
            if(ucKScan[0] == 0xE0 && ucKScan[1] == 0xF0)
            {
                uiVKey = ExtendedKscanVirtualKey(ucKScan[2]);
                if(uiVKey!= VK_NONE)
                {
                    VirtualKeys[iVKeysReturned]     = uiVKey;
                    KeyEvents[iVKeysReturned]       = 0;

                    rguiScanCode[iVKeysReturned]    = (ucKScan[0]<<8) + ucKScan[2];
                    rgfKeyUp[iVKeysReturned]        = TRUE;
                    iVKeysReturned++;
                }            
            }
            ulNum = 0;
        }

        //
        // I am not going to worry about break and pause keys right know.
        // There is little use for this in Windows CE.
        //
        
    }

    //
    // Disable and enable the SPI port
    //
    *SPI_CR1        = SPICR1_MS | SPICR1_RIE;
    *SPI_ICR        = 0;
    *SPI_CR1        = SPICR1_MS | SPICR1_RIE | SPICR1_SSE;  

    //
    // Clear GPIO pin 14 to enable the keyboard again.  This allows
    // the keyboard to send keys.
    //
    HalWriteCommonReg(GPIO_PBDR, 0x40, 0x0);
    // DEBUGMSG(1,(L"GetEvent_Exit\n"));


    return iVKeysReturned;
}



//****************************************************************************
// KeybdPdd_ToggleKeyNotification
//****************************************************************************
// Called when keys are toggled on a keyboard.
// 
//
extern "C" 
void WINAPI KeybdPdd_ToggleKeyNotification
(
    KEY_STATE_FLAGS KeyStateFlags
)
{
/*
    v_KeyStateToggled = KeyStateFlags;
*/
    return;
}

//****************************************************************************
// KeybdPdd_KeyStateToggled
//****************************************************************************
// Informs Windows that a key has been toggled.
// 
//
extern "C"
KEY_STATE_FLAGS WINAPI KeybdPdd_KeyStateToggled(void)
{
    return v_KeyStateToggled;
}

//****************************************************************************
// KeybdPdd_DllEntry
//****************************************************************************
// Called by the MDD on Dll state changes.
// 
//
extern "C" 
BOOL  WINAPI KeybdPdd_DllEntry
(
    HANDLE hinstDLL,        // @parm Standard Dll entry arg.
    DWORD Op,               // @parm Standard Dll entry arg.
    LPVOID lpvReserved      // @parm Standard Dll entry arg.
)
{
    //
    //REVIEW shouldn't allow more than one attachment.
    //
    if ( Op == DLL_PROCESS_ATTACH ) 
    {
        DEBUGREGISTER((HINSTANCE)hinstDLL);
        //dpCurSettings.ulZoneMask = ZONE_INIT | ZONE_ERROR;
    }

    return (TRUE);
}

//****************************************************************************
// Ps2KeybdIsrThread
//****************************************************************************
// Keyboard PDD ISR/IST.
// 
//
DWORD Ps2KeybdIsrThread(DWORD dwContext)
{
    DWORD   dwTransferred = 0;
    int iPriority = 145;
    extern UINT v_uiPddId;
    extern PFN_KEYBD_EVENT v_pfnKeybdEvent;

    KEYBD_IST keybdIst;
       
    // set the thread priority
    CeSetThreadPriority(GetCurrentThread(), iPriority);

    ghInterrupt = CreateEvent(NULL, FALSE, FALSE, NULL);
    if ( ghInterrupt == NULL)
    {
        goto leave;
    }

    if ( !InterruptInitialize(gIntrKeyboard, ghInterrupt, NULL, 0) )
    {
        goto leave;
    }

    keybdIst.hevInterrupt       = ghInterrupt;

    //
    // System interrupt number.
    //
    keybdIst.dwSysIntr_Keybd    = gIntrKeyboard;
    keybdIst.uiPddId            = v_uiPddId;
    keybdIst.pfnGetKeybdEvent   = KeybdPdd_GetEventEx2;
    keybdIst.pfnKeybdEvent      = v_pfnKeybdEvent;

    KeybdIstLoop(&keybdIst);

leave:
    return 0;
}







⌨️ 快捷键说明

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