From 3b138276e919c96d7d578273f5b113e21d30e985 Mon Sep 17 00:00:00 2001 From: mz-fuzzy Date: Fri, 26 Feb 2016 14:36:32 -0800 Subject: [PATCH] Makefile and project structure improvements - BBB renamed to SPIDEV - SPIDEV - support for spidev device specification by RF24 constructor - LittleWire support unified with other supported linux devices - configure script introduced for auto detection/configuration - support for cross compilation including library upload/installation to a remote host - examples_RPi renamed to examples_linux - Python wrapper - preparation for cross compiling support --- Makefile | 127 ++++------ RF24.cpp | 21 +- RF24.h | 4 +- RF24_config.h | 8 +- RPi/pyRF24/crossunixccompiler.py | 38 +++ RPi/pyRF24/setup.py | 35 ++- configure | 219 ++++++++++++++++++ {examples_RPi => examples_linux}/Makefile | 0 .../extra/Makefile | 0 .../extra/rpi-hub.cpp | 0 .../extra/scanner.cpp | 0 .../gettingstarted.cpp | 0 .../gettingstarted_call_response.cpp | 0 .../interrupts/Makefile | 0 .../gettingstarted_call_response_int.cpp | 0 .../gettingstarted_call_response_int2.cpp | 0 .../interrupts/pingpair_dyn_int.cpp | 0 .../interrupts/transfer_interrupt.cpp | 0 .../pingpair_dyn.cpp | 0 .../pingpair_dyn.py | 0 {examples_RPi => examples_linux}/readme.md | 0 {examples_RPi => examples_linux}/transfer.cpp | 0 utility/LittleWire/RF24_arch_config.h | 4 +- utility/LittleWire/includes.h | 31 +++ utility/{BBB => SPIDEV}/RF24_arch_config.h | 0 utility/{BBB => SPIDEV}/compatibility.c | 0 utility/{BBB => SPIDEV}/compatibility.h | 0 utility/{BBB => SPIDEV}/gpio.cpp | 0 utility/{BBB => SPIDEV}/gpio.h | 0 utility/{BBB => SPIDEV}/includes.h | 0 utility/{BBB => SPIDEV}/spi.cpp | 31 +-- utility/{BBB => SPIDEV}/spi.h | 5 + 32 files changed, 394 insertions(+), 129 deletions(-) create mode 100644 RPi/pyRF24/crossunixccompiler.py create mode 100755 configure rename {examples_RPi => examples_linux}/Makefile (100%) rename {examples_RPi => examples_linux}/extra/Makefile (100%) rename {examples_RPi => examples_linux}/extra/rpi-hub.cpp (100%) rename {examples_RPi => examples_linux}/extra/scanner.cpp (100%) rename {examples_RPi => examples_linux}/gettingstarted.cpp (100%) rename {examples_RPi => examples_linux}/gettingstarted_call_response.cpp (100%) rename {examples_RPi => examples_linux}/interrupts/Makefile (100%) rename {examples_RPi => examples_linux}/interrupts/gettingstarted_call_response_int.cpp (100%) rename {examples_RPi => examples_linux}/interrupts/gettingstarted_call_response_int2.cpp (100%) rename {examples_RPi => examples_linux}/interrupts/pingpair_dyn_int.cpp (100%) rename {examples_RPi => examples_linux}/interrupts/transfer_interrupt.cpp (100%) rename {examples_RPi => examples_linux}/pingpair_dyn.cpp (100%) rename {examples_RPi => examples_linux}/pingpair_dyn.py (100%) rename {examples_RPi => examples_linux}/readme.md (100%) rename {examples_RPi => examples_linux}/transfer.cpp (100%) create mode 100644 utility/LittleWire/includes.h rename utility/{BBB => SPIDEV}/RF24_arch_config.h (100%) rename utility/{BBB => SPIDEV}/compatibility.c (100%) rename utility/{BBB => SPIDEV}/compatibility.h (100%) rename utility/{BBB => SPIDEV}/gpio.cpp (100%) rename utility/{BBB => SPIDEV}/gpio.h (100%) rename utility/{BBB => SPIDEV}/includes.h (100%) rename utility/{BBB => SPIDEV}/spi.cpp (89%) rename utility/{BBB => SPIDEV}/spi.h (94%) diff --git a/Makefile b/Makefile index 3955ac910..ed9144877 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ ############################################################################# # -# Makefile for librf24-bcm on Raspberry Pi +# Makefile for librf24 # # License: GPL (General Public License) # Author: Charles-Henri Hallard @@ -8,117 +8,88 @@ # # Description: # ------------ -# use make all and mak install to install the library -# You can change the install directory by editing the LIBDIR line +# use make all and make install to install the library # -PREFIX=/usr/local -# Library parameters -# where to put the lib -LIBDIR=$(PREFIX)/lib -# lib name -LIB=librf24-bcm -# shared library name -LIBNAME=$(LIB).so.1.0 +ifeq ($(wildcard Makefile.inc), ) +$(error Configuration not found. Run ./configure first) +endif -# Where to put the header files -HEADER_DIR=${PREFIX}/include/RF24 +include Makefile.inc -# The base location of support files for different devices -ARCH_DIR=utility - -ARCH=armv6zk -ifeq "$(shell uname -m)" "armv7l" -ARCH=armv7-a -endif - -# The default objects to compile -OBJECTS=RF24.o spi.o - -SHARED_LINKER_FLAGS=-shared -Wl,-soname,$@.so.1 - - - -# Detect the Raspberry Pi from cpuinfo -# Allow users to override the use of BCM2835 driver and force use of SPIDEV by specifying " sudo make install -B RF24_SPIDEV=1 " -ifeq "$(RF24_SPIDEV)" "1" -RPI=0 -else -#Count the matches for BCM2708 or BCM2709 in cpuinfo -RPI=$(shell cat /proc/cpuinfo | grep Hardware | grep -c BCM2708) - ifneq "${RPI}" "1" - RPI=$(shell cat /proc/cpuinfo | grep Hardware | grep -c BCM2709) - endif +# Objects to compile +OBJECTS=RF24.o +ifeq ($(DRIVER), MRAA) +OBJECTS+=spi.o gpio.o compatibility.o +else ifeq ($(DRIVER), RPi) +OBJECTS+=spi.o bcm2835.o interrupt.o +else ifeq ($(DRIVER), SPIDEV) +OBJECTS+=spi.o gpio.o compatibility.o endif -ifeq "$(RF24_MRAA)" "1" -SHARED_LINKER_FLAGS+=-lmraa -DRIVER_DIR=$(ARCH_DIR)/MRAA -OBJECTS+=gpio.o compatibility.o - -else ifeq "$(RPI)" "1" -DRIVER_DIR=$(ARCH_DIR)/RPi -OBJECTS+=bcm2835.o -OBJECTS+=interrupt.o -SHARED_LINKER_FLAGS+=-pthread -# The recommended compiler flags for the Raspberry Pi -CCFLAGS=-Ofast -mfpu=vfp -mfloat-abi=hard -march=$(ARCH) -mtune=arm1176jzf-s - -else -DRIVER_DIR=$(ARCH_DIR)/BBB -OBJECTS+=gpio.o compatibility.o interrupt.o -SHARED_LINKER_FLAGS+=-pthread -endif - - # make all # reinstall the library after each recompilation -all: test librf24-bcm +all: $(LIBNAME) -test: - cp ${DRIVER_DIR}/includes.h $(ARCH_DIR)/includes.h # Make the library -librf24-bcm: $(OBJECTS) - g++ ${SHARED_LINKER_FLAGS} ${CCFLAGS} -o ${LIBNAME} $^ - +$(LIBNAME): $(OBJECTS) + @echo "[Linking]" + ${CC} ${SHARED_LINKER_FLAGS} ${CFLAGS} -o ${LIBNAME} $^ + # Library parts RF24.o: RF24.cpp - g++ -Wall -fPIC ${CCFLAGS} -c $^ + ${CXX} -Wall -fPIC ${CFLAGS} -c $^ bcm2835.o: $(DRIVER_DIR)/bcm2835.c - gcc -Wall -fPIC ${CCFLAGS} -c $^ + ${CC} -Wall -fPIC ${CFLAGS} -c $^ spi.o: $(DRIVER_DIR)/spi.cpp - g++ -Wall -fPIC ${CCFLAGS} -c $^ + ${CXX} -Wall -fPIC ${CFLAGS} -c $^ compatibility.o: $(DRIVER_DIR)/compatibility.c - gcc -Wall -fPIC ${CCFLAGS} -c $(DRIVER_DIR)/compatibility.c + ${CC} -Wall -fPIC ${CFLAGS} -c $(DRIVER_DIR)/compatibility.c gpio.o: $(DRIVER_DIR)/gpio.cpp - g++ -Wall -fPIC ${CCFLAGS} -c $(DRIVER_DIR)/gpio.cpp + ${CXX} -Wall -fPIC ${CFLAGS} -c $(DRIVER_DIR)/gpio.cpp interrupt.o: $(DRIVER_DIR)/interrupt.c - g++ -Wall -fPIC ${CCFLAGS} -c $(DRIVER_DIR)/interrupt.c + ${CXX} -Wall -fPIC ${CFLAGS} -c $(DRIVER_DIR)/interrupt.c # clear build files clean: - rm -rf *.o ${LIB}.* + @echo "[Cleaning]" + rm -rf *.o ${LIBNAME}.* install: all install-libs install-headers +upload: all upload-libs upload-headers # Install the library to LIBPATH -install-libs: +install-libs: @echo "[Installing Libs]" @if ( test ! -d $(PREFIX)/lib ) ; then mkdir -p $(PREFIX)/lib ; fi - @install -m 0755 ${LIBNAME} ${LIBDIR} - @ln -sf ${LIBDIR}/${LIBNAME} ${LIBDIR}/${LIB}.so.1 - @ln -sf ${LIBDIR}/${LIBNAME} ${LIBDIR}/${LIB}.so - @ldconfig + @install -m 0755 ${LIBNAME} ${LIB_DIR} + @ln -sf ${LIB_DIR}/${LIBNAME} ${LIB_DIR}/${LIBNAME}.1 + # @${LDCONFIG} + +upload-libs: + @echo "[Uploading Libs to ${REMOTE}]" + @ssh -q -t -p ${REMOTE_PORT} ${REMOTE} "mkdir -p ${REMOTE_LIB_DIR}" + @scp -q -P ${REMOTE_PORT} ${LIBNAME} ${REMOTE}:/tmp + @ssh -q -t -p ${REMOTE_PORT} ${REMOTE} "sudo install -m 0755 /tmp/${LIBNAME} ${REMOTE_LIB_DIR} && rm /tmp/${LIBNAME} && sudo ln -sf ${REMOTE_LIB_DIR}/${LIBNAME} ${REMOTE_LIB_DIR}/${LIBNAME}.1 && sudo ldconfig" install-headers: @echo "[Installing Headers]" - @if ( test ! -d ${HEADER_DIR} ) ; then mkdir -p ${HEADER_DIR} ; fi + @mkdir -p ${HEADER_DIR}/${DRIVER_DIR} @install -m 0644 *.h ${HEADER_DIR} - @if ( test ! -d ${HEADER_DIR}/${DRIVER_DIR} ) ; then mkdir -p ${HEADER_DIR}/${DRIVER_DIR} ; fi @install -m 0644 ${DRIVER_DIR}/*.h ${HEADER_DIR}/${DRIVER_DIR} @install -m 0644 ${ARCH_DIR}/*.h ${HEADER_DIR}/${ARCH_DIR} + +upload-headers: + @echo "[Uploading Headers to ${REMOTE}]" + @ssh -q -t -p ${REMOTE_PORT} ${REMOTE} "sudo mkdir -p ${REMOTE_HEADER_DIR}/${DRIVER_DIR}" + @ssh -q -t -p ${REMOTE_PORT} ${REMOTE} "mkdir -p /tmp/RF24 && rm -rf /tmp/RF24/*" + @rsync -a --include="*.h" --include="*/" --exclude="*" -e "ssh -p ${REMOTE_PORT}" . ${REMOTE}:/tmp/RF24 + @ssh -q -t -p ${REMOTE_PORT} ${REMOTE} "sudo install -m 0644 /tmp/RF24/*.h ${REMOTE_HEADER_DIR}" + @ssh -q -t -p ${REMOTE_PORT} ${REMOTE} "sudo install -m 0644 /tmp/RF24/${DRIVER_DIR}/*.h ${REMOTE_HEADER_DIR}/${DRIVER_DIR}" + @ssh -q -t -p ${REMOTE_PORT} ${REMOTE} "sudo install -m 0644 /tmp/RF24/${ARCH_DIR}/*.h ${REMOTE_HEADER_DIR}/${ARCH_DIR}" + @ssh -q -t -p ${REMOTE_PORT} ${REMOTE} "rm -rf /tmp/RF24" diff --git a/RF24.cpp b/RF24.cpp index 2dcd88f49..2d0272eea 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -580,15 +580,16 @@ bool RF24::begin(void) gpio.begin(ce_pin,csn_pin); #endif - - switch(csn_pin){ //Ensure valid hardware CS pin - case 0: break; - case 1: break; - // Allow BCM2835 enums for RPi - case 8: csn_pin = 0; break; - case 7: csn_pin = 1; break; - default: csn_pin = 0; break; - } + #ifdef RF24_RPi + switch(csn_pin){ //Ensure valid hardware CS pin + case 0: break; + case 1: break; + // Allow BCM2835 enums for RPi + case 8: csn_pin = 0; break; + case 7: csn_pin = 1; break; + default: csn_pin = 0; break; + } + #endif _SPI.begin(csn_pin); @@ -936,7 +937,7 @@ void RF24::startWrite( const void* buf, uint8_t len, const bool multicast ){ //write_payload( buf, len ); write_payload( buf, len,multicast? W_TX_PAYLOAD_NO_ACK : W_TX_PAYLOAD ) ; ce(HIGH); - #if defined(CORE_TEENSY) || !defined(ARDUINO) || defined (RF24_BBB) || defined (RF24_DUE) + #if defined(CORE_TEENSY) || !defined(ARDUINO) || defined (RF24_SPIDEV) || defined (RF24_DUE) delayMicroseconds(10); #endif ce(LOW); diff --git a/RF24.h b/RF24.h index aaa43e830..71d0d725f 100644 --- a/RF24.h +++ b/RF24.h @@ -17,10 +17,8 @@ #include "RF24_config.h" -#if defined (RF24_LINUX) +#if defined (RF24_LINUX) || defined (LITTLEWIRE) #include "utility/includes.h" -#elif LITTLEWIRE - #include #elif defined SOFTSPI #include #endif diff --git a/RF24_config.h b/RF24_config.h index aef3d431a..49ffed50e 100644 --- a/RF24_config.h +++ b/RF24_config.h @@ -30,7 +30,8 @@ #endif //Generic Linux/ARM and //http://iotdk.intel.com/docs/master/mraa/ -#if ( defined (__linux) || defined (LINUX) ) && defined( __arm__ ) || defined(MRAA) // BeagleBone Black running GNU/Linux or any other ARM-based linux device +//#if ( defined (__linux) || defined (LINUX) ) && defined( __arm__ ) || defined(MRAA) // BeagleBone Black running GNU/Linux or any other ARM-based linux device +#if ( defined (__linux) || defined (LINUX) ) || defined(LITTLEWIRE) || defined(MRAA) // BeagleBone Black running GNU/Linux or any other ARM-based linux device // The Makefile checks for bcm2835 (RPi) and copies the correct includes.h file to /utility/includes.h (Default is spidev config) // This behavior can be overridden by calling 'make RF24_SPIDEV=1' or 'make RF24_MRAA=1' @@ -42,11 +43,6 @@ #define RF24_TINY #include "utility/ATTiny/RF24_arch_config.h" -//LittleWire -#elif defined(LITTLEWIRE) - - #include "utility/LittleWire/RF24_arch_config.h" - //Teensy #elif defined (TEENSYDUINO) diff --git a/RPi/pyRF24/crossunixccompiler.py b/RPi/pyRF24/crossunixccompiler.py new file mode 100644 index 000000000..0532c15e9 --- /dev/null +++ b/RPi/pyRF24/crossunixccompiler.py @@ -0,0 +1,38 @@ +import sys +from distutils import unixccompiler +from distutils import ccompiler + + +def register(): + sys.modules['distutils.crossunixccompiler'] = sys.modules[__name__] + ccompiler.compiler_class['crossunix'] = (__name__, + 'CrossUnixCCompiler', + 'UNIX-style compiler for cross compilation') + + +def try_remove_all(lst, starts): + lst[:] = [x for x in lst if not x.startswith(starts)] + + +class CrossUnixCCompiler(unixccompiler.UnixCCompiler): + def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): + try_remove_all(self.compiler_so, ('-m64', '-fstack-protector-strong', '-mtune=generic')) + try_remove_all(cc_args, '-I/usr') + try_remove_all(pp_opts, '-I/usr') + return unixccompiler.UnixCCompiler._compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts) + + def link(self, target_desc, objects, + output_filename, output_dir=None, libraries=None, + library_dirs=None, runtime_library_dirs=None, + export_symbols=None, debug=0, extra_preargs=None, + extra_postargs=None, build_temp=None, target_lang=None): + try_remove_all(self.library_dirs, ('/usr')) + return unixccompiler.UnixCCompiler.link(self, target_desc, objects, output_filename, output_dir, libraries, + library_dirs, runtime_library_dirs, export_symbols, debug, + extra_preargs, extra_postargs, build_temp, target_lang) + + def _fix_lib_args(self, libraries, library_dirs, runtime_library_dirs): + self.__class__ = unixccompiler.UnixCCompiler + ret = unixccompiler.UnixCCompiler._fix_lib_args(self, libraries, library_dirs, runtime_library_dirs) + self.__class__ = CrossUnixCCompiler + return ret diff --git a/RPi/pyRF24/setup.py b/RPi/pyRF24/setup.py index d56221495..8b37bb05f 100755 --- a/RPi/pyRF24/setup.py +++ b/RPi/pyRF24/setup.py @@ -1,18 +1,37 @@ #!/usr/bin/env python -from distutils.core import setup, Extension +import os import sys +# import distutils.core +import setuptools +import crossunixccompiler + + +def process_configparams(): + with open('../Makefile.inc') as f: + config_lines = f.readlines() + + for line in config_lines: + identifier, value = line.split('=', 1) + os.environ[identifier] = value + if sys.version_info >= (3,): BOOST_LIB = 'boost_python3' else: BOOST_LIB = 'boost_python' -module_RF24 = Extension('RF24', - libraries = ['rf24-bcm', BOOST_LIB], - sources = ['pyRF24.cpp']) +process_configparams() +crossunixccompiler.register() + +# module_RF24 = distutils.core.Extension('RF24', +module_RF24 = setuptools.Extension('RF24', + libraries=['rf24', BOOST_LIB], + sources=['pyRF24.cpp'] + ) -setup(name='RF24', - version='1.1', - ext_modules=[module_RF24] - ) +# distutils.core.setup(name='RF24', +setuptools.setup(name='RF24', + version='1.1', + ext_modules=[module_RF24] + ) diff --git a/configure b/configure new file mode 100755 index 000000000..15fa2fd33 --- /dev/null +++ b/configure @@ -0,0 +1,219 @@ +#!/bin/bash +# set -x + +CROSS_CC=arm-linux-gnueabihf-gcc +CROSS_CXX=arm-linux-gnueabihf-g++ + +function help { + echo "configure script for RF24 library." + echo "Parameters:" + echo "OS=[LINUX|DARWIN] - Operating system." + echo "ARCH= - cpu architecture as passed to --arch to gcc" + +} + +function execute_check { + if [ "${REMOTE}" ]; then + ssh -o 'PreferredAuthentications=publickey' -o 'ConnectTimeout=30' -o 'BatchMode=yes' -o 'StrictHostKeyChecking=no' -p ${REMOTE_PORT} ${REMOTE} $1 + else + eval $1 + fi +} + +params="OS ARCH DRIVER CFLAGS PREFIX REMOTE_PREFIX LIB LIBNAME CC CXX LIB_DIR REMOTE_LIB_DIR HEADER_DIR REMOTE_HEADER_DIR DRIVER_DIR ARCH_DIR REMOTE REMOTE_HOST REMOTE_USER REMOTE_PORT SHARED_LINKER_FLAGS LDCONFIG REMOTE_LDCONFIG EXAMPLES_DIR REMOTE_EXAMPLES_DIR" +for i in "$@"; do + if [ "$i" = "-h" ] || [ "$i" = "--help" ]; then + help + exit 0 + fi + found=0 + for param in ${params}; do + if [[ "$i" = ${param}=* ]]; then + eval ${param}="${i#*=}" + shift + found=1 + break + fi + done + if [ "$found" = "0" ]; then + echo "[ERROR] Unknown option detected: ${i}" + exit 1 + fi +done + +#******************************************* +# remote machine verification +if [ "${REMOTE_HOST}" ]; then + if [ "${REMOTE_USER}" ]; then + REMOTE=${REMOTE_USER}@${REMOTE_HOST} + else + REMOTE=${REMOTE_HOST} + fi + if [ -z "${REMOTE_PORT}" ]; then + REMOTE_PORT=22 + fi + echo "[SECTION] Checking remote host." + if [ "$(nmap ${REMOTE_HOST} -Pn --host-timeout 30s -p ${REMOTE_PORT} 2>/dev/null | grep open)" ]; then + echo " [OK] ssh daemon on ${REMOTE_HOST} port ${REMOTE_PORT} seems to be listening." + else + echo " [WARNING] ssh on ${REMOTE_HOST} port ${REMOTE_PORT} seems not to be listening or nmap not installed." + fi + if [[ "$(execute_check 'echo ok 2>/dev/null')" ]]; then + echo " [OK] Remote machine ssh passwordless login configured fine." + else + echo " [WARNING] Remote machine ssh and/or passwordless login check failed." + fi + if [[ $(execute_check "sudo echo ok 2>/dev/null") ]]; then + echo " [OK] Remote machine sudo configured fine." + else + echo " [WARNING] Remote machine sudo test failed." + fi +fi + +if [ -z "${CC}" ]; then + echo "[SECTION] Detecting arm compilation environment." + if [[ $(command -v ${CROSS_CC} 2>/dev/null) ]]; then + echo " [OK] ${CROSS_CC} detected." + CC=${CROSS_CC} + CROSS_SYSROOT="$(${CC} --print-sysroot)" + if [ "${CROSS_SYSROOT}" = "/" ]; then + CROSS_SYSROOT="" + fi + else + echo " [INFO] ${CROSS_CC} not found." + fi + if [[ $(command -v ${CROSS_CXX} 2>/dev/null) ]]; then + echo " [OK] ${CROSS_CXX} detected." + CXX=${CROSS_CXX} + else + echo " [INFO] ${CROSS_CXX} not found." + fi +fi + +if [ "${CROSS_SYSROOT}" ]; then + PREFIX="${CROSS_SYSROOT}/usr/local" +fi + +PREFIX=${PREFIX:-/usr/local} +REMOTE_PREFIX=${REMOTE_PREFIX:-/usr/local} +LIB_DIR=${LIB_DIR:-${PREFIX}/lib} +REMOTE_LIB_DIR=${REMOTE_LIB_DIR:-${REMOTE_PREFIX}/lib} +HEADER_DIR=${HEADER_DIR:-${PREFIX}/include/RF24} +REMOTE_HEADER_DIR=${REMOTE_HEADER_DIR:-${REMOTE_PREFIX}/include/RF24} +EXAMPLES_DIR=${EXAMPLES_DIR:-${PREFIX}/bin} +REMOTE_EXAMPLES_DIR=${REMOTE_EXAMPLES_DIR:-${REMOTE_PREFIX}/bin} +LDCONFIG=${LDCONFIG:-ldconfig} +REMOTE_LDCONFIG=${REMOTE_LDCONFIG:-/sbin/ldconfig} +LIB=${LIB:-rf24} +CC=${CC:-gcc} +CXX=${CXX:-g++} +ARCH_DIR=${ARCH_DIR:-utility} + +#******************************************* +# CPU detection +if [ -z "${ARCH}" ]; then + echo "[SECTION] Detecting CPU architecture." + ARCH_DETECT=$(execute_check "uname -m") + echo " [INFO] ${ARCH_DETECT} detected." + case ${ARCH_DETECT} in + armv6l) + echo " [OK] Using armv6zk as ARCH." + ARCH=armv6zk + ;; + armv7l) + echo " [OK] Using armv7-a as ARCH." + ARCH=armv7-a + ;; + *) + echo " [INFO] No explicit ARCH set." + ;; + esac +fi + +if [ "${ARCH}" ]; then + CFLAGS+=" -march=${ARCH}" +fi + +#******************************************* +# DRIVER detection +if [ -z "${DRIVER}" ]; then + echo "[SECTION] Detecting DRIVER" + if [[ $(execute_check 'ls /dev/spidev* 2>/dev/null') ]]; then + DRIVER=SPIDEV + elif [[ $(execute_check "cat /proc/cpuinfo | grep Hardware | grep 'BCM2708\|BCM2709'") ]]; then + DRIVER=RPi + elif [[ $(execute_check "${REMOTE_LDCONFIG} -p | grep libmraa") ]]; then + DRIVER=MRAA + elif [[ $(execute_check "${REMOTE_LDCONFIG} -p | grep liblittlewire-spi") ]]; then + DRIVER=LittleWire + else + echo " [ERROR] No supported platform detected. Run configure with DRIVER= to set a platform explicitly." + exit 1 + fi + echo " [OK] DRIVER detected:${DRIVER}." +fi + + + +case ${DRIVER} in +SPIDEV) + ;; +RPi) + SHARED_LINKER_FLAGS+=" -pthread" + ;; +MRAA) + SHARED_LINKER_FLAGS+=" -lmraa" + ;; +LittleWire) + SHARED_LINKER_FLAGS+=" -llittlewire-spi" + ;; +*) + echo "[ERROR] Unsupported DRIVER: ${DRIVER}." + exit 1 + ;; +esac + +#******************************************* +# OS detection +if [ -z "${OS}" ]; then + echo "[SECTION] Detecting OS." + OS=$(execute_check "uname") + OS=${OS^^} + echo " [INFO] OS detected:${OS}." +fi + +case ${OS} in +LINUX) + DYN_SUFFIX=so + SHARED_LINKER_FLAGS+=" -shared -Wl,-soname,lib${LIB}.${DYN_SUFFIX}" + ;; +DARWIN) + DYN_SUFFIX=dylib + SHARED_LINKER_FLAGS+=" -dynamiclib -install_name ${LIB_DIR}/lib${LIB}.${DYN_SUFFIX}" + ;; +*) + echo "[ERROR] Unsupported OS: ${OS}." + exit 1 + ;; +esac + + +LIBNAME=${LIBNAME:-lib${LIB}.${DYN_SUFFIX}} +DRIVER_DIR=${DRIVER_DIR:-${ARCH_DIR}/${DRIVER}} +CFLAGS+=" -O2 -Wall -g" + +echo "[SECTION] Preparing configuration." +cp ${DRIVER_DIR}/includes.h ${ARCH_DIR}/includes.h + +echo "[SECTION] Saving configuration." +echo -n "" > Makefile.inc +for param in ${params}; do + if [[ ${!param} ]]; then + echo ${param}=${!param} >> Makefile.inc + fi +done + +echo "[SECTION] Cleaning previous builds." +make clean >/dev/null + +echo "[OK] Finished." diff --git a/examples_RPi/Makefile b/examples_linux/Makefile similarity index 100% rename from examples_RPi/Makefile rename to examples_linux/Makefile diff --git a/examples_RPi/extra/Makefile b/examples_linux/extra/Makefile similarity index 100% rename from examples_RPi/extra/Makefile rename to examples_linux/extra/Makefile diff --git a/examples_RPi/extra/rpi-hub.cpp b/examples_linux/extra/rpi-hub.cpp similarity index 100% rename from examples_RPi/extra/rpi-hub.cpp rename to examples_linux/extra/rpi-hub.cpp diff --git a/examples_RPi/extra/scanner.cpp b/examples_linux/extra/scanner.cpp similarity index 100% rename from examples_RPi/extra/scanner.cpp rename to examples_linux/extra/scanner.cpp diff --git a/examples_RPi/gettingstarted.cpp b/examples_linux/gettingstarted.cpp similarity index 100% rename from examples_RPi/gettingstarted.cpp rename to examples_linux/gettingstarted.cpp diff --git a/examples_RPi/gettingstarted_call_response.cpp b/examples_linux/gettingstarted_call_response.cpp similarity index 100% rename from examples_RPi/gettingstarted_call_response.cpp rename to examples_linux/gettingstarted_call_response.cpp diff --git a/examples_RPi/interrupts/Makefile b/examples_linux/interrupts/Makefile similarity index 100% rename from examples_RPi/interrupts/Makefile rename to examples_linux/interrupts/Makefile diff --git a/examples_RPi/interrupts/gettingstarted_call_response_int.cpp b/examples_linux/interrupts/gettingstarted_call_response_int.cpp similarity index 100% rename from examples_RPi/interrupts/gettingstarted_call_response_int.cpp rename to examples_linux/interrupts/gettingstarted_call_response_int.cpp diff --git a/examples_RPi/interrupts/gettingstarted_call_response_int2.cpp b/examples_linux/interrupts/gettingstarted_call_response_int2.cpp similarity index 100% rename from examples_RPi/interrupts/gettingstarted_call_response_int2.cpp rename to examples_linux/interrupts/gettingstarted_call_response_int2.cpp diff --git a/examples_RPi/interrupts/pingpair_dyn_int.cpp b/examples_linux/interrupts/pingpair_dyn_int.cpp similarity index 100% rename from examples_RPi/interrupts/pingpair_dyn_int.cpp rename to examples_linux/interrupts/pingpair_dyn_int.cpp diff --git a/examples_RPi/interrupts/transfer_interrupt.cpp b/examples_linux/interrupts/transfer_interrupt.cpp similarity index 100% rename from examples_RPi/interrupts/transfer_interrupt.cpp rename to examples_linux/interrupts/transfer_interrupt.cpp diff --git a/examples_RPi/pingpair_dyn.cpp b/examples_linux/pingpair_dyn.cpp similarity index 100% rename from examples_RPi/pingpair_dyn.cpp rename to examples_linux/pingpair_dyn.cpp diff --git a/examples_RPi/pingpair_dyn.py b/examples_linux/pingpair_dyn.py similarity index 100% rename from examples_RPi/pingpair_dyn.py rename to examples_linux/pingpair_dyn.py diff --git a/examples_RPi/readme.md b/examples_linux/readme.md similarity index 100% rename from examples_RPi/readme.md rename to examples_linux/readme.md diff --git a/examples_RPi/transfer.cpp b/examples_linux/transfer.cpp similarity index 100% rename from examples_RPi/transfer.cpp rename to examples_linux/transfer.cpp diff --git a/utility/LittleWire/RF24_arch_config.h b/utility/LittleWire/RF24_arch_config.h index 6a074bc9f..a7546f3e3 100644 --- a/utility/LittleWire/RF24_arch_config.h +++ b/utility/LittleWire/RF24_arch_config.h @@ -9,7 +9,7 @@ #include // Additional fixes for LittleWire - #include + #include #include extern LittleWireSPI _SPI; @@ -35,4 +35,4 @@ #endif -#endif \ No newline at end of file +#endif diff --git a/utility/LittleWire/includes.h b/utility/LittleWire/includes.h new file mode 100644 index 000000000..8e4b6af0f --- /dev/null +++ b/utility/LittleWire/includes.h @@ -0,0 +1,31 @@ + + /** + * @file includes.h + * Configuration defines for RF24/Linux + */ + + /** + * Example of includes.h for RF24 Linux portability + * + * @defgroup Porting_Includes Porting: Includes + * + * + * @{ + */ + +#ifndef __RF24_INCLUDES_H__ +#define __RF24_INCLUDES_H__ + + /** + * Define a specific platform for this configuration + */ + #define LITTLEWIRE + + /** + * Load the correct configuration for this platform + */ + #include "LittleWire/RF24_arch_config.h" + +#endif + +/*@}*/ diff --git a/utility/BBB/RF24_arch_config.h b/utility/SPIDEV/RF24_arch_config.h similarity index 100% rename from utility/BBB/RF24_arch_config.h rename to utility/SPIDEV/RF24_arch_config.h diff --git a/utility/BBB/compatibility.c b/utility/SPIDEV/compatibility.c similarity index 100% rename from utility/BBB/compatibility.c rename to utility/SPIDEV/compatibility.c diff --git a/utility/BBB/compatibility.h b/utility/SPIDEV/compatibility.h similarity index 100% rename from utility/BBB/compatibility.h rename to utility/SPIDEV/compatibility.h diff --git a/utility/BBB/gpio.cpp b/utility/SPIDEV/gpio.cpp similarity index 100% rename from utility/BBB/gpio.cpp rename to utility/SPIDEV/gpio.cpp diff --git a/utility/BBB/gpio.h b/utility/SPIDEV/gpio.h similarity index 100% rename from utility/BBB/gpio.h rename to utility/SPIDEV/gpio.h diff --git a/utility/BBB/includes.h b/utility/SPIDEV/includes.h similarity index 100% rename from utility/BBB/includes.h rename to utility/SPIDEV/includes.h diff --git a/utility/BBB/spi.cpp b/utility/SPIDEV/spi.cpp similarity index 89% rename from utility/BBB/spi.cpp rename to utility/SPIDEV/spi.cpp index 749bb9067..3950f08c0 100644 --- a/utility/BBB/spi.cpp +++ b/utility/SPIDEV/spi.cpp @@ -16,32 +16,19 @@ SPI::SPI() { void SPI::begin(int busNo){ - - //BBB: - if(!busNo){ - this->device = "/dev/spidev1.0";; - }else{ - this->device = "/dev/spidev1.1";; - } - - //RPi: - /*if(!busNo){ - this->device = "/dev/spidev0.0";; - }else{ - this->device = "/dev/spidev0.1";; - }*/ - - + this->device = "/dev/spidev0.0"; + /* set spidev accordingly to busNo like: + * busNo = 23 -> /dev/spidev2.3 + * + * a bit messy but simple + * */ + this->device[11] += (busNo / 10) % 10; + this->device[13] += busNo % 10; this->bits = 8; -// this->speed = 24000000; // 24Mhz - proly doesnt work -// this->speed = 16000000; // 16Mhz - this->speed = 8000000; // 8Mhz -// this->speed = 4000000; -// this->speed = 2000000; // 2Mhz + this->speed = RF24_SPIDEV_SPEED; this->mode=0; //this->mode |= SPI_NO_CS; this->init(); - } void SPI::init() diff --git a/utility/BBB/spi.h b/utility/SPIDEV/spi.h similarity index 94% rename from utility/BBB/spi.h rename to utility/SPIDEV/spi.h index 8b2960364..4bf041b2e 100644 --- a/utility/BBB/spi.h +++ b/utility/SPIDEV/spi.h @@ -35,6 +35,11 @@ #include #include +#ifndef RF24_SPIDEV_SPEED +/* 8MHz as default */ +#define RF24_SPIDEV_SPEED 8000000 +#endif + #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) using namespace std;