From 81f3b0b81c4fe1eb96f6e403aa905a42284c574b Mon Sep 17 00:00:00 2001 From: leeboby Date: Thu, 27 Feb 2020 10:47:39 +0800 Subject: [PATCH] Support Orange Pi Zero Plus (H5) --- .gitignore | 1 + build | 2 +- examples/blink.c | 10 +++-- gpio/Makefile | 10 +++++ gpio/OrangePi.c | 78 +++++++++++++++++++++++++++++++- wiringPi/Makefile | 10 +++++ wiringPi/OrangePi.c | 107 ++++++++++++++++++++++++++++++++++++++++++-- wiringPi/OrangePi.h | 8 ++-- 8 files changed, 213 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 2dd061a..e6ad4ba 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ debian-template/wiringPi debian-template/wiringpi-*.deb gpio/gpio examples/speed +examples/blink diff --git a/build b/build index f3519e5..da81928 100755 --- a/build +++ b/build @@ -49,7 +49,7 @@ select_boards() local choice local call=${1} - boards=("OrangePi_PC2" "OrangePi_A64" "OrangePi_ZERO" "OrangePi_H3" "OrangePi_LITE2" "OrangePi_H3_ZEROPLUS2" "OrangePi_3" "OrangePi_RK3399" "OrangePi_ONEPLUS" "OrangePi_4") + boards=("OrangePi_PC2" "OrangePi_ZEROPLUS" "OrangePi_A64" "OrangePi_ZERO" "OrangePi_H3" "OrangePi_LITE2" "OrangePi_H3_ZEROPLUS2" "OrangePi_3" "OrangePi_RK3399" "OrangePi_ONEPLUS" "OrangePi_4") printf "All available boards:\n" for var in ${boards[@]} ; do diff --git a/examples/blink.c b/examples/blink.c index 22de0f4..72cae6c 100644 --- a/examples/blink.c +++ b/examples/blink.c @@ -1,22 +1,24 @@ #include #include +#define NUM 17 + int main (void) { int i = 0; wiringPiSetup () ; - for (i=0; i<28; i++) + for (i = 0; i < NUM; i++) pinMode (i, OUTPUT) ; - for (;;) + for ( ;; ) { - for (i=0; i<28; i++) + for (i = 0; i < NUM; i++) digitalWrite (i, HIGH) ; // On delay (500) ; // mS - for (i=0; i<28; i++) + for (i = 0; i < NUM; i++) digitalWrite (i, LOW) ; // Off delay (500) ; } diff --git a/gpio/Makefile b/gpio/Makefile index 51c9687..586946f 100755 --- a/gpio/Makefile +++ b/gpio/Makefile @@ -42,6 +42,7 @@ LIBS = -lwiringPi -lwiringPiDev -lpthread -lrt -lm -lcrypt ifeq ($(PLATFORM),) #PLATFORM = OrangePi_2G-IOT #PLATFORM = OrangePi_PC2 + #PLATFORM = OrangePi_ZEROPLUS #PLATFORM = OrangePi_A64 #PLATFORM = OrangePi_H5 #PLATFORM = OrangePi_ZERO @@ -63,6 +64,11 @@ EXTRA_CFLAGS = -DCONFIG_ORANGEPI_PC2 EXTRA_CFLAGS += -DCONFIG_ORANGEPI endif +ifeq ($(PLATFORM), OrangePi_ZEROPLUS) +EXTRA_CFLAGS = -DCONFIG_ORANGEPI_ZEROPLUS +EXTRA_CFLAGS += -DCONFIG_ORANGEPI +endif + ifeq ($(PLATFORM), OrangePi_A64) EXTRA_CFLAGS = -DCONFIG_ORANGEPI_A64 EXTRA_CFLAGS += -DCONFIG_ORANGEPI @@ -121,6 +127,10 @@ ifeq ($(PLATFORM), OrangePi_PC2) SRC += OrangePi.c endif +ifeq ($(PLATFORM), OrangePi_ZEROPLUS) + SRC += OrangePi.c +endif + ifeq ($(PLATFORM), OrangePi_A64) SRC += OrangePi.c endif diff --git a/gpio/OrangePi.c b/gpio/OrangePi.c index 64778fb..dde84c2 100755 --- a/gpio/OrangePi.c +++ b/gpio/OrangePi.c @@ -66,7 +66,79 @@ char *physNames[64] = "GPIO.19", "GPIO.20", NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, }; -#endif +#endif /* PC2 */ + + +#ifdef CONFIG_ORANGEPI_ZEROPLUS +int physToWpi [64] = //return wiringPI pin +{ + -1, // 0 + -1, -1, // 1, 2 + 0, -1, //3, 4 + 1, -1, //5, 6 + 2, 3, //7, 8 + -1, 4, //9,10 + 5, 6, //11,12 + 7, -1, //13,14 + 8, 9, //15,16 + -1, 10, //17,18 + 11, -1, //19,20 + 12, 13, //21,22 + 14, 15, //23, 24 + -1, 16, // 25, 26 + + -1, -1, //27, 28 + -1, -1, //29, 30 + -1, -1, //31, 32 + -1, -1, //33, 34 + -1, -1, //35, 36 + -1, -1, //37, 38 + -1, -1, //39, 40 + -1, -1, //41, 42 +// Padding: + + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 56 + -1, -1, -1, -1, -1, -1, -1, // ... 63 +}; + +char *physNames[64] = +{ + NULL, + + " 3.3v", "5v ", + " SDA.0", "5v ", + " SCL.0", "GND ", + " PA6", "TxD.1 ", + " GND", "RxD.1 ", + " RXD.2", "PA07 ", + " TXD.2", "GND ", + " CTS.2", "SDA.1 ", + " 3.3v", "SCL.1 ", + " MOSI.1", "GND ", + " MISO.1", "RTS.2 ", + " SCLK.1", "CS.1 ", + " GND", "PA10 ", + + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, +}; +#endif /* ZEROPLUS */ #ifdef CONFIG_ORANGEPI_2G_IOT char *physNames[64] = @@ -722,6 +794,8 @@ void OrangePiReadAll(void) wiringPiDebug = FALSE; #ifdef CONFIG_ORANGEPI_PC2 printf (" +------+-----+----------+------+---+ OPi PC2 +---+------+----------+-----+------+\n"); +#elif CONFIG_ORANGEPI_ZEROPLUS + printf (" +------+-----+----------+------+---+ ZEROPLUS +---+------+----------+-----+------+\n"); #elif CONFIG_ORANGEPI_2G_IOT printf (" +-----+-----+----------+------+---+OrangePi 2G-IOT+---+---+------+---------+-----+--+\n"); #elif CONFIG_ORANGEPI_H3 || CONFIG_ORANGEPI_H3_ZEROPLUS2 @@ -753,6 +827,8 @@ void OrangePiReadAll(void) printf (" | GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |\n"); #ifdef CONFIG_ORANGEPI_PC2 printf (" +------+-----+----------+------+---+ OPi PC2 +---+------+----------+-----+------+\n"); +#elif CONFIG_ORANGEPI_ZEROPLUS + printf (" +------+-----+----------+------+---+ ZEROPLUS +---+------+----------+-----+------+\n"); #elif CONFIG_ORANGEPI_2G_IOT printf (" +------+-----+----------+------+---+OrangePi 2G-IOT+---+------+----------+-----+-----+\n"); #elif CONFIG_ORANGEPI_H3 || CONFIG_ORANGEPI_H3_ZEROPLUS2 diff --git a/wiringPi/Makefile b/wiringPi/Makefile index 5e6d22d..72ba20e 100755 --- a/wiringPi/Makefile +++ b/wiringPi/Makefile @@ -47,6 +47,7 @@ LIBS = -lm -lpthread -lrt -lcrypt ifeq ($(PLATFORM),) #PLATFORM = OrangePi_2G-IOT #PLATFORM = OrangePi_PC2 + #PLATFORM = OrangePi_ZEROPLUS #PLATFORM = OrangePi_A64 #PLATFORM = OrangePi_H3 #PLATFORM = OrangePi_LITE2 @@ -67,6 +68,11 @@ EXTRA_CFLAGS = -DCONFIG_ORANGEPI_PC2 EXTRA_CFLAGS += -DCONFIG_ORANGEPI endif +ifeq ($(PLATFORM), OrangePi_ZEROPLUS) +EXTRA_CFLAGS = -DCONFIG_ORANGEPI_ZEROPLUS +EXTRA_CFLAGS += -DCONFIG_ORANGEPI +endif + ifeq ($(PLATFORM), OrangePi_A64) EXTRA_CFLAGS = -DCONFIG_ORANGEPI_A64 EXTRA_CFLAGS += -DCONFIG_ORANGEPI @@ -141,6 +147,10 @@ ifeq ($(PLATFORM), OrangePi_PC2) SRC += OrangePi.c endif +ifeq ($(PLATFORM), OrangePi_ZEROPLUS) +SRC += OrangePi.c +endif + ifeq ($(PLATFORM), OrangePi_A64) SRC += OrangePi.c endif diff --git a/wiringPi/OrangePi.c b/wiringPi/OrangePi.c index e0238cf..e608b7c 100755 --- a/wiringPi/OrangePi.c +++ b/wiringPi/OrangePi.c @@ -209,7 +209,108 @@ int ORANGEPI_PIN_MASK[9][32] = //[BANK] [INDEX] {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PH {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PI }; -#endif /* CONFIG_ORANGEPI_2G_IOT */ +#endif /* PC2 */ + + +#ifdef CONFIG_ORANGEPI_ZEROPLUS +int pinToGpioOrangePi [64] = +{ + 12, 11, 6, 198, 199, 1, 7, 0, 3, // From the Original Wiki - GPIO 0 through 7: wpi 0 - 7 + 19, 18, // I2C - SDA0, SCL0 wpi 8 - 9 + 15, 16, // SPI - CE1, CE0 wpi 10 - 11 + 2, 14, 13, // SPI - MOSI, MISO, SCLK wpi 12 - 14 + 10, -1, // UART - Tx, Rx wpi 15 - 16 + -1, -1, -1, -1, // Rev 2: New GPIOs 8 though 11 wpi 17 - 20 + -1, -1, -1, -1, -1, // B+ wpi 21, 22, 23, 24, 25 + -1, -1, // wpi 26, 27 + -1, -1, //PA4, PA5(PWM0) wpi 28, 29 + + -1, -1, // B+ wpi 30, 31 + +// Padding: + + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 47 + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 63 +}; + +int physToGpioOrangePi [64] = +{ + -1, // 0 + -1, -1, // 1, 2 + 12, -1, + 11, -1, + 6, 198, + -1, 199, + 1, 7, + 0, -1, + 3, 19, + -1, 18, + 15, -1, + 16, 2, + 14, 13, + -1, 10, // 25, 26 + + -1, -1, //27, 28 + -1, -1, //29, 30 + -1, -1, //31, 32 + -1, -1, //33, 34 + -1, -1, //35, 36 + -1, -1, //37, 38 + -1, -1, //39, 40 + -1, -1, //41, 42 +// Padding: + + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 56 + -1, -1, -1, -1, -1, -1, -1, // ... 63 +}; + +int physToPinOrangePi [64] = //return wiringPI pin +{ + -1, // 0 + -1, -1, // 1, 2 + 0, -1, //3, 4 + 1, -1, //5, 6 + 2, 3, //7, 8 + -1, 4, //9,10 + 5, 6, //11,12 + 7, -1, //13,14 + 8, 9, //15,16 + -1, 10, //17,18 + 11, -1, //19,20 + 12, 13, //21,22 + 14, 15, //23, 24 + -1, 16, // 25, 26 + + -1, -1, //27, 28 + -1, -1, //29, 30 + -1, -1, //31, 32 + -1, -1, //33, 34 + -1, -1, //35, 36 + -1, -1, //37, 38 + -1, -1, //39, 40 + -1, -1, //41, 42 +// Padding: + + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 56 + -1, -1, -1, -1, -1, -1, -1, // ... 63 +}; + +int ORANGEPI_PIN_MASK[12][32] = //[BANK] [INDEX] +{ + { 0, 1, 2, 3,-1,-1, 6, 7,-1,-1,10,11,12,13,14,15,16,-1,18,19,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PA + {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PB + {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PC + {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PD + {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PE + {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PF + {-1,-1,-1,-1,-1,-1, 6, 7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PG + {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PH + {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PI + {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PJ + {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PK + {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PL +}; +#endif /* ZEROPLUS */ #ifdef CONFIG_ORANGEPI_A64 int pinToGpioOrangePi [64] = @@ -989,7 +1090,7 @@ const char *piModelNames[6] = "Compute Module", #ifdef CONFIG_ORANGEPI_2G_IOT "OrangePi 2G-IOT", -#elif CONFIG_ORANGEPI_PC2 +#elif CONFIG_ORANGEPI_PC2 || CONFIG_ORANGEPI_ZEROPLUS || CONFIG_ORANGEPI_H5_ZEROPLUS2 || CONFIG_ORANGEPI_PRIME "OrangePi PC2", #elif CONFIG_ORANGEPI_A64 "OrangePi Win/Winplus", @@ -1658,7 +1759,7 @@ int isOrangePi(void) #ifdef CONFIG_ORANGEPI_2G_IOT /* Support: OrangePi 2G-IOT and OrangePi i96 */ char *OrangePi_string = "rda8810"; -#elif CONFIG_ORANGEPI_PC2 +#elif CONFIG_ORANGEPI_PC2 || CONFIG_ORANGEPI_ZEROPLUS || CONFIG_ORANGEPI_H5_ZEROPLUS2 || CONFIG_ORANGEPI_PRIME /* Support: OrangePi PC2 */ char *OrangePi_string = "sun50iw2"; #elif CONFIG_ORANGEPI_A64 diff --git a/wiringPi/OrangePi.h b/wiringPi/OrangePi.h index 89a467b..5b19f0b 100755 --- a/wiringPi/OrangePi.h +++ b/wiringPi/OrangePi.h @@ -30,7 +30,7 @@ #endif /* CONFIG_ORANGEPI_2G_IOT */ -#ifdef CONFIG_ORANGEPI_PC2 +#if CONFIG_ORANGEPI_PC2 || CONFIG_ORANGEPI_ZEROPLUS || CONFIG_ORANGEPI_H5_ZEROPLUS2 || CONFIG_ORANGEPI_PRIME /************** OrangePi H5 ***********************/ #define GPIOA_BASE (0x01C20000) #define GPIO_NUM (0x40) @@ -75,7 +75,7 @@ #define GPIOL_BASE (0x07022000) #define GPIOL_BASE_MAP (0x07022000) #define MAP_SIZE_L (4096 * 1) -#define GPIO_PWM_OP (0x0300A000) +#define GPIO_PWM_OP (0x0300A000) #endif /*********** OrangePi RK3399 *************/ @@ -203,13 +203,13 @@ extern const char *piModelNames[6]; #ifdef CONFIG_ORANGEPI_2G_IOT extern int ORANGEPI_PIN_MASK[4][32]; -#elif CONFIG_ORANGEPI_PC2 +#elif CONFIG_ORANGEPI_PC2 || CONFIG_ORANGEPI_PRIME extern int ORANGEPI_PIN_MASK[9][32]; #elif CONFIG_ORANGEPI_A64 extern int ORANGEPI_PIN_MASK[12][32]; #elif CONFIG_ORANGEPI_H3 extern int ORANGEPI_PIN_MASK[9][32]; -#elif CONFIG_ORANGEPI_ZERO || CONFIG_ORANGEPI_H3_ZEROPLUS2 +#elif CONFIG_ORANGEPI_ZERO || CONFIG_ORANGEPI_H3_ZEROPLUS2 || CONFIG_ORANGEPI_ZEROPLUS || CONFIG_ORANGEPI_H5_ZEROPLUS2 extern int ORANGEPI_PIN_MASK[12][32]; #elif CONFIG_ORANGEPI_RK3399 extern int ORANGEPI_PIN_MASK[5][32];