Created
August 3, 2016 19:14
-
-
Save schmonz/c8a8d38019823462781e6d68126bac93 to your computer and use it in GitHub Desktop.
NetBSD Raspberry Pi: toggle onboard LED
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gpio0 16 set out act_led |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gpio=YES |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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