diff --git a/build b/build index c9001bd..bfbfa13 100755 --- a/build +++ b/build @@ -49,7 +49,7 @@ select_boards() local choice local call=${1} - boards=("orangepir1" "orangepizero" "orangepipc" "orangepipcplus" "orangepiplus2e" "orangepione" "orangepilite" "orangepiplus" "orangepizeroplus2h3" "orangepizeroplus" "orangepipc2" "orangepiprime" "orangepizeroplus2h5" "orangepiwin" "orangepiwinplus" "orangepi3" "orangepilite2" "orangepioneplus" "orangepi4" "orangepirk3399" "orangepizero2") + boards=("orangepir1" "orangepizero" "orangepipc" "orangepipcplus" "orangepiplus2e" "orangepione" "orangepilite" "orangepiplus" "orangepizeroplus2h3" "orangepizeroplus" "orangepipc2" "orangepiprime" "orangepizeroplus2h5" "orangepiwin" "orangepiwinplus" "orangepi3" "orangepilite2" "orangepioneplus" "orangepi4" "orangepirk3399" "orangepizero2" "orangepir1plus") if [[ -f /etc/orangepi-release ]]; then @@ -79,8 +79,8 @@ select_boards() fi if [ -z "${choice//[0-9]/}" ] ; then if [ $choice -ge 0 -a $choice -lt $cnt ] ; then - export BOARD="${boards[$choice]}" - break + export BOARD="${boards[$choice]}" + break fi fi printf "Invalid input ...\n" @@ -104,6 +104,7 @@ select_boards() [[ $BOARD == orangepilite2 ]] && BOARD=orangepilite2-h6 [[ $BOARD == orangepioneplus ]] && BOARD=orangepioneplus-h6 [[ $BOARD == orangepizero2 ]] && BOARD=orangepizero2-h616 + [[ $BOARD == orangepir1plus ]] && BOARD=orangepir1plus-rk3328 export BOARD="${BOARD}" } diff --git a/gpio/Makefile b/gpio/Makefile index 7cdc711..d4d1b14 100755 --- a/gpio/Makefile +++ b/gpio/Makefile @@ -99,6 +99,10 @@ ifeq ($(BOARD), orangepi4) EXTRA_CFLAGS = -DCONFIG_ORANGEPI_4 endif +ifeq ($(BOARD), orangepir1plus-rk3328) +EXTRA_CFLAGS = -DCONFIG_ORANGEPI_R1PLUS +endif + EXTRA_CFLAGS += -DCONFIG_ORANGEPI # May not need to alter anything below this line diff --git a/gpio/OrangePi.c b/gpio/OrangePi.c index 3f9deda..b6c4e22 100755 --- a/gpio/OrangePi.c +++ b/gpio/OrangePi.c @@ -923,6 +923,74 @@ char *physNames[64] = }; #endif +#ifdef CONFIG_ORANGEPI_R1PLUS +int physToWpi[64] = +{ + -1, //0 + -1, -1, //1, 2 + 0, 1, //3, 4 + 2, 3, //5, 6 + -1, -1, //7, 8 + -1, 4, //9, 10 + 5, 6, //11, 12 + 7, -1, //13, 14 + + -1, -1, //15,16 + -1, -1, //17,18 + -1, -1, //19,20 + -1, -1, //21,22 + -1, -1, //23,24 + -1, -1, //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, + + "5V ", "GND ", + "SDA.0 ", "SCK.0 ", + "TXD.1 ", "RXD.1 ", + " ", " ", + " ", "GPIO3_C0", + "CTS.1 ", "RTS.1 ", + "GPIO2_A2", " ", + 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, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL,NULL,NULL,NULL,NULL, +}; +#endif + @@ -963,6 +1031,8 @@ void OrangePiReadAll(void) printf (" +------+-----+----------+------+---+OPi RK3399+---+------+----------+-----+------+\n"); #elif CONFIG_ORANGEPI_4 printf (" +------+-----+----------+------+---+OrangePi 4+---+---+--+----------+-----+------+\n"); +#elif CONFIG_ORANGEPI_R1PLUS + printf (" +------+-----+----------+------+---+ R1 Plus +---+---+--+----------+-----+------+\n"); #endif printf (" | GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |\n"); @@ -974,6 +1044,9 @@ void OrangePiReadAll(void) #elif CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_ZEROPLUS2_H3 || CONFIG_ORANGEPI_3 || CONFIG_ORANGEPI_ZERO || CONFIG_ORANGEPI_ZEROPLUS || CONFIG_ORANGEPI_R1 || CONFIG_ORANGEPI_ZEROPLUS2_H5 for (pin = 1 ; pin <= 26; pin += 2) +#elif CONFIG_ORANGEPI_R1PLUS + for (pin = 1 ; pin <= 13; pin += 2) + #elif CONFIG_ORANGEPI_ZERO2 for (pin = 1 ; pin <= 34; pin += 2) #endif @@ -1010,6 +1083,8 @@ void OrangePiReadAll(void) printf (" +------+-----+----------+------+---+OPi RK3399+---+------+----------+-----+------+\n"); #elif CONFIG_ORANGEPI_4 printf (" +------+-----+----------+------+---+OrangePi 4+---+---+--+----------+-----+------+\n"); +#elif CONFIG_ORANGEPI_R1PLUS + printf (" +------+-----+----------+------+---+ R1 Plus +---+---+--+----------+-----+------+\n"); #endif wiringPiDebug = tmp; diff --git a/wiringPi/Makefile b/wiringPi/Makefile index 8d73ad5..c2b472f 100755 --- a/wiringPi/Makefile +++ b/wiringPi/Makefile @@ -104,6 +104,10 @@ ifeq ($(BOARD), orangepi4) EXTRA_CFLAGS = -DCONFIG_ORANGEPI_4 endif +ifeq ($(BOARD), orangepir1plus-rk3328) +EXTRA_CFLAGS = -DCONFIG_ORANGEPI_R1PLUS +endif + EXTRA_CFLAGS += -DCONFIG_ORANGEPI ############################################################################### diff --git a/wiringPi/OrangePi.c b/wiringPi/OrangePi.c index c97ec1a..876b74a 100755 --- a/wiringPi/OrangePi.c +++ b/wiringPi/OrangePi.c @@ -1247,6 +1247,107 @@ volatile uint32_t *gpio4_base; #endif /* CONFIG_ORANGEPI_4 */ // add 2019.1.8 +#ifdef CONFIG_ORANGEPI_R1PLUS +int pinToGpioOrangePi [64] = +{ + 89, 88, // 0, 1 + 100, 102, // 2, 3 + 112, 103, // 4 5 + 101, 66, // 6, 7 + -1, -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 + 89, 88, // 3, 4 + 100, 102, // 5, 6 + -1, -1, // 7, 8 + -1, 112, // 9, 10 + 103,101, // 11, 12 + 66, -1, // 13, 14 + -1, -1, // 15, 16 + -1, -1, // 17, 18 + -1, -1, // 19, 20 + -1, -1, // 21, 22 + -1, -1, // 23, 24 + -1, -1, // 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 + 0, 1, //3, 4 + 2, 3, //5, 6 + -1, -1, //7, 8 + -1, 4, //9, 10 + 5, 6, //11, 12 + 7, -1, //13, 14 + + -1, -1, //15, 16 + -1, -1, //17, 18 + -1, -1, //19, 20 + -1, -1, //21, 22 + -1, -1, //23, 24 + -1, -1, //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 *gpio3_base; +volatile uint32_t *cru_base; +volatile uint32_t *grf_base; + + +#endif /* CONFIG_ORANGEPI_R1PLUS */ +// add 2020.11.26 + /* @@ -1300,15 +1401,15 @@ const char * int2bin(uint32_t param) { unsigned int readR(unsigned int addr) { #ifdef CONFIG_ORANGEPI_2G_IOT - unsigned int val = 0; - unsigned int mmap_base = (addr & ~MAP_MASK); - unsigned int mmap_seek = (addr - mmap_base); + unsigned int val = 0; + unsigned int mmap_base = (addr & ~MAP_MASK); + unsigned int mmap_seek = (addr - mmap_base); if (mmap_base == 0x11a08000) /* Group C */ val = *((char *)OrangePi_gpioC + mmap_seek); else /* Group A, B and D */ val = *((char *)OrangePi_gpio + mmap_seek); - return val; + return val; #elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) unsigned int val = 0; unsigned int mmap_base = (addr & ~MAP_MASK); @@ -1328,8 +1429,22 @@ unsigned int readR(unsigned int addr) else if(mmap_base == GPIO4_BASE) val = *((unsigned int *)((unsigned char *)gpio4_base + mmap_seek)); else ; - return val; + return val; +#elif (defined CONFIG_ORANGEPI_R1PLUS) + unsigned int val = 0; + unsigned int mmap_base = (addr & ~MAP_MASK); + unsigned int mmap_seek = (addr - mmap_base); + if(mmap_base == CRU_BASE) + val = *((unsigned int *)((unsigned char *)cru_base + mmap_seek)); + else if(mmap_base == GRF_BASE) + val = *((unsigned int *)((unsigned char *)grf_base + mmap_seek)); + else if(mmap_base == GPIO2_BASE) + val = *((unsigned int *)((unsigned char *)gpio2_base + mmap_seek)); + else if(mmap_base == GPIO3_BASE) + val = *((unsigned int *)((unsigned char *)gpio3_base + mmap_seek)); + else ; + return val; #else uint32_t val = 0; uint32_t mmap_base = (addr & ~MAP_MASK); @@ -1376,6 +1491,18 @@ void writeR(unsigned int val, unsigned int addr) *((unsigned int *)((unsigned char *)gpio4_base + mmap_seek)) = val; else ; +#elif (defined CONFIG_ORANGEPI_R1PLUS) + unsigned int mmap_base = (addr & ~MAP_MASK); + unsigned int mmap_seek = (addr - mmap_base); + if(mmap_base == CRU_BASE) + *((unsigned int *)((unsigned char *)cru_base + mmap_seek)) = val; + else if(mmap_base == GRF_BASE) + *((unsigned int *)((unsigned char *)grf_base + mmap_seek)) = val; + else if(mmap_base == GPIO2_BASE) + *((unsigned int *)((unsigned char *)gpio2_base + mmap_seek)) = val; + else if(mmap_base == GPIO3_BASE) + *((unsigned int *)((unsigned char *)gpio3_base + mmap_seek)) = val; + else ; #else unsigned int mmap_base = (addr & ~MAP_MASK); unsigned int mmap_seek = ((addr - mmap_base) >> 2); @@ -1544,16 +1671,70 @@ int OrangePi_get_gpio_mode(int pin) else ; if (ORANGEPI_PIN_MASK[bank-1][index] != -1) { regval = readR(grf_phyaddr); - mode = (regval >> (offset << 1)) & 0x3; - if(mode == 0){ - regval = readR(ddr_phyaddr); - return (regval >> index) & 1; + mode = (regval >> (offset << 1)) & 0x3;//获取控制模式的那两位的值 + if(mode == 0){ //如果是gpio模式 + regval = readR(ddr_phyaddr);//获取gpio方向寄存器的值 + return (regval >> index) & 1;//index对应的gpio的方向值,0为in,1为out + } + return mode + 1;//如果不是gpio模式,返回的alt,从2开始,0和1是in和out + } + +#elif CONFIG_ORANGEPI_R1PLUS + unsigned int grf_phyaddr = 0, ddr_phyaddr = 0; + int offset = ((index - ((index >> 3) << 3))); + if(bank == 2){ //gpio2 + //ddr_phyaddr = GPIO2_BASE + GPIO_SWPORTA_DDR_OFFSET; + ddr_phyaddr = 0xff230004; + //grf_phyaddr = GRF_BASE + ((index >> 3) << 2) + 0x10; + if(0 == (index >> 3))//gpio2_ax + { + grf_phyaddr = GRF_BASE + 0x20; + } + else if(3 == (index >> 3))//gpio2_dx + { + grf_phyaddr = GRF_BASE + 0x34; } - return mode + 1; } + else if(bank == 3){ + //grf_phyaddr = GRF_BASE + ((index >> 3) << 2) +0x20; + ddr_phyaddr = GPIO3_BASE + GPIO_SWPORTA_DDR_OFFSET; + if (0 == (index >> 3)) + { + if(4 == offset)//gpio3_a4 + { + grf_phyaddr = GRF_BASE + 0x38; + } + else//gpio3_a567 + { + grf_phyaddr = GRF_BASE + 0x3c; + } + } + else if(2 == (index >> 3)) //gpio3_c + { + grf_phyaddr = GRF_BASE + 0x48; + } + } + else; + if (ORANGEPI_PIN_MASK[bank-1][index] != -1) { + regval = readR(grf_phyaddr); + writeR(0xffff9877, 0xff440240); -#else + if(3 == bank && (0 == (index >> 3))) //gpio3_ax需要写3位 + { + mode = (regval >> ((offset % 5) * 3)) & 0x7; + } + else + { + mode = (regval >> (offset << 1)) & 0x3; + } + if(mode == 0){ + regval = readR(ddr_phyaddr); + return (regval >> index) & 1; + } + return mode + 1; + } +#else int offset = ((index - ((index >> 3) << 3)) << 2); if (bank == 11) { @@ -1569,7 +1750,7 @@ int OrangePi_get_gpio_mode(int pin) } return mode; - + #endif } @@ -1584,7 +1765,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_R1PLUS) int offset = ((index - ((index >> 3) << 3))); unsigned int cru_phyaddr, grf_phyaddr, gpio_phyaddr; #else @@ -1635,10 +1816,46 @@ int OrangePi_set_gpio_mode(int pin, int mode) } else; +#elif (defined CONFIG_ORANGEPI_R1PLUS) + if(bank == 2){ //gpio2 + cru_phyaddr = CRU_BASE + CRU_CLKGATE_CON16_OFFSET; + //grf_phyaddr = GRF_BASE + ((index >> 3) << 2) + 0x10; + gpio_phyaddr = GPIO2_BASE + GPIO_SWPORTA_DDR_OFFSET; + if(0 == (index >> 3))//gpio2_ax + { + grf_phyaddr = GRF_BASE + 0x20; + } + else if(3 == (index >> 3))//gpio2_dx + { + grf_phyaddr = GRF_BASE + 0x34; + } + } + else if(bank == 3){ + cru_phyaddr = CRU_BASE + CRU_CLKGATE_CON16_OFFSET; + //grf_phyaddr = GRF_BASE + ((index >> 3) << 2) +0x20; + gpio_phyaddr = GPIO3_BASE + GPIO_SWPORTA_DDR_OFFSET; + if (0 == (index >> 3)) + { + if(4 == offset)//gpio3_a4 + { + grf_phyaddr = GRF_BASE + 0x38; + } + else//gpio3_a567 + { + grf_phyaddr = GRF_BASE + 0x3c; + } + } + else if(2 == (index >> 3)) //gpio3_c + { + grf_phyaddr = GRF_BASE + 0x48; + } + } + else; #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 || CONFIG_ORANGEPI_4 || CONFIG_ORANGEPI_R1PLUS) regval = readR(phyaddr); if (wiringPiDebug) printf("Before read reg val: 0x%x offset:%d\n",regval,offset); @@ -1664,6 +1881,30 @@ int OrangePi_set_gpio_mode(int pin, int mode) regval = readR(gpio_phyaddr); printf("Input mode set over reg val: %#x\n",regval); } + +#elif (defined CONFIG_ORANGEPI_R1PLUS) + writeR(0xffff9877, cru_phyaddr); + + regval = readR(grf_phyaddr); + if(3 == bank && (0 == (index >> 3))) //gpio3_a iomux需要写3位 + { + regval |= 0xffff0000; + regval &= ~(0x7 << ((offset % 5) * 3)); + } + else //其他的写两位 + { + regval |= 0xffff0000; + regval &= ~(0x3 << (offset << 1)); + } + writeR(regval, grf_phyaddr); + + regval = readR(gpio_phyaddr); + regval &= ~(1 << index); + writeR(regval, gpio_phyaddr); + if (wiringPiDebug){ + regval = readR(gpio_phyaddr); + printf("Input mode set over reg val: %#x\n",regval); + } #else regval &= ~(7 << offset); writeR(regval, phyaddr); @@ -1689,7 +1930,30 @@ int OrangePi_set_gpio_mode(int pin, int mode) regval = readR(gpio_phyaddr); printf("Out mode get value: 0x%x\n",regval); } + +#elif (defined CONFIG_ORANGEPI_R1PLUS) + writeR(0xffff9877, cru_phyaddr); + regval = readR(grf_phyaddr); + if(3 == bank && (0 == (index >> 3))) //gpio3_a iomux需要写3位 + { + regval |= 0xffff0000; + regval &= ~(0x7 << ((offset % 5) * 3)); + } + else //其他的写两位 + { + regval |= 0xffff0000; + regval &= ~(0x3 << (offset << 1)); + } + writeR(regval, grf_phyaddr); + + regval = readR(gpio_phyaddr); + regval |= 1 << index; + writeR(regval, gpio_phyaddr); + if (wiringPiDebug){ + regval = readR(gpio_phyaddr); + printf("Out mode get value: 0x%x\n",regval); + } #else regval &= ~(7 << offset); @@ -1743,7 +2007,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_R1PLUS ) unsigned int regval = 0; unsigned int cru_phyaddr = 0; @@ -1815,6 +2079,17 @@ int OrangePi_digitalWrite(int pin, int value) cru_phyaddr = CRU_BASE + CRU_CLKGATE_CON31_OFFSET; } else; + +#elif (defined CONFIG_ORANGEPI_R1PLUS) + if(bank == 2){ + phyaddr = GPIO2_BASE + GPIO_SWPORTA_DR_OFFSET; + cru_phyaddr = CRU_BASE + CRU_CLKGATE_CON16_OFFSET; + } + else if(bank == 3){ + phyaddr = GPIO3_BASE + GPIO_SWPORTA_DR_OFFSET; + cru_phyaddr = CRU_BASE + CRU_CLKGATE_CON16_OFFSET; + } + else; #endif /* Ignore unused gpio */ @@ -1825,6 +2100,8 @@ int OrangePi_digitalWrite(int pin, int value) #else #if (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) writeR(0xffff0180, cru_phyaddr); + #elif (defined CONFIG_ORANGEPI_R1PLUS) + writeR(0xffff9877, cru_phyaddr); #endif regval = readR(phyaddr); if (wiringPiDebug) @@ -1857,7 +2134,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_R1PLUS) unsigned int phyaddr; @@ -1897,17 +2174,25 @@ int OrangePi_digitalRead(int pin) #elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) unsigned int phyaddr; if(bank == 1) - phyaddr = GPIO1_BASE + GPIO_EXT_PORTA_OFFSET; + phyaddr = GPIO1_BASE + GPIO_EXT_PORTA_OFFSET; else if(bank == 2) - phyaddr = GPIO2_BASE + GPIO_EXT_PORTA_OFFSET; + phyaddr = GPIO2_BASE + GPIO_EXT_PORTA_OFFSET; else if(bank == 4) - phyaddr = GPIO4_BASE + GPIO_EXT_PORTA_OFFSET; + phyaddr = GPIO4_BASE + GPIO_EXT_PORTA_OFFSET; else; + +#elif (defined CONFIG_ORANGEPI_R1PLUS) + unsigned int phyaddr; + if(bank == 2) + phyaddr = GPIO2_BASE + GPIO_EXT_PORTA_OFFSET; + else if(bank == 3) + phyaddr = GPIO3_BASE + GPIO_EXT_PORTA_OFFSET; + else; #endif + if (ORANGEPI_PIN_MASK[bank][index] != -1) { #ifndef CONFIG_ORANGEPI_2G_IOT - val = readR(phyaddr); val = val >> index; val &= 1; @@ -1957,6 +2242,9 @@ int isOrangePi(void) #elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) /* Support: OrangePi RK3399 */ char *OrangePi_string = "rk3399"; +#elif (defined CONFIG_ORANGEPI_R1PLUS) + /* Support: OrangePi R1plus */ + char *OrangePi_string = "rk3328"; #else @@ -1980,6 +2268,8 @@ int isOrangePi(void) #if (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) strcpy(line, "Hardware : Rockchip rk3399 Family"); +#elif (defined CONFIG_ORANGEPI_R1PLUS) + strcpy(line, "Hardware : Rockchip rk3328 Family"); #endif if (strncmp(line, "Hardware", 8) != 0) diff --git a/wiringPi/OrangePi.h b/wiringPi/OrangePi.h index 87dd2df..f6dc204 100755 --- a/wiringPi/OrangePi.h +++ b/wiringPi/OrangePi.h @@ -140,6 +140,48 @@ extern volatile unsigned int *gpio4_base; //csy 2019.1.8 +/*********** OrangePi R1PLUS *************/ +#if CONFIG_ORANGEPI_R1PLUS + +#define GPIO2_BASE 0xff230000 +#define GPIO3_BASE 0xff240000 +#define GPIO_NUM (0x40) + +#define GPIO_SWPORTA_DR_OFFSET 0x00 +#define GPIO_SWPORTA_DDR_OFFSET 0x04 +#define GPIO_EXT_PORTA_OFFSET 0x50 + +#define GRF_BASE 0xff100000 +#define GRF_GPIO2A_IOMUX_OFFSET 0x20 +#define GRF_GPIO2BL_IOMUX_OFFSET 0x24 +#define GRF_GPIO2BH_IOMUX_OFFSET 0x28 +#define GRF_GPIO2CL_IOMUX_OFFSET 0x2c +#define GRF_GPIO2CH_IOMUX_OFFSET 0x30 +#define GRF_GPIO2D_IOMUX_OFFSET 0x34 + +#define GRF_GPIO3AL_IOMUX_OFFSET 0x38 +#define GRF_GPIO3AH_IOMUX_OFFSET 0x3c +#define GRF_GPIO3BL_IOMUX_OFFSET 0x40 +#define GRF_GPIO3BH_IOMUX_OFFSET 0x44 +#define GRF_GPIO3C_IOMUX_OFFSET 0x48 +#define GRF_GPIO3D_IOMUX_OFFSET 0x4c + +#define CRU_BASE 0xff440000 +#define CRU_CLKGATE_CON16_OFFSET 0x0240 //bit 7 8 9 10 9877 + +#define MEM_INFO (2048) +#define MAP_SIZE_L (4*1024) + +extern volatile unsigned int *gpio2_base; +extern volatile unsigned int *gpio3_base; +extern volatile unsigned int *cru_base; +extern volatile unsigned int *grf_base; + + +#endif /* CONFIG_ORANGEPI_R1PLUS */ +//FG 2020.11.26 + + /****************** Global data *********************/ /* Current version */ @@ -225,6 +267,9 @@ extern int ORANGEPI_PIN_MASK[9][32]; extern int ORANGEPI_PIN_MASK[12][32]; #elif CONFIG_ORANGEPI_RK3399 extern int ORANGEPI_PIN_MASK[5][32]; +#elif CONFIG_ORANGEPI_R1PLUS +extern int ORANGEPI_PIN_MASK[5][32]; + #endif #endif diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index 65a8821..ab54ae0 100755 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -777,6 +777,8 @@ int piGpioLayout (void) #if CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 strcpy(line, "Hardware : Rockchip rk3399 Family"); +#elif CONFIG_ORANGEPI_R1PLUS + strcpy(line, "Hardware : Rockchip rk3328 Family"); #endif if (strncmp (line, "Hardware", 8) != 0) @@ -793,7 +795,7 @@ int piGpioLayout (void) fclose (cpuFd) ; -#if CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 +#if CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 || CONFIG_ORANGEPI_R1PLUS strcpy(line, "Revision : 0000"); #endif @@ -959,7 +961,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 || defined CONFIG_ORANGEPI_R1PLUS) strcpy(line, "Revision : 0000"); #endif @@ -2361,7 +2363,7 @@ int wiringPiSetup (void) "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 || defined CONFIG_ORANGEPI_R1PLUS) /* GPIO */ #if CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_3 || CONFIG_ORANGEPI_ZERO2 @@ -2387,34 +2389,53 @@ int wiringPiSetup (void) "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror(errno)); #endif + +#elif CONFIG_ORANGEPI_R1PLUS + cru_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, CRU_BASE); + if ((int32_t)(unsigned long)cru_base == -1) + return wiringPiFailure(WPI_ALMOST, + "wiringPiSetup: mmap (CRU_BASE) failed: %s\n", strerror(errno)); + grf_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GRF_BASE); + if ((int32_t)(unsigned long)grf_base == -1) + return wiringPiFailure(WPI_ALMOST, + "wiringPiSetup: mmap (GRF_BASE) failed: %s\n", strerror(errno)); + gpio2_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO2_BASE); + if ((int32_t)(unsigned long)gpio2_base == -1) + return wiringPiFailure(WPI_ALMOST, + "wiringPiSetup: mmap (GPIO2_BASE) failed: %s\n", strerror(errno)); + gpio3_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO3_BASE); + if ((int32_t)(unsigned long)gpio3_base == -1) + return wiringPiFailure(WPI_ALMOST, + "wiringPiSetup: mmap (GPIO3_BASE) failed: %s\n", strerror(errno)); + #else /* CONFIG_ORANGEPI_RK3399 */ - gpio2_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO2_BASE); - if ((int32_t)(unsigned long)gpio2_base == -1) - return wiringPiFailure(WPI_ALMOST, - "wiringPiSetup: mmap (GPIO2_BASE) failed: %s\n", strerror(errno)); - cru_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, CRU_BASE); - if ((int32_t)(unsigned long)cru_base == -1) - return wiringPiFailure(WPI_ALMOST, - "wiringPiSetup: mmap (CRU_BASE) failed: %s\n", strerror(errno)); - pmucru_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, PMUCRU_BASE); - if ((int32_t)(unsigned long)pmucru_base == -1) - return wiringPiFailure(WPI_ALMOST, - "wiringPiSetup: mmap (PMUCRU_BASE) failed: %s\n", strerror(errno)); - grf_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GRF_BASE); - if ((int32_t)(unsigned long)grf_base == -1) - return wiringPiFailure(WPI_ALMOST, - "wiringPiSetup: mmap (GRF_BASE) failed: %s\n", strerror(errno)); - pmugrf_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, PMUGRF_BASE); - if ((int32_t)(unsigned long)pmugrf_base == -1) - return wiringPiFailure(WPI_ALMOST, - "wiringPiSetup: mmap (PMUGRF_BASE) failed: %s\n", strerror(errno)); - gpio1_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO1_BASE); - if ((int32_t)(unsigned long)grf_base == -1) - return wiringPiFailure(WPI_ALMOST, - "wiringPiSetup: mmap (GPIO1_BASE) failed: %s\n", strerror(errno)); - gpio4_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO4_BASE); - if ((int32_t)(unsigned long)gpio4_base == -1) - return wiringPiFailure(WPI_ALMOST, + gpio2_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO2_BASE); + if ((int32_t)(unsigned long)gpio2_base == -1) + return wiringPiFailure(WPI_ALMOST, + "wiringPiSetup: mmap (GPIO2_BASE) failed: %s\n", strerror(errno)); + cru_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, CRU_BASE); + if ((int32_t)(unsigned long)cru_base == -1) + return wiringPiFailure(WPI_ALMOST, + "wiringPiSetup: mmap (CRU_BASE) failed: %s\n", strerror(errno)); + pmucru_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, PMUCRU_BASE); + if ((int32_t)(unsigned long)pmucru_base == -1) + return wiringPiFailure(WPI_ALMOST, + "wiringPiSetup: mmap (PMUCRU_BASE) failed: %s\n", strerror(errno)); + grf_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GRF_BASE); + if ((int32_t)(unsigned long)grf_base == -1) + return wiringPiFailure(WPI_ALMOST, + "wiringPiSetup: mmap (GRF_BASE) failed: %s\n", strerror(errno)); + pmugrf_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, PMUGRF_BASE); + if ((int32_t)(unsigned long)pmugrf_base == -1) + return wiringPiFailure(WPI_ALMOST, + "wiringPiSetup: mmap (PMUGRF_BASE) failed: %s\n", strerror(errno)); + gpio1_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO1_BASE); + if ((int32_t)(unsigned long)grf_base == -1) + return wiringPiFailure(WPI_ALMOST, + "wiringPiSetup: mmap (GPIO1_BASE) failed: %s\n", strerror(errno)); + gpio4_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO4_BASE); + if ((int32_t)(unsigned long)gpio4_base == -1) + return wiringPiFailure(WPI_ALMOST, "wiringPiSetup: mmap (GPIO4_BASE) failed: %s\n", strerror(errno)); #endif /* CONFIG_ORANGEPI_RK3399 */ #endif