Exemplo n.º 1
0
BOOL LED_Close(DWORD dwOpen)
{
	PDRVCONTEXT pDrv = (PDRVCONTEXT)dwOpen;

	RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Close++ dwContext: %x\r\n"), dwOpen));

	// Verify that the context handle is valid
	if(pDrv && (pDrv->dwSize != sizeof(DRVCONTEXT))){
		return false;
	}

	UnMapRegister((void*)pDrv->pGpioRegs);

	// Count the number of opens
	InterlockedDecrement((long *)&pDrv->nNumOpens);

	RETAILMSG(RETAIL_ON, (TEXT("LED_Close-- \r\n")));

	return true;
}
/*----------------------------------------------------------------------
|       main
+---------------------------------------------------------------------*/
int WINAPI WinMain(HINSTANCE hInstance,      // handle to current instance
                   HINSTANCE hPrevInstance,  // handle to previous instance
                   LPWSTR lpCmdLine,          // pointer to command line
                   int nCmdShow)             // show state of window
{
	DWORD		ProcID;

	GPIOREG*	pGPIORegs;


	ProcID=getPROCID();
	
	if(pGPIORegs=MapRegister(GPIO_BASE))
	{
		DWORD val;

		if(ProcID==TYPE_PXA270)
			pGPIORegs->gpdr1|=(1<<(35-32)); //Set GPIO35 as output
		else if(ProcID==TYPE_PXA320)
			pGPIORegs->gpdr2|=(1<<(95-64)); //Set GPIO95 as output
		else if(ProcID==TYPE_PXA300)
			pGPIORegs->gpdr3|=(1<<(97-96)); //Set GPIO97 as output

		if(ProcID==TYPE_PXA270)
			pGPIORegs->gpsr1=(1<<(35-32)); // Set GPIO35 HIGH
		else if(ProcID==TYPE_PXA320)
			pGPIORegs->gpsr2=(1<<(95-64)); // Set GPIO95 HIGH
		else if(ProcID==TYPE_PXA300)
			pGPIORegs->gpsr3=(1<<(97-96)); // Set GPIO97 HIGH

		if(ProcID==TYPE_PXA270)
			pGPIORegs->gpcr1=(1<<(35-32)); // Set GPIO35 LOW
		else if(ProcID==TYPE_PXA320)
			pGPIORegs->gpcr2=(1<<(95-64)); // Set GPIO95 LOW
		else if(ProcID==TYPE_PXA300)
			pGPIORegs->gpcr3=(1<<(97-96)); // Set GPIO97 LOW

		if(ProcID==TYPE_PXA270)
			pGPIORegs->gpdr1&=~(1<<(35-32)); // Set GPIO35 as input
		else if(ProcID==TYPE_PXA320)
			pGPIORegs->gpdr2&=~(1<<(95-64)); // Set GPIO95 as input
		else if(ProcID==TYPE_PXA300)
			pGPIORegs->gpdr3&=~(1<<(97-96)); // Set GPIO97 as input
		

		if(ProcID==TYPE_PXA270)
			val=pGPIORegs->gplr1&(1<<(35-32)); // Get GPIO35 level
		else if(ProcID==TYPE_PXA320)
			val=pGPIORegs->gplr2&(1<<(95-64)); // Get GPIO95 level
		else if(ProcID==TYPE_PXA300)
			val=pGPIORegs->gplr3&(1<<(97-96)); // Get GPIO97 level


		UnMapRegister((void*)pGPIORegs);
	}


	
// This code would do the same, but using our GPIOLibrary (code available for purchase)
/*	{

	DWORD gpio;
	
	gpio=35;	
	if(ProcID==TYPE_PXA320) gpio=95;
	else if(ProcID==TYPE_PXA300) gpio=97;

	InitGPIOLib();

	SetGPIODir(gpio, 1);

	SetGPIOLevel(gpio,1);
	SetGPIOLevel(gpio,0);
	
	SetGPIODir(gpio, 1);
	val=GetGPIODir(gpio);


	DeInitGPIOLib();

	} */
	
    return(TRUE);
}