Skip to content

Commit

Permalink
Support Orange Pi Zero2w
Browse files Browse the repository at this point in the history
  • Loading branch information
orangepi-xunlong committed Jun 21, 2023
1 parent 9ce6d21 commit 1558d46
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 8 deletions.
1 change: 1 addition & 0 deletions examples/blink.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ unsigned char getGpioNum(void)
case PI_MODEL_4:
case PI_MODEL_5_PLUS:
case PI_MODEL_CM4:
case PI_MODEL_ZERO_2_W:
return 28;
break;
case PI_MODEL_R1_PLUS:
Expand Down
75 changes: 69 additions & 6 deletions gpio/readall.c
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,59 @@ static char * physNames_ZERO_2[64] =
" PH10", " ",
};

static int physToWpi_ZERO_2_W[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
17, 18, //27, 28
19, -1, //29, 30
20, 21, //31, 32
22, -1, //33, 34
23, 24, //35, 36
25, 26, //37, 38
-1, 27, //39, 40

-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //41-> 55
-1, -1, -1, -1, -1, -1, -1, -1 // 56-> 63
};

static char * physNames_ZERO_2_W[64] =
{
NULL,
" 3.3V", "5V ",
" SDA.1", "5V ",
" SCL.1", "GND ",
" PI00", "TXD.0 ",
" GND", "RXD.0 ",
" RXD.5", "PI01 ",
" RXD.5", "GND ",
" PWM3", "PWM4 ",
" 3.3V", "PH04 ",
" MOSI.1", "GND ",
" MISO.1", "RXD.2 ",
" SCLK.1", "CE.0 ",
" GND", "CE.1 ",
" SDA.2", "SCL.2 ",
" PWM1", "GND ",
" PWM2", "TXD.2 ",
" PI15", "GND ",
" PI12", "PH10 ",
" PI16", "PI04 ",
" GND", "PI03 ",
};

static int physToWpi_RK3399[64] =
{
-1, //0
Expand Down Expand Up @@ -1225,9 +1278,9 @@ static void piPlusReadall (int model)
*/
void OrangePiReadAll(int model)
{
int pin;
int pin;
int tmp = wiringPiDebug;
wiringPiDebug = FALSE;
wiringPiDebug = FALSE;

switch (model)
{
Expand Down Expand Up @@ -1291,6 +1344,12 @@ void OrangePiReadAll(int model)
physNames = physNames_ZERO_2;
alts = alts_common;
break;
case PI_MODEL_ZERO_2_W:
printf (" +------+-----+----------+--------+---+ ZERO2W +---+--------+----------+-----+------+\n");
physToWpi = physToWpi_ZERO_2_W;
physNames = physNames_ZERO_2_W;
alts = alts_common;
break;
case PI_MODEL_RK3399:
printf (" +------+-----+----------+--------+---+OPi RK3399+---+--------+----------+-----+------+\n");
physToWpi = physToWpi_RK3399;
Expand Down Expand Up @@ -1350,8 +1409,8 @@ void OrangePiReadAll(int model)
break ;
}

printf (" | GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |\n");
printf (" +------+-----+----------+--------+---+----++----+---+--------+----------+-----+------+\n");
printf (" | GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |\n");
printf (" +------+-----+----------+--------+---+----++----+---+--------+----------+-----+------+\n");

switch (model)
{
Expand All @@ -1363,6 +1422,7 @@ void OrangePiReadAll(int model)
case PI_MODEL_WIN:
case PI_MODEL_5_PLUS:
case PI_MODEL_CM4:
case PI_MODEL_ZERO_2_W:
for (pin = 1 ; pin <= 40; pin += 2)
readallPhys(pin);
break;
Expand Down Expand Up @@ -1391,8 +1451,8 @@ void OrangePiReadAll(int model)
break ;
}

printf (" +------+-----+----------+--------+---+----++----+---+--------+----------+-----+------+\n");
printf (" | GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |\n");
printf (" +------+-----+----------+--------+---+----++----+---+--------+----------+-----+------+\n");
printf (" | GPIO | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | GPIO |\n");

switch (model)
{
Expand Down Expand Up @@ -1426,6 +1486,9 @@ void OrangePiReadAll(int model)
case PI_MODEL_ZERO_2:
printf (" +------+-----+----------+--------+---+ H616 +---+--------+----------+-----+------+\n");
break;
case PI_MODEL_ZERO_2_W:
printf (" +------+-----+----------+--------+---+ ZERO2W +---+--------+----------+-----+------+\n");
break;
case PI_MODEL_RK3399:
printf (" +------+-----+----------+--------+---+OPi RK3399+---+--------+----------+-----+------+\n");
break;
Expand Down
83 changes: 81 additions & 2 deletions wiringPi/wiringPi.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,22 @@ static int ORANGEPI_PIN_MASK_ZERO_2[12][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,},//PE
};

static int ORANGEPI_PIN_MASK_ZERO_2_W[12][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,},//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,},//PF
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PG
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PH
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PI
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PJ
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,},//PK
{-1,-1,-1,-1,-1,-1,-1,-1,-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
};

static int ORANGEPI_PIN_MASK_800[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,},
Expand Down Expand Up @@ -697,6 +713,30 @@ int pinToGpio_ZERO_2[64] =
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 63
};

int pinToGpio_ZERO_2_W[64] =
{
264, 263, // 0, 1
256, 224, // 2, 3
225, 226, // 4 5
257, 227, // 6, 7
269, 270, // 8, 9
228, 231, //10,11
232, 262, //12,13
230, 229, //14,15
233, 266, //16,17
265, 267, //18,19
268, 261, //20,21
271, 258, //22,23
234, 272, //24,25
260, 259, //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_RK3399[64] =
{
43, 44, // 0, 1
Expand Down Expand Up @@ -1190,6 +1230,34 @@ int physToGpio_ZERO_2[64] =
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, // ... 63
};

int physToGpio_ZERO_2_W[64] =
{
-1,
-1, -1,
264, -1,
263, -1,
256, 224,
-1, 225,
226, 257,
227, -1,
269, 270,
-1, 228,
231, -1,
232, 262,
230, 229,
-1, 233,
266, 265,
267, -1,
268, 261,
271, -1,
258, 234,
272, 260,
-1, 259,

-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_RK3399[64] =//head num map to OrangePi
{
-1, // 0
Expand Down Expand Up @@ -1802,6 +1870,7 @@ void piBoardId (int * model)
else if (strncmp(revision, "orangepizeroplus2h5.", 20) == 0) { *model = PI_MODEL_ZERO_PLUS_2; }
else if (strncmp(revision, "orangepizeroplus2-h5.", 21) == 0) { *model = PI_MODEL_ZERO_PLUS_2; }
else if (strncmp(revision, "orangepizero2.", 14) == 0) { *model = PI_MODEL_ZERO_2; }
else if (strncmp(revision, "orangepizero2w.", 14) == 0) { *model = PI_MODEL_ZERO_2_W; }
else if (strncmp(revision, "orangepizero3.", 14) == 0) { *model = PI_MODEL_ZERO_2; }
else if (strncmp(revision, "orangepirk3399.", 15) == 0) { *model = PI_MODEL_RK3399; }
else if (strncmp(revision, "orangepi-rk3399.", 16) == 0) { *model = PI_MODEL_RK3399; }
Expand Down Expand Up @@ -2895,6 +2964,7 @@ void set_soc_info(void)
case PI_MODEL_3:
case PI_MODEL_LTIE_2:
case PI_MODEL_ZERO_2:
case PI_MODEL_ZERO_2_W:
sunxi_gpio_info_t.gpio_base_addr = H6_GPIO_BASE_ADDR;
sunxi_gpio_info_t.r_gpio_base_addr = H6_R_GPIO_BASE_ADDR;
sunxi_gpio_info_t.gpio_base_offset = 0x0;
Expand Down Expand Up @@ -3001,6 +3071,11 @@ int wiringPiSetup (void)
physToGpio = physToGpio_ZERO_2;
ORANGEPI_PIN_MASK = ORANGEPI_PIN_MASK_ZERO_2;
break;
case PI_MODEL_ZERO_2_W:
pinToGpio = pinToGpio_ZERO_2_W;
physToGpio = physToGpio_ZERO_2_W;
ORANGEPI_PIN_MASK = ORANGEPI_PIN_MASK_ZERO_2_W;
break;
case PI_MODEL_800:
pinToGpio = pinToGpio_800;
physToGpio = physToGpio_800;
Expand Down Expand Up @@ -3079,8 +3154,8 @@ int wiringPiSetup (void)
case PI_MODEL_3: case PI_MODEL_LTIE_2: case PI_MODEL_ZERO_2:
case PI_MODEL_ZERO: case PI_MODEL_ZERO_PLUS_2: case PI_MODEL_WIN:
case PI_MODEL_PRIME: case PI_MODEL_PC_2: case PI_MODEL_ZERO_PLUS:
case PI_MODEL_H3:
case PI_MODEL_H3: case PI_MODEL_ZERO_2_W:

sunxi_gpio_info_t.gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, sunxi_gpio_info_t.gpio_base_addr);
if ((int32_t)(unsigned long)sunxi_gpio_info_t.gpio == -1)
return wiringPiFailure(WPI_ALMOST, "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror(errno));
Expand Down Expand Up @@ -3364,6 +3439,10 @@ int wiringPiSetupSys (void)
pinToGpio = pinToGpio_ZERO_2;
physToGpio = physToGpio_ZERO_2;
break;
case PI_MODEL_ZERO_2_W:
pinToGpio = pinToGpio_ZERO_2_W;
physToGpio = physToGpio_ZERO_2_W;
break;
case PI_MODEL_800:
pinToGpio = pinToGpio_800;
physToGpio = physToGpio_800;
Expand Down
1 change: 1 addition & 0 deletions wiringPi/wiringPi.h
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ extern int wiringPiDebug;

/* Allwinner H616 */
#define PI_MODEL_ZERO_2 9
#define PI_MODEL_ZERO_2_W 10


/* Rockchip RK3399 */
Expand Down

0 comments on commit 1558d46

Please sign in to comment.