From 4ed666d3fb0124478dcec20b0e78232b7f332e92 Mon Sep 17 00:00:00 2001 From: Paul Kramer Date: Thu, 5 Jan 2023 19:46:37 +0100 Subject: [PATCH] feat: prepare for OrangePi boards --- OpenSprinkler.cpp | 6 +++--- OpenSprinkler.h | 2 +- build.sh | 26 ++++++++++++++++++++++++++ defines.h | 18 ++++++++++++++++++ gpio.cpp | 4 ++-- gpio.h | 2 +- utils.cpp | 2 +- utils.h | 2 +- 8 files changed, 53 insertions(+), 9 deletions(-) diff --git a/OpenSprinkler.cpp b/OpenSprinkler.cpp index 798d4d6d..da92a5a8 100644 --- a/OpenSprinkler.cpp +++ b/OpenSprinkler.cpp @@ -93,7 +93,7 @@ extern ProgramData pd; LiquidCrystal OpenSprinkler::lcd; extern SdFat sd; #else - #if defined(OSPI) + #if defined(OSPI) || defined(OSOPI) byte OpenSprinkler::pin_sr_data = PIN_SR_DATA; #endif // todo future: LCD define for Linux-based systems @@ -817,7 +817,7 @@ void OpenSprinkler::begin() { pinMode(PIN_SR_CLOCK, OUTPUT); - #if defined(OSPI) + #if defined(OSPI) || defined(OSOPI) pin_sr_data = PIN_SR_DATA; // detect RPi revision unsigned int rev = detect_rpi_rev(); @@ -1189,7 +1189,7 @@ void OpenSprinkler::apply_all_station_bits() { for(s=0;s<8;s++) { digitalWrite(PIN_SR_CLOCK, LOW); - #if defined(OSPI) // if OSPI, use dynamically assigned pin_sr_data + #if defined(OSPI) || defined(OSOPI) // if OSPI, use dynamically assigned pin_sr_data digitalWrite(pin_sr_data, (sbits & ((byte)1<<(7-s))) ? HIGH : LOW ); #else digitalWrite(PIN_SR_DATA, (sbits & ((byte)1<<(7-s))) ? HIGH : LOW ); diff --git a/OpenSprinkler.h b/OpenSprinkler.h index f5d4771b..2b534403 100644 --- a/OpenSprinkler.h +++ b/OpenSprinkler.h @@ -175,7 +175,7 @@ class OpenSprinkler { // todo: LCD define for RPI/BBB #endif -#if defined(OSPI) +#if defined(OSPI) || defined(OSOPI) static byte pin_sr_data; // RPi shift register data pin to handle RPi rev. 1 #endif diff --git a/build.sh b/build.sh index 8c5df9f5..8bcadab8 100755 --- a/build.sh +++ b/build.sh @@ -20,6 +20,32 @@ elif [ "$1" == "osbo" ]; then apt-get install -y libmosquitto-dev echo "Compiling firmware..." g++ -o OpenSprinkler -DOSBO main.cpp OpenSprinkler.cpp program.cpp opensprinkler_server.cpp utils.cpp weather.cpp gpio.cpp etherport.cpp mqtt.cpp -lpthread -lmosquitto +elif [ "$1" == "opipc" ]; then + echo "Installing required libraries..." + apt-get update + apt-get install -y libmosquitto-dev + echo "Downloading and installing wiringOP..." + if [ -d "wiringOP" ]; then + echo "wiringOP folder exists, updating to latest master" + cd wiringOP + git checkout master + git pull + else + git clone https://github.com/orangepi-xunlong/wiringOP.git + cd wiringOP + fi + ./build clean + ./build + cd .. + echo "Done installing wiringOP" + if ! command -v gpio &> /dev/null + then + echo "Command gpio is required and is not installed" + exit 0 + fi + echo "Compiling firmware..." + g++ -o OpenSprinkler -DOSOPI -std=c++14 main.cpp OpenSprinkler.cpp program.cpp opensprinkler_server.cpp utils.cpp weather.cpp gpio.cpp etherport.cpp mqtt.cpp -lpthread -lmosquitto + else echo "Installing required libraries..." apt-get update diff --git a/defines.h b/defines.h index 47575e85..53cda374 100755 --- a/defines.h +++ b/defines.h @@ -421,6 +421,24 @@ enum { #define PIN_FREE_LIST {5,6,7,8,9,10,11,12,13,16,18,19,20,21,23,24,25,26} // free GPIO pins #define ETHER_BUFFER_SIZE 16384 +#elif defined(OSOPI) // for OSPi on OrangePi + + #define OS_HW_VERSION OSPI_HW_VERSION_BASE + #define PIN_SR_LATCH 3 // shift register latch pin + #define PIN_SR_DATA 0 // shift register data pin + #define PIN_SR_DATA_ALT 199 // shift register data pin (alternative, for RPi 1 rev. 1 boards) + #define PIN_SR_CLOCK 6 // shift register clock pin + #define PIN_SR_OE 1 // shift register output enable pin + #define PIN_SENSOR1 13 + #define PIN_SENSOR2 68 + #define PIN_RFTX 14 // RF transmitter pin + //#define PIN_BUTTON_1 23 // button 1 + //#define PIN_BUTTON_2 24 // button 2 + //#define PIN_BUTTON_3 25 // button 3 + + #define PIN_FREE_LIST {2,7,8,9,10,11,12,18,19,20,21,64,65,66,67,71,110,198,200,201} // free GPIO pins + #define ETHER_BUFFER_SIZE 16384 + #elif defined(OSBO) // for OSBo #define OS_HW_VERSION OSBO_HW_VERSION_BASE diff --git a/gpio.cpp b/gpio.cpp index 2d4825b5..20e86a65 100644 --- a/gpio.cpp +++ b/gpio.cpp @@ -175,7 +175,7 @@ byte digitalReadExt(byte pin) { } #endif -#elif defined(OSPI) || defined(OSBO) +#elif defined(OSPI) || defined(OSBO) || defined(OSOPI) #include #include @@ -281,7 +281,7 @@ void pinMode(int pin, byte mode) { } close(fd); -#if defined(OSPI) +#if defined(OSPI) || defined(OSOPI) if(mode==INPUT_PULLUP) { char cmd[BUFFER_MAX]; //snprintf(cmd, BUFFER_MAX, "gpio -g mode %d up", pin); diff --git a/gpio.h b/gpio.h index 67f82566..e734a168 100644 --- a/gpio.h +++ b/gpio.h @@ -125,7 +125,7 @@ byte digitalReadExt(byte pin); #define OUTPUT 0 #define INPUT 1 -#if defined(OSPI) +#if defined(OSPI) || defined(OSOPI) #define INPUT_PULLUP 2 #else #define INPUT_PULLUP INPUT diff --git a/utils.cpp b/utils.cpp index 9d4a938e..bc9fa22e 100644 --- a/utils.cpp +++ b/utils.cpp @@ -143,7 +143,7 @@ ulong micros (void) return (ulong)(now - epochMicro) ; } -#if defined(OSPI) +#if defined(OSPI) || defined(OSOPI) unsigned int detect_rpi_rev() { FILE * filp; unsigned int rev; diff --git a/utils.h b/utils.h index bd968122..d7d4cc3c 100644 --- a/utils.h +++ b/utils.h @@ -78,7 +78,7 @@ void str2mac(const char *_str, byte mac[]); ulong millis(); ulong micros(); void initialiseEpoch(); - #if defined(OSPI) + #if defined(OSPI) || defined(OSOPI) unsigned int detect_rpi_rev(); #endif