Browse Source

add compiler macros to dectect libgpiod version

main
cinnaboot 1 month ago
parent
commit
b00a367dc0
  1. 7
      Makefile
  2. 4
      src/spi.cpp
  3. 14
      src/spi.h

7
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

4
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

14
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);

Loading…
Cancel
Save