In previous articles I have developed a driver to access GPIO Pins, Windows CE: Using a Driver to Read/Write Hardware Registers, and a wrapper API for the driver, Windows CE: Developing an API to Access a Driver. Now it is time to use them from an application.
Because the real work is done in the driver, and because we have some simple to use wrapper functions, this application is very simple. It starts by calling the InitGPIOAPI() function, then it sets GPIO Pin 30 to be an output and then toggles the pin high and low.
#include <Windows.h>
#include <GPIO_API.h>
 
int WINAPI WinMain(     HINSTANCE hInstance,
                                                                                HINSTANCE hPrevInstance,
                                                                                LPTSTR    lpCmdLine,
                                                                                int       nCmdShow)
{
                HANDLE hGPIO_API;     
                DWORD count;
 
                RETAILMSG( 1, (TEXT("Testing GPIO\n")));
 
                hGPIO_API = InitGPIOAPI();
 
                if( hGPIO_API != INVALID_HANDLE_VALUE )
                {
                                SetOutputGPIOPin( hGPIO_API, 30 );
 
                                for( count = 0; count < 20; count++ )
                                {
                                                SetGPIOPin( hGPIO_API, 30 );
                                                RETAILMSG( 1, (TEXT( "set GPIO 30 is %s\r\n"), ReadGPIOPin(hGPIO_API, 30)?TEXT("Set"):TEXT("Clear")));
                                                Sleep( 1000 );
 
                                                ClearGPIOPin( hGPIO_API, 30 );
                                                RETAILMSG( 1, (TEXT( "clear GPIO 30 is %s\r\n"), ReadGPIOPin(hGPIO_API, 30)?TEXT("Set"):TEXT("Clear")));
                                                Sleep( 1000 );
                                }
                                DeinitGPIOAPI( hGPIO_API );
                }
                RETAILMSG(1,(TEXT("Done\n")));
 
                return 0;
}
Copyright © 2010 – Bruce Eitman
All Rights Reserved