add support for NanoPi NEO Core, NEO Core2 and K1 Plus

This commit is contained in:
Lawrence-Tang 2018-06-07 15:50:20 +08:00
parent 30edaf15cd
commit 4d22e3fd65
8 changed files with 728 additions and 277 deletions

View File

@ -9,6 +9,9 @@ NanoPi NEO2
NanoPi NEO Plus2
NanoPi M1
NanoPi M1 Plus
NanoPi NEO Core
NanoPi NEO Core2
NanoPi K1 Plus
# Installation
@ -26,34 +29,63 @@ The WiringNP library contains a set of gpio commands. Users can use them to acce
```
gpio readall
```
If your installation is successful the following messages will show up. Here is the message list for NEO2:
If your installation is successful the following messages will show up. Here is the message list for NanoPi NEO Core:
```
root@FriendlyARM:~# gpio readall
+-----+-----+----------+------+---+-NanoPi NEO/NEO2--+------+----------+-----+-----+
+-----+-----+----------+------+---+-NanoPi-NEO-Core--+------+----------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+
| | | 3.3V | | | 1 || 2 | | | 5V | | |
| 12 | 8 | GPIOA12 | OFF | 0 | 3 || 4 | | | 5V | | |
| 11 | 9 | GPIOA11 | OFF | 0 | 5 || 6 | | | 0v | | |
| 203 | 7 | GPIOG11 | OUT | 1 | 7 || 8 | 0 | OFF | GPIOG6 | 15 | 198 |
| | | 0v | | | 9 || 10 | 0 | OFF | GPIOG7 | 16 | 199 |
| 0 | 0 | GPIOA0 | OFF | 0 | 11 || 12 | 0 | OFF | GPIOA6 | 1 | 6 |
| | | 3.3v | | | 1 || 2 | | | 5v | | |
| 12 | 8 | GPIOA12 | ALT5 | 0 | 3 || 4 | | | 5v | | |
| 11 | 9 | GPIOA11 | ALT5 | 0 | 5 || 6 | | | 0v | | |
| 203 | 7 | GPIOG11 | OUT | 1 | 7 || 8 | 0 | ALT5 | GPIOG6 | 15 | 198 |
| | | 0v | | | 9 || 10 | 0 | ALT5 | GPIOG7 | 16 | 199 |
| 0 | 0 | GPIOA0 | OUT | 0 | 11 || 12 | 1 | OUT | GPIOA6 | 1 | 6 |
| 2 | 2 | GPIOA2 | OFF | 0 | 13 || 14 | | | 0v | | |
| 3 | 3 | GPIOA3 | OFF | 0 | 15 || 16 | 0 | OFF | GPIOG8 | 4 | 200 |
| | | 3.3v | | | 17 || 18 | 0 | OFF | GPIOG9 | 5 | 201 |
| 64 | 12 | GPIOC0 | OFF | 0 | 19 || 20 | | | 0v | | |
| 65 | 13 | GPIOC1 | OFF | 0 | 21 || 22 | 0 | OFF | GPIOA1 | 6 | 1 |
| 66 | 14 | GPIOC2 | OFF | 0 | 23 || 24 | 0 | OFF | GPIOC3 | 10 | 67 |
| | | 3.3v | | | 17 || 18 | 0 | ALT2 | GPIOG9 | 5 | 201 |
| 64 | 12 | GPIOC0 | ALT4 | 0 | 19 || 20 | | | 0v | | |
| 65 | 13 | GPIOC1 | ALT4 | 0 | 21 || 22 | 1 | OUT | GPIOA1 | 6 | 1 |
| 66 | 14 | GPIOC2 | ALT4 | 0 | 23 || 24 | 1 | OUT | GPIOC3 | 10 | 67 |
+-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+----------+------+---+-NanoPi NEO/NEO2--+------+----------+-----+-----+
+-----+-----+----------+------+---+-NanoPi-NEO-Core--+------+----------+-----+-----+
+-----+----NanoPi NEO/NEO2 Debug UART-+----+
| BCM | wPi | Name | Mode | V | Ph |
+-----+-----+----------+------+---+----+
| 4 | 17 | GPIOA4 | ALT5 | 0 | 37 |
| 5 | 18 | GPIOA5 | ALT4 | 0 | 38 |
+-----+-----+----------+------+---+----+
+-----+-----+----------+---- NanoPi-NEO-Core USB/Audio ----+----------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+
| | | 5v | | | 25 || 26 | 0 | ALT4 | GPIOA15 | 22 | 15 |
| | | USB1 | | | 27 || 28 | 0 | ALT4 | GPIOA16 | 23 | 16 |
| | | USB1 | | | 29 || 30 | 0 | ALT4 | GPIOA14 | 21 | 14 |
| | | USB2 | | | 31 || 32 | 0 | ALT4 | GPIOA13 | 20 | 13 |
| | | USB2 | | | 33 || 34 | | | Mic | | |
| | | IR | | | 35 || 36 | | | Mic | | |
| 17 | 19 | GPIOA17 | OFF | 0 | 37 || 38 | | | Audio | | |
| | | I2S | | | 39 || 40 | | | Audio | | |
| | | I2S | | | 41 || 42 | 0 | ALT5 | GPIOA5 | 18 | 5 |
| | | I2S | | | 43 || 44 | 0 | ALT5 | GPIOA4 | 17 | 4 |
| | | I2S | | | 45 || 46 | | | 5V | | |
| | | 0v | | | 47 || 48 | | | 0v | | |
+-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+----------+------+---+-NanoPi-NEO-Core--+------+----------+-----+-----+
+-----+-----+----------+---- NanoPi-NEO-Core Network ----+----------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+
| | | Eth | | | 49 || 50 | | | Eth | | |
| | | Eth | | | 51 || 52 | | | Eth | | |
| | | Eth | | | 53 || 54 | | | Eth | | |
| | | NC | | | 55 || 56 | | | NC | | |
| | | NC | | | 57 || 58 | | | NC | | |
| | | 0v | | | 59 || 60 | | | 0v | | |
| | | USB3 | | | 61 || 62 | 0 | OFF | GPIOA7 | 24 | 7 |
| | | USB3 | | | 63 || 64 | | | GPIOE12 | | |
| | | 5v | | | 65 || 66 | | | GPIOE13 | | |
| | | 5v | | | 67 || 68 | | | 3.3v | | |
+-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+----------+------+---+-NanoPi-NEO-Core--+------+----------+-----+-----+
```
# Code Sample with WiringNP
connect a LED module to a NanoPi (Pin7), Make a C source file:

View File

@ -1133,10 +1133,8 @@ int main (int argc, char *argv [])
int boardId;
boardId = getBoardType(&retBoardInfo);
if (boardId >= 0) {
if (boardId > ALLWINNER_BASE && boardId <= ALLWINNER_MAX
&& boardId != NanoPi_A64
&& boardId != NanoPi_NEO_Core) {
&& boardId != NanoPi_A64) {
printf ("NanoPi Details:\n") ;
printf (" Type: %s, Revision: %d, Maker: FriednlyELEC\n\n",
retBoardInfo->boardDisplayName, retBoardInfo->kernelRevision) ;

View File

@ -80,8 +80,9 @@ static char *alts [] =
"IN", "OUT", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "OFF"
} ;
#define MAX_PIN_COUNT 74
static int physToWpi_m1 [64] =
static int physToWpi_m1 [MAX_PIN_COUNT] =
{
-1, // 0
-1, -1, // 1, 2
@ -106,10 +107,13 @@ static int physToWpi_m1 [64] =
-1, 29, //39, 40
-1, -1, 32, 33, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //41-> 55
-1, -1, -1, -1, -1, -1, -1, -1 // 56-> 63
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
} ;
static char *physNames_m1 [64] =
static char *physNames_m1 [MAX_PIN_COUNT] =
{
NULL,
@ -132,23 +136,27 @@ static char *physNames_m1 [64] =
" GPIO.23", "0v ",
" GPIO.24", "CTS1 ",
" GPIO.25", "TxD1 ",
" 0v", "RxD1 ",
" 0v", "RxD1 ", //39, 40
" 0v", " 5v",
" GPIO.4", " GPIO.5",
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL, //49, 50
"GPIO.17", "GPIO.18",
"GPIO.19", "GPIO.20",
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, //55 ~ 63
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, //64 ~ 73
} ;
static int physToWpi_neo [64] =
static int physToWpi_neo [MAX_PIN_COUNT] =
{
-1, // 0
/* 24pins */
-1, -1, // 1, 2
8, -1, // 3, 4
9, -1, // 5, 6
@ -162,26 +170,28 @@ static int physToWpi_neo [64] =
13, 6, //21, 22
14, 10, //23, 24
-1, -1, //25, 26
-1, -1, //27, 28
-1, -1, //29, 30
-1, -1, //31, 32
-1, -1, //33, 34
-1, -1, //35, 36
/* 12pins */
-1, -1, //25, 26 -> 1, 2
-1, -1, //27, 28 -> 3, 4
-1, -1, //29, 30 -> 5, 6 "GPIOL11 "
19, -1, //31, 32 -> 7, 8
-1, -1, //33, 34 -> 9, 10
-1, -1, //35, 36 -> 11, 12
17, 18, //37, 38
/* 39~63 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
} ;
//guenter ende
//guenter orange pi
static char *physNames_neo [64] =
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
} ;
static char *physNames_neo [MAX_PIN_COUNT] =
{
NULL,
/* 24 Pin */
/* 24 Pin */
" 3.3V", "5V ",
" GPIOA12", "5V ",
" GPIOA11", "0v ",
@ -195,16 +205,21 @@ static char *physNames_neo [64] =
" GPIOC1", "GPIOA1 ",
" GPIOC2", "GPIOC3 ",
/* 12 Pin */
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
/* 12 Pin */
" 5V", " USB-DP1", //25, 26 -> 1, 2
" USB-DM1", " USB-DP2", //27, 28 -> 3, 4
" USB-DM2", " IR-RX", //29, 30 -> 5, 6 "GPIOL11 "
" GPIOA17", " PCM/I2C", //31, 32 -> 7, 8
" PCM/I2C", " PCM/I2C", //33, 34 -> 9, 10
" PCM/I2C", " 0V", //35, 36 -> 11, 12
/* UART0, tx, rx */
" GPIOA4", " GPIOA5",
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL, //47, 48
NULL, NULL,
NULL, NULL,
@ -213,15 +228,17 @@ static char *physNames_neo [64] =
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, //63
//64 ~ 73
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL
} ;
static int physToWpi_duo [64] =
static int physToWpi_duo [MAX_PIN_COUNT] =
{
-1, // 0
-1, -1, // 1, 2
@ -250,9 +267,12 @@ static int physToWpi_duo [64] =
/* 39~63 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
} ;
static char *physNames_duo [64] =
static char *physNames_duo [MAX_PIN_COUNT] =
{
NULL,
/* 32 Pin */
@ -280,22 +300,124 @@ static char *physNames_duo [64] =
/* UART0, tx, rx */
NULL, NULL,
NULL, NULL, //39, 40
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL, //49, 50
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL, //59, 60
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL
NULL, NULL, //71, 72
NULL //73
} ;
static int physToWpi_neocore [MAX_PIN_COUNT] =
{
/* GPIO-1 24Pin */
-1, // 0
-1, -1, // 1, 2 -> 1, 2
8, -1, // 3, 4 -> 3, 4
9, -1, // 5, 6 -> 5, 6
7, 15, // 7, 8 -> 7, 8
-1, 16, // 9, 10 -> 9, 10
0, 1, //11, 12 -> 11, 12
2, -1, //13, 14 -> 13, 14
3, 4, //15, 16 -> 15, 16
-1, 5, //17, 18 -> 17, 18
12, -1, //19, 20 -> 19, 20
13, 6, //21, 22 -> 21, 22
14, 10, //23, 24 -> 23, 24
/* GPIO-2 24Pin */
-1, 22, //25, 26 -> 1, 2
-1, 23, //27, 28 -> 3, 4
-1, 21, //29, 30 -> 5, 6
-1, 20, //31, 32 -> 7, 8
-1, -1, //33, 34 -> 9, 10
-1, -1, //35, 36 -> 11, 12
19, -1, //37, 38 -> 13, 14
-1, -1, //39, 40 -> 15, 16
-1, 18, //41, 42 -> 17, 18
-1, 17, //43, 44 -> 19, 20
-1, -1, //45, 46 -> 21, 22
-1, -1, //47, 48 -> 23, 24
/* GPIO-3 24Pin */
-1, -1, //49, 50 -> 1, 2
-1, -1, //51, 52 -> 3, 4
-1, -1, //53, 54 -> 5, 6
-1, -1, //55, 56 -> 7, 8
-1, -1, //57, 58 -> 9, 10
-1, -1, //59, 60 -> 11, 12
-1, 24, //61, 62 -> 13, 14
-1, -1, //63, 64 -> 15, 16
-1, -1, //65, 66 -> 17, 18
-1, -1, //67, 68 -> 19, 20
-1, -1, //69, 70 -> 21, 22
-1, -1, //71, 72 -> 23, 24
-1, //73
} ;
static char *physNames_neocore [MAX_PIN_COUNT] =
{
NULL, // 0
/* GPIO-1 24Pin */
" 3.3v", "5v ", // 1, 2 -> 1, 2
" GPIOA12", "5v ", // 3, 4 -> 3, 4
" GPIOA11", "0v ", // 5, 6 -> 5, 6
" GPIOG11", "GPIOG6 ", // 7, 8 -> 7, 8
" 0v", "GPIOG7 ", // 9, 10 -> 9, 10
" GPIOA0", "GPIOA6 ", //11, 12 -> 11, 12
" GPIOA2", "0v ", //13, 14 -> 13, 14
" GPIOA3", "GPIOG8 ", //15, 16 -> 15, 16
" 3.3v", "GPIOG9 ", //17, 18 -> 17, 18
" GPIOC0", "0v ", //19, 20 -> 19, 20
" GPIOC1", "GPIOA1 ", //21, 22 -> 21, 22
" GPIOC2", "GPIOC3 ", //23, 24 -> 23, 24
/* GPIO-2 24Pin */
" 5v", "GPIOA15 ", //25, 26 -> 1, 2
" USB1", "GPIOA16 ", //27, 28 -> 3, 4
" USB1", "GPIOA14 ", //29, 30 -> 5, 6
" USB2", "GPIOA13 ", //31, 32 -> 7, 8
" USB2", "Mic ", //33, 34 -> 9, 10
" IR", "Mic ", //35, 36 -> 11, 12 " GPIOL11"
" GPIOA17", "Audio ", //37, 38 -> 13, 14
" I2S", "Audio ", //39, 40 -> 15, 16
" I2S", "GPIOA5 ", //41, 42 -> 17, 18
" I2S", "GPIOA4 ", //43, 44 -> 19, 20
" I2S", "5V ", //45, 46 -> 21, 22
" 0v", "0v ", //47, 48 -> 23, 24
/* GPIO-3 20Pin */
" Eth", "Eth ", //49, 50 -> 1, 2
" Eth", "Eth ", //51, 52 -> 3, 4
" Eth", "Eth ", //53, 54 -> 5, 6
" NC", "NC ", //55, 56 -> 7, 8
" NC", "NC ", //57, 58 -> 9, 10
" 0v", "0v ", //59, 60 -> 11, 12
" USB3", "GPIOA7 ", //61, 62 -> 13, 14
" USB3", "GPIOE12 ", //63, 64 -> 15, 16
" 5v", "GPIOE13 ", //65, 66 -> 17, 18
" 5v", "3.3v ", //67, 68 -> 19, 20
NULL, NULL, //69, 70 -> 21, 22
NULL, NULL, //71, 72 -> 23, 24
NULL, //73
} ;
/*
* readallPhys:
* Given a physical pin output the data on it and the next pin:
@ -309,7 +431,7 @@ static void readallPhys (int boardId, int physPin, int pair)
int *physToWpi;
char **physNames;
if (boardId == NanoPi_M1 || boardId == NanoPi_M1_Plus || boardId == NanoPi_M1_Plus2) {
if (boardId == NanoPi_M1 || boardId == NanoPi_K1_Plus || boardId == NanoPi_M1_Plus || boardId == NanoPi_M1_Plus2) {
physToWpi = physToWpi_m1;
physNames = physNames_m1;
} else if (boardId == NanoPi_NEO || boardId == NanoPi_NEO_Air || boardId == NanoPi_NEO2 || boardId == NanoPi_NEO_Plus2) {
@ -318,6 +440,9 @@ static void readallPhys (int boardId, int physPin, int pair)
} else if (boardId == NanoPi_Duo) {
physToWpi = physToWpi_duo;
physNames = physNames_duo;
} else if (boardId == NanoPi_NEO_Core || boardId == NanoPi_NEO_Core2) {
physToWpi = physToWpi_neocore;
physNames = physNames_neocore;
} else {
return ;
}
@ -391,8 +516,6 @@ static void readallPhys (int boardId, int physPin, int pair)
printf (" |\n") ;
}
//guenter
void NanoPiReadAll()
{
int pin ;
@ -401,8 +524,7 @@ void NanoPiReadAll()
boardId = getBoardType(&retBoardInfo);
if (boardId >= 0) {
if (boardId > ALLWINNER_BASE && boardId <= ALLWINNER_MAX
&& boardId != NanoPi_A64
&& boardId != NanoPi_NEO_Core) {
&& boardId != NanoPi_A64) {
// nothing to do.
} else {
printf ("This NanoPi model is currently not supported. ") ;
@ -416,9 +538,15 @@ void NanoPiReadAll()
}
int pinCount;
if (boardId == NanoPi_M1 || boardId == NanoPi_M1_Plus || boardId == NanoPi_M1_Plus2) {
if (boardId == NanoPi_M1 || boardId == NanoPi_K1_Plus || boardId == NanoPi_M1_Plus || boardId == NanoPi_M1_Plus2) {
pinCount = 40;
} else if (boardId == NanoPi_NEO || boardId == NanoPi_NEO_Air || boardId == NanoPi_NEO2 || boardId == NanoPi_NEO_Plus2) {
} else if (boardId == NanoPi_NEO
|| boardId == NanoPi_NEO_Air
|| boardId == NanoPi_NEO2
|| boardId == NanoPi_NEO_Plus2
|| boardId == NanoPi_NEO_Core
|| boardId == NanoPi_NEO_Core2
) {
pinCount = 24;
} else if (boardId == NanoPi_Duo) {
pinCount = 32;
@ -426,7 +554,7 @@ void NanoPiReadAll()
return ;
}
/* Print 1 ~ 24/40 pins */
printf (" +-----+-----+----------+------+---+-%s--+------+----------+-----+-----+\n", retBoardInfo->boardDisplayName) ;
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf (" +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+\n") ;
@ -437,8 +565,45 @@ void NanoPiReadAll()
printf (" +-----+-----+----------+------+---+-%s--+------+----------+-----+-----+\n", retBoardInfo->boardDisplayName) ;
printf ("\n");
/* Print Second 1 ~ 12/24 pins */
if (boardId == NanoPi_M1 || boardId == NanoPi_K1_Plus || boardId == NanoPi_M1_Plus || boardId == NanoPi_M1_Plus2) {
// nothing to do.
} else if (boardId == NanoPi_NEO || boardId == NanoPi_NEO_Air || boardId == NanoPi_NEO2 || boardId == NanoPi_NEO_Plus2) {
printf (" +-----+----%s USB/Audio-+----+\n", retBoardInfo->boardDisplayName) ;
printf (" | BCM | wPi | Name | Mode | V | Ph |\n") ;
printf (" +-----+-----+----------+------+---+----+\n") ;
for (pin = 25 ; pin <= 36 ; pin++) {
readallPhys (boardId, pin, 0) ;
}
printf (" +-----+-----+----------+------+---+----+\n") ;
printf ("\n");
} else if (boardId == NanoPi_Duo || boardId == NanoPi_NEO_Core || boardId == NanoPi_NEO_Core2) {
// nothing to do.
}
if (boardId == NanoPi_M1 || boardId == NanoPi_M1_Plus || boardId == NanoPi_M1_Plus2) {
if (boardId == NanoPi_NEO_Core || boardId == NanoPi_NEO_Core2) {
printf (" +-----+-----+----------+---- %s USB/Audio ----+----------+-----+-----+\n", retBoardInfo->boardDisplayName) ;
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf (" +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+\n") ;
for (pin = 25 ; pin <= 48 ; pin += 2)
readallPhys (boardId, pin, 1) ;
printf (" +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+\n") ;
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf (" +-----+-----+----------+------+---+-%s--+------+----------+-----+-----+\n", retBoardInfo->boardDisplayName) ;
printf ("\n");
printf (" +-----+-----+----------+---- %s Network ----+----------+-----+-----+\n", retBoardInfo->boardDisplayName) ;
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf (" +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+\n") ;
for (pin = 49 ; pin <= 68 ; pin += 2)
readallPhys (boardId, pin, 1) ;
printf (" +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+\n") ;
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf (" +-----+-----+----------+------+---+-%s--+------+----------+-----+-----+\n", retBoardInfo->boardDisplayName) ;
printf ("\n");
}
if (boardId == NanoPi_M1 || boardId == NanoPi_K1_Plus || boardId == NanoPi_M1_Plus || boardId == NanoPi_M1_Plus2) {
printf (" +-----+----%s Debug UART-+----+\n", retBoardInfo->boardDisplayName) ;
printf (" | BCM | wPi | Name | Mode | V | Ph |\n") ;
printf (" +-----+-----+----------+------+---+----+\n") ;
@ -446,6 +611,7 @@ void NanoPiReadAll()
readallPhys (boardId, pin, 0) ;
}
printf (" +-----+-----+----------+------+---+----+\n") ;
printf ("\n");
} else if (boardId == NanoPi_NEO || boardId == NanoPi_NEO_Air || boardId == NanoPi_NEO2 || boardId == NanoPi_NEO_Plus2) {
printf (" +-----+----%s Debug UART-+----+\n", retBoardInfo->boardDisplayName) ;
printf (" | BCM | wPi | Name | Mode | V | Ph |\n") ;
@ -454,11 +620,11 @@ void NanoPiReadAll()
readallPhys (boardId, pin, 0) ;
}
printf (" +-----+-----+----------+------+---+----+\n") ;
} else if (boardId == NanoPi_Duo) {
printf ("\n");
} else if (boardId == NanoPi_Duo || boardId == NanoPi_NEO_Core || boardId == NanoPi_NEO_Core2) {
// nothing to do.
}
}
//guenter ende
void doReadall (void)
{

View File

@ -26,8 +26,8 @@ BoardHardwareInfo gAllBoardHardwareInfo[] = {
//s5p6818
{"nanopi3", 1, NanoPC_T3, "NanoPC-T3",""},
{"nanopi3", 2, NanoPi_S3, "NanoPi-S3",""},
{"nanopi3", 3, Smart6818, "Smart6818",""},
{"nanopi3", 4, NanoPC_T3T, "NanoPC-T3T",""},
{"nanopi3", 5, NanoPi_Fire3, "NanoPi-Fire3",""},
{"nanopi3", 7, NanoPi_M3, "NanoPi-M3",""},
//allwinner h3
@ -38,6 +38,7 @@ BoardHardwareInfo gAllBoardHardwareInfo[] = {
{"sun8i", 0, NanoPi_M1_Plus, "NanoPi-M1-Plus", "3(0)"},
{"sun8i", 0, NanoPi_Duo, "NanoPi-Duo", "4(0)"},
{"sun8i", 0, NanoPi_NEO_Core, "NanoPi-NEO-Core", "5(0)"},
{"sun8i", 0, NanoPi_K1, "NanoPi-K1", "6(0)"},
// kernel 4.x
{"Allwinnersun8iFamily", 0, NanoPi_M1, "NanoPi-M1", "0(0)"},
{"Allwinnersun8iFamily", 0, NanoPi_NEO, "NanoPi-NEO", "1(0)"},
@ -45,6 +46,7 @@ BoardHardwareInfo gAllBoardHardwareInfo[] = {
{"Allwinnersun8iFamily", 0, NanoPi_M1_Plus, "NanoPi-M1-Plus", "3(0)"},
{"Allwinnersun8iFamily", 0, NanoPi_Duo, "NanoPi-Duo", "4(0)"},
{"Allwinnersun8iFamily", 0, NanoPi_NEO_Core, "NanoPi-NEO-Core", "5(0)"},
{"Allwinnersun8iFamily", 0, NanoPi_K1, "NanoPi-K1", "6(0)"},
// a64
@ -55,10 +57,15 @@ BoardHardwareInfo gAllBoardHardwareInfo[] = {
{"sun50iw2", 4, NanoPi_NEO2, "NanoPi-NEO2", "1(0)"},
{"sun50iw2", 4, NanoPi_M1_Plus2, "NanoPi-M1-Plus2", "3(0)"},
{"sun50iw2", 4, NanoPi_NEO_Plus2, "NanoPi-NEO-Plus2", "2(0)"},
{"sun50iw2", 4, NanoPi_NEO_Core2, "NanoPi-NEO-Core2", "0(0)"},
{"sun50iw2", 4, NanoPi_K1_Plus, "NanoPi-K1-Plus", "4(0)"},
// kernel 4.x
{"Allwinnersun50iw2Family", 4, NanoPi_NEO2, "NanoPi-NEO2", "1(0)"},
{"Allwinnersun50iw2Family", 4, NanoPi_M1_Plus2, "NanoPi-M1-Plus2", "3(0)"},
{"Allwinnersun50iw2Family", 4, NanoPi_NEO_Plus2, "NanoPi-NEO-Plus2", "2(0)"},
{"Allwinnersun50iw2Family", 4, NanoPi_NEO_Core2, "NanoPi-NEO-Core2", "0(0)"},
{"Allwinnersun50iw2Family", 4, NanoPi_K1_Plus, "NanoPi-K1-Plus", "4(0)"},
//k2
{"Amlogic", 0, NanoPi_K2, "NanoPi-K2", ""},
@ -67,15 +74,17 @@ BoardHardwareInfo gAllBoardHardwareInfo[] = {
static int getFieldValueInCpuInfo(char* hardware, int hardwareMaxLen, char* revision, int revisionMaxLen )
{
int n,i,j;
char lineUntrim[1024], line[1024],*p,*p2;
char lineUntrim[1024], line[1024],line2[1024],*p,*p2;
FILE *f;
int isGotHardware = 0;
int isGotRevision = 0;
if (!(f = fopen("/sys/devices/platform/board/info", "r"))) {
if (!(f = fopen("/proc/cpuinfo", "r"))) {
LOGE("open /proc/cpuinfo failed.");
return -1;
}
}
while (!feof(f)) {
if(!fgets(lineUntrim, sizeof(lineUntrim), f)) {
@ -92,32 +101,22 @@ static int getFieldValueInCpuInfo(char* hardware, int hardwareMaxLen, char* revi
n = strlen(line);
if (n>0) {
//LOGD("LINE: %s\n", line);
if (isGotHardware == 0) {
if (p = strtok(line, ":")) {
if (strncasecmp(p, "Hardware", strlen("Hardware")) == 0) {
if (p = strtok(0, ":")) {
memset(hardware,0,hardwareMaxLen);
strncpy(hardware, p, hardwareMaxLen-1);
isGotHardware = 1;
}
continue;
}
}
}
if (isGotRevision == 0) {
if (p2 = strtok(line, ":")) {
if (strncasecmp(p2, "Revision", strlen("Revision")) == 0) {
if (p2 = strtok(0, ":")) {
memset(revision,0,revisionMaxLen);
strncpy(revision, p2, revisionMaxLen-1);
isGotRevision = 1;
}
continue;
}
}
#define GetKeyValue(isGot,valP,keyName,buff,buffLen) \
if (isGot==0) { \
strcpy(line2, line); \
if (valP=strtok(line2, ":")) { \
if (strncasecmp(valP,keyName,strlen(keyName))==0) { \
if (valP=strtok(0, ":")) { \
memset(buff,0,buffLen); \
strncpy(buff,valP,buffLen-1); \
isGot=1; \
} \
continue; \
} \
} \
}
GetKeyValue(isGotHardware,p,"Hardware",hardware,hardwareMaxLen);
GetKeyValue(isGotRevision,p2,"Revision",revision,revisionMaxLen);
if (isGotHardware == 1 && isGotRevision == 1) {
break;
@ -139,7 +138,7 @@ static int getAllwinnerBoardID(char* boardId, int boardIdMaxLen )
int ret = -1;
if (!(f = fopen("/sys/class/sunxi_info/sys_info", "r"))) {
LOGE("open /proc/cpuinfo failed.");
LOGE("open /sys/class/sunxi_info/sys_info failed.");
return -1;
}

View File

@ -39,9 +39,8 @@ typedef struct {
//s5p6818
#define S5P6818_BASE (6818)
#define NanoPC_T3 (S5P6818_BASE+1)
#define NanoPi_S3 (S5P6818_BASE+2)
#define Smart6818 (S5P6818_BASE+3)
#define NanoPC_T3T (S5P6818_BASE+4)
#define NanoPi_Fire3 (S5P6818_BASE+5)
#define NanoPi_M3 (S5P6818_BASE+7)
#define S5P6818_MAX NanoPi_M3
@ -62,7 +61,10 @@ typedef struct {
#define NanoPi_NEO_Plus2 (ALLWINNER_BASE+8)
#define NanoPi_NEO_Core (ALLWINNER_BASE+9)
#define NanoPi_Duo (ALLWINNER_BASE+10)
#define ALLWINNER_MAX NanoPi_Duo
#define NanoPi_NEO_Core2 (ALLWINNER_BASE+11)
#define NanoPi_K1 (ALLWINNER_BASE+12)
#define NanoPi_K1_Plus (ALLWINNER_BASE+13)
#define ALLWINNER_MAX NanoPi_K1_Plus
//amlogic
#define AMLOGIC_BASE (8000)

View File

@ -86,11 +86,6 @@
#define ENV_CODES "WIRINGPI_CODES"
// Mask for the bottom 64 pins which belong to the Banana Pro
// The others are available for the other devices
#define PI_GPIO_MASK (0xFFFFFFC0)
struct wiringPiNodeStruct *wiringPiNodes = NULL;
// BCM Magic
@ -267,11 +262,16 @@ int wiringPiReturnCodes = FALSE;
// sysFds:
// Map a file descriptor from the /sys/class/gpio/gpioX/value
static int sysFds [64] ={
#define MAX_PIN_COUNT 74
static int sysFds [MAX_PIN_COUNT] ={
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
// ISR Data
@ -284,6 +284,7 @@ static int upDnConvert[3] = {7, 7, 5};
static int *pinToGpio = 0;
static int *physToGpio = 0;
static int *physToPin = 0;
static int *syspin = 0;
// Doing it the Arduino way with lookup tables...
@ -305,7 +306,8 @@ static int *physToPin = 0;
// 192 - 223 = PG00-PG31
// nanopi m1 done
static int pinToGpio_m1 [64] ={
// wPi number to /sys/gpio number
static int pinToGpio_m1 [MAX_PIN_COUNT] ={
0, 6, // 0, 1
2, 3, // 2, 3
200, 201, // 4 5
@ -326,10 +328,13 @@ static int pinToGpio_m1 [64] ={
4, 5, // 32, 33 Debug UART pins
-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
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
static int pinToGpio_neo [64] ={
// wPi number to /sys/gpio number
static int pinToGpio_neo [MAX_PIN_COUNT] ={
0, //0
/* 24 Pin */
6, 2, //1, 2
@ -341,7 +346,7 @@ static int pinToGpio_neo [64] ={
65, 66, //13, 14
198, 199, //15, 16
4, 5, //17, 18
-1, -1, //19, 20
17, -1, //19, 20
-1, 1, //21, 22
-1, -1, //23, 24
@ -359,11 +364,14 @@ static int pinToGpio_neo [64] ={
/* 39~63 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
// wPi number to /sys/gpio number
static int pinToGpio_duo [64] ={
static int pinToGpio_duo [MAX_PIN_COUNT] ={
16, //0
/* 32 Pin */
-1, 14, //1, 2
@ -393,8 +401,46 @@ static int pinToGpio_duo [64] ={
/* 39~63 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
// guenter neu ende
// wPi number to /sys/gpio number
static int pinToGpio_neocore [MAX_PIN_COUNT] ={
0, //0
6, 2, //1, 2
3, 200, //3, 4
201, 1, //5, 6
203, 12, //7, 8
11, 67, //9, 10
-1, 64, //11, 12
65, 66, //13, 14
198, 199, //15, 16
4, 5, //17, 18
17, 13, //19, 20
14, 15, //21, 22
16, 7, //23, 24
-1, -1, //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
/* 39~63 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
/*
@ -426,7 +472,7 @@ static int pinTobcm [64] ={
// Also add in the P5 connector, so the P5 pins are 3,4,5,6, so 53,54,55,56
static int physToGpio_neo [64] ={
static int physToGpio_neo [MAX_PIN_COUNT] ={
-1,
/* 24 Pin */
-1, -1, //1, 2
@ -446,7 +492,7 @@ static int physToGpio_neo [64] ={
-1, -1, //25, 26
-1, -1, //27, 28
-1, -1, //29, 30
-1, -1, //31, 32
17, -1, //31, 32
-1, -1, //33, 34
-1, -1, //35, 36
@ -456,10 +502,62 @@ static int physToGpio_neo [64] ={
/* 39~63 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
static int physToGpio_m1 [64] ={
static int physToGpio_neocore [MAX_PIN_COUNT] ={
-1,
/* GPIO-1 24Pin */
-1, -1, //1, 2
12, -1, //3, 4
11, -1, //5, 6
203, 198, //7, 8
-1, 199, //9, 10
0, 6, //11, 12
2, -1, //13, 14
3, 200, //15, 16
-1, 201, //17, 18
64, -1, //19, 20
65, 1, //21, 22
66, 67, //23, 24
/* GPIO-2 24Pin */
-1, 15, //25, 26 -> 1, 2
-1, 16, //27, 28 -> 3, 4
-1, 14, //29, 30 -> 5, 6
-1, 13, //31, 32 -> 7, 8
-1, -1, //33, 34 -> 9, 10
-1, -1, //35, 36 -> 11, 12
17, -1, //37, 38 -> 13, 14
-1, -1, //39, 40 -> 15, 16
-1, 5, //41, 42 -> 17, 18
-1, 4, //43, 44 -> 19, 20
-1, -1, //45, 46 -> 21, 22
-1, -1, //47, 48 -> 23, 24
/* GPIO-3 24Pin */
-1, -1, //49, 50 -> 1, 2
-1, -1, //51, 52 -> 3, 4
-1, -1, //53, 54 -> 5, 6
-1, -1, //55, 56 -> 7, 8
-1, -1, //57, 58 -> 9, 10
-1, -1, //59, 60 -> 11, 12
-1, 7, //61, 62 -> 13, 14
-1, -1, //63, 64 -> 15, 16
-1, -1, //65, 66 -> 17, 18
-1, -1, //67, 68 -> 19, 20
-1, -1, //69, 70 -> 21, 22
-1, -1, //71, 72 -> 23, 24
-1, //73
};
static int physToGpio_m1 [MAX_PIN_COUNT] ={
-1, // 0
-1, -1, // 1, 2
12, -1, // 3, 4
@ -483,11 +581,14 @@ static int physToGpio_m1 [64] ={
-1, 14, //39, 40
-1, -1, 4, 5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, //41-> 55
-1, -1, -1, -1, -1, -1, -1, -1 // 56-> 63
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
// phys pin number to /sys/gpio number
static int physToGpio_duo [64] ={
static int physToGpio_duo [MAX_PIN_COUNT] ={
-1, //0
/* 32 Pin */
-1, -1, //1, 2
@ -517,28 +618,75 @@ static int physToGpio_duo [64] ={
/* 39~63 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
//
static int syspin [64] ={
-1, -1, 2, 3, 4, 5, 6, 7, //GPIO0,1 used to I2C
static int syspin_neo [MAX_PIN_COUNT] ={
-1, -1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
/*static int edge [64] ={
static int syspin_neocore [MAX_PIN_COUNT] ={
-1, -1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
static int syspin_m1 [MAX_PIN_COUNT] ={
-1, -1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
static int syspin_duo [MAX_PIN_COUNT] ={
-1, -1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
/*static int edge [MAX_PIN_COUNT] ={
-1, -1, -1, -1, 4, -1, -1, 7, //support the INT
8, 9, 10, 11, -1, -1, 14, 15,
-1, 17, -1, -1, -1, -1, 22, 23,
24, 25, -1, 27, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
// 64~73
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};*/
static int physToPin_m1 [64] = //return wiringPI pin
static int physToPin_m1 [MAX_PIN_COUNT] = //return wiringPI pin
{
-1, // 0
-1, -1, // 1, 2
@ -566,9 +714,12 @@ static int physToPin_m1 [64] = //return wiringPI pin
-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
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
static int physToPin_neo [64] = //return wiringPI pin
static int physToPin_neo [MAX_PIN_COUNT] = //return wiringPI pin
{
-1, // 0
-1, -1, // 1, 2
@ -587,7 +738,7 @@ static int physToPin_neo [64] = //return wiringPI pin
-1, -1, //25, 26
-1, -1, //27, 28
-1, -1, //29, 30
-1, -1, //31, 32
19, -1, //31, 32
-1, -1, //33, 34
-1, -1, //35, 36
@ -596,9 +747,62 @@ static int physToPin_neo [64] = //return wiringPI pin
/* 39~63 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
static int physToPin_duo [64] = //return wiringPI pin //note: same as physToWpi
static int physToPin_neocore [MAX_PIN_COUNT] = //return wiringPI pin
{
/* GPIO-1 24Pin */
-1, // 0
-1, -1, // 1, 2 -> 1, 2
8, -1, // 3, 4 -> 3, 4
9, -1, // 5, 6 -> 5, 6
7, 15, // 7, 8 -> 7, 8
-1, 16, // 9, 10 -> 9, 10
0, 1, //11, 12 -> 11, 12
2, -1, //13, 14 -> 13, 14
3, 4, //15, 16 -> 15, 16
-1, 5, //17, 18 -> 17, 18
12, -1, //19, 20 -> 19, 20
13, 6, //21, 22 -> 21, 22
14, 10, //23, 24 -> 23, 24
/* GPIO-2 24Pin */
-1, 22, //25, 26 -> 1, 2
-1, 23, //27, 28 -> 3, 4
-1, 21, //29, 30 -> 5, 6
-1, 20, //31, 32 -> 7, 8
-1, -1, //33, 34 -> 9, 10
-1, -1, //35, 36 -> 11, 12
19, -1, //37, 38 -> 13, 14
-1, -1, //39, 40 -> 15, 16
-1, 18, //41, 42 -> 17, 18
-1, 17, //43, 44 -> 19, 20
-1, -1, //45, 46 -> 21, 22
-1, -1, //47, 48 -> 23, 24
/* GPIO-3 24Pin */
-1, -1, //49, 50 -> 1, 2
-1, -1, //51, 52 -> 3, 4
-1, -1, //53, 54 -> 5, 6
-1, -1, //55, 56 -> 7, 8
-1, -1, //57, 58 -> 9, 10
-1, -1, //59, 60 -> 11, 12
-1, 24, //61, 62 -> 13, 14
-1, -1, //63, 64 -> 15, 16
-1, -1, //65, 66 -> 17, 18
-1, -1, //67, 68 -> 19, 20
-1, -1, //69, 70 -> 21, 22
-1, -1, //71, 72 -> 23, 24
-1, //73
};
static int physToPin_duo [MAX_PIN_COUNT] = //return wiringPI pin //note: same as physToWpi
{
-1, // 0
-1, -1, // 1, 2
@ -627,6 +831,9 @@ static int physToPin_duo [64] = //return wiringPI pin //note: same as physToWpi
/* 39~63 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
};
// pins available on pin out by banks
@ -1075,7 +1282,6 @@ int isA20(void) {
return 0;
}
}
/* guenter ende */
int piBoardRev(void) {
BoardHardwareInfo* retBoardInfo;
@ -1083,8 +1289,7 @@ int piBoardRev(void) {
boardId = getBoardType(&retBoardInfo);
if (boardId >= 0) {
if (boardId > ALLWINNER_BASE && boardId <= ALLWINNER_MAX
&& boardId != NanoPi_A64
&& boardId != NanoPi_NEO_Core) {
&& boardId != NanoPi_A64) {
version = BPRVER;
if (wiringPiDebug)
printf("piBoardRev: %d\n", version);
@ -1119,8 +1324,7 @@ void piBoardId(int *model, int *rev, int *mem, int *maker, int *overVolted) {
boardId = getBoardType(&retBoardInfo);
if (boardId >= 0) {
if (boardId > ALLWINNER_BASE && boardId <= ALLWINNER_MAX
&& boardId != NanoPi_A64
&& boardId != NanoPi_NEO_Core) {
&& boardId != NanoPi_A64) {
*model = boardId;
*rev = PI_VERSION_1_2;
*mem = 1024;
@ -1152,7 +1356,11 @@ int wpiPinToGpio(int wpiPin) {
printf("please call wiringPiSetup first.\n");
return -1;
}
return pinToGpio [wpiPin & 63];
if (wpiPin >= MAX_PIN_COUNT || wpiPin < 0) {
printf("Invalid pin index.\n");
return -1;
}
return pinToGpio [wpiPin];
}
/*
@ -1167,7 +1375,11 @@ int physPinToGpio(int physPin) {
printf("please call wiringPiSetup first.\n");
return -1;
}
return physToGpio [physPin & 63];
if (physPin >= MAX_PIN_COUNT || physPin < 0) {
printf("Invalid pin index.\n");
return -1;
}
return physToGpio [physPin];
}
/*
@ -1181,7 +1393,11 @@ int physPinToPin(int physPin) {
printf("please call wiringPiSetup first.\n");
return -1;
}
return physToPin [physPin & 63];
if (physPin >= MAX_PIN_COUNT || physPin < 0) {
printf("Invalid pin index.\n");
return -1;
}
return physToPin [physPin];
}
/*
@ -1204,7 +1420,10 @@ void setPadDrive(int group, int value) {
int getAlt(int pin) {
int alt;
pin &= 63;
if (pin >= MAX_PIN_COUNT || pin < 0) {
printf("Invalid pin index.\n");
return -1;
}
if (pinToGpio == 0 || physToGpio == 0) {
printf("please call wiringPiSetup first.\n");
@ -1216,8 +1435,7 @@ int getAlt(int pin) {
pin = pinToGpio [pin];
else if (wiringPiMode == WPI_MODE_PHYS)
pin = physToGpio[pin];
else if (wiringPiMode == WPI_MODE_GPIO)
//pin = pinTobcm[pin];
else if (wiringPiMode == WPI_MODE_GPIO) //pin = pinTobcm[pin];
pin = pin;
else return 0;
@ -1334,12 +1552,10 @@ struct wiringPiNodeStruct *wiringPiNewNode(int pinBase, int numPins) {
struct wiringPiNodeStruct *node;
// Minimum pin base is 64
if (pinBase < 64)
(void)wiringPiFailure(WPI_FATAL, "wiringPiNewNode: pinBase of %d is < 64\n", pinBase);
// Check all pins in-case there is overlap:
for (pin = pinBase; pin < (pinBase + numPins); ++pin)
if (wiringPiFindNode(pin) != NULL)
(void)wiringPiFailure(WPI_FATAL, "wiringPiNewNode: Pin %d overlaps with existing definition\n", pin);
@ -1398,8 +1614,8 @@ void pinMode(int pin, int mode) {
return -1;
}
if ((pin & PI_GPIO_MASK) == 0) // On-board pin
{
// On-board pin
if (pin > 0 && pin < MAX_PIN_COUNT) {
if (wiringPiMode == WPI_MODE_PINS) {
pin = pinToGpio [pin];
if (wiringPiDebug) {
@ -1410,8 +1626,8 @@ void pinMode(int pin, int mode) {
if (wiringPiDebug) {
printf(">>> physToGpio[pin] ret %d\n", pin);
}
} else if (wiringPiMode == WPI_MODE_GPIO) {
// pin = pinTobcm[pin];
} else if (wiringPiMode == WPI_MODE_GPIO) { // pin = pinTobcm[pin];
pin = pin;
if (wiringPiDebug) {
@ -1424,8 +1640,8 @@ void pinMode(int pin, int mode) {
}
return;
}
if (-1 == pin) /*VCC or GND return directly*/ {
/*VCC or GND return directly*/
if (-1 == pin) {
//printf("[%s:L%d] the pin:%d is invaild,please check it over!\n", __func__, __LINE__, pin);
return;
}
@ -1449,8 +1665,10 @@ void pinMode(int pin, int mode) {
sunxi_set_gpio_mode(pin, PWM_OUTPUT);
wiringPinMode = PWM_OUTPUT;
return;
} else
} else {
return;
}
} else {
if ((node = wiringPiFindNode(pin)) != NULL)
node->pinMode(node, pin, mode);
@ -1478,8 +1696,7 @@ void pullUpDnControl(int pin, int pud) {
pud = upDnConvert[pud];
if ((pin & PI_GPIO_MASK) == 0) // On-Board Pin
{
if (pin > 0 && pin < MAX_PIN_COUNT) {
if (wiringPiMode == WPI_MODE_PINS)
pin = pinToGpio [pin];
else if (wiringPiMode == WPI_MODE_PHYS)
@ -1524,8 +1741,7 @@ int digitalRead(int pin) {
return;
}
if ((pin & PI_GPIO_MASK) == 0) // On-Board Pin
{
if (pin > 0 && pin < MAX_PIN_COUNT) {
if (wiringPiMode == WPI_MODE_GPIO_SYS) // Sys mode
{
if (wiringPiDebug) {
@ -1536,10 +1752,15 @@ int digitalRead(int pin) {
//printf("%d %s,%d invalid pin,please check it over.\n",pin,__func__, __LINE__);
return 0;
}
//TODO: fix me
/*
if (syspin[pin] == -1) {
//printf("%d %s,%d invalid pin,please check it over.\n",pin,__func__, __LINE__);
return 0;
}
*/
if (sysFds [pin] == -1) {
if (wiringPiDebug)
printf("pin %d sysFds -1.%s,%d\n", pin, __func__, __LINE__);
@ -1596,25 +1817,31 @@ void digitalWrite(int pin, int value) {
if (wiringPiDebug)
printf("%s,%d\n", __func__, __LINE__);
if ((pin & PI_GPIO_MASK) == 0) // On-Board Pin
{
if (pin > 0 && pin < MAX_PIN_COUNT) {
/**/ if (wiringPiMode == WPI_MODE_GPIO_SYS) // Sys mode
{
if (wiringPiDebug) {
printf("%d %s,%d invalid pin,please check it over.\n", pin, __func__, __LINE__);
}
if (pin == 0) {
//printf("%d %s,%d invalid pin,please check it over.\n",pin,__func__, __LINE__);
printf("%d %s,%d invalid pin,please check it over.\n",pin,__func__, __LINE__);
return;
}
//TODO: fix me
/*
if (syspin[pin] == -1) {
//printf("%d %s,%d invalid pin,please check it over.\n",pin,__func__, __LINE__);
printf("%d %s,%d invalid pin,please check it over.\n",pin,__func__, __LINE__);
return;
}
*/
if (sysFds [pin] == -1) {
if (wiringPiDebug)
printf("pin %d sysFds -1.%s,%d\n", pin, __func__, __LINE__);
}
if (sysFds [pin] != -1) {
if (wiringPiDebug)
printf("pin %d :%d.%s,%d\n", pin, sysFds [pin], __func__, __LINE__);
@ -1907,8 +2134,8 @@ int wiringPiISR(int pin, int mode, void (*function)(void)) {
return wiringPiFailure(WPI_FATAL, "wiringPiISR: Not implemented");
if ((pin < 0) || (pin > 63))
return wiringPiFailure(WPI_FATAL, "wiringPiISR: pin must be 0-63 (%d)\n", pin);
if ((pin < 0) || (pin >= MAX_PIN_COUNT))
return wiringPiFailure(WPI_FATAL, "wiringPiISR: pin must be 0-%d (%d)\n", MAX_PIN_COUNT-1,pin);
/**/ if (wiringPiMode == WPI_MODE_UNINITIALISED)
return wiringPiFailure(WPI_FATAL, "wiringPiISR: wiringPi has not been initialised. Unable to continue.\n");
@ -2108,18 +2335,26 @@ int wiringPiSetup(void) {
wiringPiMode = WPI_MODE_PINS;
int boardId = model;
if (boardId == NanoPi_M1 || boardId == NanoPi_M1_Plus || boardId == NanoPi_M1_Plus2) {
if (boardId == NanoPi_M1 || boardId == NanoPi_M1_Plus || boardId == NanoPi_M1_Plus2 || boardId == NanoPi_K1_Plus) {
pinToGpio = pinToGpio_m1;
physToGpio = physToGpio_m1;
physToPin = physToPin_m1;
syspin = syspin_m1;
} else if (boardId == NanoPi_NEO || boardId == NanoPi_NEO_Air || boardId == NanoPi_NEO2 || boardId == NanoPi_NEO_Plus2) {
pinToGpio = pinToGpio_neo;
physToGpio = physToGpio_neo;
physToPin = physToPin_neo;
syspin = syspin_neo;
} else if (boardId == NanoPi_Duo) {
pinToGpio = pinToGpio_duo;
physToGpio = physToGpio_duo;
physToPin = physToPin_duo;
syspin = syspin_duo;
} else if (boardId == NanoPi_NEO_Core || boardId == NanoPi_NEO_Core2) {
pinToGpio = pinToGpio_neocore;
physToGpio = physToGpio_neocore;
physToPin = physToPin_neocore;
syspin = syspin_neocore;
} else {
return -1;
}
@ -2191,20 +2426,9 @@ int wiringPiSetupSys(void) {
if (wiringPiDebug)
printf("wiringPi: wiringPiSetupSys called\n");
//boardRev = piBoardRev();
for (pin = 1; pin < 32; ++pin) {
sprintf(fName, "/sys/class/gpio/gpio%d/value", pin);
sysFds [pin] = open(fName, O_RDWR);
}
initialiseEpoch();
wiringPiMode = WPI_MODE_GPIO_SYS;
piBoardId(&model, &rev, &mem, &maker, &overVolted);
int boardId = model;
if (boardId == NanoPi_M1 || boardId == NanoPi_M1_Plus || boardId == NanoPi_M1_Plus2) {
if (boardId == NanoPi_M1 || boardId == NanoPi_M1_Plus || boardId == NanoPi_M1_Plus2 || boardId == NanoPi_K1_Plus) {
pinToGpio = pinToGpio_m1;
physToGpio = physToGpio_m1;
physToPin = physToPin_m1;
@ -2216,7 +2440,20 @@ int wiringPiSetupSys(void) {
pinToGpio = pinToGpio_duo;
physToGpio = physToGpio_duo;
physToPin = physToPin_duo;
} else if (boardId == NanoPi_NEO_Core || boardId == NanoPi_NEO_Core2) {
pinToGpio = pinToGpio_neocore;
physToGpio = physToGpio_neocore;
physToPin = physToPin_neocore;
}
for (pin = 1; pin < MAX_PIN_COUNT; ++pin) {
if (physToGpio[pin] != -1) {
sprintf(fName, "/sys/class/gpio/gpio%d/value", physToGpio[pin]);
sysFds [pin] = open(fName, O_RDWR);
}
}
initialiseEpoch();
wiringPiMode = WPI_MODE_GPIO_SYS;
return 0;
}

View File

@ -1,7 +1,7 @@
/*
* wiringPiSPI.c:
* Simplified SPI access routines
* Copyright (c) 2012 Gordon Henderson
* Copyright (c) 2012-2015 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
@ -28,6 +28,7 @@
#include <errno.h>
#include <string.h>
#include <sys/ioctl.h>
#include <asm/ioctl.h>
#include <linux/spi/spidev.h>
#include "wiringPi.h"
@ -38,11 +39,10 @@
// The SPI bus parameters
// Variables as they need to be passed as pointers later on
const static char *spiDev0 = "/dev/spidev0.0" ;
const static char *spiDev1 = "/dev/spidev0.1" ;
const static uint8_t spiMode = 0 ;
const static uint8_t spiBPW = 8 ;
const static uint16_t spiDelay = 0 ;
static const char *spiDev0 = "/dev/spidev0.0" ;
static const char *spiDev1 = "/dev/spidev0.1" ;
static const uint8_t spiBPW = 8 ;
static const uint16_t spiDelay = 0 ;
static uint32_t spiSpeeds [2] ;
static int spiFds [2] ;
@ -75,6 +75,11 @@ int wiringPiSPIDataRW (int channel, unsigned char *data, int len)
channel &= 1 ;
// Mentioned in spidev.h but not used in the original kernel documentation
// test program )-:
memset (&spi, 0, sizeof (spi)) ;
spi.tx_buf = (unsigned long)data ;
spi.rx_buf = (unsigned long)data ;
spi.len = len ;
@ -87,16 +92,17 @@ int wiringPiSPIDataRW (int channel, unsigned char *data, int len)
/*
* wiringPiSPISetup:
* Open the SPI device, and set it up, etc.
* wiringPiSPISetupMode:
* Open the SPI device, and set it up, with the mode, etc.
*********************************************************************************
*/
int wiringPiSPISetup (int channel, int speed)
int wiringPiSPISetupMode (int channel, int speed, int mode)
{
int fd ;
channel &= 1 ;
mode &= 3 ; // Mode is 0, 1, 2 or 3
channel &= 1 ; // Channel is 0 or 1
if ((fd = open (channel == 0 ? spiDev0 : spiDev1, O_RDWR)) < 0)
return wiringPiFailure (WPI_ALMOST, "Unable to open SPI device: %s\n", strerror (errno)) ;
@ -105,10 +111,8 @@ int wiringPiSPISetup (int channel, int speed)
spiFds [channel] = fd ;
// Set SPI parameters.
// Why are we reading it afterwriting it? I've no idea, but for now I'm blindly
// copying example code I've seen online...
if (ioctl (fd, SPI_IOC_WR_MODE, &spiMode) < 0)
if (ioctl (fd, SPI_IOC_WR_MODE, &mode) < 0)
return wiringPiFailure (WPI_ALMOST, "SPI Mode Change failure: %s\n", strerror (errno)) ;
if (ioctl (fd, SPI_IOC_WR_BITS_PER_WORD, &spiBPW) < 0)
@ -119,3 +123,15 @@ int wiringPiSPISetup (int channel, int speed)
return fd ;
}
/*
* wiringPiSPISetup:
* Open the SPI device, and set it up, etc. in the default MODE 0
*********************************************************************************
*/
int wiringPiSPISetup (int channel, int speed)
{
return wiringPiSPISetupMode (channel, speed, 0) ;
}

View File

@ -28,6 +28,7 @@ extern "C" {
int wiringPiSPIGetFd (int channel) ;
int wiringPiSPIDataRW (int channel, unsigned char *data, int len) ;
int wiringPiSPISetupMode (int channel, int speed, int mode) ;
int wiringPiSPISetup (int channel, int speed) ;
#ifdef __cplusplus