From 7ee2dd55a8c757ec7838c8879de943acea694319 Mon Sep 17 00:00:00 2001 From: "gp.coder" Date: Sun, 16 Feb 2020 18:25:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0OrangePi4B=E7=9A=84=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build | 2 +- examples/Makefile | 4 +- examples/isr | Bin 0 -> 18264 bytes examples/isr.c | 44 ++++++-------- gpio/Makefile | 12 +++- gpio/OrangePi.c | 101 ++++++++++++++++++++++++++++++-- gpio/gpio.c | 2 +- wiringPi/Makefile | 12 +++- wiringPi/OrangePi.c | 138 +++++++++++++++++++++++++++++++++++++++----- wiringPi/OrangePi.h | 2 +- wiringPi/wiringPi.c | 22 ++++--- 11 files changed, 276 insertions(+), 63 deletions(-) create mode 100755 examples/isr diff --git a/build b/build index f3519e5..442537a 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_A64" "OrangePi_ZERO" "OrangePi_H3" "OrangePi_LITE2" "OrangePi_H3_ZEROPLUS2" "OrangePi_3" "OrangePi_RK3399" "OrangePi_ONEPLUS" "OrangePi_4" "OrangePi_4B") printf "All available boards:\n" for var in ${boards[@]} ; do diff --git a/examples/Makefile b/examples/Makefile index 97ee0ee..0da8f35 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -26,8 +26,8 @@ ifneq ($V,1) Q ?= @ endif -#DEBUG = -g -O0 -DEBUG = -O3 +DEBUG = -g -O0 +#DEBUG = -O3 CC = gcc INCLUDE = -I/usr/local/include CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe diff --git a/examples/isr b/examples/isr new file mode 100755 index 0000000000000000000000000000000000000000..da8a9337ae6e9e1bf0502f8811b160aca50e52ec GIT binary patch literal 18264 zcmeHPdvsgHnV%~uwj$Y%9p_=d5II13TDBAC1))(K631;`n-~a%?zL>mwoYV8=#kj4 z3ns9quv=KXNr7#7B*4-nr;i+EWw9cJT8c8^(iEz3mTT`43dyoEWEfj ziGZj8?U9%&52*yD>Nu!XbL!Q&8!5>Nmj;aVG!1jg9#T3*mz7E$t5qncLe@rI$=4%| zs{BZ!(#UBmIfP@gPFarJBDtel?x>dIbc6PrQ?4J?jm}10Zl;%_j1EqTmyW-9I~yT; zf9RpBD>g!obd;-KK-Y^?ZqJr@thXf|X^zJdx#8w;INdk6usxVb2HTYXq@Q>@*Ig!E zA~lsVr^;s_PZ*W|>fHbN%FpVrU3t^2#-?L4Rt1;Y_k5MgrsE_XRIghP&b5Rmbbzp# zI2&+^AGW{KvGUdTpM2{d{_5#Bt~l-RHJcj`-1cG3*6yV{fAjKhYp(q5T_eO+?r;mg zSUt74)J+xwTvJs}^$8TSiXmX+lX?6Cz+4jq{l7R%@xKndt_1%JW%vim;8&HwF9aUI zX&zL~Qg%JSOZoW$6qLemD1#p=gI^3hfYUs>VYgPy5{t<($1zXhGexa|50v5GR0dz7 zaZ?ZV(&;7o!^$%J)Ul?E8sXswN&9M-u`BSrY>TC1iGd9RxL{qUq>BER&6< zyVtIWClk@`aBn;+Y%nS5lfi=Xxy=c zPu@!*0uZ@t>`n|rZV?AY2bCX0%C}#YyYl7yesJpny46ooLcF8j1B}0;-al70mAb_e}q&<{B1pMZYWK|c-pO$YrfXxEpe zEvfHkpyxX17eIG7=zj&>>!4o(z1=~-2KoU-pDspUIs@n1Zn5uI?$G#~XNs|3qu!&a zqxiIQ{3fJ*A9s%5jP&OJ=o~*ZF>%*hIA!_!o#P=P9{cx+iP_vfzz>O#7`qW^6H@%l zd~cT!-Jth39qAlj4*r0c^BVC}o0-G5KJOgwKt7~p zk6rh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LZq*k{H%WJ=0k OqB!X9PdE>Q6#oY;qhF)| literal 0 HcmV?d00001 diff --git a/examples/isr.c b/examples/isr.c index abc6aec..50138fb 100644 --- a/examples/isr.c +++ b/examples/isr.c @@ -50,14 +50,14 @@ static volatile int globalCounter [8] ; ********************************************************************************* */ -void myInterrupt0 (void) { ++globalCounter [0] ; } -void myInterrupt1 (void) { ++globalCounter [1] ; } -void myInterrupt2 (void) { ++globalCounter [2] ; } -void myInterrupt3 (void) { ++globalCounter [3] ; } -void myInterrupt4 (void) { ++globalCounter [4] ; } -void myInterrupt5 (void) { ++globalCounter [5] ; } -void myInterrupt6 (void) { ++globalCounter [6] ; } -void myInterrupt7 (void) { ++globalCounter [7] ; } +void myInterrupt0 (void) { ++globalCounter [0] ; delay(100);if(digitalRead(0)==LOW){ printf ("key 1 press\n");fflush (stdout) ;}} +void myInterrupt1 (void) { ++globalCounter [1] ; delay(100);if(digitalRead(1)==LOW){ printf ("key 2 press\n");fflush (stdout) ;}} +void myInterrupt2 (void) { ++globalCounter [2] ; delay(100);if(digitalRead(2)==LOW){ printf ("key 3 press\n");fflush (stdout) ;}} +void myInterrupt3 (void) { ++globalCounter [3] ; delay(100);if(digitalRead(3)==LOW){ printf ("key 4 press\n");fflush (stdout) ;}} +void myInterrupt4 (void) { ++globalCounter [4] ; delay(100);if(digitalRead(4)==LOW){ printf ("key 5 press\n");fflush (stdout) ;}} +void myInterrupt5 (void) { ++globalCounter [5] ; delay(100);if(digitalRead(5)==LOW){ printf ("key 6 press\n");fflush (stdout) ;}} +void myInterrupt6 (void) { ++globalCounter [6] ; delay(100);if(digitalRead(6)==LOW){ printf ("key 7 press\n");fflush (stdout) ;}} +void myInterrupt7 (void) { ++globalCounter [7] ; delay(100);if(digitalRead(7)==LOW){ printf ("key 8 press\n");fflush (stdout) ;}} /* @@ -68,7 +68,7 @@ void myInterrupt7 (void) { ++globalCounter [7] ; } int main (void) { - int gotOne, pin ; + int gotOne, pin ,ret; int myCounter [8] ; for (pin = 0 ; pin < 8 ; ++pin) @@ -82,28 +82,18 @@ int main (void) wiringPiISR (3, INT_EDGE_FALLING, &myInterrupt3) ; wiringPiISR (4, INT_EDGE_FALLING, &myInterrupt4) ; wiringPiISR (5, INT_EDGE_FALLING, &myInterrupt5) ; - wiringPiISR (6, INT_EDGE_FALLING, &myInterrupt6) ; - wiringPiISR (7, INT_EDGE_FALLING, &myInterrupt7) ; + + // wiringPiISR (6, INT_EDGE_FALLING, &myInterrupt6) ; + // wiringPiISR (7, INT_EDGE_FALLING, &myInterrupt7) ; + + printf ("Waiting ... \n") ; + fflush (stdout) ; for (;;) { gotOne = 0 ; - printf ("Waiting ... ") ; fflush (stdout) ; - - for (;;) - { - for (pin = 0 ; pin < 8 ; ++pin) - { - if (globalCounter [pin] != myCounter [pin]) - { - printf (" Int on pin %d: Counter: %5d\n", pin, globalCounter [pin]) ; - myCounter [pin] = globalCounter [pin] ; - ++gotOne ; - } - } - if (gotOne != 0) - break ; - } + + sleep(1); } return 0 ; diff --git a/gpio/Makefile b/gpio/Makefile index 51c9687..f025959 100755 --- a/gpio/Makefile +++ b/gpio/Makefile @@ -30,8 +30,8 @@ ifneq ($V,1) Q ?= @ endif -#DEBUG = -g -O0 -DEBUG = -O2 +DEBUG = -g -O0 +#DEBUG = -O2 CC = gcc INCLUDE = -I$(DESTDIR)$(PREFIX)/include CFLAGS = $(DEBUG) -Wall -Wextra $(INCLUDE) -Winline -pipe @@ -108,6 +108,10 @@ EXTRA_CFLAGS = -DCONFIG_ORANGEPI_4 EXTRA_CFLAGS += -DCONFIG_ORANGEPI endif +ifeq ($(PLATFORM), OrangePi_4B) +EXTRA_CFLAGS = -DCONFIG_ORANGEPI_4B +EXTRA_CFLAGS += -DCONFIG_ORANGEPI +endif # May not need to alter anything below this line ############################################################################### @@ -157,6 +161,10 @@ ifeq ($(PLATFORM), OrangePi_4) SRC += OrangePi.c endif +ifeq ($(PLATFORM), OrangePi_4B) + SRC += OrangePi.c +endif + OBJ = $(SRC:.c=.o) all: gpio diff --git a/gpio/OrangePi.c b/gpio/OrangePi.c index fd0bbca..910755c 100755 --- a/gpio/OrangePi.c +++ b/gpio/OrangePi.c @@ -710,7 +710,98 @@ char *physNames[64] = }; #endif +#ifdef CONFIG_ORANGEPI_4B +int pinToGpioOrangePi [64] = +{ + 150, 33, // 0, 1 + 50, 35, // 2, 3 + 92, 54, // 4 5 + 55, 56, // 6, 7 + 149, -1, // 8, 9 + -1, -1, //10,11 + + -1, -1, //12,13 + + -1, -1, //14,15 + -1, -1, //16,17 + -1, -1, //18,19 + -1, -1, //20,21 + -1, -1, //22,23 + -1, -1, //24,25 + + + -1, -1, //26,27 + + -1, -1, //28,29 + -1, -1, //30,31 + + -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 physToWpi[64] = +{ + -1, // 0 + -1, -1, // 1, 2 + -1, -1, //3, 4 + -1, -1, //5, 6 + 0, -1, //7, 8 + -1, -1, //9,10 + 1, 2, //11,12 + 3, -1, //13,14 + 4, 5, //15,16 + -1, 6, //17,18 + -1, -1, //19,20 + -1, 7, //21,22 + -1, -1, //23, 24 + -1, 8, // 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 + // Padding: + + -1, -1, -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 ", + "I2C2_SDA", "5V ", + "I2C2_SCL", "0v ", + "GPIO4_C6", "I2C3_SCL", + " 0v", "I2C3_SDA", + "GPIO1_A1", "GPIO1_C2", + "GPIO1_A3", "0v ", + "GPIO2_D4", "GPIO1_C6", + " 0v", "GPIO1_C7", + "UART4_TX", "0v ", + "UART4_RX", "GPIO1_D0", + "SPI1_CLK", "SPI1_CS ", + " 0v", "GPIO4_C5", + "I2C2_SDA", "I2C2_SCL", + " I2S0_RX", "0v ", + " I2S0_TX", "I2S_CLK ", + "I2S0_SCK", "0v ", + "I2S0_SI0", "I2S0_SO0", + "I2S0_SI1", "I2S0_SI2", + " 0v", "I2S0_SI3", + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, +}; +#endif /* @@ -737,14 +828,15 @@ void OrangePiReadAll(void) printf (" +------+-----+----------+------+---+OrangePi RK3399---+---+------+---------+-----+--+\n"); #elif CONFIG_ORANGEPI_4 printf (" +------+-----+----------+------+---+OrangePi 4---+---+------+---------+-----+--+\n"); - +#elif CONFIG_ORANGEPI_4B + printf (" +------+-----+----------+------+---+OrangePi 4B---+---+------+---------+-----+--+\n"); #endif printf (" | GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |\n"); printf (" +------+-----+----------+------+---+----++----+---+------+----------+-----+------+\n"); -#if defined CONFIG_ORANGEPI_H3 || defined CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 +#if defined CONFIG_ORANGEPI_H3 || defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4 || defined CONFIG_ORANGEPI_4B for (pin = 1 ; pin <= 42 ; pin += 2) -#else CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_H3_ZEROPLUS2 || CONFIG_ORANGEPI_3 +#elif CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_H3_ZEROPLUS2 || CONFIG_ORANGEPI_3 for (pin = 1 ; pin <= 26 ; pin += 2) #endif readallPhys(pin); @@ -767,7 +859,8 @@ void OrangePiReadAll(void) printf (" +------+-----+----------+------+---+OrangePi RK3399---+---+------+---------+-----+--+\n"); #elif CONFIG_ORANGEPI_4 printf (" +------+-----+----------+------+---+OrangePi 4---+---+------+---------+-----+--+\n"); - +#elif CONFIG_ORANGEPI_4B + printf (" +------+-----+----------+------+---+OrangePi 4B---+---+------+---------+-----+--+\n"); #endif wiringPiDebug = tmp; diff --git a/gpio/gpio.c b/gpio/gpio.c index 01258f1..8b20d64 100755 --- a/gpio/gpio.c +++ b/gpio/gpio.c @@ -429,7 +429,7 @@ static void doI2Cdetect (UNU int argc, char *argv []) ********************************************************************************* */ -static void doSerialTest (UNU int argc, char *argv []) +static int doSerialTest (UNU int argc, char *argv []) { int fd ; int count ; diff --git a/wiringPi/Makefile b/wiringPi/Makefile index 8cc4468..2f7eba4 100755 --- a/wiringPi/Makefile +++ b/wiringPi/Makefile @@ -34,8 +34,8 @@ endif STATIC=libwiringPi.a DYNAMIC=libwiringPi.so.$(VERSION) -#DEBUG = -g -O0 -DEBUG = -O2 +DEBUG = -g -O0 +#DEBUG = -O2 CC = gcc INCLUDE = -I. DEFS = -D_GNU_SOURCE @@ -112,6 +112,10 @@ EXTRA_CFLAGS = -DCONFIG_ORANGEPI_4 EXTRA_CFLAGS += -DCONFIG_ORANGEPI endif +ifeq ($(PLATFORM), OrangePi_4B) +EXTRA_CFLAGS = -DCONFIG_ORANGEPI_4B +EXTRA_CFLAGS += -DCONFIG_ORANGEPI +endif ############################################################################### SRC = wiringPi.c \ @@ -177,6 +181,10 @@ ifeq ($(PLATFORM), OrangePi_4) SRC += OrangePi.c endif +ifeq ($(PLATFORM), OrangePi_4B) +SRC += OrangePi.c +endif + HEADERS = $(shell ls *.h) OBJ = $(SRC:.c=.o) diff --git a/wiringPi/OrangePi.c b/wiringPi/OrangePi.c index 03ce106..7a3d48a 100755 --- a/wiringPi/OrangePi.c +++ b/wiringPi/OrangePi.c @@ -971,7 +971,111 @@ volatile uint32_t *gpio4_base; #endif /* CONFIG_ORANGEPI_4 */ // add 2019.1.8 +#ifdef CONFIG_ORANGEPI_4B +int pinToGpioOrangePi [64] = +{ + 150, 33, // 0, 1 + 50, 35, // 2, 3 + 92, 54, // 4 5 + 55, 56, // 6, 7 + 149, -1, // 8, 9 + -1, -1, //10,11 + + -1, -1, //12,13 + + -1, -1, //14,15 + -1, -1, //16,17 + -1, -1, //18,19 + -1, -1, //20,21 + -1, -1, //22,23 + -1, -1, //24,25 + + -1, -1, //26,27 + + -1, -1, //28,29 + -1, -1, //30,31 + + -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] =//head num map to OrangePi +{ + -1, // 0 + -1, -1, // 1, 2 + -1, -1, // 3, 4 + -1, -1, // 5, 6 + 150, -1, // 7, 8 + -1, -1, // 9, 10 + 33, 50, // 11, 12 + 35, -1, // 13, 14 + 92, 54, // 15, 16 + -1, 55, // 17, 18 + -1, -1, // 19, 20 + -1, 56, // 21, 22 + -1, -1, // 23, 24 + -1, 149, // 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 +// Padding: + -1, -1, -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 + -1, -1, //3, 4 + -1, -1, //5, 6 + 0, -1, //7, 8 + -1, -1, //9,10 + 1, 2, //11,12 + 3, -1, //13,14 + 4, 5, //15,16 + -1, 6, //17,18 + -1, -1, //19,20 + -1, 7, //21,22 + -1, -1, //23, 24 + -1, 8, // 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 + // Padding: + + -1, -1, -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[5][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,},//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,},//PD + }; + +volatile uint32_t *gpio2_base; +volatile uint32_t *cru_base; +volatile uint32_t *grf_base; +volatile uint32_t *pmugrf_base; +volatile uint32_t *pmucru_base; +volatile uint32_t *gpio1_base; +volatile uint32_t *gpio4_base; +#endif /* CONFIG_ORANGEPI_4B */ +// add 2020.02.16 /* * Data for use with the boardId functions. @@ -997,6 +1101,8 @@ const char *piModelNames[6] = "OrangePi H3 family", #elif CONFIG_ORANGEPI_ZERO "OrangePi Zero", +#elif CONFIG_ORANGEPI_4B + "OrangePi 4B", #endif }; @@ -1033,7 +1139,7 @@ unsigned int readR(unsigned int addr) else /* Group A, B and D */ val = *((char *)OrangePi_gpio + mmap_seek); return val; -#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) +#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4 || defined CONFIG_ORANGEPI_4B) unsigned int val = 0; unsigned int mmap_base = (addr & ~MAP_MASK); unsigned int mmap_seek = (addr - mmap_base); @@ -1081,7 +1187,7 @@ void writeR(unsigned int val, unsigned int addr) else *((char *)OrangePi_gpio + mmap_seek) = val; -#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) +#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4 || defined CONFIG_ORANGEPI_4B) unsigned int mmap_base = (addr & ~MAP_MASK); unsigned int mmap_seek = (addr - mmap_base); if(mmap_base == CRU_BASE) @@ -1245,12 +1351,12 @@ void sunxi_pwm_set_act(int act_cys) { int OrangePi_get_gpio_mode(int pin) { unsigned int regval = 0; - unsigned int bank = pin >> 5; //算出 pin 属于哪一组 H6 有 2/3/5/6/7 - unsigned int index = pin - (bank << 5); //算出 pin 属于组中的第多少个 + unsigned int bank = pin >> 5; //锟斤拷锟 pin 锟斤拷锟斤拷锟斤拷一锟斤拷 H6 锟斤拷 2/3/5/6/7 + unsigned int index = pin - (bank << 5); //锟斤拷锟 pin 锟斤拷锟斤拷锟斤拷锟叫的第讹拷锟劫革拷 unsigned int phyaddr = 0; unsigned char mode = -1; -#if (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) +#if (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4 || defined CONFIG_ORANGEPI_4B) unsigned int grf_phyaddr = 0, ddr_phyaddr = 0; int offset = ((index - ((index >> 3) << 3))); if(bank == 1){ @@ -1308,7 +1414,7 @@ int OrangePi_set_gpio_mode(int pin, int mode) unsigned int phyaddr = 0; #ifdef CONFIG_ORANGEPI_2G_IOT unsigned int base_address = 0; -#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) +#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4 || defined CONFIG_ORANGEPI_4B) int offset = ((index - ((index >> 3) << 3))); unsigned int cru_phyaddr, grf_phyaddr, gpio_phyaddr; #else @@ -1340,7 +1446,7 @@ int OrangePi_set_gpio_mode(int pin, int mode) phyaddr = base_address + OEN_SET_OUT_REGISTER; else printf("Invalid mode\n"); -#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) +#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4 || defined CONFIG_ORANGEPI_4B) if(bank == 1){ cru_phyaddr = PMUCRU_BASE + PMUCRU_CLKGATE_CON1_OFFSET; grf_phyaddr = PMUGRF_BASE + ((index >> 3) << 2) + 0x10; @@ -1362,7 +1468,7 @@ int OrangePi_set_gpio_mode(int pin, int mode) #endif /* Ignore unused gpio */ if (ORANGEPI_PIN_MASK[bank][index] != -1) { -#if ! (defined CONFIG_ORANGEPI_2G_IOT || defined CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4) +#if ! (defined CONFIG_ORANGEPI_2G_IOT || defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4 || defined CONFIG_ORANGEPI_4B) regval = readR(phyaddr); if (wiringPiDebug) printf("Before read reg val: 0x%x offset:%d\n",regval,offset); @@ -1375,7 +1481,7 @@ int OrangePi_set_gpio_mode(int pin, int mode) #ifdef CONFIG_ORANGEPI_2G_IOT writeR(GPIO_BIT(index), phyaddr); -#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) +#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4 || defined CONFIG_ORANGEPI_4B) writeR(0xffff0180, cru_phyaddr); regval = readR(grf_phyaddr); regval |= 0x3 << ((offset << 1) | 0x10); @@ -1466,7 +1572,7 @@ int OrangePi_digitalWrite(int pin, int value) #ifdef CONFIG_ORANGEPI_2G_IOT unsigned int base_address = 0; -#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) +#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4 || defined CONFIG_ORANGEPI_4B) unsigned int regval = 0; unsigned int cru_phyaddr = 0; @@ -1524,7 +1630,7 @@ int OrangePi_digitalWrite(int pin, int value) else printf("Invalid value\n"); -#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) +#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4 || defined CONFIG_ORANGEPI_4B) if(bank == 1){ phyaddr = GPIO1_BASE + GPIO_SWPORTA_DR_OFFSET; cru_phyaddr = PMUCRU_BASE + PMUCRU_CLKGATE_CON1_OFFSET; @@ -1546,7 +1652,7 @@ int OrangePi_digitalWrite(int pin, int value) writeR(GPIO_BIT(index), phyaddr); #else - #if (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) + #if (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4 || defined CONFIG_ORANGEPI_4B) writeR(0xffff0180, cru_phyaddr); #endif regval = readR(phyaddr); @@ -1579,7 +1685,7 @@ int OrangePi_digitalRead(int pin) int bank = pin >> 5; int index = pin - (bank << 5); int val; -#if ! (defined CONFIG_ORANGEPI_2G_IOT || defined CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4) +#if ! (defined CONFIG_ORANGEPI_2G_IOT || defined CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 || defined CONFIG_ORANGEPI_4B) unsigned int phyaddr; @@ -1616,7 +1722,7 @@ int OrangePi_digitalRead(int pin) phys_SET_R = base_address + SET_REGISTER; phys_VAL_R = base_address + VAL_REGISTER; -#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) +#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4 || defined CONFIG_ORANGEPI_4B) unsigned int phyaddr; if(bank == 1) phyaddr = GPIO1_BASE + GPIO_EXT_PORTA_OFFSET; @@ -1673,7 +1779,7 @@ int isOrangePi(void) #elif CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_3 /* Support: OrangePi zero */ char *OrangePi_string = "sun50iw6"; -#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) +#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4 || defined CONFIG_ORANGEPI_4B) /* Support: OrangePi RK3399 */ char *OrangePi_string = "rk3399"; @@ -1697,7 +1803,7 @@ int isOrangePi(void) fclose(cpuFd); -#if (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) +#if (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4 || defined CONFIG_ORANGEPI_4B) strcpy(line, "Hardware : Rockchip rk3399 Family"); #endif diff --git a/wiringPi/OrangePi.h b/wiringPi/OrangePi.h index 3c4b258..ce2155b 100755 --- a/wiringPi/OrangePi.h +++ b/wiringPi/OrangePi.h @@ -77,7 +77,7 @@ #endif /*********** OrangePi RK3399 *************/ -#if CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 +#if CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 || CONFIG_ORANGEPI_4B #define GPIO1_BASE 0xff730000 #define GPIO2_BASE 0xff780000 diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index 34f7040..269661a 100755 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -329,12 +329,18 @@ int wiringPiTryGpioMem = FALSE ; // sysFds: // Map a file descriptor from the /sys/class/gpio/gpioX/value -static int sysFds [64] = +static int sysFds [160] = { -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, -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, + -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, + -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, + -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, }; // ISR Data @@ -775,7 +781,7 @@ int piGpioLayout (void) break ; -#if CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 +#if CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 || CONFIG_ORANGEPI_4B strcpy(line, "Hardware : Rockchip rk3399 Family"); #endif @@ -793,7 +799,7 @@ int piGpioLayout (void) fclose (cpuFd) ; -#if CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 +#if CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 || CONFIG_ORANGEPI_4B strcpy(line, "Revision : 0000"); #endif @@ -959,7 +965,7 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty) break ; fclose (cpuFd) ; -#if (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) +#if (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4 || CONFIG_ORANGEPI_4B) strcpy(line, "Revision : 0000"); #endif @@ -2030,7 +2036,9 @@ int wiringPiISR (int pin, int mode, void (*function)(void)) else modeS = "both" ; - sprintf (pinS, "%d", bcmGpioPin) ; + + //gpio edge 鍛戒护琛屾帴鍙楀弬鏁颁负wpi缂栫爜 + sprintf (pinS, "%d", pin) ; if ((pid = fork ()) < 0) // Fail return wiringPiFailure (WPI_FATAL, "wiringPiISR: fork failed: %s\n", strerror (errno)) ; @@ -2060,7 +2068,7 @@ int wiringPiISR (int pin, int mode, void (*function)(void)) if (sysFds [bcmGpioPin] == -1) { sprintf (fName, "/sys/class/gpio/gpio%d/value", bcmGpioPin) ; - if ((sysFds [bcmGpioPin] = open (fName, O_RDWR)) < 0) + if ((sysFds [bcmGpioPin] = open (fName, O_RDONLY)) < 0) return wiringPiFailure (WPI_FATAL, "wiringPiISR: unable to open %s: %s\n", fName, strerror (errno)) ; } @@ -2360,7 +2368,7 @@ int wiringPiSetup (void) return wiringPiFailure(WPI_ALMOST, "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror(errno)); #else -#if ! (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) +#if ! (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4 || CONFIG_ORANGEPI_4B) /* GPIO */ #ifdef CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_3 gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, GPIO_BASE);