コード例 #1
0
int main() {

	// Turn libsoc debug off (0) or on (1)
	libsoc_set_debug(0);

	printf("Requesting GPIO\n");
	gpio* motion_int = libsoc_gpio_request(MOTION_GPIO, LS_SHARED);

	printf("Setting direction\n");
	libsoc_gpio_set_direction(motion_int, INPUT);

	printf("Setting edge\n");
	libsoc_gpio_set_edge(motion_int, RISING);

	printf("Waiting for interrupt\n");

	int ret;

	while (1) {

		libsoc_gpio_wait_interrupt(motion_int, -1);
		printf("Motion detected!\n");

		do {
			ret = libsoc_gpio_wait_interrupt(motion_int, 1000);
		}
		while(ret != EXIT_FAILURE); 
	}

	return 0;
}
コード例 #2
0
ファイル: blink.c プロジェクト: LiveWang/96BoardsExamples
int main()
{
	gpio *gpio_led;

	gpio_led = libsoc_gpio_request(GPIO_LED, LS_SHARED);
    
	if ((gpio_led == NULL)) {
		fprintf(stderr, "Unable to request GPIOs\n");
        	goto fail;
	}

	libsoc_gpio_set_direction(gpio_led, OUTPUT);

	if ((libsoc_gpio_get_direction(gpio_led) != OUTPUT)) {
		fprintf(stderr, "Unable to set led/btn directions\n");
		goto fail;
	}
	
	while (1) {
		libsoc_gpio_set_level(gpio_led, 1);
		usleep(500000);
		libsoc_gpio_set_level(gpio_led, 0);
		usleep(500000);
    }

fail:
	if (gpio_led)
		libsoc_gpio_free(gpio_led);

    return EXIT_SUCCESS;
}
コード例 #3
0
ファイル: pushLED.c プロジェクト: MarkAYoder/bone101
int main(void) {
  // Enable debug output
  libsoc_set_debug(1);

  // Request gpios
  gpio_output = libsoc_gpio_request(GPIO_OUTPUT, LS_SHARED);
  gpio_input = libsoc_gpio_request(GPIO_INPUT, LS_SHARED);

  // Set direction to OUTPUT
  libsoc_gpio_set_direction(gpio_output, OUTPUT);
  
  // Set direction to INPUT
  libsoc_gpio_set_direction(gpio_input, INPUT);

  // Set edge to BOTH
  libsoc_gpio_set_edge(gpio_input, BOTH);

  // Setup callback
  libsoc_gpio_callback_interrupt(gpio_input, &callback_test, 
                      (void*) &interrupt_count);
  
  printf("Push the button...\n"); 
  // Disaple debug output so the code will respond faster
  libsoc_set_debug(0);

  sleep(10);
  
  libsoc_set_debug(1);
 
  // Cancel the callback on interrupt
  libsoc_gpio_callback_interrupt_cancel(gpio_input);
  
  //If gpio_request was successful
  if (gpio_input) { // Free gpio request memory
    libsoc_gpio_free(gpio_input);
  }
  
  if (gpio_output) { // Free gpio request memory
    libsoc_gpio_free(gpio_output);
  }
  
  return EXIT_SUCCESS;
}
コード例 #4
0
ファイル: gpio.c プロジェクト: bcousson/gbsim
void gpio_init(void)
{
	int i;

	if (bbb_backend) {
		/*
		 * Grab the four onboard LEDs (gpio1:24-27) and then
		 * P9-12 and P8-26 (gpio1:28-29) to support input. The
		 * pins on the header can be used in loopback mode for
		 * testing.
		 */
		for (i=0; i<6; i++)
			gpios[i] = libsoc_gpio_request(56+i, LS_GREEDY);
	}
}