mirror of
https://github.com/vsergeev/c-periphery.git
synced 2026-02-06 15:12:17 +08:00
gpio: add conditional compilation of cdev implementation
with special thanks to Ryan Barnett <ryan.barnett@rockwellcollins.com> for the original implementation.
This commit is contained in:
@@ -3,12 +3,13 @@ project(periphery C)
|
||||
|
||||
option(BUILD_TESTS "Build test programs" ON)
|
||||
|
||||
# Check for Linux kernel headers
|
||||
# Check for Linux kernel header files for character device GPIO support
|
||||
include(CheckIncludeFiles)
|
||||
CHECK_INCLUDE_FILES(linux/gpio.h HAVE_LINUX_HEADERS)
|
||||
if(NOT HAVE_LINUX_HEADERS)
|
||||
message(FATAL_ERROR "c-periphery needs Linux kernel headers")
|
||||
CHECK_INCLUDE_FILES(linux/gpio.h HAVE_CDEV_GPIO_HEADERS)
|
||||
if(NOT HAVE_CDEV_GPIO_HEADERS)
|
||||
message(WARNING "Linux kernel header files not found for character device GPIO support. c-periphery will be built with legacy sysfs GPIO support only.")
|
||||
endif()
|
||||
add_definitions(-DPERIPHERY_GPIO_CDEV_SUPPORT=$<BOOL:${HAVE_CDEV_GPIO_HEADERS}>)
|
||||
|
||||
# Library version
|
||||
set(VERSION "2.2.1")
|
||||
|
||||
4
Makefile
4
Makefile
@@ -4,6 +4,8 @@ SRCS = src/gpio.c src/led.c src/pwm.c src/spi.c src/i2c.c src/mmio.c src/serial.
|
||||
SRCDIR = src
|
||||
OBJDIR = obj
|
||||
|
||||
PERIPHERY_GPIO_CDEV_SUPPORT ?= 1
|
||||
|
||||
TEST_PROGRAMS = $(basename $(wildcard tests/*.c))
|
||||
|
||||
###########################################################################
|
||||
@@ -14,7 +16,7 @@ COMMIT_ID := $(shell git describe --abbrev --always --tags --dirty 2>/dev/null |
|
||||
|
||||
CFLAGS += -std=gnu99 -pedantic
|
||||
CFLAGS += -Wall -Wextra -Wno-unused-parameter $(DEBUG) -fPIC
|
||||
CFLAGS += -DPERIPHERY_VERSION_COMMIT=\"$(COMMIT_ID)\"
|
||||
CFLAGS += -DPERIPHERY_VERSION_COMMIT=\"$(COMMIT_ID)\" -DPERIPHERY_GPIO_CDEV_SUPPORT=$(PERIPHERY_GPIO_CDEV_SUPPORT)
|
||||
LDFLAGS +=
|
||||
|
||||
ifdef CROSS_COMPILE
|
||||
|
||||
21
src/gpio.c
21
src/gpio.c
@@ -20,7 +20,10 @@
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#if PERIPHERY_GPIO_CDEV_SUPPORT
|
||||
#include <linux/gpio.h>
|
||||
#endif
|
||||
|
||||
#include "gpio.h"
|
||||
|
||||
@@ -837,6 +840,8 @@ int gpio_open_sysfs(gpio_t *gpio, unsigned int line, gpio_direction_t direction)
|
||||
/* cdev implementation */
|
||||
/*********************************************************************************/
|
||||
|
||||
#if PERIPHERY_GPIO_CDEV_SUPPORT
|
||||
|
||||
static int _gpio_cdev_reopen(gpio_t *gpio, gpio_direction_t direction, gpio_edge_t edge, gpio_bias_t bias, gpio_drive_t drive, bool inverted) {
|
||||
uint32_t flags = 0;
|
||||
|
||||
@@ -1362,3 +1367,19 @@ int gpio_open_name(gpio_t *gpio, const char *path, const char *name, gpio_direct
|
||||
|
||||
return gpio_open_name_advanced(gpio, path, name, &config);
|
||||
}
|
||||
|
||||
#else /* PERIPHERY_GPIO_CDEV_SUPPORT */
|
||||
|
||||
int gpio_open_advanced(gpio_t *gpio, const char *path, unsigned int line, const gpio_config_t *config) {
|
||||
return _gpio_error(gpio, GPIO_ERROR_UNSUPPORTED, 0, "c-periphery library built without character device GPIO support.");
|
||||
}
|
||||
|
||||
int gpio_open_name_advanced(gpio_t *gpio, const char *path, const char *name, const gpio_config_t *config) {
|
||||
return _gpio_error(gpio, GPIO_ERROR_UNSUPPORTED, 0, "c-periphery library built without character device GPIO support.");
|
||||
}
|
||||
|
||||
int gpio_open(gpio_t *gpio, const char *path, unsigned int line, gpio_direction_t direction) {
|
||||
return _gpio_error(gpio, GPIO_ERROR_UNSUPPORTED, 0, "c-periphery library built without character device GPIO support.");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user