Skip to content

Commit 17639b3

Browse files
committed
Libgpio v2
1 parent 2db5147 commit 17639b3

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

‎ArduinoCore-Linux/cores/rasperry_pi/HardwareGPIO_RPI.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ namespace arduino {
3333
// -------------------------------------------------------------------------
3434
// libgpiod v1 vs v2 compatibility layer
3535
//
36+
// Version is detected at cmake time via pkg-config and passed as LIBGPIOD_V2.
3637
// v1: gpiod_chip_open_by_name(), gpiod_line*, gpiod_line_request_output(), etc.
3738
// v2: gpiod_chip_open(path), gpiod_line_request*, gpiod_line_settings, etc.
38-
// Detected via GPIOD_API_VERSION macro (defined as 2 in gpiod v2 headers).
3939
// -------------------------------------------------------------------------
4040

41-
#if defined(GPIOD_API_VERSION) && GPIOD_API_VERSION >= 2
41+
#if defined(LIBGPIOD_V2)
4242

4343
// ---- libgpiod v2 implementation ----------------------------------------
4444

‎CMakeLists.txt‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,17 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/Arduino.cmake)
7171

7272
if (USE_RPI)
7373
target_compile_options(arduino_emulator PUBLIC -DUSE_RPI)
74-
target_link_libraries(arduino_emulator gpiod)
74+
find_package(PkgConfig REQUIRED)
75+
pkg_check_modules(GPIOD REQUIRED libgpiod)
76+
target_link_libraries(arduino_emulator ${GPIOD_LIBRARIES})
77+
target_include_directories(arduino_emulator PUBLIC ${GPIOD_INCLUDE_DIRS})
78+
# Detect libgpiod major version and pass it as a compile definition
79+
if(GPIOD_VERSION VERSION_GREATER_EQUAL "2.0")
80+
message(STATUS "libgpiod v2 detected (${GPIOD_VERSION})")
81+
target_compile_definitions(arduino_emulator PUBLIC LIBGPIOD_V2)
82+
else()
83+
message(STATUS "libgpiod v1 detected (${GPIOD_VERSION})")
84+
endif()
7585
endif(USE_RPI)
7686

7787
if (USE_REMOTE)

0 commit comments

Comments
 (0)