beautypg.com

Ktt20/pitx software guide – Kontron KTT20-pITX User Manual

Page 54

background image

KTD-S0045-D

Page 50 Windows® Embedded Compact 7 (WEC7) BSP


KTT20/pITX Software Guide

Defines PORT_C as input and reads each pin:

#include
#include
#include

// define IO controls
#define IOCTL_GPIO_GET_INPUT \
CTL_CODE

(FILE_DEVICE_USERDRIVER, 3302, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define IOCTL_GPIO_CONFIG_INPUT \
CTL_CODE

(FILE_DEVICE_USERDRIVER, 3304, METHOD_BUFFERED, FILE_ANY_ACCESS)

// define ports
#define GPIO_PORT_A

0

#define GPIO_PORT_B

1

#define GPIO_PORT_C

2

#define GPIO_PORT_D

3

#define GPIO_PORT_E

4

#define GPIO_PORT_F

5

// index conversion macros
#define GET_INDEX(port, pin) ((port << 3) | (0x07 & pin))

int _tmain (int argc, TCHAR *argv[])
{
HANDLE

hDev;

UINT i;

UCHAR ucBuffIn, ucBuffOut, val = 0;


// Create handle

hDev = CreateFile (L"PIO1:", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);

if (hDev != INVALID_HANDLE_VALUE)

{

for (i = 7; i >= 0; i--)

{

ucBuffIn = GET_INDEX (GPIO_PORT_C, i);

if (! DeviceIoControl (hDev, IOCTL_GPIO_CONFIG_INPUT,

&ucBuffIn,

sizeof

(UCHAR), &ucBuffOut, sizeof (UCHAR),

NULL,

NULL))

wprintf (TEXT ("Error: DeviceIoControl_CONFIG_INPUT failed\r\n"));

if (! DeviceIoControl (hDev, IOCTL_GPIO_GET_INPUT,

&ucBuffIn,

sizeof

(UCHAR), &ucBuffOut, sizeof (UCHAR),

NULL,

NULL))

wprintf (TEXT ("Error: DeviceIoControl_GET_INPUT failed\r\n"));

val |= (ucBuffOut & 0x01);

if (i > 0)

val

<<=

1;

}

wprintf (TEXT ("Input value = 0x%02X\r\n"), val);

Sleep

(2000);

}
}

This manual is related to the following products: