#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
#include "sys/ioctl.h"
#include "fcntl.h"
#include "time.h"
#include "string.h"
#include "linux/gpio_syscalls.h"

int main(int argc, char **argv) {

  // set PA0 as output
  gpiosetdir(PORTA, DIROUT, PA0);

  // set PB7 as output
  gpiosetdir(PORTB, DIROUT, PB7);

  // set IOG24 as output
  gpiosetdir(PORTG, DIROUT, PG24);

  // set IOG8-15 as output
  gpiosetdir(PORTG, DIROUT, PG8_15);

  while(1) {
    gpiosetbits(PORTA, PA0);
    gpiosetbits(PORTB, PB7);
    gpiotogglebit(PORTG, PG24);
    gpiosetbits(PORTG, PG8);
    printf("%d\n", (gpiogetbits(PORTG, PG2))?(1):(0));
    sleep(1);

    gpioclearbits(PORTA, PA0);
    gpioclearbits(PORTB, PB7);
    gpiotogglebit(PORTG, PG24);
    gpioclearbits(PORTG, PG8);
    printf("%d\n", (gpiogetbits(PORTG, PG2))?(1):(0));

    sleep(1);
  }
  return(0);
}
