add support for NanoPi
This commit is contained in:
parent
03a8ddeadd
commit
30edaf15cd
20
README.md
20
README.md
|
@ -2,13 +2,17 @@
|
||||||
This is a GPIO access library for NanoPi. It is based on the WiringOP for Orange PI which is based on original WiringPi for Raspberry Pi.
|
This is a GPIO access library for NanoPi. It is based on the WiringOP for Orange PI which is based on original WiringPi for Raspberry Pi.
|
||||||
|
|
||||||
Currently supported boards:
|
Currently supported boards:
|
||||||
NanoPI Neo
|
NanoPi Neo
|
||||||
|
NanoPi Neo Air
|
||||||
|
NanoPi Duo
|
||||||
NanoPi NEO2
|
NanoPi NEO2
|
||||||
NanoPI M1
|
NanoPi NEO Plus2
|
||||||
|
NanoPi M1
|
||||||
|
NanoPi M1 Plus
|
||||||
|
|
||||||
# Installation
|
# Installation
|
||||||
|
|
||||||
## Install WiringNP on NEO/NEO2
|
## Install WiringNP
|
||||||
Log into your nano board via SSH, open a terminal and install the WiringNP library by running the following commands:
|
Log into your nano board via SSH, open a terminal and install the WiringNP library by running the following commands:
|
||||||
```
|
```
|
||||||
git clone https://github.com/friendlyarm/WiringNP
|
git clone https://github.com/friendlyarm/WiringNP
|
||||||
|
@ -17,16 +21,6 @@ chmod 755 build
|
||||||
./build
|
./build
|
||||||
```
|
```
|
||||||
|
|
||||||
## Install WiringNP on NanoPi M1
|
|
||||||
Log into your nano board via SSH, open a terminal and install the WiringNP library by running the following commands:
|
|
||||||
```
|
|
||||||
git clone https://github.com/friendlyarm/WiringNP
|
|
||||||
cd WiringNP/
|
|
||||||
git checkout nanopi-m1
|
|
||||||
chmod 755 build
|
|
||||||
./build
|
|
||||||
```
|
|
||||||
|
|
||||||
# Verify WiringNP
|
# Verify WiringNP
|
||||||
The WiringNP library contains a set of gpio commands. Users can use them to access the GPIO pins on a nano board. You can verify your WiringNP by running the following command:
|
The WiringNP library contains a set of gpio commands. Users can use them to access the GPIO pins on a nano board. You can verify your WiringNP by running the following command:
|
||||||
```
|
```
|
||||||
|
|
32
gpio/gpio.c
32
gpio/gpio.c
|
@ -1084,7 +1084,6 @@ static void doPwmClock (int argc, char *argv [])
|
||||||
int main (int argc, char *argv [])
|
int main (int argc, char *argv [])
|
||||||
{
|
{
|
||||||
int i ;
|
int i ;
|
||||||
int model, rev, mem, maker, overVolted ;
|
|
||||||
|
|
||||||
if (getenv ("WIRINGPI_DEBUG") != NULL)
|
if (getenv ("WIRINGPI_DEBUG") != NULL)
|
||||||
{
|
{
|
||||||
|
@ -1129,19 +1128,28 @@ int main (int argc, char *argv [])
|
||||||
printf ("This is free software with ABSOLUTELY NO WARRANTY.\n") ;
|
printf ("This is free software with ABSOLUTELY NO WARRANTY.\n") ;
|
||||||
printf ("For details type: %s -warranty\n", argv [0]) ;
|
printf ("For details type: %s -warranty\n", argv [0]) ;
|
||||||
printf ("\n") ;
|
printf ("\n") ;
|
||||||
piBoardId (&model, &rev, &mem, &maker, &overVolted) ;
|
|
||||||
if (model == PI_MODEL_UNKNOWN)
|
BoardHardwareInfo* retBoardInfo;
|
||||||
{
|
int boardId;
|
||||||
printf ("Your Raspberry Pi has an unknown model type. Please report this to\n") ;
|
boardId = getBoardType(&retBoardInfo);
|
||||||
printf (" projects@drogon.net\n") ;
|
if (boardId >= 0) {
|
||||||
|
|
||||||
|
if (boardId > ALLWINNER_BASE && boardId <= ALLWINNER_MAX
|
||||||
|
&& boardId != NanoPi_A64
|
||||||
|
&& boardId != NanoPi_NEO_Core) {
|
||||||
|
printf ("NanoPi Details:\n") ;
|
||||||
|
printf (" Type: %s, Revision: %d, Maker: FriednlyELEC\n\n",
|
||||||
|
retBoardInfo->boardDisplayName, retBoardInfo->kernelRevision) ;
|
||||||
|
} else {
|
||||||
|
printf ("This NanoPi model is currently not supported. ") ;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
printf ("Your NanoPi has an unknown model type. Please report this to\n") ;
|
||||||
|
printf (" support@friendlyarm.com\n") ;
|
||||||
printf ("with a copy of your /proc/cpuinfo if possible\n") ;
|
printf ("with a copy of your /proc/cpuinfo if possible\n") ;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
printf ("Banana Pro Details:\n") ;
|
|
||||||
printf (" Type: %s, Revision: %s, Memory: %dMB, Maker: %s %s\n",
|
|
||||||
piModelNames [model], piRevisionNames [rev], mem, piMakerNames [maker], overVolted ? "[OV]" : "") ;
|
|
||||||
}
|
|
||||||
return 0 ;
|
return 0 ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
240
gpio/readall.c
240
gpio/readall.c
|
@ -80,8 +80,73 @@ static char *alts [] =
|
||||||
"IN", "OUT", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "OFF"
|
"IN", "OUT", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "OFF"
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
// guenter anfang
|
|
||||||
static int physToWpi [64] =
|
static int physToWpi_m1 [64] =
|
||||||
|
{
|
||||||
|
-1, // 0
|
||||||
|
-1, -1, // 1, 2
|
||||||
|
8, -1, // 3, 4
|
||||||
|
9, -1, // 5, 6
|
||||||
|
7, 15, // 7, 8
|
||||||
|
-1, 16, // 9, 10
|
||||||
|
0, 1, //11, 12
|
||||||
|
2, -1, //13, 14
|
||||||
|
3, 4, //15, 16
|
||||||
|
-1, 5, //17, 18
|
||||||
|
12, -1, //19, 20
|
||||||
|
13, 6, //21, 22
|
||||||
|
14, 10, //23, 24
|
||||||
|
-1, 11, //25, 26
|
||||||
|
30, 31, //27, 28
|
||||||
|
21, -1, //29, 30
|
||||||
|
22, 26, //31, 32
|
||||||
|
23, -1, //33, 34
|
||||||
|
24, 27, //35, 36
|
||||||
|
25, 28, //37, 38
|
||||||
|
-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
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
static char *physNames_m1 [64] =
|
||||||
|
{
|
||||||
|
NULL,
|
||||||
|
|
||||||
|
" 3.3v", "5v ",
|
||||||
|
" SDA.0", "5V ",
|
||||||
|
" SCL.0", "0v ",
|
||||||
|
" GPIO.7", "TxD3 ",
|
||||||
|
" 0v", "RxD3 ",
|
||||||
|
" RxD2", "GPIO.1 ",
|
||||||
|
" TxD2", "0v ",
|
||||||
|
" CTS2", "GPIO.4 ",
|
||||||
|
" 3.3v", "GPIO.5 ",
|
||||||
|
" MOSI", "0v ",
|
||||||
|
" MISO", "RTS2 ",
|
||||||
|
" SCLK", "CE0 ",
|
||||||
|
" 0v", "GPIO.11 ",
|
||||||
|
" SDA.1", "SCL.1 ",
|
||||||
|
" GPIO.21", "0v ",
|
||||||
|
" GPIO.22", "RTS1 ",
|
||||||
|
" GPIO.23", "0v ",
|
||||||
|
" GPIO.24", "CTS1 ",
|
||||||
|
" GPIO.25", "TxD1 ",
|
||||||
|
" 0v", "RxD1 ",
|
||||||
|
|
||||||
|
" 0v", " 5v",
|
||||||
|
" GPIO.4", " GPIO.5",
|
||||||
|
|
||||||
|
NULL, NULL,
|
||||||
|
NULL, NULL,
|
||||||
|
NULL, NULL,
|
||||||
|
"GPIO.17", "GPIO.18",
|
||||||
|
"GPIO.19", "GPIO.20",
|
||||||
|
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
|
static int physToWpi_neo [64] =
|
||||||
{
|
{
|
||||||
-1, // 0
|
-1, // 0
|
||||||
-1, -1, // 1, 2
|
-1, -1, // 1, 2
|
||||||
|
@ -113,7 +178,7 @@ static int physToWpi [64] =
|
||||||
//guenter ende
|
//guenter ende
|
||||||
|
|
||||||
//guenter orange pi
|
//guenter orange pi
|
||||||
static char *physNames [64] =
|
static char *physNames_neo [64] =
|
||||||
{
|
{
|
||||||
NULL,
|
NULL,
|
||||||
/* 24 Pin */
|
/* 24 Pin */
|
||||||
|
@ -155,7 +220,80 @@ static char *physNames [64] =
|
||||||
NULL, NULL,
|
NULL, NULL,
|
||||||
NULL
|
NULL
|
||||||
} ;
|
} ;
|
||||||
// guenter ende
|
|
||||||
|
static int physToWpi_duo [64] =
|
||||||
|
{
|
||||||
|
-1, // 0
|
||||||
|
-1, -1, // 1, 2
|
||||||
|
-1, -1, // 3, 4
|
||||||
|
-1, -1, // 5, 6
|
||||||
|
-1, -1, // 7, 8
|
||||||
|
-1, -1, // 9, 10
|
||||||
|
8, -1, //11, 12
|
||||||
|
9, -1, //13, 14
|
||||||
|
7, -1, //15, 16
|
||||||
|
0, -1, //17, 18
|
||||||
|
2, -1, //19, 20
|
||||||
|
3, 16, //21, 22
|
||||||
|
12, -1, //23, 24
|
||||||
|
|
||||||
|
13, -1, //25, 26
|
||||||
|
-1, -1, //27, 28
|
||||||
|
14, -1, //29, 30
|
||||||
|
15, -1, //31, 32
|
||||||
|
/* ---------nanopi duo end----------- */
|
||||||
|
-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,
|
||||||
|
} ;
|
||||||
|
|
||||||
|
static char *physNames_duo [64] =
|
||||||
|
{
|
||||||
|
NULL,
|
||||||
|
/* 32 Pin */
|
||||||
|
" MIC_N", "EPhySPD ",
|
||||||
|
" MIC_P", "EPhyLinK",
|
||||||
|
"LineOutR", "EPhyTXP ",
|
||||||
|
"LineOutL", "EPhyTXN ",
|
||||||
|
" CVBS", "EPhyRXP ",
|
||||||
|
" GPIOG6", "EPhyRXN ",
|
||||||
|
" GPIOG7", "USB-DP2 ", //13, 14
|
||||||
|
" GPIOA15", "USB-DM2 ",
|
||||||
|
" GPIOA16", "USB-DP3 ",
|
||||||
|
" GPIOA14", "USB-DM3 ",
|
||||||
|
" GPIOA13", "GPIOG11 ",
|
||||||
|
" GPIOA12", "IR-RX ",
|
||||||
|
" GPIOA11", "0v ", //25, 26
|
||||||
|
" 0v", "3.3v ",
|
||||||
|
" GPIOA4", "5v ",
|
||||||
|
" GPIOA5", "5v ",
|
||||||
|
/* ---------nanopi duo end----------- */
|
||||||
|
|
||||||
|
NULL, NULL,
|
||||||
|
NULL, NULL,
|
||||||
|
|
||||||
|
/* UART0, tx, rx */
|
||||||
|
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
|
||||||
|
} ;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -165,9 +303,24 @@ static char *physNames [64] =
|
||||||
*********************************************************************************
|
*********************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void readallPhys (int physPin, int pair)
|
static void readallPhys (int boardId, int physPin, int pair)
|
||||||
{
|
{
|
||||||
int pin ;
|
int pin ;
|
||||||
|
int *physToWpi;
|
||||||
|
char **physNames;
|
||||||
|
|
||||||
|
if (boardId == NanoPi_M1 || 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) {
|
||||||
|
physToWpi = physToWpi_neo;
|
||||||
|
physNames = physNames_neo;
|
||||||
|
} else if (boardId == NanoPi_Duo) {
|
||||||
|
physToWpi = physToWpi_duo;
|
||||||
|
physNames = physNames_duo;
|
||||||
|
} else {
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
if (physPinToGpio (physPin) == -1)
|
if (physPinToGpio (physPin) == -1)
|
||||||
printf (" | | ") ;
|
printf (" | | ") ;
|
||||||
|
@ -240,45 +393,80 @@ static void readallPhys (int physPin, int pair)
|
||||||
|
|
||||||
|
|
||||||
//guenter
|
//guenter
|
||||||
void NanoPiReadAll(void)
|
void NanoPiReadAll()
|
||||||
{
|
{
|
||||||
int pin ;
|
int pin ;
|
||||||
|
BoardHardwareInfo* retBoardInfo;
|
||||||
|
int boardId;
|
||||||
|
boardId = getBoardType(&retBoardInfo);
|
||||||
|
if (boardId >= 0) {
|
||||||
|
if (boardId > ALLWINNER_BASE && boardId <= ALLWINNER_MAX
|
||||||
|
&& boardId != NanoPi_A64
|
||||||
|
&& boardId != NanoPi_NEO_Core) {
|
||||||
|
// nothing to do.
|
||||||
|
} else {
|
||||||
|
printf ("This NanoPi model is currently not supported. ") ;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
printf ("Your NanoPi has an unknown model type. Please report this to\n") ;
|
||||||
|
printf (" support@friendlyarm.com\n") ;
|
||||||
|
printf ("with a copy of your /proc/cpuinfo if possible\n") ;
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
printf (" +-----+-----+----------+------+---+-NanoPi NEO/NEO2--+------+----------+-----+-----+\n") ;
|
int pinCount;
|
||||||
|
if (boardId == NanoPi_M1 || 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) {
|
||||||
|
pinCount = 24;
|
||||||
|
} else if (boardId == NanoPi_Duo) {
|
||||||
|
pinCount = 32;
|
||||||
|
} else {
|
||||||
|
return ;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
printf (" +-----+-----+----------+------+---+-%s--+------+----------+-----+-----+\n", retBoardInfo->boardDisplayName) ;
|
||||||
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
|
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
|
||||||
printf (" +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+\n") ;
|
printf (" +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+\n") ;
|
||||||
for (pin = 1 ; pin <= 24 ; pin += 2)
|
for (pin = 1 ; pin <= pinCount ; pin += 2)
|
||||||
readallPhys (pin, 1) ;
|
readallPhys (boardId, pin, 1) ;
|
||||||
printf (" +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+\n") ;
|
printf (" +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+\n") ;
|
||||||
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
|
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
|
||||||
printf (" +-----+-----+----------+------+---+-NanoPi NEO/NEO2--+------+----------+-----+-----+\n") ;
|
printf (" +-----+-----+----------+------+---+-%s--+------+----------+-----+-----+\n", retBoardInfo->boardDisplayName) ;
|
||||||
printf ("\n");
|
printf ("\n");
|
||||||
|
|
||||||
printf (" +-----+----NanoPi NEO/NEO2 Debug UART-+----+\n") ;
|
|
||||||
printf (" | BCM | wPi | Name | Mode | V | Ph |\n") ;
|
if (boardId == NanoPi_M1 || boardId == NanoPi_M1_Plus || boardId == NanoPi_M1_Plus2) {
|
||||||
printf (" +-----+-----+----------+------+---+----+\n") ;
|
printf (" +-----+----%s Debug UART-+----+\n", retBoardInfo->boardDisplayName) ;
|
||||||
for (pin = 37 ; pin <= 38 ; pin++) {
|
printf (" | BCM | wPi | Name | Mode | V | Ph |\n") ;
|
||||||
readallPhys (pin, 0) ;
|
printf (" +-----+-----+----------+------+---+----+\n") ;
|
||||||
|
for (pin = 41 ; pin < 45 ; pin++) {
|
||||||
|
readallPhys (boardId, pin, 0) ;
|
||||||
|
}
|
||||||
|
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") ;
|
||||||
|
printf (" +-----+-----+----------+------+---+----+\n") ;
|
||||||
|
for (pin = 37 ; pin <= 38 ; pin++) {
|
||||||
|
readallPhys (boardId, pin, 0) ;
|
||||||
|
}
|
||||||
|
printf (" +-----+-----+----------+------+---+----+\n") ;
|
||||||
|
} else if (boardId == NanoPi_Duo) {
|
||||||
|
// nothing to do.
|
||||||
}
|
}
|
||||||
printf (" +-----+-----+----------+------+---+----+\n") ;
|
|
||||||
}
|
}
|
||||||
//guenter ende
|
//guenter ende
|
||||||
|
|
||||||
void doReadall (void)
|
void doReadall (void)
|
||||||
{
|
{
|
||||||
int model, rev, mem, maker, overVolted ;
|
if (wiringPiNodes != NULL) // External readall
|
||||||
|
|
||||||
if (wiringPiNodes != NULL) // External readall
|
|
||||||
{
|
{
|
||||||
doReadallExternal () ;
|
doReadallExternal () ;
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
piBoardId (&model, &rev, &mem, &maker, &overVolted) ;
|
NanoPiReadAll();
|
||||||
|
|
||||||
if (model == PI_MODEL_M1) {
|
|
||||||
NanoPiReadAll();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
printf ("Oops - unable to determine board type... model: %d\n", model) ;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ SRC = wiringPi.c \
|
||||||
wiringSerial.c wiringShift.c \
|
wiringSerial.c wiringShift.c \
|
||||||
piHiPri.c piThread.c \
|
piHiPri.c piThread.c \
|
||||||
wiringPiSPI.c wiringPiI2C.c \
|
wiringPiSPI.c wiringPiI2C.c \
|
||||||
softPwm.c softTone.c softServo.c \
|
softPwm.c softTone.c softServo.c \
|
||||||
mcp23008.c mcp23016.c mcp23017.c \
|
mcp23008.c mcp23016.c mcp23017.c \
|
||||||
mcp23s08.c mcp23s17.c \
|
mcp23s08.c mcp23s17.c \
|
||||||
sr595.c \
|
sr595.c \
|
||||||
|
@ -55,7 +55,8 @@ SRC = wiringPi.c \
|
||||||
mcp3002.c mcp3004.c mcp4802.c mcp3422.c \
|
mcp3002.c mcp3004.c mcp4802.c mcp3422.c \
|
||||||
max31855.c max5322.c \
|
max31855.c max5322.c \
|
||||||
sn3218.c \
|
sn3218.c \
|
||||||
drcSerial.c
|
drcSerial.c \
|
||||||
|
boardtype_friendlyelec.c
|
||||||
|
|
||||||
OBJ = $(SRC:.c=.o)
|
OBJ = $(SRC:.c=.o)
|
||||||
|
|
||||||
|
@ -116,6 +117,7 @@ install-headers:
|
||||||
@install -m 0644 pcf8574.h $(DESTDIR)$(PREFIX)/include
|
@install -m 0644 pcf8574.h $(DESTDIR)$(PREFIX)/include
|
||||||
@install -m 0644 pcf8591.h $(DESTDIR)$(PREFIX)/include
|
@install -m 0644 pcf8591.h $(DESTDIR)$(PREFIX)/include
|
||||||
@install -m 0644 sn3218.h $(DESTDIR)$(PREFIX)/include
|
@install -m 0644 sn3218.h $(DESTDIR)$(PREFIX)/include
|
||||||
|
@install -m 0644 boardtype_friendlyelec.h $(DESTDIR)$(PREFIX)/include
|
||||||
|
|
||||||
.PHONEY: install
|
.PHONEY: install
|
||||||
install: $(DYNAMIC) install-headers
|
install: $(DYNAMIC) install-headers
|
||||||
|
@ -135,6 +137,7 @@ install-static: $(STATIC) install-headers
|
||||||
uninstall:
|
uninstall:
|
||||||
@echo "[UnInstall]"
|
@echo "[UnInstall]"
|
||||||
@rm -f $(DESTDIR)$(PREFIX)/include/wiringPi.h
|
@rm -f $(DESTDIR)$(PREFIX)/include/wiringPi.h
|
||||||
|
@rm -f $(DESTDIR)$(PREFIX)/include/boardtype_friendlyelec.h
|
||||||
@rm -f $(DESTDIR)$(PREFIX)/include/wiringSerial.h
|
@rm -f $(DESTDIR)$(PREFIX)/include/wiringSerial.h
|
||||||
@rm -f $(DESTDIR)$(PREFIX)/include/wiringShift.h
|
@rm -f $(DESTDIR)$(PREFIX)/include/wiringShift.h
|
||||||
@rm -f $(DESTDIR)$(PREFIX)/include/softPwm.h
|
@rm -f $(DESTDIR)$(PREFIX)/include/softPwm.h
|
||||||
|
@ -169,6 +172,7 @@ depend:
|
||||||
# DO NOT DELETE
|
# DO NOT DELETE
|
||||||
|
|
||||||
wiringPi.o: softPwm.h softTone.h wiringPi.h
|
wiringPi.o: softPwm.h softTone.h wiringPi.h
|
||||||
|
boardtype_friendlyelec.o: boardtype_friendlyelec.h
|
||||||
wiringSerial.o: wiringSerial.h
|
wiringSerial.o: wiringSerial.h
|
||||||
wiringShift.o: wiringPi.h wiringShift.h
|
wiringShift.o: wiringPi.h wiringShift.h
|
||||||
piHiPri.o: wiringPi.h
|
piHiPri.o: wiringPi.h
|
||||||
|
|
|
@ -0,0 +1,276 @@
|
||||||
|
#include "boardtype_friendlyelec.h"
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
|
const char* s5p_board_cputempfile = "/sys/class/hwmon/hwmon0/device/temp_label";
|
||||||
|
const char* s5p_board_max_cputempfile = "/sys/class/hwmon/hwmon0/device/temp_max";
|
||||||
|
const char* allwinner_tempfile = "/sys/class/thermal/thermal_zone0/temp";
|
||||||
|
|
||||||
|
#define LOGD printf
|
||||||
|
#define LOGE printf
|
||||||
|
|
||||||
|
BoardHardwareInfo gAllBoardHardwareInfo[] = {
|
||||||
|
{"MINI6410", -1, S3C6410_COMMON, "S3C6410_Board",""},
|
||||||
|
{"MINI210", -1, S5PV210_COMMON, "S5PV210_Board",""},
|
||||||
|
{"TINY4412", -1, S5P4412_COMMON, "S5P4412_Board",""},
|
||||||
|
{"mini2451", 0, S3C2451_COMMON, "S3C2451_Board", ""},
|
||||||
|
|
||||||
|
//s5p4418
|
||||||
|
{"nanopi2", 0, NanoPi2, "NanoPi2",""},
|
||||||
|
{"nanopi2", 1, NanoPC_T2, "NanoPC-T2",""},
|
||||||
|
{"nanopi2", 2, NanoPi_S2, "NanoPi-S2",""},
|
||||||
|
{"nanopi2", 3, Smart4418, "Smart4418",""},
|
||||||
|
{"nanopi2", 4, NanoPi2_Fire, "NanoPi2-Fire",""},
|
||||||
|
{"nanopi2", 5, NanoPi_M2, "NanoPi-M2",""},
|
||||||
|
{"nanopi2", 7, NanoPi_M2A, "NanoPi-M2A",""},
|
||||||
|
{"nanopi2", 0x103, Smart4418SDK, "Smart4418SDK",""},
|
||||||
|
|
||||||
|
//s5p6818
|
||||||
|
{"nanopi3", 1, NanoPC_T3, "NanoPC-T3",""},
|
||||||
|
{"nanopi3", 2, NanoPi_S3, "NanoPi-S3",""},
|
||||||
|
{"nanopi3", 3, Smart6818, "Smart6818",""},
|
||||||
|
{"nanopi3", 7, NanoPi_M3, "NanoPi-M3",""},
|
||||||
|
|
||||||
|
//allwinner h3
|
||||||
|
// kernel 3.x
|
||||||
|
{"sun8i", 0, NanoPi_M1, "NanoPi-M1", "0(0)"},
|
||||||
|
{"sun8i", 0, NanoPi_NEO, "NanoPi-NEO", "1(0)"},
|
||||||
|
{"sun8i", 0, NanoPi_NEO_Air, "NanoPi-NEO-Air", "2(0)"},
|
||||||
|
{"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)"},
|
||||||
|
// kernel 4.x
|
||||||
|
{"Allwinnersun8iFamily", 0, NanoPi_M1, "NanoPi-M1", "0(0)"},
|
||||||
|
{"Allwinnersun8iFamily", 0, NanoPi_NEO, "NanoPi-NEO", "1(0)"},
|
||||||
|
{"Allwinnersun8iFamily", 0, NanoPi_NEO_Air, "NanoPi-NEO-Air", "2(0)"},
|
||||||
|
{"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)"},
|
||||||
|
|
||||||
|
|
||||||
|
// a64
|
||||||
|
{"sun50iw1p1", 0, NanoPi_A64, "NanoPi-A64", "0"},
|
||||||
|
|
||||||
|
//allwinner h5
|
||||||
|
// kernel 3.x
|
||||||
|
{"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)"},
|
||||||
|
// 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)"},
|
||||||
|
|
||||||
|
//k2
|
||||||
|
{"Amlogic", 0, NanoPi_K2, "NanoPi-K2", ""},
|
||||||
|
};
|
||||||
|
|
||||||
|
static int getFieldValueInCpuInfo(char* hardware, int hardwareMaxLen, char* revision, int revisionMaxLen )
|
||||||
|
{
|
||||||
|
int n,i,j;
|
||||||
|
char lineUntrim[1024], line[1024],*p,*p2;
|
||||||
|
FILE *f;
|
||||||
|
int isGotHardware = 0;
|
||||||
|
int isGotRevision = 0;
|
||||||
|
|
||||||
|
if (!(f = fopen("/proc/cpuinfo", "r"))) {
|
||||||
|
LOGE("open /proc/cpuinfo failed.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!feof(f)) {
|
||||||
|
if(!fgets(lineUntrim, sizeof(lineUntrim), f)) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
j=0;
|
||||||
|
for(i=0; i<strlen(lineUntrim);i++) {
|
||||||
|
if (lineUntrim[i] == ' ' || lineUntrim[i] == '\t' || lineUntrim[i] == '\r' || lineUntrim[i] == '\n') {
|
||||||
|
} else {
|
||||||
|
line[j++]=lineUntrim[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
line[j] = 0x00;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isGotHardware == 1 && isGotRevision == 1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
return isGotHardware + isGotRevision;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int getAllwinnerBoardID(char* boardId, int boardIdMaxLen )
|
||||||
|
{
|
||||||
|
int n,i,j;
|
||||||
|
char lineUntrim[1024], line[1024],*p;
|
||||||
|
const char* sunxi_board_id_fieldname = "sunxi_board_id";
|
||||||
|
FILE *f;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (!(f = fopen("/sys/class/sunxi_info/sys_info", "r"))) {
|
||||||
|
LOGE("open /proc/cpuinfo failed.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (!feof(f)) {
|
||||||
|
if(!fgets(lineUntrim, sizeof(lineUntrim), f)) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
j=0;
|
||||||
|
for(i=0; i<strlen(lineUntrim);i++) {
|
||||||
|
if (lineUntrim[i] == ' ' || lineUntrim[i] == '\t' || lineUntrim[i] == '\r' || lineUntrim[i] == '\n') {
|
||||||
|
} else {
|
||||||
|
line[j++]=lineUntrim[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
line[j] = 0x00;
|
||||||
|
n = strlen(line);
|
||||||
|
if (n>0) {
|
||||||
|
//LOGD("LINE: %s\n", line);
|
||||||
|
if (p = strtok(line, ":")) {
|
||||||
|
if (strncasecmp(p, sunxi_board_id_fieldname, strlen(sunxi_board_id_fieldname)) == 0) {
|
||||||
|
//LOGD("\t\tkey=\"%s\"\n", p);
|
||||||
|
if (p = strtok(0, ":")) {
|
||||||
|
//LOGD("\t\tv=\"%s\"\n", p);
|
||||||
|
memset(boardId,0,boardIdMaxLen);
|
||||||
|
strncpy(boardId, p, boardIdMaxLen-1);
|
||||||
|
ret = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fclose(f);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getBoardType(BoardHardwareInfo** retBoardInfo) {
|
||||||
|
char hardware[255];
|
||||||
|
char revision[255];
|
||||||
|
char allwinnerBoardID[255];
|
||||||
|
int ret;
|
||||||
|
int i;
|
||||||
|
memset(hardware, 0, sizeof(hardware));
|
||||||
|
memset(revision, 0, sizeof(revision));
|
||||||
|
if ((ret = getFieldValueInCpuInfo(hardware, sizeof(hardware), revision, sizeof(revision))) > 0) {
|
||||||
|
//LOGD("hardware:%s,revision:%s\n", hardware, revision);
|
||||||
|
} else {
|
||||||
|
//LOGD("%s, ret:%d\n", "getFieldValueInCpuInfo failed", ret);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* a64 = "sun50iw1p1";
|
||||||
|
const char* amlogic = "Amlogic";
|
||||||
|
const char* h3 = "sun8i";
|
||||||
|
const char* h5 = "sun50iw2";
|
||||||
|
const char* h3_kernel4 = "Allwinnersun8iFamily";
|
||||||
|
const char* h5_kernel4 = "Allwinnersun50iw2Family";
|
||||||
|
|
||||||
|
//a64 and amlogic, only check hardware
|
||||||
|
if (strncasecmp(hardware, a64, strlen(a64)) == 0 || strncasecmp(hardware, amlogic, strlen(amlogic)) == 0) {
|
||||||
|
for (i=0; i<(sizeof(gAllBoardHardwareInfo)/sizeof(BoardHardwareInfo)); i++) {
|
||||||
|
if (strncasecmp(gAllBoardHardwareInfo[i].kernelHardware, hardware, strlen(gAllBoardHardwareInfo[i].kernelHardware)) == 0) {
|
||||||
|
if (retBoardInfo != 0) {
|
||||||
|
*retBoardInfo = &gAllBoardHardwareInfo[i];
|
||||||
|
}
|
||||||
|
return gAllBoardHardwareInfo[i].boardTypeId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// h3 and h5, check hardware and boardid
|
||||||
|
if (strncasecmp(hardware, h3, strlen(h3)) == 0 || strncasecmp(hardware, h5, strlen(h5)) == 0
|
||||||
|
|| strncasecmp(hardware, h3_kernel4, strlen(h3_kernel4)) == 0 || strncasecmp(hardware, h5_kernel4, strlen(h5_kernel4)) == 0) {
|
||||||
|
int ret = getAllwinnerBoardID(allwinnerBoardID, sizeof(allwinnerBoardID));
|
||||||
|
if (ret == 0) {
|
||||||
|
//LOGD("got boardid: %s\n", allwinnerBoardID);
|
||||||
|
for (i=0; i<(sizeof(gAllBoardHardwareInfo)/sizeof(BoardHardwareInfo)); i++) {
|
||||||
|
//LOGD("\t\t enum, start compare[%d]: %s <--> %s\n", i, gAllBoardHardwareInfo[i].kernelHardware, hardware);
|
||||||
|
if (strncasecmp(gAllBoardHardwareInfo[i].kernelHardware, hardware, strlen(gAllBoardHardwareInfo[i].kernelHardware)) == 0) {
|
||||||
|
if (strncasecmp(gAllBoardHardwareInfo[i].allwinnerBoardID, allwinnerBoardID, strlen(gAllBoardHardwareInfo[i].allwinnerBoardID)) == 0) {
|
||||||
|
if (retBoardInfo != 0) {
|
||||||
|
*retBoardInfo = &gAllBoardHardwareInfo[i];
|
||||||
|
}
|
||||||
|
return gAllBoardHardwareInfo[i].boardTypeId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//LOGD("\t\t enum, end compare[%d]\n", i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen(revision) == 0) {
|
||||||
|
//LOGD("failed, revision is empty.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
char revision2[255];
|
||||||
|
sprintf(revision2, "0x%s", revision);
|
||||||
|
int iRev;
|
||||||
|
iRev = strtol(revision2, NULL, 16);
|
||||||
|
|
||||||
|
// other, check hardware and revision
|
||||||
|
for (i=0; i<(sizeof(gAllBoardHardwareInfo)/sizeof(BoardHardwareInfo)); i++) {
|
||||||
|
if (strncasecmp(gAllBoardHardwareInfo[i].kernelHardware, hardware, strlen(gAllBoardHardwareInfo[i].kernelHardware)) == 0) {
|
||||||
|
if (gAllBoardHardwareInfo[i].kernelRevision == -1
|
||||||
|
|| gAllBoardHardwareInfo[i].kernelRevision == iRev
|
||||||
|
) {
|
||||||
|
if (retBoardInfo != 0) {
|
||||||
|
*retBoardInfo = &gAllBoardHardwareInfo[i];
|
||||||
|
}
|
||||||
|
return gAllBoardHardwareInfo[i].boardTypeId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
int main() {
|
||||||
|
BoardHardwareInfo* retBoardInfo;
|
||||||
|
int boardId;
|
||||||
|
boardId = getBoardType(&retBoardInfo);
|
||||||
|
if (boardId >= 0) {
|
||||||
|
printf("boardName:%s,boardId:%d\n", retBoardInfo->boardDisplayName, boardId);
|
||||||
|
} else {
|
||||||
|
printf("%s, ret:%d\n", "failed", boardId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
*/
|
|
@ -0,0 +1,73 @@
|
||||||
|
#ifndef __FRIENDLYELEC_BOARDTYPE_H__
|
||||||
|
#define __FRIENDLYELEC_BOARDTYPE_H__
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <linux/fs.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char kernelHardware[255];
|
||||||
|
int kernelRevision;
|
||||||
|
int boardTypeId;
|
||||||
|
char boardDisplayName[255];
|
||||||
|
char allwinnerBoardID[255];
|
||||||
|
} BoardHardwareInfo;
|
||||||
|
|
||||||
|
#define S3C6410_COMMON (6410)
|
||||||
|
#define S5PV210_COMMON (210)
|
||||||
|
#define S5P4412_COMMON (4412)
|
||||||
|
#define S5P4418_BASE (4418)
|
||||||
|
#define NanoPi2 (S5P4418_BASE+0)
|
||||||
|
#define NanoPC_T2 (S5P4418_BASE+1)
|
||||||
|
#define NanoPi_S2 (S5P4418_BASE+2)
|
||||||
|
#define Smart4418 (S5P4418_BASE+3)
|
||||||
|
#define NanoPi2_Fire (S5P4418_BASE+4)
|
||||||
|
#define NanoPi_M2 (S5P4418_BASE+5)
|
||||||
|
#define NanoPi_M2A (S5P4418_BASE+7)
|
||||||
|
#define Smart4418SDK (S5P4418_BASE+0x103)
|
||||||
|
#define S5P4418_MAX Smart4418SDK
|
||||||
|
|
||||||
|
//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_M3 (S5P6818_BASE+7)
|
||||||
|
#define S5P6818_MAX NanoPi_M3
|
||||||
|
|
||||||
|
//s3c2451
|
||||||
|
#define S3C2451_BASE (2451)
|
||||||
|
#define S3C2451_COMMON (S3C2451_BASE+0)
|
||||||
|
|
||||||
|
|
||||||
|
//allwinner
|
||||||
|
#define ALLWINNER_BASE (7000)
|
||||||
|
#define NanoPi_M1 (ALLWINNER_BASE+1)
|
||||||
|
#define NanoPi_NEO (ALLWINNER_BASE+2)
|
||||||
|
#define NanoPi_NEO_Air (ALLWINNER_BASE+3)
|
||||||
|
#define NanoPi_M1_Plus (ALLWINNER_BASE+4)
|
||||||
|
#define NanoPi_A64 (ALLWINNER_BASE+5)
|
||||||
|
#define NanoPi_NEO2 (ALLWINNER_BASE+6)
|
||||||
|
#define NanoPi_M1_Plus2 (ALLWINNER_BASE+7)
|
||||||
|
#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
|
||||||
|
|
||||||
|
//amlogic
|
||||||
|
#define AMLOGIC_BASE (8000)
|
||||||
|
#define NanoPi_K2 (AMLOGIC_BASE+1)
|
||||||
|
|
||||||
|
extern int getBoardType(BoardHardwareInfo** retBoardInfo);
|
||||||
|
|
||||||
|
#endif
|
|
@ -250,33 +250,6 @@ int wiringPiCodes = FALSE;
|
||||||
// The order of entries here to correspond with the PI_MODEL_X
|
// The order of entries here to correspond with the PI_MODEL_X
|
||||||
// and PI_VERSION_X defines in wiringPi.h
|
// and PI_VERSION_X defines in wiringPi.h
|
||||||
// Only intended for the gpio command - use at your own risk!
|
// Only intended for the gpio command - use at your own risk!
|
||||||
|
|
||||||
const char *piModelNames [6] ={
|
|
||||||
"Unknown",
|
|
||||||
"Model A",
|
|
||||||
"Model B",
|
|
||||||
"Model B+",
|
|
||||||
"Compute Module",
|
|
||||||
"Banana Pro", //add for BananaPro by LeMaker team
|
|
||||||
};
|
|
||||||
|
|
||||||
const char *piRevisionNames [5] ={
|
|
||||||
"Unknown",
|
|
||||||
"1",
|
|
||||||
"1.1",
|
|
||||||
"1.2",
|
|
||||||
"2",
|
|
||||||
};
|
|
||||||
|
|
||||||
const char *piMakerNames [5] ={
|
|
||||||
"Unknown",
|
|
||||||
"Egoman",
|
|
||||||
"Sony",
|
|
||||||
"Qusda",
|
|
||||||
"LeMaker", //add for BananaPro by LeMaker team
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// Time for easy calculations
|
// Time for easy calculations
|
||||||
|
|
||||||
static uint64_t epochMilli, epochMicro;
|
static uint64_t epochMilli, epochMicro;
|
||||||
|
@ -308,6 +281,11 @@ static int sysFds [64] ={
|
||||||
|
|
||||||
static int upDnConvert[3] = {7, 7, 5};
|
static int upDnConvert[3] = {7, 7, 5};
|
||||||
|
|
||||||
|
static int *pinToGpio = 0;
|
||||||
|
static int *physToGpio = 0;
|
||||||
|
static int *physToPin = 0;
|
||||||
|
|
||||||
|
|
||||||
// Doing it the Arduino way with lookup tables...
|
// Doing it the Arduino way with lookup tables...
|
||||||
// Yes, it's probably more innefficient than all the bit-twidling, but it
|
// Yes, it's probably more innefficient than all the bit-twidling, but it
|
||||||
// does tend to make it all a bit clearer. At least to me!
|
// does tend to make it all a bit clearer. At least to me!
|
||||||
|
@ -327,9 +305,31 @@ static int upDnConvert[3] = {7, 7, 5};
|
||||||
// 192 - 223 = PG00-PG31
|
// 192 - 223 = PG00-PG31
|
||||||
// nanopi m1 done
|
// nanopi m1 done
|
||||||
|
|
||||||
|
static int pinToGpio_m1 [64] ={
|
||||||
|
0, 6, // 0, 1
|
||||||
|
2, 3, // 2, 3
|
||||||
|
200, 201, // 4 5
|
||||||
|
1, 203, // 6, 7
|
||||||
|
12, 11, // 8, 9
|
||||||
|
67, 17, //10,11
|
||||||
|
64, 65, //12,13
|
||||||
|
66, 198, //14,15
|
||||||
|
199, -1, //16,17
|
||||||
|
-1, -1, //18,19
|
||||||
|
-1, 20, //20,21
|
||||||
|
21, 8, //22,23
|
||||||
|
13, 9, //24,25
|
||||||
|
7, 16, //26,27
|
||||||
|
15, 14, //28,29
|
||||||
|
19, 18, //30,31
|
||||||
|
|
||||||
|
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
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
static int pinToGpio [64] ={
|
static int pinToGpio_neo [64] ={
|
||||||
0, //0
|
0, //0
|
||||||
/* 24 Pin */
|
/* 24 Pin */
|
||||||
6, 2, //1, 2
|
6, 2, //1, 2
|
||||||
|
@ -360,6 +360,40 @@ static int pinToGpio [64] ={
|
||||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// wPi number to /sys/gpio number
|
||||||
|
static int pinToGpio_duo [64] ={
|
||||||
|
16, //0
|
||||||
|
/* 32 Pin */
|
||||||
|
-1, 14, //1, 2
|
||||||
|
13, -1, //3, 4
|
||||||
|
-1, -1, //5, 6
|
||||||
|
15, 198, //7, 8
|
||||||
|
199, -1, //9, 10
|
||||||
|
-1, 12, //11, 12
|
||||||
|
11, 4, //13, 14
|
||||||
|
5, 203, //15, 16
|
||||||
|
-1, -1, //17, 18
|
||||||
|
-1, -1, //19, 20
|
||||||
|
-1, -1, //21, 22
|
||||||
|
-1, -1, //23, 24
|
||||||
|
-1, -1, //25, 26
|
||||||
|
-1, -1, //27, 28
|
||||||
|
-1, -1, //29, 30
|
||||||
|
-1, -1, //31, 32
|
||||||
|
/* ---------nanopi duo end----------- */
|
||||||
|
|
||||||
|
-1, -1, //33, 34
|
||||||
|
-1, -1, //35, 36
|
||||||
|
|
||||||
|
/* UART0 Tx,Rx */
|
||||||
|
-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,
|
||||||
|
};
|
||||||
// guenter neu ende
|
// guenter neu ende
|
||||||
|
|
||||||
|
|
||||||
|
@ -392,8 +426,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
|
// Also add in the P5 connector, so the P5 pins are 3,4,5,6, so 53,54,55,56
|
||||||
|
|
||||||
|
|
||||||
// nanopi neo2
|
static int physToGpio_neo [64] ={
|
||||||
static int physToGpio [64] ={
|
|
||||||
-1,
|
-1,
|
||||||
/* 24 Pin */
|
/* 24 Pin */
|
||||||
-1, -1, //1, 2
|
-1, -1, //1, 2
|
||||||
|
@ -424,6 +457,67 @@ static int physToGpio [64] ={
|
||||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static int physToGpio_m1 [64] ={
|
||||||
|
-1, // 0
|
||||||
|
-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
|
||||||
|
-1, 17, //25, 26
|
||||||
|
19, 18, //27, 28
|
||||||
|
20, -1, //29, 30
|
||||||
|
21, 7, //31, 32
|
||||||
|
8, -1, //33, 34
|
||||||
|
16, 13, //35, 36
|
||||||
|
9, 15, //37, 38
|
||||||
|
-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
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// phys pin number to /sys/gpio number
|
||||||
|
static int physToGpio_duo [64] ={
|
||||||
|
-1, //0
|
||||||
|
/* 32 Pin */
|
||||||
|
-1, -1, //1, 2
|
||||||
|
-1, -1, //3, 4
|
||||||
|
-1, -1, //5, 6
|
||||||
|
-1, -1, //7, 8
|
||||||
|
-1, -1, //9, 10
|
||||||
|
198,-1, //11, 12
|
||||||
|
199,-1, //13, 14
|
||||||
|
15, -1, //15, 16
|
||||||
|
16, -1, //17, 18
|
||||||
|
14, -1, //19, 20
|
||||||
|
13, 203, //21, 22
|
||||||
|
12, -1, //23, 24
|
||||||
|
11, -1, //25, 26
|
||||||
|
-1, -1, //27, 28
|
||||||
|
4, -1, //29, 30
|
||||||
|
5, -1, //31, 32
|
||||||
|
/* ---------nanopi duo end----------- */
|
||||||
|
|
||||||
|
-1, -1, //33, 34
|
||||||
|
-1, -1, //35, 36
|
||||||
|
|
||||||
|
/* UART0 Tx,Rx */
|
||||||
|
-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,
|
||||||
|
};
|
||||||
//
|
//
|
||||||
|
|
||||||
static int syspin [64] ={
|
static int syspin [64] ={
|
||||||
|
@ -444,7 +538,37 @@ static int syspin [64] ={
|
||||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||||
};*/
|
};*/
|
||||||
|
|
||||||
static int physToPin [64] = //return wiringPI pin
|
static int physToPin_m1 [64] = //return wiringPI pin
|
||||||
|
{
|
||||||
|
-1, // 0
|
||||||
|
-1, -1, // 1, 2
|
||||||
|
8, -1, //3, 4
|
||||||
|
9, -1, //5, 6
|
||||||
|
7, 15, //7, 8
|
||||||
|
-1, 16, //9,10
|
||||||
|
0, 1, //11,12
|
||||||
|
2, -1, //13,14
|
||||||
|
3, 4, //15,16
|
||||||
|
-1, 5, //17,18
|
||||||
|
12, -1, //19,20
|
||||||
|
13, 6, //21,22
|
||||||
|
14, 10, //23, 24
|
||||||
|
-1, 11, // 25, 26
|
||||||
|
|
||||||
|
30, 31, //27, 28
|
||||||
|
21, -1, //29, 30
|
||||||
|
22, 26, //31, 32
|
||||||
|
23, -1, //33, 34
|
||||||
|
24, 27, //35, 36
|
||||||
|
25, 28, //37, 38
|
||||||
|
-1, 29, //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 int physToPin_neo [64] = //return wiringPI pin
|
||||||
{
|
{
|
||||||
-1, // 0
|
-1, // 0
|
||||||
-1, -1, // 1, 2
|
-1, -1, // 1, 2
|
||||||
|
@ -474,6 +598,37 @@ static int physToPin [64] = //return wiringPI pin
|
||||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int physToPin_duo [64] = //return wiringPI pin //note: same as physToWpi
|
||||||
|
{
|
||||||
|
-1, // 0
|
||||||
|
-1, -1, // 1, 2
|
||||||
|
-1, -1, // 3, 4
|
||||||
|
-1, -1, // 5, 6
|
||||||
|
-1, -1, // 7, 8
|
||||||
|
-1, -1, // 9, 10
|
||||||
|
8, -1, //11, 12
|
||||||
|
9, -1, //13, 14
|
||||||
|
7, -1, //15, 16
|
||||||
|
0, -1, //17, 18
|
||||||
|
2, -1, //19, 20
|
||||||
|
3, 16, //21, 22
|
||||||
|
12, -1, //23, 24
|
||||||
|
|
||||||
|
13, -1, //25, 26
|
||||||
|
-1, -1, //27, 28
|
||||||
|
14, -1, //29, 30
|
||||||
|
15, -1, //31, 32
|
||||||
|
/* ---------nanopi duo end----------- */
|
||||||
|
-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,
|
||||||
|
};
|
||||||
|
|
||||||
// pins available on pin out by banks
|
// pins available on pin out by banks
|
||||||
static int BP_PIN_MASK[9][32] = //[BANK] [INDEX]
|
static int BP_PIN_MASK[9][32] = //[BANK] [INDEX]
|
||||||
{
|
{
|
||||||
|
@ -680,7 +835,7 @@ int sunxi_get_gpio_mode(int pin) {
|
||||||
printf("read reg val: 0x%x offset:%d return: %d\n", regval, offset, reval);
|
printf("read reg val: 0x%x offset:%d return: %d\n", regval, offset, reval);
|
||||||
return reval;
|
return reval;
|
||||||
} else {
|
} else {
|
||||||
printf("line:%d pin(=%d) number error\n", pin, __LINE__);
|
printf("line:%d pin(=%d) number error\n", __LINE__, pin);
|
||||||
return reval;
|
return reval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -736,7 +891,7 @@ void sunxi_set_gpio_mode(int pin, int mode) {
|
||||||
delayMicroseconds(200);
|
delayMicroseconds(200);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf("line:%dpin number error\n", __LINE__);
|
printf("line:%d pin(%d) number error\n", __LINE__,pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -920,58 +1075,25 @@ int isA20(void) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*end 2014.09.18*/
|
|
||||||
|
|
||||||
/*add for NEO/NEO2 */
|
|
||||||
int isNEO(void) {
|
|
||||||
FILE *cpuFd;
|
|
||||||
char line [120];
|
|
||||||
char *d;
|
|
||||||
if ((cpuFd = fopen("/proc/cpuinfo", "r")) == NULL)
|
|
||||||
piBoardRevOops("Unable to open /proc/cpuinfo");
|
|
||||||
while (fgets(line, 120, cpuFd) != NULL) {
|
|
||||||
if (strncmp(line, "Hardware", 8) == 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
fclose(cpuFd);
|
|
||||||
if (strncmp(line, "Hardware", 8) != 0)
|
|
||||||
piBoardRevOops("No \"Hardware\" line");
|
|
||||||
|
|
||||||
for (d = &line [strlen(line) - 1]; (*d == '\n') || (*d == '\r'); --d)
|
|
||||||
*d = 0;
|
|
||||||
if (wiringPiDebug)
|
|
||||||
printf("piboardRev: Hardware string: %s\n", line);
|
|
||||||
|
|
||||||
if (strstr(line, "sun50i") != NULL || strstr(line, "sun8i") != NULL)
|
|
||||||
{
|
|
||||||
if (wiringPiDebug)
|
|
||||||
printf("Hardware:%s\n", line);
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
if (wiringPiDebug)
|
|
||||||
printf("Hardware:%s\n", line);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* guenter ende */
|
/* guenter ende */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int piBoardRev(void) {
|
int piBoardRev(void) {
|
||||||
|
BoardHardwareInfo* retBoardInfo;
|
||||||
/*add for orange pi guenter */
|
int boardId;
|
||||||
if (isNEO())
|
boardId = getBoardType(&retBoardInfo);
|
||||||
{
|
if (boardId >= 0) {
|
||||||
|
if (boardId > ALLWINNER_BASE && boardId <= ALLWINNER_MAX
|
||||||
|
&& boardId != NanoPi_A64
|
||||||
|
&& boardId != NanoPi_NEO_Core) {
|
||||||
version = BPRVER;
|
version = BPRVER;
|
||||||
if (wiringPiDebug)
|
if (wiringPiDebug)
|
||||||
printf("piboardRev: %d\n", version);
|
printf("piBoardRev: %d\n", version);
|
||||||
return BPRVER;
|
return BPRVER;
|
||||||
|
} else {
|
||||||
|
printf ("This NanoPi model is currently not supported. ") ;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
piBoardRevOops("Is not NanoPi NEO/NEO2 based board");
|
piBoardRevOops("Is not NanoPi based board. ");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -992,64 +1114,30 @@ void piBoardId(int *model, int *rev, int *mem, int *maker, int *overVolted) {
|
||||||
|
|
||||||
(void) piBoardRev(); // Call this first to make sure all's OK. Don't care about the result.
|
(void) piBoardRev(); // Call this first to make sure all's OK. Don't care about the result.
|
||||||
|
|
||||||
if ((cpuFd = fopen("/proc/cpuinfo", "r")) == NULL)
|
BoardHardwareInfo* retBoardInfo;
|
||||||
piBoardRevOops("Unable to open /proc/cpuinfo");
|
int boardId;
|
||||||
|
boardId = getBoardType(&retBoardInfo);
|
||||||
while (fgets(line, 120, cpuFd) != NULL)
|
if (boardId >= 0) {
|
||||||
if (strncmp(line, "Revision", 8) == 0)
|
if (boardId > ALLWINNER_BASE && boardId <= ALLWINNER_MAX
|
||||||
break;
|
&& boardId != NanoPi_A64
|
||||||
|
&& boardId != NanoPi_NEO_Core) {
|
||||||
fclose(cpuFd);
|
*model = boardId;
|
||||||
|
*rev = PI_VERSION_1_2;
|
||||||
if (strncmp (line, "Revision", 8) != 0){
|
*mem = 1024;
|
||||||
if(isNEO()){
|
*maker = PI_MAKER_FRIENDLYELEC;
|
||||||
strcpy(line,"0000") ;
|
} else {
|
||||||
}else{
|
*model = 0;
|
||||||
piBoardRevOops ("No \"Revision\" line") ;
|
*rev = 0;
|
||||||
|
*mem = 0;
|
||||||
|
*maker = 0;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
|
||||||
// Chomp trailing CR/NL
|
|
||||||
|
|
||||||
for (c = &line [strlen(line) - 1]; (*c == '\n') || (*c == '\r'); --c)
|
|
||||||
*c = 0;
|
|
||||||
|
|
||||||
if (wiringPiDebug)
|
|
||||||
printf("piboardId: Revision string: %s\n", line);
|
|
||||||
|
|
||||||
// Scan to first digit
|
|
||||||
|
|
||||||
for (c = line; *c; ++c)
|
|
||||||
if (isdigit(*c))
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Make sure its long enough
|
|
||||||
|
|
||||||
if (strlen(c) < 4)
|
|
||||||
piBoardRevOops("Bogus \"Revision\" line");
|
|
||||||
|
|
||||||
// If longer than 4, we'll assume it's been overvolted
|
|
||||||
|
|
||||||
*overVolted = strlen(c) > 4;
|
|
||||||
|
|
||||||
// Extract last 4 characters:
|
|
||||||
|
|
||||||
c = c + strlen(c) - 4;
|
|
||||||
|
|
||||||
// Fill out the replys as appropriate
|
|
||||||
|
|
||||||
if (strcmp(c, "0000") == 0) {
|
|
||||||
*model = PI_MODEL_M1;
|
|
||||||
*rev = PI_VERSION_1_2;
|
|
||||||
*mem = 1024;
|
|
||||||
*maker = PI_MAKER_LEMAKER;
|
|
||||||
} //end 2014.09.30
|
|
||||||
else {
|
|
||||||
*model = 0;
|
*model = 0;
|
||||||
*rev = 0;
|
*rev = 0;
|
||||||
*mem = 0;
|
*mem = 0;
|
||||||
*maker = 0;
|
*maker = 0;
|
||||||
}
|
}
|
||||||
|
*overVolted = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1060,6 +1148,10 @@ void piBoardId(int *model, int *rev, int *mem, int *maker, int *overVolted) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int wpiPinToGpio(int wpiPin) {
|
int wpiPinToGpio(int wpiPin) {
|
||||||
|
if (pinToGpio == 0) {
|
||||||
|
printf("please call wiringPiSetup first.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return pinToGpio [wpiPin & 63];
|
return pinToGpio [wpiPin & 63];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1071,6 +1163,10 @@ int wpiPinToGpio(int wpiPin) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int physPinToGpio(int physPin) {
|
int physPinToGpio(int physPin) {
|
||||||
|
if (physToGpio == 0) {
|
||||||
|
printf("please call wiringPiSetup first.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return physToGpio [physPin & 63];
|
return physToGpio [physPin & 63];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1081,6 +1177,10 @@ int physPinToGpio(int physPin) {
|
||||||
*********************************************************************************
|
*********************************************************************************
|
||||||
*/
|
*/
|
||||||
int physPinToPin(int physPin) {
|
int physPinToPin(int physPin) {
|
||||||
|
if (physToPin == 0) {
|
||||||
|
printf("please call wiringPiSetup first.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
return physToPin [physPin & 63];
|
return physToPin [physPin & 63];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1106,6 +1206,11 @@ int getAlt(int pin) {
|
||||||
|
|
||||||
pin &= 63;
|
pin &= 63;
|
||||||
|
|
||||||
|
if (pinToGpio == 0 || physToGpio == 0) {
|
||||||
|
printf("please call wiringPiSetup first.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
//printf("[%s:L%d] the pin:%d mode: %d is invaild,please check it over!\n", __func__, __LINE__, pin, wiringPiMode);
|
//printf("[%s:L%d] the pin:%d mode: %d is invaild,please check it over!\n", __func__, __LINE__, pin, wiringPiMode);
|
||||||
if (wiringPiMode == WPI_MODE_PINS)
|
if (wiringPiMode == WPI_MODE_PINS)
|
||||||
pin = pinToGpio [pin];
|
pin = pinToGpio [pin];
|
||||||
|
@ -1287,6 +1392,12 @@ void pinMode(int pin, int mode) {
|
||||||
|
|
||||||
if (wiringPiDebug)
|
if (wiringPiDebug)
|
||||||
printf("Func: %s, Line: %d,pin:%d,mode:%d\n", __func__, __LINE__, pin, mode);
|
printf("Func: %s, Line: %d,pin:%d,mode:%d\n", __func__, __LINE__, pin, mode);
|
||||||
|
|
||||||
|
if (pinToGpio == 0 || physToGpio == 0) {
|
||||||
|
printf("please call wiringPiSetup first.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if ((pin & PI_GPIO_MASK) == 0) // On-board pin
|
if ((pin & PI_GPIO_MASK) == 0) // On-board pin
|
||||||
{
|
{
|
||||||
if (wiringPiMode == WPI_MODE_PINS) {
|
if (wiringPiMode == WPI_MODE_PINS) {
|
||||||
|
@ -1360,6 +1471,10 @@ void pinMode(int pin, int mode) {
|
||||||
void pullUpDnControl(int pin, int pud) {
|
void pullUpDnControl(int pin, int pud) {
|
||||||
struct wiringPiNodeStruct *node = wiringPiNodes;
|
struct wiringPiNodeStruct *node = wiringPiNodes;
|
||||||
|
|
||||||
|
if (pinToGpio == 0 || physToGpio == 0) {
|
||||||
|
printf("please call wiringPiSetup first.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
pud = upDnConvert[pud];
|
pud = upDnConvert[pud];
|
||||||
|
|
||||||
|
@ -1404,6 +1519,11 @@ int digitalRead(int pin) {
|
||||||
struct wiringPiNodeStruct *node = wiringPiNodes;
|
struct wiringPiNodeStruct *node = wiringPiNodes;
|
||||||
int oldPin = pin;
|
int oldPin = pin;
|
||||||
|
|
||||||
|
if (pinToGpio == 0 || physToGpio == 0) {
|
||||||
|
printf("please call wiringPiSetup first.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ((pin & PI_GPIO_MASK) == 0) // On-Board Pin
|
if ((pin & PI_GPIO_MASK) == 0) // On-Board Pin
|
||||||
{
|
{
|
||||||
if (wiringPiMode == WPI_MODE_GPIO_SYS) // Sys mode
|
if (wiringPiMode == WPI_MODE_GPIO_SYS) // Sys mode
|
||||||
|
@ -1533,6 +1653,11 @@ void digitalWrite(int pin, int value) {
|
||||||
void pwmWrite(int pin, int value) {
|
void pwmWrite(int pin, int value) {
|
||||||
struct wiringPiNodeStruct *node = wiringPiNodes;
|
struct wiringPiNodeStruct *node = wiringPiNodes;
|
||||||
|
|
||||||
|
if (pinToGpio == 0 || physToGpio == 0) {
|
||||||
|
printf("please call wiringPiSetup first.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
uint32_t a_val = 0;
|
uint32_t a_val = 0;
|
||||||
if (pwmmode == 1)//sycle
|
if (pwmmode == 1)//sycle
|
||||||
|
@ -1658,6 +1783,11 @@ void digitalWriteByte(int value) {
|
||||||
int mask = 1;
|
int mask = 1;
|
||||||
int pin;
|
int pin;
|
||||||
|
|
||||||
|
if (pinToGpio == 0 || physToGpio == 0) {
|
||||||
|
printf("please call wiringPiSetup first.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (wiringPiMode == WPI_MODE_GPIO_SYS || wiringPiMode == WPI_MODE_GPIO) {
|
if (wiringPiMode == WPI_MODE_GPIO_SYS || wiringPiMode == WPI_MODE_GPIO) {
|
||||||
|
|
||||||
for (pin = 0; pin < 8; ++pin) {
|
for (pin = 0; pin < 8; ++pin) {
|
||||||
|
@ -1704,6 +1834,11 @@ int waitForInterrupt(int pin, int mS) {
|
||||||
uint8_t c;
|
uint8_t c;
|
||||||
struct pollfd polls;
|
struct pollfd polls;
|
||||||
|
|
||||||
|
if (pinToGpio == 0 || physToGpio == 0) {
|
||||||
|
printf("please call wiringPiSetup first.\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/**/ if (wiringPiMode == WPI_MODE_PINS)
|
/**/ if (wiringPiMode == WPI_MODE_PINS)
|
||||||
pin = pinToGpio [pin];
|
pin = pinToGpio [pin];
|
||||||
else if (wiringPiMode == WPI_MODE_PHYS)
|
else if (wiringPiMode == WPI_MODE_PHYS)
|
||||||
|
@ -1765,6 +1900,11 @@ static void *interruptHandler(void *arg) {
|
||||||
int wiringPiISR(int pin, int mode, void (*function)(void)) {
|
int wiringPiISR(int pin, int mode, void (*function)(void)) {
|
||||||
int bcmGpioPin;
|
int bcmGpioPin;
|
||||||
|
|
||||||
|
if (pinToGpio == 0 || physToGpio == 0) {
|
||||||
|
printf("please call wiringPiSetup first.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return wiringPiFailure(WPI_FATAL, "wiringPiISR: Not implemented");
|
return wiringPiFailure(WPI_FATAL, "wiringPiISR: Not implemented");
|
||||||
|
|
||||||
if ((pin < 0) || (pin > 63))
|
if ((pin < 0) || (pin > 63))
|
||||||
|
@ -1967,6 +2107,23 @@ int wiringPiSetup(void) {
|
||||||
piBoardId(&model, &rev, &mem, &maker, &overVolted);
|
piBoardId(&model, &rev, &mem, &maker, &overVolted);
|
||||||
wiringPiMode = WPI_MODE_PINS;
|
wiringPiMode = WPI_MODE_PINS;
|
||||||
|
|
||||||
|
int boardId = model;
|
||||||
|
if (boardId == NanoPi_M1 || boardId == NanoPi_M1_Plus || boardId == NanoPi_M1_Plus2) {
|
||||||
|
pinToGpio = pinToGpio_m1;
|
||||||
|
physToGpio = physToGpio_m1;
|
||||||
|
physToPin = physToPin_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;
|
||||||
|
} else if (boardId == NanoPi_Duo) {
|
||||||
|
pinToGpio = pinToGpio_duo;
|
||||||
|
physToGpio = physToGpio_duo;
|
||||||
|
physToPin = physToPin_duo;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2023,6 +2180,7 @@ int wiringPiSetupSys(void) {
|
||||||
//int boardRev;
|
//int boardRev;
|
||||||
int pin;
|
int pin;
|
||||||
char fName [128];
|
char fName [128];
|
||||||
|
int model, rev, mem, maker, overVolted;
|
||||||
|
|
||||||
if (getenv(ENV_DEBUG) != NULL)
|
if (getenv(ENV_DEBUG) != NULL)
|
||||||
wiringPiDebug = TRUE;
|
wiringPiDebug = TRUE;
|
||||||
|
@ -2044,5 +2202,21 @@ int wiringPiSetupSys(void) {
|
||||||
|
|
||||||
wiringPiMode = WPI_MODE_GPIO_SYS;
|
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) {
|
||||||
|
pinToGpio = pinToGpio_m1;
|
||||||
|
physToGpio = physToGpio_m1;
|
||||||
|
physToPin = physToPin_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;
|
||||||
|
} else if (boardId == NanoPi_Duo) {
|
||||||
|
pinToGpio = pinToGpio_duo;
|
||||||
|
physToGpio = physToGpio_duo;
|
||||||
|
physToPin = physToPin_duo;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,6 @@
|
||||||
// Intended for the GPIO program Use at your own risk.
|
// Intended for the GPIO program Use at your own risk.
|
||||||
|
|
||||||
#define PI_MODEL_UNKNOWN 0
|
#define PI_MODEL_UNKNOWN 0
|
||||||
#define PI_MODEL_M1 1
|
|
||||||
|
|
||||||
#define PI_VERSION_UNKNOWN 0
|
#define PI_VERSION_UNKNOWN 0
|
||||||
#define PI_VERSION_1 1
|
#define PI_VERSION_1 1
|
||||||
|
@ -84,17 +83,12 @@
|
||||||
#define PI_MAKER_EGOMAN 1
|
#define PI_MAKER_EGOMAN 1
|
||||||
#define PI_MAKER_SONY 2
|
#define PI_MAKER_SONY 2
|
||||||
#define PI_MAKER_QISDA 3
|
#define PI_MAKER_QISDA 3
|
||||||
#define PI_MAKER_LEMAKER 4 //add for BananaPro by LeMaker team
|
#define PI_MAKER_LEMAKER 4 //add for BananaPro by LeMaker team
|
||||||
|
#define PI_MAKER_FRIENDLYELEC 5 //add for FriendlyELEC team
|
||||||
|
|
||||||
#define BPRVER 3 //add for BananaPro by lemaker team
|
#define BPRVER 3 //add for BananaPro by lemaker team
|
||||||
|
|
||||||
extern const char *piModelNames [6] ;
|
|
||||||
extern const char *piRevisionNames [5] ;
|
|
||||||
extern const char *piMakerNames [5] ;
|
|
||||||
|
|
||||||
|
|
||||||
// Intended for the GPIO program Use at your own risk.
|
// Intended for the GPIO program Use at your own risk.
|
||||||
|
|
||||||
// Threads
|
// Threads
|
||||||
|
|
||||||
#define PI_THREAD(X) void *X (void *dummy)
|
#define PI_THREAD(X) void *X (void *dummy)
|
||||||
|
@ -148,11 +142,7 @@ extern "C" {
|
||||||
|
|
||||||
// Data
|
// Data
|
||||||
|
|
||||||
//extern const char *piModelNames [] ;
|
|
||||||
//extern const char *piRevisionNames[] ;
|
|
||||||
|
|
||||||
// Internal
|
// Internal
|
||||||
|
|
||||||
extern int wiringPiFailure (int fatal, const char *message, ...) ;
|
extern int wiringPiFailure (int fatal, const char *message, ...) ;
|
||||||
|
|
||||||
// Core wiringPi functions
|
// Core wiringPi functions
|
||||||
|
@ -219,6 +209,8 @@ extern void delayMicroseconds (unsigned int howLong) ;
|
||||||
extern unsigned int millis (void) ;
|
extern unsigned int millis (void) ;
|
||||||
extern unsigned int micros (void) ;
|
extern unsigned int micros (void) ;
|
||||||
|
|
||||||
|
#include "boardtype_friendlyelec.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue