Browse Source

Support Orange Pi Zero 2

pull/26/head
leeboby 5 years ago
parent
commit
7b9d467a35
  1. 3
      build
  2. 8
      examples/blink.c
  3. 4
      gpio/Makefile
  4. 69
      gpio/OrangePi.c
  5. 4
      wiringPi/Makefile
  6. 78
      wiringPi/OrangePi.c
  7. 12
      wiringPi/OrangePi.h
  8. 11
      wiringPi/wiringPi.c

3
build

@ -49,7 +49,7 @@ select_boards()
local choice local choice
local call=${1} 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 if [[ -f /etc/orangepi-release ]]; then
@ -103,6 +103,7 @@ select_boards()
[[ $BOARD == orangepi3 ]] && BOARD=orangepi3-h6 [[ $BOARD == orangepi3 ]] && BOARD=orangepi3-h6
[[ $BOARD == orangepilite2 ]] && BOARD=orangepilite2-h6 [[ $BOARD == orangepilite2 ]] && BOARD=orangepilite2-h6
[[ $BOARD == orangepioneplus ]] && BOARD=orangepioneplus-h6 [[ $BOARD == orangepioneplus ]] && BOARD=orangepioneplus-h6
[[ $BOARD == orangepizero2 ]] && BOARD=orangepizero2-h616
export BOARD="${BOARD}" export BOARD="${BOARD}"
} }

8
examples/blink.c

@ -1,9 +1,9 @@
#include <stdio.h> #include <stdio.h>
#include <wiringPi.h> #include <wiringPi.h>
//#define NUM 17 //26pin #define NUM 17 //26pin
//#define NUM 19 //for orangepi4 //#define NUM 19 //for orangepi4
#define NUM 28 //40pin //#define NUM 28 //40pin
int main (void) int main (void)
{ {
@ -18,11 +18,11 @@ int main (void)
{ {
for (i = 0; i < NUM; i++) for (i = 0; i < NUM; i++)
digitalWrite (i, HIGH) ; // On digitalWrite (i, HIGH) ; // On
delay (500) ; // mS delay (2000) ; // mS
for (i = 0; i < NUM; i++) for (i = 0; i < NUM; i++)
digitalWrite (i, LOW) ; // Off digitalWrite (i, LOW) ; // Off
delay (500) ; delay (2000) ;
} }
return 0; return 0;

4
gpio/Makefile

@ -79,6 +79,10 @@ ifeq ($(BOARD), orangepi3-h6)
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_3 EXTRA_CFLAGS = -DCONFIG_ORANGEPI_3
endif endif
ifeq ($(BOARD), orangepizero2-h616)
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_ZERO2
endif
ifeq ($(BOARD), orangepizeroplus2h3) ifeq ($(BOARD), orangepizeroplus2h3)
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_ZEROPLUS2_H3 EXTRA_CFLAGS = -DCONFIG_ORANGEPI_ZEROPLUS2_H3
endif endif

69
gpio/OrangePi.c

@ -671,6 +671,69 @@ char *physNames [64] =
}; };
#endif #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 #ifdef CONFIG_ORANGEPI_RK3399
int pinToGpioOrangePi [64] = int pinToGpioOrangePi [64] =
{ {
@ -886,6 +949,8 @@ void OrangePiReadAll(void)
printf (" +------+-----+----------+------+---+ OPi H6 +---+------+----------+-----+------+\n"); printf (" +------+-----+----------+------+---+ OPi H6 +---+------+----------+-----+------+\n");
#elif CONFIG_ORANGEPI_3 #elif CONFIG_ORANGEPI_3
printf (" +------+-----+----------+------+---+ OPi 3 +---+------+----------+-----+------+\n"); printf (" +------+-----+----------+------+---+ OPi 3 +---+------+----------+-----+------+\n");
#elif CONFIG_ORANGEPI_ZERO2
printf (" +------+-----+----------+------+---+ Zero 2 +---+------+----------+-----+------+\n");
#elif CONFIG_ORANGEPI_RK3399 #elif CONFIG_ORANGEPI_RK3399
printf (" +------+-----+----------+------+---+OPi RK3399+---+------+----------+-----+------+\n"); printf (" +------+-----+----------+------+---+OPi RK3399+---+------+----------+-----+------+\n");
#elif CONFIG_ORANGEPI_4 #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 #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) 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) for (pin = 1 ; pin <= 26; pin += 2)
#endif #endif
readallPhys(pin); readallPhys(pin);
@ -928,6 +993,8 @@ void OrangePiReadAll(void)
printf (" +------+-----+----------+------+---+ OPi H6 +---+------+----------+-----+------+\n"); printf (" +------+-----+----------+------+---+ OPi H6 +---+------+----------+-----+------+\n");
#elif CONFIG_ORANGEPI_3 #elif CONFIG_ORANGEPI_3
printf (" +------+-----+----------+------+---+ OPi 3 +---+------+----------+-----+------+\n"); printf (" +------+-----+----------+------+---+ OPi 3 +---+------+----------+-----+------+\n");
#elif CONFIG_ORANGEPI_ZERO2
printf (" +------+-----+----------+------+---+ Zero 2 +---+------+----------+-----+------+\n");
#elif CONFIG_ORANGEPI_RK3399 #elif CONFIG_ORANGEPI_RK3399
printf (" +------+-----+----------+------+---+OPi RK3399+---+------+----------+-----+------+\n"); printf (" +------+-----+----------+------+---+OPi RK3399+---+------+----------+-----+------+\n");
#elif CONFIG_ORANGEPI_4 #elif CONFIG_ORANGEPI_4

4
wiringPi/Makefile

@ -84,6 +84,10 @@ ifeq ($(BOARD), orangepi3-h6)
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_3 EXTRA_CFLAGS = -DCONFIG_ORANGEPI_3
endif endif
ifeq ($(BOARD), orangepizero2-h616)
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_ZERO2
endif
ifeq ($(BOARD), orangepizeroplus2h3) ifeq ($(BOARD), orangepizeroplus2h3)
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_ZEROPLUS2_H3 EXTRA_CFLAGS = -DCONFIG_ORANGEPI_ZEROPLUS2_H3
endif endif

78
wiringPi/OrangePi.c

@ -957,6 +957,79 @@ int ORANGEPI_PIN_MASK[12][32] = //[BANK] [INDEX]
#endif #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
-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[12][32] = //[BANK] [INDEX]
{
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,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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 #ifdef CONFIG_ORANGEPI_RK3399
int pinToGpioOrangePi[64] = int pinToGpioOrangePi[64] =
{ {
@ -1647,6 +1720,7 @@ int OrangePi_set_gpio_mode(int pin, int mode)
} }
} else } else
printf("Pin mode failed!\n"); printf("Pin mode failed!\n");
return 0; return 0;
} }
@ -1763,6 +1837,7 @@ int OrangePi_digitalWrite(int pin, int value)
#endif #endif
} else } else
printf("Pin mode failed!\n"); printf("Pin mode failed!\n");
return 0; return 0;
} }
@ -1868,6 +1943,9 @@ int isOrangePi(void)
#elif CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_3 #elif CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_3
/* Support: OrangePi zero */ /* Support: OrangePi zero */
char *OrangePi_string = "sun50iw6"; char *OrangePi_string = "sun50iw6";
#elif CONFIG_ORANGEPI_ZERO2
/* Support: OrangePi zero */
char *OrangePi_string = "sun50iw9";
#elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) #elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4)
/* Support: OrangePi RK3399 */ /* Support: OrangePi RK3399 */
char *OrangePi_string = "rk3399"; char *OrangePi_string = "rk3399";

12
wiringPi/OrangePi.h

@ -78,6 +78,18 @@
#define GPIO_PWM_OP (0x0300A000) #define GPIO_PWM_OP (0x0300A000)
#endif #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 *************/ /*********** OrangePi RK3399 *************/
#if CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 #if CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4

11
wiringPi/wiringPi.c

@ -2360,10 +2360,12 @@ int wiringPiSetup (void)
return wiringPiFailure(WPI_ALMOST, return wiringPiFailure(WPI_ALMOST,
"wiringPiSetup: mmap (GPIO) failed: %s\n", strerror(errno)); "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror(errno));
#else #else
#if ! (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) #if ! (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4)
/* GPIO */ /* GPIO */
#if (CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_3) #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); gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, GPIO_BASE);
#else #else
gpio = (uint32_t *)mmap(0, BLOCK_SIZE * 10, PROT_READ | PROT_WRITE, MAP_SHARED, fd, GPIO_BASE); gpio = (uint32_t *)mmap(0, BLOCK_SIZE * 10, PROT_READ | PROT_WRITE, MAP_SHARED, fd, GPIO_BASE);
#endif #endif
@ -2375,7 +2377,6 @@ int wiringPiSetup (void)
pwm = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PWM) ; pwm = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PWM) ;
if (pwm == MAP_FAILED) if (pwm == MAP_FAILED)
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (PWM) failed: %s\n", strerror (errno)) ; 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 #if CONFIG_ORANGEPI_WIN || CONFIG_ORANGEPI_ZEROPLUS2_H3 || CONFIG_ORANGEPI_3 || CONFIG_ORANGEPI_ZEROPLUS2_H5
/* GPIOC connect CPU with Modem */ /* GPIOC connect CPU with Modem */
@ -2385,6 +2386,7 @@ int wiringPiSetup (void)
return wiringPiFailure(WPI_ALMOST, return wiringPiFailure(WPI_ALMOST,
"wiringPiSetup: mmap (GPIO) failed: %s\n", strerror(errno)); "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror(errno));
#endif #endif
#else /* CONFIG_ORANGEPI_RK3399 */ #else /* CONFIG_ORANGEPI_RK3399 */
gpio2_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO2_BASE); 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) if ((int32_t)(unsigned long)gpio2_base == -1)
@ -2414,9 +2416,6 @@ int wiringPiSetup (void)
if ((int32_t)(unsigned long)gpio4_base == -1) if ((int32_t)(unsigned long)gpio4_base == -1)
return wiringPiFailure(WPI_ALMOST, return wiringPiFailure(WPI_ALMOST,
"wiringPiSetup: mmap (GPIO4_BASE) failed: %s\n", strerror(errno)); "wiringPiSetup: mmap (GPIO4_BASE) failed: %s\n", strerror(errno));
#endif /* CONFIG_ORANGEPI_RK3399 */ #endif /* CONFIG_ORANGEPI_RK3399 */
#endif #endif

Loading…
Cancel
Save