Skip to content

Commit

Permalink
review IRQ support in Linux drivers
Browse files Browse the repository at this point in the history
- switch RPi driver to char-dev IRQ
- wrap wiringPiIsr() into attachInterrupt()
- adjust build system generators (lib and examples)
- use IRQException instead of GPIOException
- make defined RF24_LINUX_GPIO_CHIP more agnostic of selected driver (applied to RPi and SPIDEV drivers)
- fix compiling wiringPi with examples using old makefile
- update URL in examples_linux/README
- remove explicit wiringPi from list of linked libs in pyRF24/setup.py
  • Loading branch information
2bndy5 committed Mar 17, 2024
1 parent cf6d5f2 commit a066d0c
Show file tree
Hide file tree
Showing 18 changed files with 326 additions and 163 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ if(DEFINED RF24_SPI_SPEED)
)
endif()
# allow user customization of default GPIO chip used with the SPIDEV driver
if(DEFINED RF24_SPIDEV_GPIO_CHIP)
message(STATUS "RF24_SPIDEV_GPIO_CHIP set to ${RF24_SPIDEV_GPIO_CHIP}")
if(DEFINED RF24_LINUX_GPIO_CHIP)
message(STATUS "RF24_LINUX_GPIO_CHIP set to ${RF24_LINUX_GPIO_CHIP}")
target_compile_definitions(${LibTargetName} PUBLIC
RF24_SPIDEV_GPIO_CHIP="${RF24_SPIDEV_GPIO_CHIP}"
RF24_LINUX_GPIO_CHIP="${RF24_LINUX_GPIO_CHIP}"
)
endif()

Expand Down
10 changes: 2 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,9 @@ OBJECTS=RF24.o
ifeq ($(DRIVER), MRAA)
OBJECTS+=spi.o gpio.o compatibility.o
else ifeq ($(DRIVER), RPi)
OBJECTS+=spi.o bcm2835.o compatibility.o
ifneq (,$(findstring -lpigpio,$(SHARED_LINKER_LIBS)))
OBJECTS+=interrupt.o
endif
OBJECTS+=spi.o bcm2835.o compatibility.o interrupt.o
else ifeq ($(DRIVER), SPIDEV)
OBJECTS+=spi.o gpio.o compatibility.o
ifneq (,$(findstring -lpigpio,$(SHARED_LINKER_LIBS)))
OBJECTS+=interrupt.o
endif
OBJECTS+=spi.o gpio.o compatibility.o interrupt.o
else ifeq ($(DRIVER), wiringPi)
OBJECTS+=spi.o
else ifeq ($(DRIVER), pigpio)
Expand Down
29 changes: 3 additions & 26 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
CROSS_CC=arm-linux-gnueabihf-gcc
CROSS_CXX=arm-linux-gnueabihf-g++

pigpio_detected=0

function help {
cat <<EOF
configure script for RF24 library.
Expand Down Expand Up @@ -58,11 +56,6 @@ function execute_check {
fi
}

if [[ -f "/usr/lib/libpigpio.so" || -f "/usr/local/lib/libpigpio.so" || -f "/usr/arm-linux-gnueabihf/lib/libpigpio.so" ]]; then
echo "[INFO] pigpio lib found."
pigpio_detected=1
fi

function die {
echo "[ERROR] $1"
exit $2
Expand Down Expand Up @@ -192,7 +185,7 @@ function detect_driver {
result=MRAA
elif [[ $(execute_check "${REMOTE_LDCONFIG} -p | grep liblittlewire-spi") ]]; then
result=LittleWire
elif [ $pigpio_detected -eq 1 ]; then
elif [[ -f "/usr/lib/libpigpio.so" || -f "/usr/local/lib/libpigpio.so" || -f "/usr/arm-linux-gnueabihf/lib/libpigpio.so" ]]; then
result=pigpio
else
result=""
Expand Down Expand Up @@ -407,24 +400,12 @@ fi

case ${DRIVER} in
wiringPi)
SHARED_LINKER_LIBS+=" -lpigpio -lwiringPi"
SHARED_LINKER_LIBS+=" -lwiringPi"
CFLAGS+=" -lwiringPi"
;;
SPIDEV)
if [ $pigpio_detected -eq 1 ]; then
echo "[INFO] linking to pigpio for interrupt compatibility"
SHARED_LINKER_LIBS+=" -lpigpio"
else
CFLAGS+=" -DRF24_NO_INTERRUPT"
fi
;;
RPi)
if [ $pigpio_detected -eq 1 ]; then
echo "[INFO] linking to pigpio for interrupt compatibility"
SHARED_LINKER_LIBS+=" -lpigpio"
else
CFLAGS+=" -DRF24_NO_INTERRUPT"
fi
;;
MRAA)
SHARED_LINKER_LIBS+=" -lmraa"
Expand All @@ -433,11 +414,7 @@ LittleWire)
SHARED_LINKER_LIBS+=" -llittlewire-spi"
;;
pigpio)
if [ $pigpio_detected -eq 0 ]; then
die "[ERROR] pigpio was not detected. Make sure pigpio is installed." 2
else
SHARED_LINKER_LIBS+=" -lpigpio"
fi
SHARED_LINKER_LIBS+=" -lpigpio"
;;
*)
die "Unsupported DRIVER: ${DRIVER}." 2
Expand Down
12 changes: 3 additions & 9 deletions examples_linux/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ find_library(RF24 rf24 REQUIRED)
message(STATUS "using RF24 library: ${RF24}")

# conditionally append "interruptConfigure" to the EXAMPLES_LIST
if("${RF24_DRIVER}" STREQUAL "MRAA" OR "${RF24_DRIVER}" STREQUAL "wiringPi" OR "${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND")
if("${RF24_DRIVER}" STREQUAL "MRAA")
message(STATUS "Skipping interruptConfigure.cpp example as it is incompatible with selected driver library")
else() # not using MRAA or wiringPi drivers (or pigpio lib was found)
list(APPEND EXAMPLES_LIST interruptConfigure)
Expand Down Expand Up @@ -52,16 +52,10 @@ elseif("${RF24_DRIVER}" STREQUAL "wiringPi")
else()
message(FATAL "Lib ${RF24_DRIVER} not found.")
endif()
elseif(NOT "${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND" AND NOT DEFINED RF24_NO_INTERUPT)
if(NOT "${RF24_DRIVER}" STREQUAL "pigpio")
message(STATUS "linking to ${LibPIGPIO} for interrupt support")
else()
message(STATUS "linking to ${LibPIGPIO}")
endif()
elseif(NOT "${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND")
message(STATUS "linking to ${LibPIGPIO}")
# linking to pigpio requires pthread to be listed as last linked lib
list(APPEND linked_libs ${LibPIGPIO} pthread)
else()
message(STATUS "Disabling IRQ pin support")
endif()

foreach(example ${EXAMPLES_LIST})
Expand Down
2 changes: 1 addition & 1 deletion examples_linux/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ include ../Makefile.inc

# define all programs
PROGRAMS = gettingstarted acknowledgementPayloads manualAcknowledgements streamingData multiceiverDemo scanner
ifneq (,$(findstring -lpigpio,$(SHARED_LINKER_LIBS)))
ifneq ($(DRIVER), MRAA)
PROGRAMS+=interruptConfigure
endif

Expand Down
2 changes: 2 additions & 0 deletions examples_linux/Makefile.examples
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ SOURCES = $(PROGRAMS:=.cpp)
LIBS=-l$(LIB)
ifeq ($(DRIVER), LittleWire)
LIBS+= -llittlewire-spi
else ifeq ($(DRIVER), wiringPi)
LIBS+= -lwiringPi -lcrypt -lrt
endif

all: $(PROGRAMS)
Expand Down
3 changes: 0 additions & 3 deletions examples_linux/ncurses/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,3 @@ target_link_libraries(${example} PUBLIC
${linked_libs}
${CURSES_LIBRARIES}
)
if("${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND" OR DEFINED RF24_NO_INTERRUPT)
target_compile_definitions(${example} PUBLIC RF24_NO_INTERRUPT)
endif()
2 changes: 1 addition & 1 deletion examples_linux/readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Note: These examples were originally designed for RPi, but should work on any supported Linux platform, with the proper pin configuration.

See http://tmrh20.github.io/RF24 for more information
See http://nRF24.github.io/RF24 for more information
11 changes: 1 addition & 10 deletions pyRF24/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
os.environ[identifier] = value

except FileNotFoundError: # assuming lib was built & installed with CMake

# get LIB_VERSION from library.properties file for Arduino IDE
with open(os.path.join(git_dir, "library.properties"), "r", encoding="utf-8") as f:
for line in f.read().splitlines():
Expand All @@ -44,7 +43,6 @@

# check C++ RF24 lib is installed
finally:

# check for possible linker flags set via CFLAGS environment variable
for flag in cflags.split("-"):
if flag.startswith("L"):
Expand All @@ -71,13 +69,6 @@
)
)

# avoid IRQ support if pigpio is not available; link to pigpio if it is found
found_pigpio = False
for symlink_loc in symlink_directory:
if os.path.exists(symlink_loc + "/libpigpio.so"):
found_pigpio = True
# IRQ pin features will be implemented in python via pigpio's python API or RPi.GPIO
cflags += " -DRF24_NO_INTERRUPT"

# append any additionally found compiler flags
os.environ["CFLAGS"] = cflags
Expand Down Expand Up @@ -114,7 +105,7 @@
Extension(
"RF24",
sources=["pyRF24.cpp"],
libraries=["rf24", BOOST_LIB] + (["pigpio"] if found_pigpio else [])
libraries=["rf24", BOOST_LIB],
)
],
)
38 changes: 12 additions & 26 deletions utility/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ if ("${RF24_DRIVER}" STREQUAL "wiringPi") # Use wiringPi
${CMAKE_CURRENT_LIST_DIR}/${RF24_DRIVER}/includes.h
${CMAKE_CURRENT_LIST_DIR}/${RF24_DRIVER}/spi.cpp
${CMAKE_CURRENT_LIST_DIR}/${RF24_DRIVER}/RF24_arch_config.h
${CMAKE_CURRENT_LIST_DIR}/${RF24_DRIVER}/interrupt.h
PARENT_SCOPE
)
install(FILES
${RF24_DRIVER}/includes.h
${RF24_DRIVER}/spi.h
${RF24_DRIVER}/RF24_arch_config.h
${RF24_DRIVER}/interrupt.h
DESTINATION include/RF24/utility/${RF24_DRIVER}
)
elseif("${RF24_DRIVER}" STREQUAL "RPi") # use RPi
Expand All @@ -23,34 +25,18 @@ elseif("${RF24_DRIVER}" STREQUAL "RPi") # use RPi
${RF24_DRIVER}/spi.h
${RF24_DRIVER}/compatibility.h
${RF24_DRIVER}/RF24_arch_config.h
${RF24_DRIVER}/interrupt.h
DESTINATION include/RF24/utility/${RF24_DRIVER}
)
if(NOT "${LibPIGPIO}" STREQUAL "LibPIGPIO-NOTFOUND" AND NOT DEFINED RF24_NO_INTERRUPT)
set(RF24_LINKED_DRIVER ${LibPIGPIO} PARENT_SCOPE)
message(STATUS "linking to pigpio lib for interrupt functionality")
install(FILES
${RF24_DRIVER}/interrupt.h
DESTINATION include/RF24/utility/${RF24_DRIVER}
)
set(RF24_DRIVER_SOURCES
${CMAKE_CURRENT_LIST_DIR}/${RF24_DRIVER}/includes.h
${CMAKE_CURRENT_LIST_DIR}/${RF24_DRIVER}/bcm2835.c
${CMAKE_CURRENT_LIST_DIR}/${RF24_DRIVER}/spi.cpp
${CMAKE_CURRENT_LIST_DIR}/${RF24_DRIVER}/compatibility.cpp
${CMAKE_CURRENT_LIST_DIR}/${RF24_DRIVER}/RF24_arch_config.h
${CMAKE_CURRENT_LIST_DIR}/${RF24_DRIVER}/interrupt.cpp
PARENT_SCOPE
)
else()
set(RF24_DRIVER_SOURCES
${CMAKE_CURRENT_LIST_DIR}/${RF24_DRIVER}/includes.h
${CMAKE_CURRENT_LIST_DIR}/${RF24_DRIVER}/bcm2835.c
${CMAKE_CURRENT_LIST_DIR}/${RF24_DRIVER}/spi.cpp
${CMAKE_CURRENT_LIST_DIR}/${RF24_DRIVER}/compatibility.cpp
${CMAKE_CURRENT_LIST_DIR}/${RF24_DRIVER}/RF24_arch_config.h
PARENT_SCOPE
)
endif()
set(RF24_DRIVER_SOURCES
${CMAKE_CURRENT_LIST_DIR}/${RF24_DRIVER}/includes.h
${CMAKE_CURRENT_LIST_DIR}/${RF24_DRIVER}/bcm2835.c
${CMAKE_CURRENT_LIST_DIR}/${RF24_DRIVER}/spi.cpp
${CMAKE_CURRENT_LIST_DIR}/${RF24_DRIVER}/compatibility.cpp
${CMAKE_CURRENT_LIST_DIR}/${RF24_DRIVER}/RF24_arch_config.h
${CMAKE_CURRENT_LIST_DIR}/${RF24_DRIVER}/interrupt.cpp
PARENT_SCOPE
)
elseif("${RF24_DRIVER}" STREQUAL "SPIDEV") # use SPIDEV
if(NOT SPIDEV_EXISTS)
message(WARNING "Detecting /dev/spidev0.0 failed - continuing anyway. Please make sure SPI is enabled.")
Expand Down
4 changes: 1 addition & 3 deletions utility/RPi/includes.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#include <cstring> // memcpy() used in RF24.cpp
#include "RPi/bcm2835.h"
#include "RPi/RF24_arch_config.h"
#ifndef RF24_NO_INTERRUPT
#include "RPi/interrupt.h"
#endif
#include "RPi/interrupt.h"

#endif // RF24_UTILITY_INCLUDES_H_
Loading

0 comments on commit a066d0c

Please sign in to comment.