smckbpdd.cpp

来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· C++ 代码 · 共 2,209 行 · 第 1/5 页

CPP
2,209
字号
    DEBUGMSG(ZONE_INIT, 
  (TEXT("KeybdPdd_InitializeDriver: Calling InitAddresses routine . . .\r\n")));

    if( ! KeybdDriverInitializeAddresses() )
    {
        SMCKBD_DEBUG( &KbdSmc, "InitializeAddresses() failed! \r\n" );
        goto init_error_return;
    }

    //
    // Initialize SMC channel for operations
    //

    DEBUGMSG(ZONE_INIT, 
      (TEXT("KeybdPdd_InitializeDriver: Calling SmcInit routine . . .\r\n")));

    if( ! SmcKbd_SmcInit( &KbdSmc ) )
    {
        SMCKBD_DEBUG( &KbdSmc, "SMC channel init failed! \r\n" );
        DEBUGMSG(ZONE_ERROR, 
          (TEXT("KeybdPdd_InitializeDriver: SMC Channel init failed! \r\n" )));
        goto init_error_return;
    }

    //
    // Initialize IR receiver for operation
    //

    DEBUGMSG(ZONE_INIT, 
      (TEXT("KeybdPdd_InitializeDriver: Calling SmcIrKbdRcvrInit routine . . .\
\r\n")));

    if( ! SmcKbd_SmcIrKbdRcvrInit( &KbdSmc ) )
    {
        SMCKBD_DEBUG( &KbdSmc, "IR Receiver init failed! \r\n" );
        DEBUGMSG(ZONE_ERROR, 
          (TEXT("KeybdPdd_InitializeDriver: IR Receiver init failed! \r\n" )));
        goto init_error_return;
    }

    //
    //  Unmask all SMC event interrupts.
    //

    DEBUGMSG( ZONE_INIT, 
      ( TEXT("Unmasking SMC %2x Event Interrupts\r\n"), (&KbdSmc)->SmcNum ) );

    (&KbdSmc)->RegsPtr->smc_smce = 0xff;
    (&KbdSmc)->RegsPtr->smc_smcm = 
                ( EVENT_RX | EVENT_TX | EVENT_BUSY | EVENT_BRK | EVENT_BRKE );

    //
    // issue callback to connect driver
    //

    DEBUGMSG(ZONE_INIT, 
 (TEXT("KeybdPdd_InitializeDriver: Calling *pfnKeybdEventCallback . . .\r\n")));

    (*pfnKeybdEventCallback)(KEYBD_DEVICE_CONNECT, 0);

    DEBUGMSG(ZONE_FUNCTION || ZONE_INIT, 
      (TEXT("KeybdPdd_InitializeDriver: Exit OK\r\n")));

    return TRUE;

    //////////////////////////////////////////////////////
    //
    // Handle error case
    //

init_error_return:

    if ( v_pDPRam )
    {
        VirtualFree((PVOID)v_pDPRam, 0, MEM_RELEASE);
    }

    v_pDPRam = 0;

#if (defined(MOTO_ADS) || defined(MOTO_FADS) || defined(SDB_RPXL) || defined(SDB_CLLF))

    if ( v_pBCSR )
    {
        VirtualFree((PVOID)v_pBCSR, 0, MEM_RELEASE);
    }

    v_pBCSR = 0;

#endif // MOTO_ADS || MOTO_FADS || SDB_RPXL || SDB_CLLF

    DEBUGMSG(ZONE_ERROR, (TEXT("KeybdPdd_InitializeDriver: Exit Failure\r\n")));

    return FALSE;
}



////////////////////////////////////////////////////////////////////////////////
//
//  @doc EXTERNAL
//
//  @func
//
//  Called by the MDD to retrieve keyboard events after SYSINTR_KEYBD is 
//  signalled. 
//
//  @parm   Buffer to put virtual keys which were detected.
//  @parm   Buffer to put key state flags. 
//
//  @rdesc  Number of key events.  0 is allowed.
//
////////////////////////////////////////////////////////////////////////////////

INT WINAPI
KeybdPdd_GetEvent(
    UINT32 VirtualKeys[16],
    KEY_STATE_FLAGS KeyEvents[16]
    )
{
    SMC_CHANNEL *smc = &KbdSmc;
    UINT32    VKey;
    UINT      nEvents = 0;
    UINT8     smcEvent;

    BOOLEAN   status_ok = TRUE;

    // Get the Event register status.

    smcEvent = smc->RegsPtr->smc_smce;

    DEBUGMSG(ZONE_EVENT_HANDLER_DEBUG, 
      (TEXT("KeybdPdd_GetEvent: Entry - Event = %02x\r\n"), smcEvent));

    //////////////////////////////////////////////////////////////
    // Switch on various events to be handled.
    //////////////////////////////////////////////////////////////
    //
    // Check for receive event
    //

    if( smcEvent & EVENT_RX )
    {
        DEBUGMSG( ZONE_EVENT_HANDLER_DEBUG, 
          ( TEXT("KbdPdd_GetEvent: Rx Event -\r\n") ) );

        SMC_BD *rbd = smc->ProcRxBD;

//Entry Point for clearing a clog of packet data in BD queue
next_bd:

////////////////////////////////////////////////
// The BD buffer address entry must be converted to a virtual address
// before accessing packet data, since CPU accesses use virtual addresses.
// Translate physical adx to virtual adx with 16-bit mask. 
////////////////////////////////////////////////

        PM_IR_RCVR_PKT *pktPtr =
     ((PM_IR_RCVR_PKT *)( ((UINT32)rbd->bd_addr & 0xffff) | (UINT32)v_pDPRam ));

        DEBUGMSG( ZONE_EVENT_HANDLER_DEBUG, 
          ( TEXT("pktPtr = %8x\r\n"), pktPtr ) );

#ifdef MOUSE_CURSOR_ON
//This is a pre-munged mouse packet
        PM_MOUSE_RCVR_PKT *mouse_pktPtr = (PM_MOUSE_RCVR_PKT *)pktPtr;

        DEBUGMSG( ZONE_EVENT_HANDLER_DEBUG, 
          ( TEXT("mouse_pktPtr = %8x\r\n"), mouse_pktPtr ) );
#endif


#ifdef SMC_KBD_DEBUG
        // Clear event(s) on exit

        smc->last_event = smcEvent;
        smc->rx_bd_status = rbd->bd_status;
        smc->rx_count += rbd->bd_length;
        smc->cur_rx_pkt = pktPtr; 
#endif

        ///////////////////////////////////////////////////////////
        //
        // Check for packet reception errors
        //

        DEBUGMSG( ZONE_EVENT_HANDLER_DEBUG, 
          ( TEXT("bd_status = %04x\r\n"), rbd->bd_status ) );


        if( rbd->bd_status & RBD_EMPTY )
        {
            SMCKBD_DEBUG( smc, "RBD_EMPTY status Unexpected !!!\r\n" );
            status_ok = FALSE;
        }

        else if( rbd->bd_status & RBD_STATUS_ERROR_MASK )
        {
            SMCKBD_DEBUG( smc, "Error Detected in ProcRxBD\r\n" );
            status_ok = FALSE;
        }

        ///////////////////////////////////////////////////////////
        //
        // Ensure packet is valid and one we want to process
        //

        else if( pktPtr->pktHdr != RCVR_PKT_HEADER )
        {
            SMCKBD_DEBUG( smc, "Packet reception out of SYNC !!!!!\r\n" );
            DEBUGMSG( ZONE_ERROR, 
              ( TEXT("BAD PktHdr = %02x\r\n"), pktPtr->pktHdr ) );
            status_ok = FALSE;
        }

        /*
         * Get keycode from packet (discard mouse packet and repeat data)
         *     Discard:    Mouse packets
         *                 Repeated Keys
         */

        else if( rbd->bd_length != 0x04 )
        {
            SMCKBD_DEBUG( smc, "Buffer length NOT KB Packet size !!!!!\r\n" );
            DEBUGMSG( ZONE_ERROR, 
              ( TEXT("BAD Pkt Length = %04x\r\n"), rbd->bd_length ) );
            status_ok = FALSE;
        }

        else if( (pktPtr->devId & DEV_ID_MASK) == 0 )
        {
            // keyboard packet

        DEBUGMSG( ZONE_EVENT_HANDLER_DEBUG, 
          ( TEXT("ScanCode = %02x\r\n"), pktPtr->keyCode ) );

            VKey = IrScanCodeToVKey( pktPtr->keyCode, pktPtr->keyStates);

            if( VKey )
            {
                // valid Virtual Key translation

                if( ! (pktPtr->keyStates & KEYSTATE_BREAK) )
                {
                    // key down event - check for auto-repeated key

                    if( pktPtr->keyCode != v_PrevKeyScanCode )
                    {
                        // Not auto repeat key
#ifdef SMC_KBD_DEBUG
                        smc->key_count++;
#endif
                        // update previous scan code
                        v_PrevKeyScanCode = pktPtr->keyCode;
      
                        //
                        // Check for special handling keys
                        //

#ifdef WINCEPROFILE
            if (VKey == VK_F8)      // Monte Carlo with buffering
                ProfileStart(200,8);
            if (VKey == VK_F9 )
                ProfileStart(200,4);    // KCALL profiling
            if (VKey == VK_F10 )
                ProfileStart(200,2);    // OBJCALL profiling
            if (VKey == VK_F11)     
                ProfileStart(200,0);    // Monte Carlo
            if (VKey == VK_F12 )
                ProfileStop();      // Disable profiling
#endif

                        if( VKey == VK_SPECIAL )
                        {
                            unsigned char txCode = 0;

                            switch( pktPtr->keyCode )
                            {
                            case KEYCODE_CAPITAL:
                                VKey = VK_CAPITAL;
                                txCode = IR_RCVR_CAPS_LOCK_LED;
                                DEBUGMSG( ZONE_EVENT_HANDLER_DEBUG, 
                                  ( TEXT("CAPS_LOCK detected . . .\r\n") ) );
                                break;
    
                            case KEYCODE_NUMLOCK:
                                VKey = VK_NUMLOCK;
                                txCode = IR_RCVR_NUM_LOCK_LED;
                                v_NumLockState ^= VK_NUMLOCK;
                                DEBUGMSG( ZONE_EVENT_HANDLER_DEBUG, 
                                  ( TEXT("NUM_LOCK detected . . .\r\n") ) );
                                break;
    
                            case KEYCODE_SCROLL:
                                VKey = VK_SCROLL;
                                txCode = IR_RCVR_SCROLL_LOCK_LED;
                                DEBUGMSG( ZONE_EVENT_HANDLER_DEBUG, 
                                  ( TEXT("SCROLL_LOCK detected . . .\r\n") ) );
                                break;
    
                            default:
                                SMCKBD_DEBUG(
                                    &KbdSmc,
                                    "Invalid VK_SPECIAL keycode\r\n" );
                                ASSERT( FALSE );
                            }
    
                            //
                            // Set up transmit to receiver to toggle LED
                            //

                            if( txCode )
                            {
                                DEBUGMSG( ZONE_EVENT_HANDLER_DEBUG, 
                     ( TEXT("Sending LED Command to IR Receiver . . .\r\n") ) );

                                v_LEDstate ^= txCode;
                                if ( ! (SmcKbd_PutChar(&KbdSmc, v_LEDstate))) {
                                    DEBUGMSG(ZONE_ERROR, 
                                      (TEXT("SmcKbd_PutChar() FAILED!!!\r\n")));
                                }
                            }
                        }

                        VirtualKeys[0] = VKey;
                        KeyEvents[0] = KeyStateDownFlag;
                        nEvents++;     // increment nEvents++;

                        DEBUGMSG( ZONE_EVENT_HANDLER_DEBUG,
            ( TEXT("ScanCode = %02x - VKey = %02x - KeyStateDown = %02x\r\n"),
                pktPtr->keyCode, VKey, KeyStateDownFlag ) );
                    }
                }
                else
                {
                   // key being released -

                    VirtualKeys[0] = VKey;
                    KeyEvents[0] = 0;
                    nEvents++;     // increment nEvents++;

                    DEBUGMSG( ZONE_EVENT_HANDLER_DEBUG,
            ( TEXT("ScanCode = %02x - VKey = %02x - KeyStateDown = %02x\r\n"),
                pktPtr->keyCode, VKey, 0 ) );

                    //
                    // This check must be made for the case of multiple down
                    // codes before a release code for "previous" downs.
                    // Only clear the previous key code if the release is for
                    // that key.  Otherwise, it has already been changed.
                    //

                    if( pktPtr->keyCode == v_PrevKeyScanCode )
                    {
                        v_PrevKeyScanCode = 0;
                    }
                }
            }
            else
            {
              SMCKBD_DEBUG( smc,
                "SmcKbd_GetEvent: Rx Error OR Out Of Sync Error !!!!!\r\n" );

              DEBUGMSG( ZONE_ERROR,
                ( TEXT("No VKey Match for ScanCode %02x -\r\n"),
                    pktPtr->keyCode ) );
            }
        }
        else
/*
**********************************************************************************
// It haa now been verified that the packet is mouse data, not keyboard data.  From here, 
// the data is processed so that it is prepared for the mouse_event callback.
**********************************************************************************
*/
        {
#ifdef SMC_KBD_DEBUG
            smc->mouse_count++;
#endif

#ifdef MOUSE_CURSOR_ON

// First, select out 2 LSB's of device ID   
    mouse_event_ID = ( (mouse_pktPtr->devId) & 0x03 );
    DEBUGMSG( ZONE_EVENT_HANDLER_DEBUG, 
          ( TEXT("mouse_event_ID : = %x\r\n"), mouse_event_ID  ) );

// Check for mouse button events:

    if (mouse_event_ID == DID_L_BTN_DOWN)
    {
        dwFlagIr |= MOUSEEVENTF_LEFTDOWN;  //Left mouse button went down
        DEBUGMSG( ZONE_EVENT_HANDLER_DEBUG, 
            ( TEXT("LDdr\r\n") ));          
    }

    else if (mouse_event_ID == DID_R_BTN_DOWN)
    {
        dwFlagIr |= MOUSEEVENTF_RIGHTDOWN;  //Right mouse button went down
        DEBUGMSG( ZONE_EVENT_HANDLER_DEBUG, 
            ( TEXT("RDdr\r\n") ));
    }

// Because the same ID is used for left-up and right-up (e.g. 0), first 
// must compare the previous ID to check if state was left-down or right-down
    
    else if (mouse_event_ID == DID_NO_BTN)
        {
            if (Event_devIdLast == DID_L_BTN_DOWN)
            {
                dwFlagIr |= MOUSEEVENTF_LEFTUP;     //Left button up
                DEBUGMSG( ZONE_EVENT_HANDLER_DEBUG, 
                    ( TEXT("LUdr\r\n") ));
            }

            if (Event_devIdLast == DID_R_BTN_DOWN)
            {
                dwFlagIr |= MOUSEEVENTF_RIGHTUP;        //Right button up
                DEBUGMSG( ZONE_EVENT_HANDLER_DEBUG, 
                    ( TEXT("RUdr\r\n") ));
            }
        }

//  If no button was pushed, make sure no flags are set
    else  dwFlagIr = 0x0000; 

// Checking to see if mouse actually moved 

    if ( ( mouse_pktPtr->x_data != 0x00 ) || ( mouse_pktPtr->y_data != 0x00 ) )
    {
        dwFlagIr |= MOUSEEVENTF_MOVE;
        DEBUGMSG( ZONE_EVENT_HANDLER_DEBUG, 
            ( TEXT("MouseMovedr: \r\n") ));
    }

//  Need to clean up x and y data:
    dxIr = (DWORD)mouse_pktPtr->x_data;
    //If 8-bit dxIR is negative extend out to fit into a 32 bit 2's comp
    if ( dxIr & 0x80)
        dxIr |= 0xFFFFFF00;
            
    dyIr = (DWORD)mouse_pktPtr->y_data;
    if ( dyIr & 0x80)

⌨️ 快捷键说明

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