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

📄 kbd_old.cpp

📁 此压缩包为杰得开发得z228的BSP的源代码,可以实现很多功能,尤其是视频解码有很好的效果.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*
 * ------------------------
 *
 * Jade chip 
 *
 * ------------------------
 * File:     kbmouse.cpp
 * Release:  Version 1.0
 * ------------------------
*/

#include <windows.h>
#include <ceddk.h>
#include <ddkreg.h>

#include <keybdpdd.h>
#include <laymgr.h>

#include "oalintr.h"
#include "platform.h"

#include "pl050port.hpp"
#include "pl050keybd.hpp"
#include "gpiodrv.h"

#define DBG_KBD 1

static pl050Port *port1 = NULL, *port2 = NULL;
static pl050Keybd *kbdport = NULL;

UINT v_uiPddId;
PFN_KEYBD_EVENT v_pfnKeybdEvent;

//yz_add
HANDLE g_GPIO1Event;
HANDLE g_GPIO2Event;

DWORD Keybd_GpioIST(PVOID pvParam);
unsigned int KbdISRUpcall(bool timedout, unsigned int scancode);



static KEYBD_PDD GPIOpl050Pdd = {
    2,//PS2_AT_PDD,
    _T("pl050 GPIO"),
};


BOOL
WINAPI
GPIO_pl050_Entry(
    UINT uiPddId,
    PFN_KEYBD_EVENT pfnKeybdEvent,
    PKEYBD_PDD *ppKeybdPdd
    )
{
    SETFNAME(_T("PS2_pl050_Entry"));

    BOOL    fRet = FALSE;

    pl050Port *port;
	DWORD dwSysIntrKeybd = 0, dwSysIntrMouse = 0;

    v_uiPddId = uiPddId;
    v_pfnKeybdEvent = pfnKeybdEvent;
 	RETAILMSG(1, (TEXT("Keybd driver Entry\r\n")));
    DEBUGMSG(ZONE_INIT, (_T("%s: Initialize PS/2 ID %u\r\n"), pszFname, 
        uiPddId));
    DEBUGCHK(ppKeybdPdd != NULL);

    *ppKeybdPdd = &GPIOpl050Pdd;

    if (port1 != NULL)
    {
        fRet = TRUE;
        goto leave;
    }
    
//-----------------------------------------------------
//yz_add for GPIO
	{
    PGPIO_INFO		pGpioHead = NULL;
	PHYSICAL_ADDRESS PhysicalAddress;
	
    RETAILMSG (DBG_KBD, (TEXT("+GIO_Init\r\n")));
	
    // Allocate our control structure.
    pGpioHead = (PGPIO_INFO)LocalAlloc(LPTR, sizeof(GPIO_INFO));
    // Check that LocalAlloc did stuff ok too.
    if ( !pGpioHead ) {
        RETAILMSG(DBG_KBD, (TEXT("Error allocating memory for pGpioHead, GIO_Init failed\r\n")));
        return FALSE;
    }

    // Initially, open list is empty.
//    InitializeListHead( &pGpioHead->OpenList );
//    InitializeCriticalSection(&(pGpioHead->OpenCS));

	pGpioHead->dwAllocatedPinMask = 0;
	// Setup the GPIO base register pointers
	// Map a virtual memory address to the physical base address
	PhysicalAddress.HighPart = 0;
	PhysicalAddress.LowPart = GPIO1_BASE;
	pGpioHead->pGpio1Regs = (PGPIO_REGS)MmMapIoSpace( PhysicalAddress, sizeof(GPIO_REGS), FALSE);
	if(pGpioHead->pGpio1Regs == NULL)
	{
        RETAILMSG(DBG_KBD, (TEXT("GIO_Init: Error GPIO1 MmMapIoSpace failed\r\n")));
		//GIO_Deinit(pGpioHead);
		return FALSE;
	}
	RETAILMSG(DBG_KBD, (TEXT("GIO_Init: GPIO1 regs = 0x%X\r\n"), pGpioHead->pGpio1Regs));	

	PhysicalAddress.HighPart = 0;
	PhysicalAddress.LowPart = GPIO2_BASE;
	pGpioHead->pGpio2Regs = (PGPIO_REGS)MmMapIoSpace( PhysicalAddress, sizeof(GPIO_REGS), FALSE);
	if(pGpioHead->pGpio2Regs == NULL)
	{
        RETAILMSG(DBG_KBD, (TEXT("GIO_Init: Error GPIO2 MmMapIoSpace failed\r\n")));
		//GIO_Deinit(pGpioHead);
		return FALSE;
	}
	RETAILMSG(DBG_KBD, (TEXT("GIO_Init: GPIO2 regs = 0x%X\r\n"), pGpioHead->pGpio2Regs));		

	// Create the interrupt event for the GPIO1 IST
	//pGpioHead->hGpio1ISTEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
	g_GPIO1Event = CreateEvent(NULL, FALSE, FALSE, NULL);
	g_GPIO2Event = CreateEvent(NULL, FALSE, FALSE, NULL);
	
	//if(pGpioHead->hGpio1ISTEvent == NULL)
	if(g_GPIO1Event == NULL || g_GPIO2Event == NULL)
	{
        RETAILMSG(DBG_KBD, (TEXT("GIO_Init: Error creating GPIO1 IST event\r\n")));
		//GIO_Deinit(pGpioHead);
		return FALSE;
	}

	// Enable the interrupts for the GPIO1 subsystem
	//InterruptInitialize(SYSINTR_GPIO1, pGpioHead->hGpio1ISTEvent, NULL, 0);
	if(!(InterruptInitialize(SYSINTR_KBD, g_GPIO1Event, NULL, 0)))
	{
		RETAILMSG(DBG_KBD, (TEXT("GIO_Init: Error cann't initialize interrupt 1!\r\n")));
	}
/*
	if(!(InterruptInitialize(SYSINTR_GPIO2, g_GPIO2Event, NULL, 0)))
	{
		RETAILMSG(DBG_KBD, (TEXT("GIO_Init: Error cann't initialize interrupt 2!\r\n")));
	}
*/	
	// Launch the GPIO1 IST
	pGpioHead->hGpio1ISTThread = CreateThread(NULL, 0, Keybd_GpioIST, pGpioHead, 0, NULL );
	if(pGpioHead->hGpio1ISTThread == NULL)
	{
        RETAILMSG(DBG_KBD, (TEXT("GIO_Init: Error creating GPIO1 IST\r\n")));
		//GIO_Deinit(pGpioHead);
		return NULL;
	}
	// Make sure the thread has a higher priority than the driver
	CeSetThreadPriority(pGpioHead->hGpio1ISTThread, 200);
	
	}
//------end

	RETAILMSG(DBG_KBD, (TEXT("keybd 3\r\n")));
	
    if (!(port1 = new pl050Port) ||        
        !(kbdport = new pl050Keybd))        
    {
        RETAILMSG(1, (TEXT("Heap exhausted !\r\n")));

        goto dodelete;
    }
	
	port1->Initialise();

	RETAILMSG(DBG_KBD, (TEXT("port1->Initialise()!\r\n")));
	
	port = port1;

 
    if (!(kbdport->Initialise(port)))		    
    {
        RETAILMSG(1, (TEXT("Could not initialise kbd\r\n")));

        goto dodelete;
    }

    fRet = TRUE;
	RETAILMSG(DBG_KBD, (TEXT("KBD initial END!\r\n")));

dodelete:
    if (!fRet)
    {
        delete port1;
        port1 = NULL;

        delete port2;
        port2 = NULL;

        delete kbdport;
        kbdport = NULL;
    }
    
leave:
    return fRet;
}


//yz_add for GPIO
//key scan code array
//unsigned int key_code[4][4] = {{0x1C, 0x32, 0x21, 0x23}, {0x3a, 0x5a, 0x24, 0x0D}, {0x1f/*win L*/,0x27,1,1}, {1,1,1,1}};
//1-9,0 a-f  (1-9,0 ESC, Back, F1-F4)
//unsigned int key_code[4][4] = {{0x16, 0x1E, 0x26, 0x25}, {0x2E, 0x36, 0x3D, 0x3E}, {0x46, 0x45, 0x76, 0x66/*0x1C, 0x32*/}, {0x5, 0x6, 0x4, 0xC}/*{0x21, 0x23, 0x24, 0x2B}*/};
//up,Enter,left,0,right,down,0,0
//unsigned int key_code[4][4] = {{0x75, 0x5a, 0x6B, 0x0}, {0x74, 0x72, 0x0, 0x0}, {0x0, 0x0, 0x0, 0x0}, {0x0, 0x0, 0x0, 0x0}};
//unsigned int key_code[4][4] = {{0x76, 0x5a, 0x75, 0x0}, {0x72, 0x1C, 0x6B, 0x0}, {0x74, 0x32, 0x0D/*tab*/, 0x0}, {0x0, 0x0, 0x0, 0x0}};

//(game, right, TAB, 0), (Enter, left, SPACE, 0), (esc, up, down, 0), (0,0,0,0)
unsigned char key_code1[4][4] = {{0, 0x74, 0x0D, 0x0}, {0x5A, 0x6B, 0x29, 0x0}, {0x76, 0x75, 0x72, 0x0}, {0x0, 0x0, 0x0, 0x0}};
//{game, f, TAB, 0), (BS, s, SPACE, 0), (h, e, d, 0), (0,0,0,0) // e: 0x24, s: 0x1B, d: 0x23, f:0x2B, BS: 0x66 h: 0x33
unsigned char key_code2[4][4] = {{0, 0x2B, 0x0D, 0x0}, {0x66, 0x1B, 0x29, 0x0}, {0x33, 0x24, 0x23, 0x0}, {0x0, 0x0, 0x0, 0x0}};


// Gpio1ISTThread - This is the GPIO1 IST for the GPIO device driver
//
#define GET_GPIO5_DAT()		(unsigned char)(pGpioHead->pGpio1Regs->Padding1[254] & 0x07)
#define GET_GPIO5_RIS()		(unsigned char)(pGpioHead->pGpio1Regs->GPIORIS5 & 0x07)
//#define SET_GPIO5_IC(n)		pGpioHead->pGpio1Regs->GPIOIC5 = (unsigned char) n

#define GET_GPIO6_DAT()		(unsigned char)(pGpioHead->pGpio2Regs->Padding1[254] & 0x07)
#define SET_GPIO6_DAT(n)	pGpioHead->pGpio2Regs->Padding1[254] |= ((unsigned char)n & 0x07)

DWORD Keybd_GpioIST(PVOID pvParam)
{
	PGPIO_INFO pGpioHead = (PGPIO_INFO)pvParam;
	DWORD	dwEvent;//, dwIntStatus, dwdata, dwdata2;
	unsigned char cIntStatus, cdata, cdata2, temp, templ, temph;
	unsigned char ScanKeyStat[3][3], CurKeyStat[3][3], key_code[4][4];
	unsigned int yz_key = 0;
	BOOL	fExit = FALSE;
	BOOL	yz_keyup = TRUE;
	BOOL	yz_run = FALSE;
	int i,j, keychange, keydown;


    	RETAILMSG (1, (TEXT("Keybd: GPIO IST thread starting 1.0 \r\n")));
	
	//init key stat: UP
	for(i = 0; i < 3; i++)
	{
		for(j = 0; j < 3; j++)
		{

⌨️ 快捷键说明

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