Browse Source

增加OrangePi4B的支持

pull/8/head
gp.coder 5 years ago
parent
commit
7ee2dd55a8
  1. 2
      build
  2. 4
      examples/Makefile
  3. BIN
      examples/isr
  4. 44
      examples/isr.c
  5. 12
      gpio/Makefile
  6. 101
      gpio/OrangePi.c
  7. 2
      gpio/gpio.c
  8. 12
      wiringPi/Makefile
  9. 138
      wiringPi/OrangePi.c
  10. 2
      wiringPi/OrangePi.h
  11. 22
      wiringPi/wiringPi.c

2
build

@ -49,7 +49,7 @@ select_boards()
local choice local choice
local call=${1} 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" printf "All available boards:\n"
for var in ${boards[@]} ; do for var in ${boards[@]} ; do

4
examples/Makefile

@ -26,8 +26,8 @@ ifneq ($V,1)
Q ?= @ Q ?= @
endif endif
#DEBUG = -g -O0 DEBUG = -g -O0
DEBUG = -O3 #DEBUG = -O3
CC = gcc CC = gcc
INCLUDE = -I/usr/local/include INCLUDE = -I/usr/local/include
CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe CFLAGS = $(DEBUG) -Wall $(INCLUDE) -Winline -pipe

BIN
examples/isr

Binary file not shown.

44
examples/isr.c

@ -50,14 +50,14 @@ static volatile int globalCounter [8] ;
********************************************************************************* *********************************************************************************
*/ */
void myInterrupt0 (void) { ++globalCounter [0] ; } void myInterrupt0 (void) { ++globalCounter [0] ; delay(100);if(digitalRead(0)==LOW){ printf ("key 1 press\n");fflush (stdout) ;}}
void myInterrupt1 (void) { ++globalCounter [1] ; } void myInterrupt1 (void) { ++globalCounter [1] ; delay(100);if(digitalRead(1)==LOW){ printf ("key 2 press\n");fflush (stdout) ;}}
void myInterrupt2 (void) { ++globalCounter [2] ; } void myInterrupt2 (void) { ++globalCounter [2] ; delay(100);if(digitalRead(2)==LOW){ printf ("key 3 press\n");fflush (stdout) ;}}
void myInterrupt3 (void) { ++globalCounter [3] ; } void myInterrupt3 (void) { ++globalCounter [3] ; delay(100);if(digitalRead(3)==LOW){ printf ("key 4 press\n");fflush (stdout) ;}}
void myInterrupt4 (void) { ++globalCounter [4] ; } void myInterrupt4 (void) { ++globalCounter [4] ; delay(100);if(digitalRead(4)==LOW){ printf ("key 5 press\n");fflush (stdout) ;}}
void myInterrupt5 (void) { ++globalCounter [5] ; } void myInterrupt5 (void) { ++globalCounter [5] ; delay(100);if(digitalRead(5)==LOW){ printf ("key 6 press\n");fflush (stdout) ;}}
void myInterrupt6 (void) { ++globalCounter [6] ; } void myInterrupt6 (void) { ++globalCounter [6] ; delay(100);if(digitalRead(6)==LOW){ printf ("key 7 press\n");fflush (stdout) ;}}
void myInterrupt7 (void) { ++globalCounter [7] ; } 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 main (void)
{ {
int gotOne, pin ; int gotOne, pin ,ret;
int myCounter [8] ; int myCounter [8] ;
for (pin = 0 ; pin < 8 ; ++pin) for (pin = 0 ; pin < 8 ; ++pin)
@ -82,28 +82,18 @@ int main (void)
wiringPiISR (3, INT_EDGE_FALLING, &myInterrupt3) ; wiringPiISR (3, INT_EDGE_FALLING, &myInterrupt3) ;
wiringPiISR (4, INT_EDGE_FALLING, &myInterrupt4) ; wiringPiISR (4, INT_EDGE_FALLING, &myInterrupt4) ;
wiringPiISR (5, INT_EDGE_FALLING, &myInterrupt5) ; 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 (;;) for (;;)
{ {
gotOne = 0 ; gotOne = 0 ;
printf ("Waiting ... ") ; fflush (stdout) ;
sleep(1);
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 ;
}
} }
return 0 ; return 0 ;

12
gpio/Makefile

@ -30,8 +30,8 @@ ifneq ($V,1)
Q ?= @ Q ?= @
endif endif
#DEBUG = -g -O0 DEBUG = -g -O0
DEBUG = -O2 #DEBUG = -O2
CC = gcc CC = gcc
INCLUDE = -I$(DESTDIR)$(PREFIX)/include INCLUDE = -I$(DESTDIR)$(PREFIX)/include
CFLAGS = $(DEBUG) -Wall -Wextra $(INCLUDE) -Winline -pipe CFLAGS = $(DEBUG) -Wall -Wextra $(INCLUDE) -Winline -pipe
@ -108,6 +108,10 @@ EXTRA_CFLAGS = -DCONFIG_ORANGEPI_4
EXTRA_CFLAGS += -DCONFIG_ORANGEPI EXTRA_CFLAGS += -DCONFIG_ORANGEPI
endif endif
ifeq ($(PLATFORM), OrangePi_4B)
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_4B
EXTRA_CFLAGS += -DCONFIG_ORANGEPI
endif
# May not need to alter anything below this line # May not need to alter anything below this line
############################################################################### ###############################################################################
@ -157,6 +161,10 @@ ifeq ($(PLATFORM), OrangePi_4)
SRC += OrangePi.c SRC += OrangePi.c
endif endif
ifeq ($(PLATFORM), OrangePi_4B)
SRC += OrangePi.c
endif
OBJ = $(SRC:.c=.o) OBJ = $(SRC:.c=.o)
all: gpio all: gpio

101
gpio/OrangePi.c

@ -710,7 +710,98 @@ char *physNames[64] =
}; };
#endif #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"); printf (" +------+-----+----------+------+---+OrangePi RK3399---+---+------+---------+-----+--+\n");
#elif CONFIG_ORANGEPI_4 #elif CONFIG_ORANGEPI_4
printf (" +------+-----+----------+------+---+OrangePi 4---+---+------+---------+-----+--+\n"); printf (" +------+-----+----------+------+---+OrangePi 4---+---+------+---------+-----+--+\n");
#elif CONFIG_ORANGEPI_4B
printf (" +------+-----+----------+------+---+OrangePi 4B---+---+------+---------+-----+--+\n");
#endif #endif
printf (" | GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |\n"); printf (" | GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |\n");
printf (" +------+-----+----------+------+---+----++----+---+------+----------+-----+------+\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) 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) for (pin = 1 ; pin <= 26 ; pin += 2)
#endif #endif
readallPhys(pin); readallPhys(pin);
@ -767,7 +859,8 @@ void OrangePiReadAll(void)
printf (" +------+-----+----------+------+---+OrangePi RK3399---+---+------+---------+-----+--+\n"); printf (" +------+-----+----------+------+---+OrangePi RK3399---+---+------+---------+-----+--+\n");
#elif CONFIG_ORANGEPI_4 #elif CONFIG_ORANGEPI_4
printf (" +------+-----+----------+------+---+OrangePi 4---+---+------+---------+-----+--+\n"); printf (" +------+-----+----------+------+---+OrangePi 4---+---+------+---------+-----+--+\n");
#elif CONFIG_ORANGEPI_4B
printf (" +------+-----+----------+------+---+OrangePi 4B---+---+------+---------+-----+--+\n");
#endif #endif
wiringPiDebug = tmp; wiringPiDebug = tmp;

2
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 fd ;
int count ; int count ;

12
wiringPi/Makefile

@ -34,8 +34,8 @@ endif
STATIC=libwiringPi.a STATIC=libwiringPi.a
DYNAMIC=libwiringPi.so.$(VERSION) DYNAMIC=libwiringPi.so.$(VERSION)
#DEBUG = -g -O0 DEBUG = -g -O0
DEBUG = -O2 #DEBUG = -O2
CC = gcc CC = gcc
INCLUDE = -I. INCLUDE = -I.
DEFS = -D_GNU_SOURCE DEFS = -D_GNU_SOURCE
@ -112,6 +112,10 @@ EXTRA_CFLAGS = -DCONFIG_ORANGEPI_4
EXTRA_CFLAGS += -DCONFIG_ORANGEPI EXTRA_CFLAGS += -DCONFIG_ORANGEPI
endif endif
ifeq ($(PLATFORM), OrangePi_4B)
EXTRA_CFLAGS = -DCONFIG_ORANGEPI_4B
EXTRA_CFLAGS += -DCONFIG_ORANGEPI
endif
############################################################################### ###############################################################################
SRC = wiringPi.c \ SRC = wiringPi.c \
@ -177,6 +181,10 @@ ifeq ($(PLATFORM), OrangePi_4)
SRC += OrangePi.c SRC += OrangePi.c
endif endif
ifeq ($(PLATFORM), OrangePi_4B)
SRC += OrangePi.c
endif
HEADERS = $(shell ls *.h) HEADERS = $(shell ls *.h)
OBJ = $(SRC:.c=.o) OBJ = $(SRC:.c=.o)

138
wiringPi/OrangePi.c

@ -971,8 +971,112 @@ volatile uint32_t *gpio4_base;
#endif /* CONFIG_ORANGEPI_4 */ #endif /* CONFIG_ORANGEPI_4 */
// add 2019.1.8 // 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. * Data for use with the boardId functions.
* The order of entries here to correspond with the PI_MODEL_X * The order of entries here to correspond with the PI_MODEL_X
@ -997,6 +1101,8 @@ const char *piModelNames[6] =
"OrangePi H3 family", "OrangePi H3 family",
#elif CONFIG_ORANGEPI_ZERO #elif CONFIG_ORANGEPI_ZERO
"OrangePi Zero", "OrangePi Zero",
#elif CONFIG_ORANGEPI_4B
"OrangePi 4B",
#endif #endif
}; };
@ -1033,7 +1139,7 @@ unsigned int readR(unsigned int addr)
else /* Group A, B and D */ else /* Group A, B and D */
val = *((char *)OrangePi_gpio + mmap_seek); val = *((char *)OrangePi_gpio + mmap_seek);
return val; 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 val = 0;
unsigned int mmap_base = (addr & ~MAP_MASK); unsigned int mmap_base = (addr & ~MAP_MASK);
unsigned int mmap_seek = (addr - mmap_base); unsigned int mmap_seek = (addr - mmap_base);
@ -1081,7 +1187,7 @@ void writeR(unsigned int val, unsigned int addr)
else else
*((char *)OrangePi_gpio + mmap_seek) = val; *((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_base = (addr & ~MAP_MASK);
unsigned int mmap_seek = (addr - mmap_base); unsigned int mmap_seek = (addr - mmap_base);
if(mmap_base == CRU_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) int OrangePi_get_gpio_mode(int pin)
{ {
unsigned int regval = 0; unsigned int regval = 0;
unsigned int bank = pin >> 5; //算出 pin 属于哪一组 H6 有 2/3/5/6/7 unsigned int bank = pin >> 5; //<EFBFBD><EFBFBD><EFBFBD> pin <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> H6 <EFBFBD><EFBFBD> 2/3/5/6/7
unsigned int index = pin - (bank << 5); //算出 pin 属于组中的第多少个 unsigned int index = pin - (bank << 5); //<EFBFBD><EFBFBD><EFBFBD> pin <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĵڶ<EFBFBD><EFBFBD>ٸ<EFBFBD>
unsigned int phyaddr = 0; unsigned int phyaddr = 0;
unsigned char mode = -1; 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; unsigned int grf_phyaddr = 0, ddr_phyaddr = 0;
int offset = ((index - ((index >> 3) << 3))); int offset = ((index - ((index >> 3) << 3)));
if(bank == 1){ if(bank == 1){
@ -1308,7 +1414,7 @@ int OrangePi_set_gpio_mode(int pin, int mode)
unsigned int phyaddr = 0; unsigned int phyaddr = 0;
#ifdef CONFIG_ORANGEPI_2G_IOT #ifdef CONFIG_ORANGEPI_2G_IOT
unsigned int base_address = 0; 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))); int offset = ((index - ((index >> 3) << 3)));
unsigned int cru_phyaddr, grf_phyaddr, gpio_phyaddr; unsigned int cru_phyaddr, grf_phyaddr, gpio_phyaddr;
#else #else
@ -1340,7 +1446,7 @@ int OrangePi_set_gpio_mode(int pin, int mode)
phyaddr = base_address + OEN_SET_OUT_REGISTER; phyaddr = base_address + OEN_SET_OUT_REGISTER;
else else
printf("Invalid mode\n"); 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){ if(bank == 1){
cru_phyaddr = PMUCRU_BASE + PMUCRU_CLKGATE_CON1_OFFSET; cru_phyaddr = PMUCRU_BASE + PMUCRU_CLKGATE_CON1_OFFSET;
grf_phyaddr = PMUGRF_BASE + ((index >> 3) << 2) + 0x10; grf_phyaddr = PMUGRF_BASE + ((index >> 3) << 2) + 0x10;
@ -1362,7 +1468,7 @@ int OrangePi_set_gpio_mode(int pin, int mode)
#endif #endif
/* Ignore unused gpio */ /* Ignore unused gpio */
if (ORANGEPI_PIN_MASK[bank][index] != -1) { 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); regval = readR(phyaddr);
if (wiringPiDebug) if (wiringPiDebug)
printf("Before read reg val: 0x%x offset:%d\n",regval,offset); 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 #ifdef CONFIG_ORANGEPI_2G_IOT
writeR(GPIO_BIT(index), phyaddr); 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); writeR(0xffff0180, cru_phyaddr);
regval = readR(grf_phyaddr); regval = readR(grf_phyaddr);
regval |= 0x3 << ((offset << 1) | 0x10); regval |= 0x3 << ((offset << 1) | 0x10);
@ -1466,7 +1572,7 @@ int OrangePi_digitalWrite(int pin, int value)
#ifdef CONFIG_ORANGEPI_2G_IOT #ifdef CONFIG_ORANGEPI_2G_IOT
unsigned int base_address = 0; 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 regval = 0;
unsigned int cru_phyaddr = 0; unsigned int cru_phyaddr = 0;
@ -1524,7 +1630,7 @@ int OrangePi_digitalWrite(int pin, int value)
else else
printf("Invalid value\n"); 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){ if(bank == 1){
phyaddr = GPIO1_BASE + GPIO_SWPORTA_DR_OFFSET; phyaddr = GPIO1_BASE + GPIO_SWPORTA_DR_OFFSET;
cru_phyaddr = PMUCRU_BASE + PMUCRU_CLKGATE_CON1_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); writeR(GPIO_BIT(index), phyaddr);
#else #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); writeR(0xffff0180, cru_phyaddr);
#endif #endif
regval = readR(phyaddr); regval = readR(phyaddr);
@ -1579,7 +1685,7 @@ int OrangePi_digitalRead(int pin)
int bank = pin >> 5; int bank = pin >> 5;
int index = pin - (bank << 5); int index = pin - (bank << 5);
int val; 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; unsigned int phyaddr;
@ -1616,7 +1722,7 @@ int OrangePi_digitalRead(int pin)
phys_SET_R = base_address + SET_REGISTER; phys_SET_R = base_address + SET_REGISTER;
phys_VAL_R = base_address + VAL_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; unsigned int phyaddr;
if(bank == 1) if(bank == 1)
phyaddr = GPIO1_BASE + GPIO_EXT_PORTA_OFFSET; phyaddr = GPIO1_BASE + GPIO_EXT_PORTA_OFFSET;
@ -1673,7 +1779,7 @@ 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 (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4) #elif (defined CONFIG_ORANGEPI_RK3399 || defined CONFIG_ORANGEPI_4 || defined CONFIG_ORANGEPI_4B)
/* Support: OrangePi RK3399 */ /* Support: OrangePi RK3399 */
char *OrangePi_string = "rk3399"; char *OrangePi_string = "rk3399";
@ -1697,7 +1803,7 @@ int isOrangePi(void)
fclose(cpuFd); 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"); strcpy(line, "Hardware : Rockchip rk3399 Family");
#endif #endif

2
wiringPi/OrangePi.h

@ -77,7 +77,7 @@
#endif #endif
/*********** OrangePi RK3399 *************/ /*********** OrangePi RK3399 *************/
#if CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 #if CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 || CONFIG_ORANGEPI_4B
#define GPIO1_BASE 0xff730000 #define GPIO1_BASE 0xff730000
#define GPIO2_BASE 0xff780000 #define GPIO2_BASE 0xff780000

22
wiringPi/wiringPi.c

@ -329,12 +329,18 @@ int wiringPiTryGpioMem = FALSE ;
// sysFds: // sysFds:
// Map a file descriptor from the /sys/class/gpio/gpioX/value // 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,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -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 // ISR Data
@ -775,7 +781,7 @@ int piGpioLayout (void)
break ; break ;
#if CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 #if CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 || CONFIG_ORANGEPI_4B
strcpy(line, "Hardware : Rockchip rk3399 Family"); strcpy(line, "Hardware : Rockchip rk3399 Family");
#endif #endif
@ -793,7 +799,7 @@ int piGpioLayout (void)
fclose (cpuFd) ; fclose (cpuFd) ;
#if CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 #if CONFIG_ORANGEPI_RK3399 || CONFIG_ORANGEPI_4 || CONFIG_ORANGEPI_4B
strcpy(line, "Revision : 0000"); strcpy(line, "Revision : 0000");
#endif #endif
@ -959,7 +965,7 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty)
break ; break ;
fclose (cpuFd) ; 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"); strcpy(line, "Revision : 0000");
#endif #endif
@ -2030,7 +2036,9 @@ int wiringPiISR (int pin, int mode, void (*function)(void))
else else
modeS = "both" ; modeS = "both" ;
sprintf (pinS, "%d", bcmGpioPin) ;
//gpio edge 命令行接受参数为wpi编码
sprintf (pinS, "%d", pin) ;
if ((pid = fork ()) < 0) // Fail if ((pid = fork ()) < 0) // Fail
return wiringPiFailure (WPI_FATAL, "wiringPiISR: fork failed: %s\n", strerror (errno)) ; 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) if (sysFds [bcmGpioPin] == -1)
{ {
sprintf (fName, "/sys/class/gpio/gpio%d/value", bcmGpioPin) ; 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)) ; 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, 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 || CONFIG_ORANGEPI_4B)
/* GPIO */ /* GPIO */
#ifdef CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_3 #ifdef CONFIG_ORANGEPI_LITE2 || CONFIG_ORANGEPI_3
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);

Loading…
Cancel
Save