CM-T3530: WinCE: GPIOs Programming

From Compulab Mediawiki
Revision as of 11:39, 21 June 2010 by Freidman (talk)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The WinCE demo image includes a GPIO driver that allows direct GPIO control. The GPIO driver is a stream driver that can be accessed using the "GIO" prefix.


Admolition note.png The GPIO driver controls only the OMAP35x General-Purpose I/O Interface. It does not include pin multiplexing control. Pin multiplexing configuration should be set to GPIO mode. For pin multiplexing details refer to section 5.5 of the

CMT3530 Reference Guide

GPIO Sample Application

This GPIO_Sample application illustrates basic functionality of CM-T3530 GPIOs in 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.

The GPIO_Sample application manipulates the following GPIOs:

  • GPIO140 - set as output (Pin 14 of connector P9 on SB-T35).
  • GPIO170 - set as input (Pin 1 of connector P11 on SB-T35).

GPIO140 voltage level can be monitored with a DVM or an oscilloscope. GPIO170 can be controlled by an external switch or button.

The GPIO_Sample performs the following actions:

  • 1Hz clock simulation on GPIO140 for 10 seconds.
  • Input voltage level monitoring on GPIO170.
  • Edge detection on GPIO170. Event handler is registered with GPIOInterruptInitialize. The handler calls GPIOInterruptDone to indicate interrupt completion.


GPIO Driver API

HANDLE GPIOOpen()

Opens an instance of the GPIO Driver. Returns a handle that should be used to access the driver

Return Values

Nonzero indicates success.


void GPIOClose(HANDLE hContext)

Closes the driver handle

Parameters

  • hContext - Handle to an open driver instance



void GPIOSetBit(HANDLE hContext,DWORD id)

Sets the GPIO output high (logical 1).

Parameters

  • hContext - Handle to an open driver instance.
  • id - GPIO number.

Remarks

Make sure the GPIO direction is setup as output.


void GPIOClrBit(HANDLE hContext,DWORD id)

Sets the GPIO output low (logical 0).

Parameters

  • hContext - Handle to an open driver instance.
  • id - GPIO number.

Remarks

Make sure the GPIO's direction is setup as output.


DWORD GPIOGetBit(HANDLE hContext,DWORD id)

Measures the GPIO voltage level.

Parameters

  • hContext - Handle to an open driver instance.
  • id - GPIO number.

Return Values

1 - Indicates high (logical 1).
0 - Indicates low (logical 0).

Remarks

Make sure the GPIO direction is setup as input.


void GPIOSetMode(HANDLE hContext, DWORD id, DWORD mode)

Sets the GPIO operation mode.

Parameters

  • hContext - Handle to an open driver instance.
  • id - GPIO number.
  • DWORD mode - GPIO operation mode. Possible modes:
#define GPIO_DIR_OUTPUT         (0 << 0)	//GPIO is set to output mode 
#define GPIO_DIR_INPUT          (1 << 0)	//GPIO is set to input mode 
#define GPIO_INT_LOW_HIGH       (1 << 1)	//Enable IRQ/Wakeup on rising edge detect 
#define GPIO_INT_HIGH_LOW       (1 << 2)	//Enable IRQ/Wakeup on falling edge detect 
#define GPIO_INT_LOW            (1 << 3)	//Enable the IRQ assertion on low level detect 
#define GPIO_INT_HIGH           (1 << 4)	//Enable the IRQ assertion on high level detect 
#define GPIO_DEBOUNCE_ENABLE    (1 << 5)	//Enable debouncing feature on the corresponding input port 

Remarks

  • After GPIO operation mode is set as output, use GPIOSetBit and GPIOClrBit to set the GPIO output level.
  • If a GPIO is setup as output, it will not generate interrupts, regardless of GPIO_INT_xxx flags.


DWORD GPIOGetMode(HANDLE hContext,DWORD id)

Returns the GPIO operating mode.

Parameters

  • hContext - Handle to an open driver instance.
  • id - GPIO number.

Return Values

GPIO operating mode as described in GPIOSetMode.


DWORD GPIOInterruptInitialize(HANDLE hContext,DWORD id,HANDLE hEvent)

Sets an interrupt on a GPIO.

Parameters

  • hContext - Handle to an open driver instance.
  • id - GPIO number.
  • hEvent - Event to be signaled when the interrupt is triggered

Return Values

Nonzero indicates success.

Remarks

  • This function must be called before using the hEvent parameter.
  • The hEvent parameter can only be used in a WaitForSingleObject call. A WaitForMultipleObjects call with hEvent will fail.
  • If you use hEvent in a call to WaitForSingleObject before you call GPIOInterruptInitialize, GPIOInterruptInitialize will fail.


DWORD GPIOInterruptDone(HANDLE hContext, DWORD id)

Signals to the kernel that GPIO interrupt processing is complete.

Parameters

  • hContext - Handle to an open driver instance.
  • id - GPIO number.

Return Values

Nonzero indicates success.

Remarks

A program calls GPIOInterruptDone when it has completed the interrupt processing and is ready for another interrupt. GPIOInterruptDone must be called to unmask the interrupt before the registered event can be signaled again.


DWORD GPIOInterruptDisable(HANDLE hContext, DWORD id)

Disables the GPIO hardware interrupt specified by interrupt identifier.

Parameters

  • hContext - Handle to an open driver instance.
  • id - GPIO number.

Return Values

Nonzero indicates success.

Remarks

A program calls GPIOInterruptDisable to disable the hardware interrupt and to unregister the event registered by GPIOInterruptInitialize. The program must call GPIOInterruptDisable before closing the event handle.