From fbd2b76dc8bbcabf79d2453537142c555f4be4d0 Mon Sep 17 00:00:00 2001 From: baiywt Date: Fri, 14 Jul 2023 10:41:34 +0800 Subject: [PATCH] Support Orange Pi 3B --- examples/blink.c | 1 + gpio/readall.c | 19 +++++++++++++++---- wiringPi/wiringPi.c | 10 ++++++++++ wiringPi/wiringPi.h | 1 + 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/examples/blink.c b/examples/blink.c index 99bb2ac..7d77eba 100644 --- a/examples/blink.c +++ b/examples/blink.c @@ -33,6 +33,7 @@ unsigned char getGpioNum(void) case PI_MODEL_4: case PI_MODEL_5_PLUS: case PI_MODEL_CM4: + case PI_MODEL_3B: case PI_MODEL_ZERO_2_W: return 28; break; diff --git a/gpio/readall.c b/gpio/readall.c index 55d0b3e..9bd7774 100644 --- a/gpio/readall.c +++ b/gpio/readall.c @@ -1070,19 +1070,19 @@ static char * physNames_CM4[64] = " 3.3V", "5V ", " SDA.2", "5V ", " SCL.2", "GND ", - "GPIO4_A4", "RXD.2 ", + " TXD.9", "RXD.2 ", " GND", "TXD.2 ", "GPIO3_C6", "GPIO3_C7", "GPIO4_A0", "GND ", - "GPIO4_A2", "GPIO4_A3", + " TXD.7", "RXD.7 ", " 3.3V", "GPIO4_A1", "SPI3_TXD", "GND ", "SPI3_RXD", "GPIO4_B1", "SPI3_CLK", "SPI3_CS1", " GND", "GPIO4_A7", " SDA.3", "SCL.3 ", - "GPIO4_A5", "GND ", - "GPIO3_D4", "GPIO4_C0", + " RXD.9", "GND ", + "GPIO3_D4", "PWM11 ", "GPIO3_D7", "GND ", "GPIO3_D0", "GPIO3_D5", "GPIO3_D3", "GPIO3_D2", @@ -1404,6 +1404,13 @@ void OrangePiReadAll(int model) physNames = physNames_CM4; alts = alts_rk3588; break; + case PI_MODEL_3B: + printf (" +------+-----+----------+--------+---+ PI3B +---+--------+----------+-----+------+\n"); + physToWpi = physToWpi_CM4; + physNames = physNames_CM4; + alts = alts_rk3588; + break; + default: printf ("Oops - unable to determine board type... model: %d\n", model); break ; @@ -1422,6 +1429,7 @@ void OrangePiReadAll(int model) case PI_MODEL_WIN: case PI_MODEL_5_PLUS: case PI_MODEL_CM4: + case PI_MODEL_3B: case PI_MODEL_ZERO_2_W: for (pin = 1 ; pin <= 40; pin += 2) readallPhys(pin); @@ -1516,6 +1524,9 @@ void OrangePiReadAll(int model) case PI_MODEL_CM4: printf (" +------+-----+----------+--------+---+ PI CM4 +---+--------+----------+-----+------+\n"); break; + case PI_MODEL_3B: + printf (" +------+-----+----------+--------+---+ PI3B +---+--------+----------+-----+------+\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 ce82d01..d65122d 100755 --- a/wiringPi/wiringPi.c +++ b/wiringPi/wiringPi.c @@ -1885,6 +1885,7 @@ void piBoardId (int * model) else if (strncmp(revision, "orangepi5b.", 11) == 0) { *model = PI_MODEL_5B; } else if (strncmp(revision, "orangepi5plus.", 14) == 0) { *model = PI_MODEL_5_PLUS; } else if (strncmp(revision, "orangepicm4.", 12) == 0) { *model = PI_MODEL_CM4; } + else if (strncmp(revision, "orangepi3b.", 11) == 0) { *model = PI_MODEL_3B; } if (wiringPiDebug) printf("piBoardId: model = %d\n", *model); @@ -3122,6 +3123,7 @@ int wiringPiSetup (void) ORANGEPI_PIN_MASK = ORANGEPI_PIN_MASK_5PLUS; break; case PI_MODEL_CM4: + case PI_MODEL_3B: pinToGpio = pinToGpio_CM4; physToGpio = physToGpio_CM4; ORANGEPI_PIN_MASK = ORANGEPI_PIN_MASK_CM4; @@ -3277,6 +3279,7 @@ int wiringPiSetup (void) break; case PI_MODEL_CM4: + case PI_MODEL_3B: /* GPIO Register */ rk3566_soc_info_t.gpio0_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, RK3566_GPIO0_BASE); @@ -3581,6 +3584,7 @@ unsigned int readR(unsigned int addr) break; case PI_MODEL_CM4: + case PI_MODEL_3B: val = 0; @@ -3712,6 +3716,7 @@ void writeR(unsigned int val, unsigned int addr) break; case PI_MODEL_CM4: + case PI_MODEL_3B: mmap_base = (addr & (~0xfff)); mmap_seek = (addr - mmap_base); @@ -3894,6 +3899,7 @@ int OrangePi_get_gpio_mode(int pin) break; case PI_MODEL_CM4: + case PI_MODEL_3B: if(bank == 0){ grf_phyaddr = RK3566_PMU_GRF_BASE + RK3566_PMU_GRF_GPIO0A_IOMUX_L_OFFSET + ((pin >> 2) << 2); @@ -4234,6 +4240,7 @@ int OrangePi_set_gpio_mode(int pin, int mode) break; case PI_MODEL_CM4: + case PI_MODEL_3B: if(bank == 0){ cru_phyaddr = RK3566_PMU_CRU_BASE + RK3566_PMUCRU_PMUGATE_CON01_OFFSET; cru_val = ~((0x3 << 9) | (0x3 << (16 + 9))); @@ -4558,6 +4565,7 @@ int OrangePi_digitalWrite(int pin, int value) break; case PI_MODEL_CM4: + case PI_MODEL_3B: if(bank == 0){ dr_phyaddr = RK3566_GPIO0_BASE + RK3566_GPIO_SWPORT_DR_L_OFFSET + ((index >> 4) << 2); @@ -4703,6 +4711,7 @@ int OrangePi_digitalRead(int pin) break; case PI_MODEL_CM4: + case PI_MODEL_3B: if(bank == 0) phyaddr = RK3566_GPIO0_BASE + RK3566_GPIO_EXT_PORT_OFFSET; @@ -4813,6 +4822,7 @@ void OrangePi_set_gpio_pullUpDnControl (int pin, int pud) break; case PI_MODEL_CM4: + case PI_MODEL_3B: if (bank == 0) phyaddr = RK3566_PMU_GRF_BASE + RK3566_PMU_GRF_GPIO0A_P_OFFSET + (((pin - 0) >> 3) << 2); diff --git a/wiringPi/wiringPi.h b/wiringPi/wiringPi.h index caeed44..8eaedca 100644 --- a/wiringPi/wiringPi.h +++ b/wiringPi/wiringPi.h @@ -355,6 +355,7 @@ extern int wiringPiDebug; /* Rockchip RK3566 */ #define PI_MODEL_CM4 27 +#define PI_MODEL_3B 28 extern const char *piModelNames [16] ;