EM-X270: WinCE: GPIOs Programming

From Compulab Mediawiki
Revision as of 14:59, 15 March 2010 by Mike (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

GPIO Sample Application

Overview

This GPIOSample application demonstrates basic functionality of EM-X270 GPIOs under Windows CE:

  • How to configure a GPIO pin as output and manipulate it.
  • How to configure a GPIO pin as input and respond to changes in signal level.
  • How to setup an edge triggered event.

Application Behavior

Prerequisites for the application:

  • A demo keypad provided with the EM-X270 evaluation kit.

The GPIOSample manipulates the following GPIOs:

  • GPIO 22 (pin 10 of P2 connector on the Keypad Demo Board) - Set as output
  • GPIO 36 (pin 9 of P2 connector on the Keypad Demo Board) - Set as input
  • GPIO 96 (pin 8 of P2 connector on the Keypad Demo Board) - Set as input
  • GPIO 107 (pin 5 of P2 connector on the Keypad Demo Board) - Set as input

GPIO22 voltage level may be monitored with a DVM or an oscilloscope. GPIO36, GPIO96 and GPIO107 may be controlled by an external switch or button.

The GPIOSample performs the following actions:

  • Edge detection on GPIO107 . Event handler is registered with GPIORegisterInterrupt. The handler calls GPIOInterruptDone to indicate interrupt completion.
  • Clock simulation on GPIO22 with a period of 3 seconds.
  • Input voltage level monitoring on GPIO36.
  • Polling on GPIO96 until it is asserted.

Available GPIOs

The following table specifies GPIOs available on the EM-X270 platform:

GPIO# PXA27X Alternate Function Conflicts with EM-X270 demo keypad driver Pin# on keypad extender (P2)
22 KP_MKOUT<7> No 10
34 KP_MKIN<3> No 1
36 KP_MKIN<7> No 9
39 KP_MKIN<4> No 3
91 KP_MKIN<6> No 7
96 KP_MKOUT<6> No 8
99 KP_MKIN<5> No 5
106 KP_MKOUT<3> No 2
107 KP_MKOUT<4> No 4
108 KP_MKOUT<5> No 6
100 KP_MKIN<0> Yes -
101 KP_MKIN<1> Yes -
102 KP_MKIN<2> Yes -
103 KP_MKOUT<0> Yes -
104 KP_MKOUT<1> Yes -
105 KP_MKOUT<2> Yes -


Admolition note.png If your application does not require keypad, you can remove EM-X270 Keypad driver from the Catalog and reuse GPIO100-GPIO105.

GPIO Driver API

Data Types

GPIO_VALUE

GPIO state enumeration

Values
GPIO_LOW
GPIO_HIGH


GPIO_EDGE_SETTINGS

Values
GPIO_REACT_ON_FALLING
GPIO_REACT_ON_RISING
GPIO_REACT_ON_BOTH
GPIO_DONT_REACT


GPIO_INTERRUPT

Fields
Name
Description
DWORD dwGpioNum
GPIO_EDGE_SETTINGS Edge
HANDLE Event




Functions

HANDLE GPIOOpen()

Opens an instance of the GPIO Driver.

Return Values
Returns a handle that should be used to access the driver. Nonzero indicates success.


void GPIOClose(HANDLE hDevice)

Closes the driver handle

Parameters
  • hDevice - Handle to an open driver instance



BOOL GPIOSetValue(HANDLE hDevice,DWORD num, GPIO_VALUE val)

Sets the state of a GPIO.

Parameters
  • hDevice - Handle to an open driver instance
  • num - GPIO number.
  • val - The desired logical state.
Return Values
TRUE - indicates success
FALSE - indicates failure
Remarks
Make sure the GPIO direction is setup as output.


BOOL GPIOGetValue(HANDLE hDevice,DWORD num,GPIO_VALUE *gpioVal)

Return the logical state of a GPIO.

Parameters
  • hDevice - Handle to an open driver instance
  • num - GPIO number.
  • gpioVal - pointer to the GPIO state variable
Return Values
TRUE - indicates success
FALSE - indicates failure
Remarks
Make sure the GPIO direction is setup as input. Returned value for an output GPIO is undefined


void GPIOSetAsInput(HANDLE hDevice, DWORD num)

Configures a GPIO as an input.

Parameters
  • hDevice - Handle to an open driver instance.
  • num - GPIO number.
Return Values
TRUE - indicates success
FALSE - indicates failure


BOOL GPIOSetAsOutput(HANDLE hDevice,DWORD num, GPIO_VALUE val)

Configures a GPIO as an output and sets its logical state.

Parameters
  • hDevice - Handle to an open driver instance
  • num - GPIO number.
  • val - The initial GPIO value
Return Values
TRUE - indicates success
FALSE - indicates failure


DWORD GPIORegisterInterrupt(HANDLE hDevice,GPIO_INTERRUPT interrupt)

Registers a GPIO as an interrupt source. The interrupt is triggered according to the configuration in GPIO_INTERRUPT.Edge member settings.

Parameters
  • hDevice - Handle to an open driver instance
  • interrupt- data structure that defines parameters for the interrupt registration
struct gpio_intr_t{
	DWORD dwGpioNum;
	GPIO_EDGE_SETTINGS  Edge;
	HANDLE	Event;
} GPIO_INTERRUPT;
Return Values
TRUE - indicates success. The handle for the interrupt event is stored in GPIO_INTERRUPT.Event
Remarks
  • This function must be called before using the GPIO_INTERRUPT.Event parameter.
  • The GPIO_INTERRUPT.Event parameter may only be used in a WaitForSingleObject call. A WaitForMultipleObjects call with GPIO_INTERRUPT.Event will fail.
  • If you use GPIO_INTERRUPT.Event in a call to WaitForSingleObject before you call GPIOInterruptInitialize, GPIOInterruptInitialize will fail.


BOOL GPIOInterruptDone(HANDLE hDevice, DWORD num)

Signals to the kernel that GPIO interrupt processing is complete.

Parameters
  • hDevice - Handle to an open driver instance
  • num - GPIO number.
Return Values
TRUE- indicates success.
Remarks
A program calls GPIOInterruptDone when it has completed the interrupt processing and is ready for another interrupt.


DWORD GPIOUnRegisterInterrupt(HANDLE hDevice, DWORD num)

Disables the GPIO hardware interrupt.

Parameters
  • hDevice - Handle to an open driver instance
  • num - GPIO number.
Return Values
TRUE - indicates success.
Remarks
A program calls GPIOUnRegisterInterrupt to disable the hardware interrupt and to unregister the event that was registered by GPIOInterruptInitialize.
Admolition note.png The exact definition of GPIO API is located in the gpio.h file in the GPIOSample project.