From c736fdd0d0d90207d30c3fc3f56780f51401007a Mon Sep 17 00:00:00 2001 From: Orange Pi <258384131@qq.com> Date: Mon, 6 Feb 2023 16:17:55 +0800 Subject: [PATCH] Support Orange Pi 5B --- VERSION | 2 +- examples/blink.c | 3 ++ gpio/readall.c | 57 +++++++++++++++++++++++++++++++ wiringPi/wiringPi.c | 82 ++++++++++++++++++++++++++++++++++++++++----- wiringPi/wiringPi.h | 3 +- 5 files changed, 137 insertions(+), 10 deletions(-) diff --git a/VERSION b/VERSION index e72716a..5d8213c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.46 +2.47 diff --git a/examples/blink.c b/examples/blink.c index 4e7c92c..a51d5c9 100644 --- a/examples/blink.c +++ b/examples/blink.c @@ -9,6 +9,9 @@ unsigned char getGpioNum(void) switch (model) { + case PI_MODEL_5B: + return 16; + break; case PI_MODEL_3: case PI_MODEL_LTIE_2: case PI_MODEL_ZERO: diff --git a/gpio/readall.c b/gpio/readall.c index f43a6ad..556d6e1 100644 --- a/gpio/readall.c +++ b/gpio/readall.c @@ -881,6 +881,53 @@ static char * physNames_5[64] = " GND", "PWM1 ", }; +static int physToWpi_5B[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, -1, //21,22 + 13, 14, //23,24 + -1, 15, //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 +}; + +static char * physNames_5B[64] = +{ + NULL, + " 3.3V", "5V ", + " SDA.5", "5V ", + " SCL.5", "GND ", + " PWM15", "RXD.0 ", + " GND", "TXD.0 ", + " CAN1_RX", "CAN2_TX ", + " CAN1_TX", "GND ", + " CAN2_RX", "SDA.1 ", + " 3.3V", "SCL.1 ", + "SPI4_TXD", "GND ", + "SPI4_RXD", "PowerKey", + "SPI4_CLK", "SPI4_CS1", + " GND", "PWM1 ", +}; + static int * physToWpi; static char ** physNames; @@ -1172,6 +1219,12 @@ void OrangePiReadAll(int model) physNames = physNames_5; alts = alts_rk3588; break; + case PI_MODEL_5B: + printf (" +------+-----+----------+--------+---+ PI5B +---+--------+----------+-----+------+\n"); + physToWpi = physToWpi_5B; + physNames = physNames_5B; + alts = alts_rk3588; + break; default: printf ("Oops - unable to determine board type... model: %d\n", model); break ; @@ -1199,6 +1252,7 @@ void OrangePiReadAll(int model) case PI_MODEL_800: case PI_MODEL_4_LTS: case PI_MODEL_5: + case PI_MODEL_5B: for (pin = 1 ; pin <= 26; pin += 2) readallPhys(pin); break; @@ -1268,6 +1322,9 @@ void OrangePiReadAll(int model) case PI_MODEL_5: printf (" +------+-----+----------+--------+---+ OPI5 +---+--------+----------+-----+------+\n"); break; + case PI_MODEL_5B: + printf (" +------+-----+----------+--------+---+ PI5B +---+--------+----------+-----+------+\n"); + break; default: printf ("Oops - unable to determine board type... model: %d\n", model); break ; diff --git a/wiringPi/wiringPi.c b/wiringPi/wiringPi.c index 7f96d5e..fa73ad4 100755 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -264,6 +264,15 @@ static int ORANGEPI_PIN_MASK_5[5][32] = //[BANK] [INDEX] {-1,-1,-1, 3, 4,-1,-1,-1, -1,-1, 2, 3, 4,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,},//GPIO4 }; +static int ORANGEPI_PIN_MASK_5B[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, 4, 5,-1,-1,},//GPIO0 + {-1,-1,-1, 3,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1, 6, 7, 0, 1, 2,-1, 4,-1, 6,-1, -1,-1, 2, 3,-1,-1,-1,-1,},//GPIO1 + {-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,},//GPIO2 + {-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,},//GPIO3 + {-1,-1,-1, 3, 4,-1,-1,-1, -1,-1, 2, 3, 4,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,},//GPIO4 +}; + static int ORANGEPI_PIN_MASK_R1_PLUS[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 @@ -786,6 +795,29 @@ int pinToGpio_5[64] = -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,// ... 63 }; +int pinToGpio_5B[64] = +{ + 47, 46, // 0, 1 + 54, 131, // 2, 3 + 132,138, // 4 5 + 29, 139, // 6, 7 + 28, 59, // 8, 9 + 58, 49, //10,11 + 48, 50, //12,13 + 52, 35, //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 pinToGpio_R1_PLUS[64] = { 89, 88, // 0, 1 @@ -1235,6 +1267,34 @@ int physToGpio_5[64] = -1, -1, -1, -1, -1, -1, -1, // ... 63 }; +int physToGpio_5B[64] = +{ + -1, // 0 + -1, -1, // 1, 2 + 47, -1, // 3, 4 + 46, -1, // 5, 6 + 54, 131, // 7, 8 + -1, 132, // 9, 10 + 138, 29, // 11, 12 + 139, -1, // 13, 14 + 28, 59, // 15, 16 + -1, 58, // 17, 18 + 49, -1, // 19, 20 + 48, -1, // 21, 22 + 50, 52, // 23, 24 + -1, 35, // 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 physToGpio_R1_PLUS[64] =//head num map to OrangePi { @@ -1629,6 +1689,7 @@ void piBoardId (int * model) else if (strncmp(revision, "orangepir1plus-lts.", 18) == 0) { *model = PI_MODEL_R1_PLUS; } else if (strncmp(revision, "orangepi-r1plus-lts.", 20) == 0) { *model = PI_MODEL_R1_PLUS; } else if (strncmp(revision, "orangepi5.", 10) == 0) { *model = PI_MODEL_5; } + else if (strncmp(revision, "orangepi5b.", 11) == 0) { *model = PI_MODEL_5B; } if (wiringPiDebug) printf("piBoardId: model = %d\n", *model); @@ -2849,6 +2910,11 @@ int wiringPiSetup (void) physToGpio = physToGpio_5; ORANGEPI_PIN_MASK = ORANGEPI_PIN_MASK_5; break; + case PI_MODEL_5B: + pinToGpio = pinToGpio_5B; + physToGpio = physToGpio_5B; + ORANGEPI_PIN_MASK = ORANGEPI_PIN_MASK_5B; + break; default: printf ("Oops - unable to determine board type... model: %d\n", OrangePiModel); break ; @@ -2941,7 +3007,7 @@ int wiringPiSetup (void) break; - case PI_MODEL_5: + case PI_MODEL_5: case PI_MODEL_5B: /* GPIO Register */ rk3588_soc_info_t.gpio0_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, RK3588_GPIO0_BASE); @@ -3175,7 +3241,7 @@ unsigned int readR(unsigned int addr) switch (OrangePiModel) { - case PI_MODEL_5: + case PI_MODEL_5: case PI_MODEL_5B: val = 0; @@ -3286,7 +3352,7 @@ void writeR(unsigned int val, unsigned int addr) switch (OrangePiModel) { - case PI_MODEL_5: + case PI_MODEL_5: case PI_MODEL_5B: mmap_base = (addr & (~0xfff)); mmap_seek = (addr - mmap_base); @@ -3414,7 +3480,7 @@ int OrangePi_get_gpio_mode(int pin) } break; - case PI_MODEL_5: + case PI_MODEL_5: case PI_MODEL_5B: rk3588_bus_ioc_phyaddr = RK3588_BUS_IOC_BASE + (0x20 * bank) + ((index >> 2) << 2); if(bank == 0){ @@ -3556,7 +3622,7 @@ int OrangePi_set_gpio_mode(int pin, int mode) switch (OrangePiModel) { - case PI_MODEL_5: + case PI_MODEL_5: case PI_MODEL_5B: rk3588_bus_ioc_phyaddr = RK3588_BUS_IOC_BASE + (0x20 * bank) + ((index >> 2) << 2); if(bank == 0){ @@ -3929,7 +3995,7 @@ int OrangePi_digitalWrite(int pin, int value) switch (OrangePiModel) { - case PI_MODEL_5: + case PI_MODEL_5: case PI_MODEL_5B: if(bank == 0){ dr_phyaddr = RK3588_GPIO0_BASE + RK3588_GPIO_SWPORT_DR_L_OFFSET + ((index / 16) << 2); @@ -4147,7 +4213,7 @@ int OrangePi_digitalRead(int pin) switch (OrangePiModel) { - case PI_MODEL_5: + case PI_MODEL_5: case PI_MODEL_5B: if(bank == 0) phyaddr = RK3588_GPIO0_BASE + RK3588_GPIO_EXT_PORT_OFFSET; @@ -4224,7 +4290,7 @@ void OrangePi_set_gpio_pullUpDnControl (int pin, int pud) switch (OrangePiModel) { - case PI_MODEL_5: + case PI_MODEL_5: case PI_MODEL_5B: if(bank == 0 && index < 12) phyaddr = RK3588_PMU1_IOC_BASE + RK3588_PMU1_IOC_GPIO0A_P + ((index >> 3) << 2); diff --git a/wiringPi/wiringPi.h b/wiringPi/wiringPi.h index 91aa55a..40f1425 100644 --- a/wiringPi/wiringPi.h +++ b/wiringPi/wiringPi.h @@ -300,8 +300,9 @@ extern int wiringPiDebug; /* Rockchip RK3328 */ #define PI_MODEL_R1_PLUS 22 -/* Rockchip RK3588 */ +/* Rockchip RK3588(s) */ #define PI_MODEL_5 24 +#define PI_MODEL_5B 25 extern const char *piModelNames [16] ;