diff --git a/build b/build index e55ab93..c9001bd 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") + boards=("orangepir1" "orangepizero" "orangepipc" "orangepipcplus" "orangepiplus2e" "orangepione" "orangepilite" "orangepiplus" "orangepizeroplus2h3" "orangepizeroplus" "orangepipc2" "orangepiprime" "orangepizeroplus2h5" "orangepiwin" "orangepiwinplus" "orangepi3" "orangepilite2" "orangepioneplus" "orangepi4" "orangepirk3399" "orangepizero2") if [[ -f /etc/orangepi-release ]]; then @@ -103,6 +103,7 @@ select_boards() [[ $BOARD == orangepi3 ]] && BOARD=orangepi3-h6 [[ $BOARD == orangepilite2 ]] && BOARD=orangepilite2-h6 [[ $BOARD == orangepioneplus ]] && BOARD=orangepioneplus-h6 + [[ $BOARD == orangepizero2 ]] && BOARD=orangepizero2-h616 export BOARD="${BOARD}" } diff --git a/examples/blink.c b/examples/blink.c index f449d35..77c0a97 100644 --- a/examples/blink.c +++ b/examples/blink.c @@ -1,9 +1,9 @@ #include #include -//#define NUM 17 //26pin +#define NUM 17 //26pin //#define NUM 19 //for orangepi4 -#define NUM 28 //40pin +//#define NUM 28 //40pin int main (void) { @@ -18,11 +18,11 @@ int main (void) { for (i = 0; i < NUM; i++) digitalWrite (i, HIGH) ; // On - delay (500) ; // mS + delay (2000) ; // mS for (i = 0; i < NUM; i++) digitalWrite (i, LOW) ; // Off - delay (500) ; + delay (2000) ; } return 0; diff --git a/gpio/Makefile b/gpio/Makefile index 9d07b8b..7cdc711 100755 --- a/gpio/Makefile +++ b/gpio/Makefile @@ -79,6 +79,10 @@ ifeq ($(BOARD), orangepi3-h6) EXTRA_CFLAGS = -DCONFIG_ORANGEPI_3 endif +ifeq ($(BOARD), orangepizero2-h616) +EXTRA_CFLAGS = -DCONFIG_ORANGEPI_ZERO2 +endif + ifeq ($(BOARD), orangepizeroplus2h3) EXTRA_CFLAGS = -DCONFIG_ORANGEPI_ZEROPLUS2_H3 endif diff --git a/gpio/OrangePi.c b/gpio/OrangePi.c index 6f7ddeb..d83bc52 100755 --- a/gpio/OrangePi.c +++ b/gpio/OrangePi.c @@ -671,6 +671,69 @@ char *physNames [64] = }; #endif +#ifdef CONFIG_ORANGEPI_ZERO2 +int physToWpi [64] = +{ + -1, // 0 + -1, -1, // 1, 2 + 0, -1, + 1, -1, + 2, 3, //7, 8 + -1, 4, + 5, 6, //11, 12 + 7, -1, + 8, 9, //15, 16 + -1, 10, + 11, -1, //19, 20 + 12, 13, + 14, 15, //23, 24 + -1, 16, // 25, 26 + + -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 ", + " SDA.3", "5V ", + " SCL.3", "GND ", + " PWM.1", "TXD.2 ", + " GND", "RXD.2 ", + " RXD.5", "PC11 ", + " TXD.5", "GND ", + " CTS.2", "PC15 ", + " 3.3V", "PC14 ", + " MOSI.1", "GND ", + " MISO.1", "RTS.2 ", + " SCLK.1", "CE.1 ", + " GND", "PC10 ", + + 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 + #ifdef CONFIG_ORANGEPI_RK3399 int pinToGpioOrangePi [64] = { @@ -886,6 +949,8 @@ void OrangePiReadAll(void) printf (" +------+-----+----------+------+---+ OPi H6 +---+------+----------+-----+------+\n"); #elif CONFIG_ORANGEPI_3 printf (" +------+-----+----------+------+---+ OPi 3 +---+------+----------+-----+------+\n"); +#elif CONFIG_ORANGEPI_ZERO2 + printf (" +------+-----+----------+------+---+ Zero 2 +---+------+----------+-----+------+\n"); #elif CONFIG_ORANGEPI_RK3399 printf (" +------+-----+----------+------+---+OPi RK3399+---+------+----------+-----+------+\n"); #elif CONFIG_ORANGEPI_4 @@ -898,7 +963,7 @@ void OrangePiReadAll(void) #if defined CONFIG_ORANGEPI_H3 || defined CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 || CONFIG_ORANGEPI_PC2 || CONFIG_ORANGEPI_PRIME || CONFIG_ORANGEPI_WIN for (pin = 1 ; pin <= 40; pin += 2) -#elif CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_ZEROPLUS2_H3 || CONFIG_ORANGEPI_3 || CONFIG_ORANGEPI_ZERO || CONFIG_ORANGEPI_ZEROPLUS || CONFIG_ORANGEPI_R1 || CONFIG_ORANGEPI_ZEROPLUS2_H5 +#elif CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_ZEROPLUS2_H3 || CONFIG_ORANGEPI_3 || CONFIG_ORANGEPI_ZERO || CONFIG_ORANGEPI_ZERO2 || CONFIG_ORANGEPI_ZEROPLUS || CONFIG_ORANGEPI_R1 || CONFIG_ORANGEPI_ZEROPLUS2_H5 for (pin = 1 ; pin <= 26; pin += 2) #endif readallPhys(pin); @@ -928,6 +993,8 @@ void OrangePiReadAll(void) printf (" +------+-----+----------+------+---+ OPi H6 +---+------+----------+-----+------+\n"); #elif CONFIG_ORANGEPI_3 printf (" +------+-----+----------+------+---+ OPi 3 +---+------+----------+-----+------+\n"); +#elif CONFIG_ORANGEPI_ZERO2 + printf (" +------+-----+----------+------+---+ Zero 2 +---+------+----------+-----+------+\n"); #elif CONFIG_ORANGEPI_RK3399 printf (" +------+-----+----------+------+---+OPi RK3399+---+------+----------+-----+------+\n"); #elif CONFIG_ORANGEPI_4 diff --git a/wiringPi/Makefile b/wiringPi/Makefile index 812bcfc..8d73ad5 100755 --- a/wiringPi/Makefile +++ b/wiringPi/Makefile @@ -84,6 +84,10 @@ ifeq ($(BOARD), orangepi3-h6) EXTRA_CFLAGS = -DCONFIG_ORANGEPI_3 endif +ifeq ($(BOARD), orangepizero2-h616) +EXTRA_CFLAGS = -DCONFIG_ORANGEPI_ZERO2 +endif + ifeq ($(BOARD), orangepizeroplus2h3) EXTRA_CFLAGS = -DCONFIG_ORANGEPI_ZEROPLUS2_H3 endif diff --git a/wiringPi/OrangePi.c b/wiringPi/OrangePi.c index 937c00f..e891344 100755 --- a/wiringPi/OrangePi.c +++ b/wiringPi/OrangePi.c @@ -957,6 +957,79 @@ int ORANGEPI_PIN_MASK[12][32] = //[BANK] [INDEX] #endif +#ifdef CONFIG_ORANGEPI_ZERO2 +int pinToGpioOrangePi [64] = +{ + 229, 228, 211, 207, 208, 227, + 75, 226, 210, 79, 78, 231, 232, + 209, 230, 233, 74, + + // 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 + 229, -1, + 228, -1, + 211, 207, + -1, 208, + 227, 75, + 226, -1, + 210, 79, + -1, 78, + 231, -1, + 232, 209, + 230, 233, + -1, 74, // 25, 26 + + -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] = +{ + -1, // 0 + -1, -1, // 1, 2 + 0, -1, + 1, -1, + 2, 3, //7, 8 + -1, 4, + 5, 6, //11, 12 + 7, -1, + 8, 9, //15, 16 + -1, 10, + 11, -1, //19, 20 + 12, 13, + 14, 15, //23, 24 + -1, 16, // 25, 26 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,-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,},//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,},//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,},//PE +}; +#endif + #ifdef CONFIG_ORANGEPI_RK3399 int pinToGpioOrangePi[64] = { @@ -1647,6 +1720,7 @@ int OrangePi_set_gpio_mode(int pin, int mode) } } else printf("Pin mode failed!\n"); + return 0; } @@ -1763,6 +1837,7 @@ int OrangePi_digitalWrite(int pin, int value) #endif } else printf("Pin mode failed!\n"); + return 0; } @@ -1868,6 +1943,9 @@ int isOrangePi(void) #elif CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_3 /* Support: OrangePi zero */ char *OrangePi_string = "sun50iw6"; +#elif CONFIG_ORANGEPI_ZERO2 + /* Support: OrangePi zero */ + char *OrangePi_string = "sun50iw9"; #elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) /* Support: OrangePi RK3399 */ char *OrangePi_string = "rk3399"; diff --git a/wiringPi/OrangePi.h b/wiringPi/OrangePi.h index 5c21fc8..87dd2df 100755 --- a/wiringPi/OrangePi.h +++ b/wiringPi/OrangePi.h @@ -78,6 +78,18 @@ #define GPIO_PWM_OP (0x0300A000) #endif +/*********** OrangePi H616 *************/ +#if CONFIG_ORANGEPI_ZERO2 +#define GPIOA_BASE (0x0300B000) +#define GPIO_NUM (0x40) +#define GPIO_BASE_MAP (0x0300B000) +#define MEM_INFO (1024) +#define GPIOL_BASE (0x07022000) +#define GPIOL_BASE_MAP (0x07022000) +#define MAP_SIZE_L (4096 * 1) +#define GPIO_PWM_OP (0x0300A000) +#endif + /*********** OrangePi RK3399 *************/ #if CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index f3c638e..15b8e82 100755 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -2360,10 +2360,12 @@ 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) + /* GPIO */ -#if (CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_3) - gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, GPIO_BASE); +#if CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_3 || CONFIG_ORANGEPI_ZERO2 + gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, GPIO_BASE); #else gpio = (uint32_t *)mmap(0, BLOCK_SIZE * 10, PROT_READ | PROT_WRITE, MAP_SHARED, fd, GPIO_BASE); #endif @@ -2375,7 +2377,6 @@ int wiringPiSetup (void) pwm = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PWM) ; if (pwm == MAP_FAILED) return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (PWM) failed: %s\n", strerror (errno)) ; - #if CONFIG_ORANGEPI_WIN || CONFIG_ORANGEPI_ZEROPLUS2_H3 || CONFIG_ORANGEPI_3 || CONFIG_ORANGEPI_ZEROPLUS2_H5 /* GPIOC connect CPU with Modem */ @@ -2385,6 +2386,7 @@ int wiringPiSetup (void) return wiringPiFailure(WPI_ALMOST, "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror(errno)); #endif + #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) @@ -2414,9 +2416,6 @@ int wiringPiSetup (void) 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