diff --git a/build b/build index 918fbd6..f3519e5 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") + boards=("OrangePi_PC2" "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/gpio/Makefile b/gpio/Makefile index 7ed1745..51c9687 100755 --- a/gpio/Makefile +++ b/gpio/Makefile @@ -103,6 +103,11 @@ EXTRA_CFLAGS = -DCONFIG_ORANGEPI_RK3399 EXTRA_CFLAGS += -DCONFIG_ORANGEPI endif +ifeq ($(PLATFORM), OrangePi_4) +EXTRA_CFLAGS = -DCONFIG_ORANGEPI_4 +EXTRA_CFLAGS += -DCONFIG_ORANGEPI +endif + # May not need to alter anything below this line ############################################################################### @@ -148,6 +153,10 @@ ifeq ($(PLATFORM), OrangePi_RK3399) SRC += OrangePi.c endif +ifeq ($(PLATFORM), OrangePi_4) + SRC += OrangePi.c +endif + OBJ = $(SRC:.c=.o) all: gpio diff --git a/gpio/OrangePi.c b/gpio/OrangePi.c index 3cdd8f2..f641437 100755 --- a/gpio/OrangePi.c +++ b/gpio/OrangePi.c @@ -618,6 +618,99 @@ char *physNames[64] = }; #endif +#ifdef CONFIG_ORANGEPI_4 +int pinToGpioOrangePi [64] = +{ + 64, 65, // 0, 1 + 150, 145, // 2, 3 + 144, 33, // 4 5 + 50, 35, // 6, 7 + 92, 54, // 8, 9 + 55, 40, //10,11 + + 39, 56, //12,13 + + 41, 42, //14,15 + 149, 64, //16,17 + 65, -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 + 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 + + 17, 18, //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 ", + " PWM1", "I2C3_SCL", + " 0v", "I2C3_SDA", + "GPIO1_A1", "GPIO1_C2", + "GPIO1_A3", "0v ", + "GPIO2_D4", "GPIO1_C6", + " 3.3v", "GPIO1_C7", + "SPI1_TXD", "0v ", + "SPI1_RXD", "GPIO1_D0", + "SPI1_CLK", "SPI1_CSn0", + " 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 + + /* @@ -642,11 +735,14 @@ void OrangePiReadAll(void) printf (" +------+-----+----------+------+---+OrangePiH6+---+------+----------+-----+------+\n"); #elif CONFIG_ORANGEPI_RK3399 printf (" +------+-----+----------+------+---+OrangePi RK3399---+---+------+---------+-----+--+\n"); +#elif CONFIG_ORANGEPI_4 + printf (" +------+-----+----------+------+---+OrangePi 4---+---+------+---------+-----+--+\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 +#if defined CONFIG_ORANGEPI_H3 || defined CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 for (pin = 1 ; pin <= 42 ; pin += 2) #else CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_H3_ZEROPLUS2 || CONFIG_ORANGEPI_3 for (pin = 1 ; pin <= 26 ; pin += 2) @@ -669,6 +765,8 @@ void OrangePiReadAll(void) printf (" +------+-----+----------+------+---+OrangePiH6+---+------+----------+-----+------+\n"); #elif CONFIG_ORANGEPI_RK3399 printf (" +------+-----+----------+------+---+OrangePi RK3399---+---+------+---------+-----+--+\n"); +#elif CONFIG_ORANGEPI_4 + printf (" +------+-----+----------+------+---+OrangePi 4---+---+------+---------+-----+--+\n"); #endif diff --git a/wiringPi/Makefile b/wiringPi/Makefile index 9969cb9..8cc4468 100755 --- a/wiringPi/Makefile +++ b/wiringPi/Makefile @@ -107,6 +107,11 @@ EXTRA_CFLAGS = -DCONFIG_ORANGEPI_RK3399 EXTRA_CFLAGS += -DCONFIG_ORANGEPI endif +ifeq ($(PLATFORM), OrangePi_4) +EXTRA_CFLAGS = -DCONFIG_ORANGEPI_4 +EXTRA_CFLAGS += -DCONFIG_ORANGEPI +endif + ############################################################################### SRC = wiringPi.c \ @@ -168,6 +173,10 @@ ifeq ($(PLATFORM), OrangePi_RK3399) SRC += OrangePi.c endif +ifeq ($(PLATFORM), OrangePi_4) +SRC += OrangePi.c +endif + HEADERS = $(shell ls *.h) OBJ = $(SRC:.c=.o) diff --git a/wiringPi/OrangePi.c b/wiringPi/OrangePi.c old mode 100644 new mode 100755 index c5d524e..b7ec3d7 --- a/wiringPi/OrangePi.c +++ b/wiringPi/OrangePi.c @@ -864,6 +864,114 @@ volatile uint32_t *gpio4_base; // add 2019.1.8 +#ifdef CONFIG_ORANGEPI_4 +int pinToGpioOrangePi [64] = +{ + 64, 65, // 0, 1 + 150, 145, // 2, 3 + 144, 33, // 4 5 + 50, 35, // 6, 7 + 92, 54, // 8, 9 + 55, 40, //10,11 + + 39, 56, //12,13 + + 41, 42, //14,15 + 149, 64, //16,17 + 65, -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 + 64, -1, // 3, 4 + 65, -1, // 5, 6 + 150, 145, // 7, 8 + -1, 144, // 9, 10 + 33, 50, // 11, 12 + 35, -1, // 13, 14 + 92, 54, // 15, 16 + -1, 55, // 17, 18 + 40, -1, // 19, 20 + 39, 56, // 21, 22 + 41, 42, // 23, 24 + -1, 149, // 25, 26 + 64, 65, // 27, 28 + -1, -1, // 29, 30 + -1, 76, // 31, 32 + -1, -1, // 33, 34 + -1, 73, // 35, 36 + -1, 74, // 37, 38 + -1, 75, // 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 + 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 + + 17, 18, //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_4 */ +// add 2019.1.8 + + /* * Data for use with the boardId functions. @@ -925,7 +1033,7 @@ unsigned int readR(unsigned int addr) else /* Group A, B and D */ val = *((char *)OrangePi_gpio + mmap_seek); return val; -#elif CONFIG_ORANGEPI_RK3399 +#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) unsigned int val = 0; unsigned int mmap_base = (addr & ~MAP_MASK); unsigned int mmap_seek = (addr - mmap_base); @@ -973,7 +1081,7 @@ void writeR(unsigned int val, unsigned int addr) else *((char *)OrangePi_gpio + mmap_seek) = val; -#elif CONFIG_ORANGEPI_RK3399 +#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) unsigned int mmap_base = (addr & ~MAP_MASK); unsigned int mmap_seek = (addr - mmap_base); if(mmap_base == CRU_BASE) @@ -1142,7 +1250,7 @@ int OrangePi_get_gpio_mode(int pin) unsigned int phyaddr = 0; unsigned char mode = -1; -#ifdef CONFIG_ORANGEPI_RK3399 +#if (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) unsigned int grf_phyaddr = 0, ddr_phyaddr = 0; int offset = ((index - ((index >> 3) << 3))); if(bank == 1){ @@ -1200,7 +1308,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 CONFIG_ORANGEPI_RK3399 +#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) int offset = ((index - ((index >> 3) << 3))); unsigned int cru_phyaddr, grf_phyaddr, gpio_phyaddr; #else @@ -1232,7 +1340,7 @@ int OrangePi_set_gpio_mode(int pin, int mode) phyaddr = base_address + OEN_SET_OUT_REGISTER; else printf("Invalid mode\n"); -#elif CONFIG_ORANGEPI_RK3399 +#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) if(bank == 1){ cru_phyaddr = PMUCRU_BASE + PMUCRU_CLKGATE_CON1_OFFSET; grf_phyaddr = PMUGRF_BASE + ((index >> 3) << 2) + 0x10; @@ -1254,7 +1362,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) +#if ! (defined CONFIG_ORANGEPI_2G_IOT || defined CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4) regval = readR(phyaddr); if (wiringPiDebug) printf("Before read reg val: 0x%x offset:%d\n",regval,offset); @@ -1267,7 +1375,7 @@ int OrangePi_set_gpio_mode(int pin, int mode) #ifdef CONFIG_ORANGEPI_2G_IOT writeR(GPIO_BIT(index), phyaddr); -#elif CONFIG_ORANGEPI_RK3399 +#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) writeR(0xffff0180, cru_phyaddr); regval = readR(grf_phyaddr); regval |= 0xffff << 16; @@ -1292,7 +1400,7 @@ int OrangePi_set_gpio_mode(int pin, int mode) writeR(GPIO_BIT(index), phyaddr); /* Set default value as 0 */ writeR(GPIO_BIT(index), base_address + CLR_REGISTER); -#elif CONFIG_ORANGEPI_RK3399 +#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) writeR(0xffff0180, cru_phyaddr); regval = readR(grf_phyaddr); regval |= 0xffff << 16; @@ -1358,7 +1466,7 @@ int OrangePi_digitalWrite(int pin, int value) #ifdef CONFIG_ORANGEPI_2G_IOT unsigned int base_address = 0; -#elif CONFIG_ORANGEPI_RK3399 +#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) unsigned int regval = 0; unsigned int cru_phyaddr = 0; @@ -1416,7 +1524,7 @@ int OrangePi_digitalWrite(int pin, int value) else printf("Invalid value\n"); -#elif CONFIG_ORANGEPI_RK3399 +#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) if(bank == 1){ phyaddr = GPIO1_BASE + GPIO_SWPORTA_DR_OFFSET; cru_phyaddr = PMUCRU_BASE + PMUCRU_CLKGATE_CON1_OFFSET; @@ -1438,7 +1546,7 @@ int OrangePi_digitalWrite(int pin, int value) writeR(GPIO_BIT(index), phyaddr); #else - #ifdef CONFIG_ORANGEPI_RK3399 + #if (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) writeR(0xffff0180, cru_phyaddr); #endif regval = readR(phyaddr); @@ -1471,7 +1579,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) +#if ! (defined CONFIG_ORANGEPI_2G_IOT || defined CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4) unsigned int phyaddr; @@ -1508,7 +1616,7 @@ int OrangePi_digitalRead(int pin) phys_SET_R = base_address + SET_REGISTER; phys_VAL_R = base_address + VAL_REGISTER; -#elif CONFIG_ORANGEPI_RK3399 +#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) unsigned int phyaddr; if(bank == 1) phyaddr = GPIO1_BASE + GPIO_EXT_PORTA_OFFSET; @@ -1565,7 +1673,7 @@ int isOrangePi(void) #elif CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_3 /* Support: OrangePi zero */ char *OrangePi_string = "sun50iw6"; -#elif CONFIG_ORANGEPI_RK3399 +#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) /* Support: OrangePi RK3399 */ char *OrangePi_string = "rk3399"; @@ -1574,9 +1682,10 @@ int isOrangePi(void) /* Non-support */ char *OrangePi_string = "none"; #endif - //printf("OrangePi String is %s\n", OrangePi_string); - return 1; + //printf("OrangePi String is %s\n", OrangePi_string); + + return 1; if ((cpuFd = fopen("/proc/cpuinfo", "r")) == NULL) piGpioLayoutOops ("Unable to open /proc/cpuinfo") ; @@ -1588,7 +1697,7 @@ int isOrangePi(void) fclose(cpuFd); -#ifdef CONFIG_ORANGEPI_RK3399 +#if (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) strcpy(line, "Hardware : Rockchip rk3399 Family"); #endif diff --git a/wiringPi/OrangePi.h b/wiringPi/OrangePi.h index 78bc5de..3c4b258 100755 --- a/wiringPi/OrangePi.h +++ b/wiringPi/OrangePi.h @@ -77,7 +77,7 @@ #endif /*********** OrangePi RK3399 *************/ -#ifdef CONFIG_ORANGEPI_RK3399 +#if CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 #define GPIO1_BASE 0xff730000 #define GPIO2_BASE 0xff780000 diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index d093c4e..34f7040 100755 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -775,7 +775,7 @@ int piGpioLayout (void) break ; -#ifdef CONFIG_ORANGEPI_RK3399 +#if CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 strcpy(line, "Hardware : Rockchip rk3399 Family"); #endif @@ -793,7 +793,7 @@ int piGpioLayout (void) fclose (cpuFd) ; -#ifdef CONFIG_ORANGEPI_RK3399 +#if CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 strcpy(line, "Revision : 0000"); #endif @@ -959,7 +959,7 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty) break ; fclose (cpuFd) ; -#ifdef CONFIG_ORANGEPI_RK3399 +#if (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) strcpy(line, "Revision : 0000"); #endif @@ -2360,7 +2360,7 @@ int wiringPiSetup (void) return wiringPiFailure(WPI_ALMOST, "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror(errno)); #else -#ifndef CONFIG_ORANGEPI_RK3399 +#if ! (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) /* GPIO */ #ifdef CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_3 gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, GPIO_BASE);