beautypg.com

Ktam3874/pitx software guide – Kontron KTAM3874-pITX User Manual

Page 69

background image

KTD-S0057-I

Page 65 Linux® Programming Examples (DebianTM)


KTAM3874/pITX Software Guide


void gpio_close_read (int gpio_pin)
{

close (fd [gpio_pin]);

}


int main (void)
{

int i, value;

printf ("\nGPIO test program\n");

if ((! gpio_export (GP2_17)) && (! gpio_set_direction (GP2_17, GPIO_OUT)))

{

if (! gpio_open_write (GP2_17))

{

for (i = 0; i < MAX_CNT; i++)

{

gpio_write

(GP2_17,

1);

usleep

(SLP_TIME);

gpio_write

(GP2_17,

0);

usleep

(SLP_TIME);

}

gpio_close_write

(GP2_17);

}

else

{

printf ("\nCannot open GPIO !\n");

gpio_unexport

(GP2_17);

return

-1;

}

gpio_unexport

(GP2_17);

}
else
{

printf ("\nGPIO init error !\n");

gpio_unexport

(GP2_17);

return

-1;

}

printf ("GPIO output part successfully finished. Please press Enter.");

getchar

();

if ((! gpio_export (GP2_17)) && (! gpio_set_direction (GP2_17, GPIO_IN)))

{

if (! gpio_open_read (GP2_17))

{

if (! gpio_read (GP2_17, &value))

printf ("Input value on GP2[17] is %d\n", value);

gpio_close_read

(GP2_17);

}

This manual is related to the following products: