From b00a367dc0596ae14756ca793fad0ecd049b8802 Mon Sep 17 00:00:00 2001 From: cinnaboot Date: Mon, 19 Oct 2026 08:07:05 -0400 Subject: [PATCH] add compiler macros to dectect libgpiod version --- Makefile | 7 ++++++- src/spi.cpp | 4 ++++ src/spi.h | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 78abb16..73addd5 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,11 @@ CXX=g++ CXXFLAGS= -std=c++11 -g -ggdb3 -Wall LDFLAGS=-lasound -lgpiod +# NOTE: add an environment variable to detect breaking API changes with +# libgpiod +LIBGPIOD_VERSION := $(shell pkgconf --modversion libgpiod | cut -f 1 -d.) +CXXFLAGS += -D LIBGPIOD_VERSION=$(LIBGPIOD_VERSION) + OBJDIR = build SRCDIR = src BINDIR = bin @@ -13,7 +18,7 @@ OBJECTS = $(patsubst $(SRCDIR)/%.cpp, $(OBJDIR)/%.o, $(SOURCES)) all: mkdirs $(OBJECTS) - ctags -R ./ + ctags -R ./ /usr/include/alsa/ $(CXX) -o $(BIN) $(OBJECTS) $(LDFLAGS) .PHONY: all diff --git a/src/spi.cpp b/src/spi.cpp index 0a2520b..c61f66a 100644 --- a/src/spi.cpp +++ b/src/spi.cpp @@ -12,6 +12,7 @@ // GPIO +#if LIBGPIOD_VERSION == 1 bool gpioInit(gpio_info* gpio, const char* chip_name, u32 line_num) { @@ -57,6 +58,9 @@ gpioSetValue(gpio_info* gpio, u32 value) return true; } +#elif LIBGPIOD_VERSION == 2 +#error "FIXME: libgpiod version 2 not implemented" +#endif // SPI diff --git a/src/spi.h b/src/spi.h index 268e5d7..fd071fb 100644 --- a/src/spi.h +++ b/src/spi.h @@ -10,6 +10,7 @@ // GPIO +#if LIBGPIOD_VERSION == 1 struct gpio_info { char chip_name[16]; @@ -17,6 +18,19 @@ struct gpio_info gpiod_chip* chip; gpiod_line* line; }; +#elif LIBGPIOD_VERSION == 2 +struct gpio_info +{ + char chip_name[16]; + u32 line_num; + gpiod_chip* chip; + gpiod_line_info* line; +}; + +#else +#error "FIXME: libgpiod version 2 not implemented" +#endif + bool gpioInit(gpio_info* gpio, const char* chip_name, u32 line_num);