Changeset View
Changeset View
Standalone View
Standalone View
lib/libgpio/gpio.c
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | gpio_open(unsigned int unit) | ||||
snprintf(device, sizeof(device), "/dev/gpioc%u", unit); | snprintf(device, sizeof(device), "/dev/gpioc%u", unit); | ||||
return (gpio_open_device(device)); | return (gpio_open_device(device)); | ||||
} | } | ||||
gpio_handle_t | gpio_handle_t | ||||
gpio_open_device(const char *device) | gpio_open_device(const char *device) | ||||
{ | { | ||||
int fd, maxpins; | return (gpio_fdopen(open(device, O_RDONLY))); | ||||
} | |||||
gpio_handle_t | |||||
gpio_fdopen(int fd) | |||||
{ | |||||
int maxpins; | |||||
int serr; | int serr; | ||||
fd = open(device, O_RDONLY); | |||||
if (fd < 0) | if (fd < 0) | ||||
return (GPIO_INVALID_HANDLE); | return (GPIO_INVALID_HANDLE); | ||||
/* | /* | ||||
* Check whether a simple ioctl works. | * Check whether a simple ioctl works. | ||||
*/ | */ | ||||
if (ioctl(fd, GPIOMAXPIN, &maxpins) < 0) { | if (ioctl(fd, GPIOMAXPIN, &maxpins) < 0) { | ||||
serr = errno; | serr = errno; | ||||
close(fd); | close(fd); | ||||
▲ Show 20 Lines • Show All 214 Lines • Show Last 20 Lines |