mirror of
https://github.com/vsergeev/c-periphery.git
synced 2026-08-18 02:54:54 +08:00
gpio: add cdev v2 impl
This commit is contained in:
+12
-6
@@ -7,13 +7,19 @@ if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE Release)
|
||||
endif()
|
||||
|
||||
# Check for Linux kernel header files for character device GPIO support
|
||||
include(CheckIncludeFiles)
|
||||
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.")
|
||||
# Check Linux kernel header files for character device GPIO support
|
||||
include(CheckSymbolExists)
|
||||
check_symbol_exists(GPIO_V2_LINES_MAX linux/gpio.h HAVE_GPIO_CDEV_V2)
|
||||
check_symbol_exists(GPIO_GET_LINEEVENT_IOCTL linux/gpio.h HAVE_GPIO_CDEV_V1)
|
||||
if(HAVE_GPIO_CDEV_V2)
|
||||
set(GPIO_CDEV_SUPPORT 2)
|
||||
elseif(HAVE_GPIO_CDEV_V1)
|
||||
set(GPIO_CDEV_SUPPORT 1)
|
||||
else()
|
||||
set(GPIO_CDEV_SUPPORT 0)
|
||||
message(WARNING "Missing character device GPIO support in Linux kernel header files. c-periphery will be built with legacy sysfs GPIO support only.")
|
||||
endif()
|
||||
add_definitions(-DPERIPHERY_GPIO_CDEV_SUPPORT=$<BOOL:${HAVE_CDEV_GPIO_HEADERS}>)
|
||||
add_definitions(-DPERIPHERY_GPIO_CDEV_SUPPORT=${GPIO_CDEV_SUPPORT})
|
||||
|
||||
# Library version
|
||||
set(VERSION "2.3.1")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
LIB = periphery.a
|
||||
SRCS = src/gpio.c src/gpio_cdev_v1.c src/gpio_sysfs.c src/led.c src/pwm.c src/spi.c src/i2c.c src/mmio.c src/serial.c src/version.c
|
||||
SRCS = src/gpio.c src/gpio_cdev_v2.c src/gpio_cdev_v1.c src/gpio_sysfs.c src/led.c src/pwm.c src/spi.c src/i2c.c src/mmio.c src/serial.c src/version.c
|
||||
|
||||
SRCDIR = src
|
||||
OBJDIR = obj
|
||||
@@ -10,7 +10,10 @@ TEST_PROGRAMS = $(basename $(wildcard tests/*.c))
|
||||
|
||||
OBJECTS = $(patsubst $(SRCDIR)/%.c,$(OBJDIR)/%.o,$(SRCS))
|
||||
|
||||
GPIO_CDEV_SUPPORT := $(shell ! echo "\#include <linux/gpio.h>" | $(CC) -E - >/dev/null 2>&1; echo $$?)
|
||||
GPIO_CDEV_V1_SUPPORT := $(shell ! echo -e "#include <linux/gpio.h>\n#ifndef GPIO_GET_LINEEVENT_IOCTL\n#error\n#endif" | $(CC) -E - >/dev/null 2>&1; echo $$?)
|
||||
GPIO_CDEV_V2_SUPPORT := $(shell ! echo -e "#include <linux/gpio.h>\n#ifndef GPIO_V2_LINES_MAX\n#error\n#endif" | $(CC) -E - >/dev/null 2>&1; echo $$?)
|
||||
GPIO_CDEV_SUPPORT = $(if $(filter 1,$(GPIO_CDEV_V2_SUPPORT)),2,$(if $(filter 1,$(GPIO_CDEV_V1_SUPPORT)),1,0))
|
||||
|
||||
COMMIT_ID := $(shell git describe --abbrev --always --tags --dirty 2>/dev/null || echo "")
|
||||
|
||||
OPT ?= -O3
|
||||
|
||||
+33
@@ -183,3 +183,36 @@ const char *gpio_errmsg(gpio_t *gpio) {
|
||||
return gpio->error.errmsg;
|
||||
}
|
||||
|
||||
#if !PERIPHERY_GPIO_CDEV_SUPPORT
|
||||
|
||||
int gpio_open(gpio_t *gpio, const char *path, unsigned int line, gpio_direction_t direction) {
|
||||
(void)path;
|
||||
(void)line;
|
||||
(void)direction;
|
||||
return _gpio_error(gpio, GPIO_ERROR_UNSUPPORTED, 0, "c-periphery library built without character device GPIO support.");
|
||||
}
|
||||
|
||||
int gpio_open_name(gpio_t *gpio, const char *path, const char *name, gpio_direction_t direction) {
|
||||
(void)gpio;
|
||||
(void)path;
|
||||
(void)name;
|
||||
(void)direction;
|
||||
return _gpio_error(gpio, GPIO_ERROR_UNSUPPORTED, 0, "c-periphery library built without character device GPIO support.");
|
||||
}
|
||||
|
||||
int gpio_open_advanced(gpio_t *gpio, const char *path, unsigned int line, const gpio_config_t *config) {
|
||||
(void)path;
|
||||
(void)line;
|
||||
(void)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) {
|
||||
(void)path;
|
||||
(void)name;
|
||||
(void)config;
|
||||
return _gpio_error(gpio, GPIO_ERROR_UNSUPPORTED, 0, "c-periphery library built without character device GPIO support.");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+3
-40
@@ -17,21 +17,15 @@
|
||||
#include "gpio.h"
|
||||
#include "gpio_internal.h"
|
||||
|
||||
#if PERIPHERY_GPIO_CDEV_SUPPORT
|
||||
#if PERIPHERY_GPIO_CDEV_SUPPORT == 1
|
||||
#include <linux/gpio.h>
|
||||
|
||||
/* Disable cdev support when building with older kernel headers that don't yet
|
||||
* support line events in the gpio-cdev abi */
|
||||
#ifndef GPIO_GET_LINEEVENT_IOCTL
|
||||
#undef PERIPHERY_GPIO_CDEV_SUPPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*********************************************************************************/
|
||||
/* cdev implementation */
|
||||
/* cdev v1 implementation */
|
||||
/*********************************************************************************/
|
||||
|
||||
#if PERIPHERY_GPIO_CDEV_SUPPORT
|
||||
#if PERIPHERY_GPIO_CDEV_SUPPORT == 1
|
||||
|
||||
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;
|
||||
@@ -585,36 +579,5 @@ 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
|
||||
|
||||
int gpio_open(gpio_t *gpio, const char *path, unsigned int line, gpio_direction_t direction) {
|
||||
(void)path;
|
||||
(void)line;
|
||||
(void)direction;
|
||||
return _gpio_error(gpio, GPIO_ERROR_UNSUPPORTED, 0, "c-periphery library built without character device GPIO support.");
|
||||
}
|
||||
|
||||
int gpio_open_name(gpio_t *gpio, const char *path, const char *name, gpio_direction_t direction) {
|
||||
(void)gpio;
|
||||
(void)path;
|
||||
(void)name;
|
||||
(void)direction;
|
||||
return _gpio_error(gpio, GPIO_ERROR_UNSUPPORTED, 0, "c-periphery library built without character device GPIO support.");
|
||||
}
|
||||
|
||||
int gpio_open_advanced(gpio_t *gpio, const char *path, unsigned int line, const gpio_config_t *config) {
|
||||
(void)path;
|
||||
(void)line;
|
||||
(void)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) {
|
||||
(void)path;
|
||||
(void)name;
|
||||
(void)config;
|
||||
return _gpio_error(gpio, GPIO_ERROR_UNSUPPORTED, 0, "c-periphery library built without character device GPIO support.");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user