Skip to content

Commit

Permalink
Support Orange Pi CM5 Tablet
Browse files Browse the repository at this point in the history
  • Loading branch information
baiywt committed Apr 1, 2024
1 parent 7f53a53 commit 5b3fbdf
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 3 deletions.
1 change: 1 addition & 0 deletions examples/blink.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ unsigned char getGpioNum(void)
case PI_MODEL_4_LTS:
case PI_MODEL_800:
case PI_MODEL_5:
case PI_MODEL_CM5:
return 17;
break;
case PI_MODEL_ZERO_2:
Expand Down
57 changes: 57 additions & 0 deletions gpio/readall.c
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,53 @@ static char * physNames_5PRO[64] =
" GND", "GPIO4_A5",
};

static int physToWpi_CM5[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, 13, //21,22
14, 15, //23,24
-1, 16, //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_CM5[64] =
{
NULL,
" 3.3V", "5V ",
" SDA.8", "5V ",
" SCL.8", "GND ",
" PWM1", "TXD.6 ",
" GND", "RXD.6 ",
" RXD.1", "GPIO1_A2",
" TXD.1", "GND ",
"GPIO1_B0", "GPIO1_A4",
" 3.3V", "GPIO1_A6",
"SPI0_TXD", "GND ",
"SPI0_RXD", "GPIO1_A7",
"SPI0_CLK", "SPI0_CS0",
" GND", "SPI0_CS1",
};

static char * physNames_5PLUS[64] =
{
NULL,
Expand Down Expand Up @@ -1633,6 +1680,12 @@ void OrangePiReadAll(int model)
physNames = physNames_900;
alts = alts_rk3588;
break;
case PI_MODEL_CM5:
printf (" +------+-----+----------+--------+---+ PI CM5 +---+--------+----------+-----+------+\n");
physToWpi = physToWpi_CM5;
physNames = physNames_CM5;
alts = alts_rk3588;
break;
case PI_MODEL_CM4:
printf (" +------+-----+----------+--------+---+ PI CM4 +---+--------+----------+-----+------+\n");
physToWpi = physToWpi_CM4;
Expand Down Expand Up @@ -1687,6 +1740,7 @@ void OrangePiReadAll(int model)
case PI_MODEL_4_LTS:
case PI_MODEL_5:
case PI_MODEL_5B:
case PI_MODEL_CM5:
for (pin = 1 ; pin <= 26; pin += 2)
readallPhys(pin);
break;
Expand Down Expand Up @@ -1774,6 +1828,9 @@ void OrangePiReadAll(int model)
case PI_MODEL_900:
printf (" +------+-----+----------+--------+---+ PI900 +---+--------+----------+-----+------+\n");
break;
case PI_MODEL_CM5:
printf (" +------+-----+----------+--------+---+ PI CM5 +---+--------+----------+-----+------+\n");
break;
case PI_MODEL_CM4:
printf (" +------+-----+----------+--------+---+ PI CM4 +---+--------+----------+-----+------+\n");
break;
Expand Down
79 changes: 79 additions & 0 deletions wiringPi/wiringPi.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,15 @@ static int ORANGEPI_PIN_MASK_5PRO[5][32] = //[BANK] [INDEX]
{-1,-1,-1, 3, 4, 5, 6, 7, -1,-1, 2, 3,-1,-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_CM5[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,},//GPIO0
{ 0, 1, 2, 3, 4,-1, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1, 6, 7,},//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,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-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_5MAX[5][32] = //[BANK] [INDEX]
{
{-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1, 5, 6, 7, 0,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,},//GPIO0
Expand Down Expand Up @@ -969,6 +978,29 @@ int pinToGpio_5PRO[64] =
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,// ... 63
};

int pinToGpio_CM5[64] =
{
63, 62, // 0, 1
35, 33, // 2, 3
32, 47, // 4 5
34, 46, // 6, 7
40, 36, // 8, 9
38, 42, //10,11
41, 39, //12,13
43, 44, //14,15
45, -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_5MAX[64] =
{
16, 15, // 0, 1
Expand Down Expand Up @@ -1618,6 +1650,35 @@ int physToGpio_5PRO[64] =
-1, -1, -1, -1, -1, -1, -1, // ... 63
};

int physToGpio_CM5[64] =
{
-1, // 0
-1, -1, // 1, 2
63, -1, // 3, 4
62, -1, // 5, 6
35, 33, // 7, 8
-1, 32, // 9, 10
47, 34, // 11, 12
46, -1, // 13, 14
40, 36, // 15, 16
-1, 38, // 17, 18
42, -1, // 19, 20
41, 39, // 21, 22
43, 44, // 23, 24
-1, 45, // 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_5MAX[64] =
{
-1, // 0
Expand Down Expand Up @@ -2163,6 +2224,7 @@ void piBoardId (int * model)
else if (strncmp(revision, "orangepi5max.", 13) == 0) { *model = PI_MODEL_5_MAX; }
else if (strncmp(revision, "orangepi5plus.", 14) == 0) { *model = PI_MODEL_5_PLUS; }
else if (strncmp(revision, "orangepi900.", 12) == 0) { *model = PI_MODEL_900; }
else if (strncmp(revision, "orangepicm5-tablet.", 12) == 0) { *model = PI_MODEL_CM5; }
else if (strncmp(revision, "orangepicm4.", 12) == 0) { *model = PI_MODEL_CM4; }
else if (strncmp(revision, "orangepi3b.", 11) == 0) { *model = PI_MODEL_3B; }
else if (strncmp(revision, "orangepi3plus.", 14) == 0) { *model = PI_MODEL_3_PLUS; }
Expand Down Expand Up @@ -2394,6 +2456,7 @@ void sunxi_pwm_set_tone(int pin,int freq)
{
case PI_MODEL_5:
case PI_MODEL_5B:
case PI_MODEL_CM5:
case PI_MODEL_5_PRO:
case PI_MODEL_5_MAX:
case PI_MODEL_5_PLUS:
Expand Down Expand Up @@ -2580,6 +2643,7 @@ void sunxi_pwm_set_clk(int pin,int clk)
{
case PI_MODEL_5:
case PI_MODEL_5B:
case PI_MODEL_CM5:
case PI_MODEL_5_PRO:
case PI_MODEL_5_MAX:
case PI_MODEL_5_PLUS:
Expand Down Expand Up @@ -2784,6 +2848,7 @@ void sunxi_pwm_set_period(int pin,unsigned int period_cys)
{
case PI_MODEL_5:
case PI_MODEL_5B:
case PI_MODEL_CM5:
case PI_MODEL_5_PRO:
case PI_MODEL_5_MAX:
case PI_MODEL_5_PLUS:
Expand Down Expand Up @@ -2925,6 +2990,7 @@ void sunxi_pwm_set_act(int pin,int act_cys)
{
case PI_MODEL_5:
case PI_MODEL_5B:
case PI_MODEL_CM5:
case PI_MODEL_5_PRO:
case PI_MODEL_5_MAX:
case PI_MODEL_5_PLUS:
Expand Down Expand Up @@ -4317,6 +4383,11 @@ int wiringPiSetup (void)
physToGpio = physToGpio_5B;
ORANGEPI_PIN_MASK = ORANGEPI_PIN_MASK_5B;
break;
case PI_MODEL_CM5:
pinToGpio = pinToGpio_CM5;
physToGpio = physToGpio_CM5;
ORANGEPI_PIN_MASK = ORANGEPI_PIN_MASK_CM5;
break;
case PI_MODEL_5_PRO:
pinToGpio = pinToGpio_5PRO;
physToGpio = physToGpio_5PRO;
Expand Down Expand Up @@ -4445,6 +4516,7 @@ int wiringPiSetup (void)
break;

case PI_MODEL_5: case PI_MODEL_5B: case PI_MODEL_5_PRO: case PI_MODEL_5_MAX: case PI_MODEL_5_PLUS: case PI_MODEL_900:
case PI_MODEL_CM5:

/* GPIO Register */
rk3588_soc_info_t.gpio0_base = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, RK3588_GPIO0_BASE);
Expand Down Expand Up @@ -4774,6 +4846,7 @@ unsigned int readR(unsigned int addr)
case PI_MODEL_5_MAX:
case PI_MODEL_5_PLUS:
case PI_MODEL_900:
case PI_MODEL_CM5:

val = 0;

Expand Down Expand Up @@ -4965,6 +5038,7 @@ void writeR(unsigned int val, unsigned int addr)
case PI_MODEL_5_MAX:
case PI_MODEL_5_PLUS:
case PI_MODEL_900:
case PI_MODEL_CM5:

mmap_base = (addr & (~0xfff));
mmap_seek = (addr - mmap_base);
Expand Down Expand Up @@ -5166,6 +5240,7 @@ int OrangePi_get_gpio_mode(int pin)
case PI_MODEL_5_MAX:
case PI_MODEL_5_PLUS:
case PI_MODEL_900:
case PI_MODEL_CM5:

rk3588_bus_ioc_phyaddr = RK3588_BUS_IOC_BASE + (0x20 * bank) + ((index >> 2) << 2);
if(bank == 0){
Expand Down Expand Up @@ -5639,6 +5714,7 @@ int OrangePi_set_gpio_mode(int pin, int mode)
case PI_MODEL_5_MAX:
case PI_MODEL_5_PLUS:
case PI_MODEL_900:
case PI_MODEL_CM5:

rk3588_bus_ioc_phyaddr = RK3588_BUS_IOC_BASE + (0x20 * bank) + ((index >> 2) << 2);
if(bank == 0){
Expand Down Expand Up @@ -6490,6 +6566,7 @@ int OrangePi_digitalWrite(int pin, int value)
case PI_MODEL_5_MAX:
case PI_MODEL_5_PLUS:
case PI_MODEL_900:
case PI_MODEL_CM5:

if(bank == 0){
dr_phyaddr = RK3588_GPIO0_BASE + RK3588_GPIO_SWPORT_DR_L_OFFSET + ((index / 16) << 2);
Expand Down Expand Up @@ -6797,6 +6874,7 @@ int OrangePi_digitalRead(int pin)
case PI_MODEL_5_MAX:
case PI_MODEL_5_PLUS:
case PI_MODEL_900:
case PI_MODEL_CM5:

if(bank == 0)
phyaddr = RK3588_GPIO0_BASE + RK3588_GPIO_EXT_PORT_OFFSET;
Expand Down Expand Up @@ -6902,6 +6980,7 @@ void OrangePi_set_gpio_pullUpDnControl (int pin, int pud)
case PI_MODEL_5_MAX:
case PI_MODEL_5_PLUS:
case PI_MODEL_900:
case PI_MODEL_CM5:

if(bank == 0 && index < 12)
phyaddr = RK3588_PMU1_IOC_BASE + RK3588_PMU1_IOC_GPIO0A_P + ((index >> 3) << 2);
Expand Down
7 changes: 4 additions & 3 deletions wiringPi/wiringPi.h
Original file line number Diff line number Diff line change
Expand Up @@ -679,13 +679,14 @@ extern int wiringPiDebug;
#define PI_MODEL_5_PRO 26
#define PI_MODEL_5_MAX 27
#define PI_MODEL_5_PLUS 28
#define PI_MODEL_CM5 29

/* Rockchip RK3566 */
#define PI_MODEL_CM4 29
#define PI_MODEL_3B 30
#define PI_MODEL_CM4 30
#define PI_MODEL_3B 31

/* S905D3 */
#define PI_MODEL_3_PLUS 31
#define PI_MODEL_3_PLUS 32

extern const char *piModelNames [16] ;

Expand Down

0 comments on commit 5b3fbdf

Please sign in to comment.