Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OrangePi Zero] Linux chip enable conditional statement #904

Merged
merged 3 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ ifneq (,$(findstring -lpigpio,$(SHARED_LINKER_LIBS)))
OBJECTS+=interrupt.o
endif
else ifeq ($(DRIVER), SPIDEV)
OBJECTS+=spi.o gpio.o compatibility.o
#OBJECTS+=spi.o gpio.o compatibility.o
OBJECTS+=spi.o compatibility.o
ifneq (,$(findstring -lpigpio,$(SHARED_LINKER_LIBS)))
OBJECTS+=interrupt.o
endif
ifneq (,$(findstring -lwiringPi,$(SHARED_LINKER_LIBS)))
OBJECTS+=interrupt.o
endif
else ifeq ($(DRIVER), wiringPi)
OBJECTS+=spi.o
else ifeq ($(DRIVER), pigpio)
Expand Down
12 changes: 11 additions & 1 deletion RF24.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#include "nRF24L01.h"
#include "RF24_config.h"
#include "RF24.h"

#ifdef ORANGEPI
#include <wiringPi.h>
#endif
/****************************************************************************/

void RF24::csn(bool mode)
Expand Down Expand Up @@ -102,10 +104,14 @@ void RF24::csn(bool mode)

void RF24::ce(bool level)
{
#ifndef RF24_LINUX
//Allow for 3-pin use on ATTiny
if (ce_pin != csn_pin) {
#endif
digitalWrite(ce_pin, level);
#ifndef RF24_LINUX
}
#endif
}

/****************************************************************************/
Expand Down Expand Up @@ -1031,6 +1037,10 @@ bool RF24::_init_pins()
gpio.begin(ce_pin, csn_pin);
#endif

#ifdef ORANGEPI
wiringPiSetup();
#endif

pinMode(ce_pin, OUTPUT);
ce(LOW);
delay(100);
Expand Down
9 changes: 9 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CROSS_CC=arm-linux-gnueabihf-gcc
CROSS_CXX=arm-linux-gnueabihf-g++

pigpio_detected=0
wiringPi_detected=0

function help {
cat <<EOF
Expand Down Expand Up @@ -63,6 +64,11 @@ if [[ -f "/usr/lib/libpigpio.so" || -f "/usr/local/lib/libpigpio.so" || -f "/usr
pigpio_detected=1
fi

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

function die {
echo "[ERROR] $1"
exit $2
Expand Down Expand Up @@ -414,6 +420,9 @@ SPIDEV)
if [ $pigpio_detected -eq 1 ]; then
echo "[INFO] linking to pigpio for interrupt compatibility"
SHARED_LINKER_LIBS+=" -lpigpio"
elif [ $wiringPi_detected -eq 1 ]; then
echo "[INFO] linking to wiringPi for interrupt compatibility"
SHARED_LINKER_LIBS+=" -lwiringPi"
else
CFLAGS+=" -DRF24_NO_INTERRUPT"
fi
Expand Down
3 changes: 2 additions & 1 deletion examples_linux/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ endif
include ../Makefile.inc

# define all programs
PROGRAMS = gettingstarted acknowledgementPayloads manualAcknowledgements streamingData multiceiverDemo scanner
PROGRAMS = gettingstarted
#PROGRAMS = gettingstarted acknowledgementPayloads manualAcknowledgements streamingData multiceiverDemo scanner
ifneq (,$(findstring -lpigpio,$(SHARED_LINKER_LIBS)))
PROGRAMS+=interruptConfigure
endif
Expand Down
2 changes: 1 addition & 1 deletion examples_linux/Makefile.examples
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ LIBS=-l$(LIB)
ifeq ($(DRIVER), LittleWire)
LIBS+= -llittlewire-spi
endif

LIBS+=-lwiringPi
all: $(PROGRAMS)

$(PROGRAMS): $(SOURCES)
Expand Down
2 changes: 1 addition & 1 deletion examples_linux/gettingstarted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ using namespace std;
// ie: RF24 radio(<ce_pin>, <a>*10+<b>); spidev1.0 is 10, spidev1.1 is 11 etc..

// Generic:
RF24 radio(22, 0);
RF24 radio(16, 10, 4000000);
/****************** Linux (BBB,x86,etc) ***********************/
// See http://nRF24.github.io/RF24/pages.html for more information on usage
// See http://iotdk.intel.com/docs/master/mraa/ for more information on MRAA
Expand Down
11 changes: 9 additions & 2 deletions utility/SPIDEV/RF24_arch_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,15 @@
#define RF24_UTILITY_SPIDEV_RF24_ARCH_CONFIG_H_

#define RF24_LINUX
#define ORANGEPI

#include <stddef.h>
#include "spi.h"
#ifdef ORANGEPI
#include <wiringPi.h>
#else
#include "gpio.h"
#endif
#include "compatibility.h"
#include <stdint.h>
#include <stdio.h>
Expand Down Expand Up @@ -54,14 +59,16 @@ typedef uint16_t prog_uint16_t;
#define pgm_read_ptr(p) (*(void* const*)(p))

// Function, constant map as a result of migrating from Arduino
#ifndef ORANGEPI
#define LOW GPIO::OUTPUT_LOW
#define HIGH GPIO::OUTPUT_HIGH
#define INPUT GPIO::DIRECTION_IN
#define OUTPUT GPIO::DIRECTION_OUT
#define digitalWrite(pin, value) GPIO::write(pin, value)
#define pinMode(pin, direction) GPIO::open(pin, direction)
#define delay(milisec) __msleep(milisec)
#define delayMicroseconds(usec) __usleep(usec)
#define millis() __millis()
#define delay(milisec) __msleep(milisec)
#define millis(void) __millis()
#endif

#endif // RF24_UTILITY_SPIDEV_RF24_ARCH_CONFIG_H_
4 changes: 2 additions & 2 deletions utility/SPIDEV/compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ extern "C" {
#include <time.h>
#include <sys/time.h>

void __msleep(int milisec);
void __msleep(unsigned int milisec);

void __usleep(int milisec);
void __usleep(unsigned int milisec);

void __start_timer();

Expand Down
13 changes: 13 additions & 0 deletions utility/SPIDEV/interrupt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,30 @@ Interrupt functions
*/

#include "interrupt.h"
#ifdef ORANGEPI
#include <wiringPi.h>
#else
#include <pigpio.h>
#endif

int attachInterrupt(int pin, int mode, void (*function)(void))
{
#ifdef ORANGEPI
wiringPiSetup();
return wiringPiISR(pin, mode, function);
#else
gpioInitialise();
return gpioSetISRFunc(pin, mode, 0, (gpioISRFunc_t)function);
#endif
}

int detachInterrupt(int pin)
{
#ifdef ORANGEPI
return wiringPiISR(pin, 0, NULL);
#else
return gpioSetISRFunc(pin, 0, 0, NULL);
#endif
}

void rfNoInterrupts()
Expand Down
6 changes: 6 additions & 0 deletions utility/SPIDEV/interrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@ Interrupt functions
#define __RF24_INTERRUPT_H__

#include "RF24_arch_config.h"
#ifdef ORANGEPI
#include <wiringPi.h>
#else
#include <pigpio.h>
#endif

#ifndef ORANGEPI
#define INT_EDGE_SETUP 0
#define INT_EDGE_FALLING FALLING_EDGE
#define INT_EDGE_RISING RISING_EDGE
#define INT_EDGE_BOTH EITHER_EDGE
#endif

#ifdef __cplusplus
extern "C" {
Expand Down