Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
NetBSD Raspberry Pi: toggle onboard LED
gpio0 16 set out act_led
gpio=YES
#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