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

Page 70

Advertising
background image

KTD-S0057-I

Page 66 Linux® Programming Examples (DebianTM)


KTAM3874/pITX Software Guide


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

("\n");

return

0;

}



You can add interrupt support with a simple extension (only an extract):

#include <poll.h>

#define IRQ_FALL

0

#define IRQ_RISE

1

#define EDGE_RISE

"rising"

#define EDGE_FALL

"falling"

#define POLL_TIMEOUT

20000

static const char *dev_edge

= "/sys/class/gpio/gpio%d/edge";


int gpio_set_edge (int gpio_pin, int rise_fall)
{
int

fd_tmp;

char

str[128];

sprintf (str, dev_edge, gpio_pin);

fd_tmp = open (str, O_WRONLY);

if (fd_tmp < 0)

return

-1;

if

(rise_fall)

{

if (write (fd_tmp, EDGE_RISE, sizeof(EDGE_RISE)-1) != sizeof(EDGE_RISE)-1)

{

close

(fd_tmp);

return

-1;

}

}

Advertising
This manual is related to the following products: