Skip to content

Instantly share code, notes, and snippets.

@schmonz
Created August 3, 2016 19:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schmonz/c8a8d38019823462781e6d68126bac93 to your computer and use it in GitHub Desktop.
Save schmonz/c8a8d38019823462781e6d68126bac93 to your computer and use it in GitHub Desktop.
NetBSD Raspberry Pi: toggle onboard LED
gpio0 16 set out act_led
#include <sys/gpio.h>
#include <sys/ioctl.h>
#include <err.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
void
toggle_onboard_raspberry_pi_led(void)
{
const size_t LED_PIN = 16;
const char *GPIO_DEVICE = "/dev/gpio0";
int file_descriptor;
struct gpio_req request;
if ((file_descriptor = open(GPIO_DEVICE, O_RDWR)) == -1)
err(EXIT_FAILURE, "open");
memset(&request, 0, sizeof(request));
request.gp_pin = LED_PIN;
if (ioctl(file_descriptor, GPIOTOGGLE, &request) == -1)
err(EXIT_FAILURE, "toggle");
if (close(file_descriptor) == -1)
err(EXIT_FAILURE, "close");
}
int
main(void)
{
toggle_onboard_raspberry_pi_led();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment