Windows CE: Writing an Application to Test GPIO Pins

<< Windows CE: Developing an API to Access a Driver | Home | Windows CE: Launching an Application when a Network Connects >>

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;

}

 

Also see the articles in this series at: Windows CE: Developing an API to Access a Driver and  Windows CE: Using a Driver to Read/Write Hardware Registers.

Copyright © 2010 – Bruce Eitman

All Rights Reserved

Sunday, August 1, 2010 7:33 PM

This article is part of the GWB Archives. Original Author: Bruce Eitman

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.