Compare commits

...

29 Commits

Author SHA1 Message Date
smallsolar ff6cf61864 Changed to work with dietpi on a NanoPI NEO 2024-04-25 16:50:10 +00:00
Lawrence-Tang 3e6817c3f7 bugfix: cannot access h3 gpio_a0 2021-04-25 09:13:27 +00:00
friendlyarm 78f7feeae3
Update README.md 2019-10-11 18:01:09 +08:00
friendlyarm aeafaef315
Update README.md 2019-10-11 18:00:56 +08:00
friendlyarm bd92a83dd0
Merge pull request #4 from Tea-NT/master
Add NanoPC-T3 support GPIO input and Output.
2019-10-11 17:55:23 +08:00
Tea-NT fe4c18b6bd Add NanoPC-T3 support GPIO input and Output. 2019-08-29 12:39:27 +08:00
friendlyarm fa138e24c6
Merge pull request #2 from troyane/improvements
Small problem fixes and code formatting improvements
2019-06-15 08:55:40 +08:00
friendlyarm 1a06132723
Merge pull request #3 from Dobrobot/master
NanoPi NEO2 / Armbian has 'sun50iw1p1' in cpuinfo
2019-06-15 08:55:20 +08:00
A C ed5a24489c
NanoPi NEO2 / Armbian has 'sun50iw1p1' in cpuinfo 2019-06-15 01:35:17 +02:00
Nazar 108f7d3a6c Use -j nproc to use all cores for speedup builds 2019-04-12 17:17:31 +03:00
Nazar 501d55bfc2 Avoid null pointer deferefence
Improve code formatting
2019-04-12 17:16:55 +03:00
Nazar 10956702a5 Avoid dead code blocks 2019-04-12 17:15:40 +03:00
Nazar 2942640d9d Do undef BLOCK_SIZE 2019-04-12 17:15:32 +03:00
Nazar 615eb8a059 Comment out usage of assignment pin=pin 2019-04-12 17:15:19 +03:00
Nazar e8dc09f3da Use correct types to avoid warnings 2019-04-12 17:14:28 +03:00
Nazar b140ff3f9d Apply better code formatting
- code formatting for ease of reading code structures 
- code formatting for defines
- code formatting for pins arrays
- general code formatting fixes
2019-04-12 17:13:40 +03:00
friendlyarm 0464ba6da0
Update README.md 2018-11-06 15:43:19 +08:00
Lawrence-Tang 9a6860b4bd add support for NanoPi-Duo2 2018-11-06 07:42:05 +00:00
Lawrence-Tang 6a608ee8ab Merge branch 'master' of https://github.com/friendlyarm/WiringNP 2018-06-07 15:51:49 +08:00
Lawrence-Tang 4d22e3fd65 add support for NanoPi NEO Core, NEO Core2 and K1 Plus 2018-06-07 15:50:20 +08:00
friendlyarm 6e76e15c9b
Merge pull request #1 from Pi4J/master
updated SPI API & impl to match current WiringPi version
2018-01-12 09:56:25 +08:00
LawrenceTang 30edaf15cd add support for NanoPi 2017-08-29 11:37:00 +08:00
Robert Savage 73fb0d8434 updated SPI API & impl to match current WiringPi version 2017-08-11 11:00:47 -04:00
friendlyarm 03a8ddeadd Update README.md 2017-06-07 14:05:02 +08:00
friendlyarm c85a321b7c Update README.md 2017-06-07 14:04:44 +08:00
LawrenceTang 4169be5160 fix compiler warnings 2017-05-18 14:54:06 +08:00
LawrenceTang c35b3fd8ea Merge branch 'master' of https://github.com/friendlyarm/WiringNP 2017-05-17 16:54:03 +08:00
LawrenceTang b480f36175 add support for NanoPi NEO/NEO2 2017-05-17 16:53:40 +08:00
LawrenceTang 3b016bd79b chmod +x build 2017-05-16 17:40:17 +08:00
12 changed files with 4297 additions and 2205 deletions

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
*.o
/gpio/gpio
libwiringPiDev.so.2.0
libwiringPi.so.2.0
/test/

177
README.md
View File

@ -1,9 +1,176 @@
# WiringNP
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:
NanoPI M1
NanoPI Neo (please ignore extra "gpio readall" pins for now)
NanoPi Neo
NanoPi Neo Air
NanoPi Duo
NanoPi Duo2
NanoPi NEO2
NanoPi NEO Plus2
NanoPi M1
NanoPi M1 Plus
NanoPi NEO Core
NanoPi NEO Core2
NanoPi K1 Plus
NanoPC T3
## PWM
PWM is supported on NanoPI M1 debug port, physical pin 4
# Installation
## Install WiringNP
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/
chmod 755 build
./build
```
# 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:
```
gpio readall
```
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-Core--+------+----------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+
| | | 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 | 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-Core--+------+----------+-----+-----+
+-----+-----+----------+---- 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:
```
vi test.c
```
Type the following lines:
```
#include <wiringPi.h>
int main(void)
{
wiringPiSetup() ;
pinMode (7, OUTPUT) ;
for(;;)
{
digitalWrite(7, HIGH) ;
delay (500) ;
digitalWrite(7, LOW) ;
delay (500) ;
}
}
```
Compile and run "test.c":
```
gcc -Wall -o test test.c -lwiringPi -lpthread
sudo ./test
```
You can see the LED is blinking.
# PWM Code Sample
The PWM pin in NanoPi NEO/NEO2 is multiplexing which can be set to either PWM or SerialPort0. To set this pin to PWM you need to run "sudo npi-config" and enter the "Advanced Options" menu to Enable/Disable PWM. Note: after PWM is enabled SerialPort0 will not be accessed and you need to login your board via SSH.
connect a Buzzer to a NanoPi NEO2, create a source file in C:
```
vi pwmtest.c
```
Type the following code:
```
#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main (void)
{
int l ;
printf ("PWM test program\n") ;
//using wiringPi Pin Number
int pin = 18;
if (wiringPiSetup () == -1)
exit (1) ;
/*
//using Physical Pin Number
int pin = 38;
if (wiringPiSetupPhys() == -1)
exit (1) ;
*/
/*
//using BCM Pin Number
int pin = 5;
if (wiringPiSetupGpio() == -1)
exit (1);
*/
pinMode (pin, PWM_OUTPUT);
for (;;) {
for (l = 0 ; l < 1024 ; ++l) {
pwmWrite (pin, l) ;
delay (1) ;
}
for (l = 1023 ; l >= 0 ; --l) {
pwmWrite (pin, l) ;
delay (1) ;
}
}
return 0 ;
}
```
Compile the pwmtest.c file and run the generated executable:
```
gcc -Wall -o pwmtest pwmtest.c -lwiringPi -lpthread
./pwmtest
```
Connect a PWM beeper to a NEO/NEO2 and the beeper will sound.

91
build Normal file → Executable file
View File

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
# check if sudo is required and save the result as ${PFX}:
[[ ${EUID} -ne 0 ]] && PFX='sudo ' || PFX=''
@ -17,21 +17,21 @@ check_make_ok() {
if [ x$1 = "xclean" ]; then
cd wiringPi
echo -n "wiringPi: " ; make clean
echo -n "wiringPi: " ; make clean
cd ../devLib
echo -n "DevLib: " ; make clean
echo -n "DevLib: " ; make clean
cd ../gpio
echo -n "gpio: " ; make clean
echo -n "gpio: " ; make clean
cd ../examples
echo -n "Examples: " ; make clean
echo -n "Examples: " ; make clean
cd Gertboard
echo -n "Gertboard: " ; make clean
echo -n "Gertboard: " ; make clean
cd ../PiFace
echo -n "PiFace: " ; make clean
echo -n "PiFace: " ; make clean
cd ../q2w
echo -n "Quick2Wire: " ; make clean
echo -n "Quick2Wire: " ; make clean
cd ../PiGlow
echo -n "PiGlow: " ; make clean
echo -n "PiGlow: " ; make clean
exit
fi
@ -45,48 +45,47 @@ if [ x$1 = "xuninstall" ]; then
exit
fi
echo "wiringPi Build script"
echo "====================="
echo
echo "wiringPi Build script"
echo "====================="
echo
echo
echo "WiringPi Library"
cd wiringPi
${PFX}make uninstall
if [ x$1 = "xstatic" ]; then
make static
check_make_ok
${PFX}make install-static
else
make
check_make_ok
${PFX}make install
fi
echo
echo "WiringPi Library"
cd wiringPi
${PFX}make uninstall
if [ x$1 = "xstatic" ]; then
make -j `nproc` static
check_make_ok
echo
echo "WiringPi Devices Library"
cd ../devLib
${PFX}make uninstall
if [ x$1 = "xstatic" ]; then
make static
check_make_ok
${PFX}make install-static
else
make
check_make_ok
${PFX}make install
fi
check_make_ok
echo
echo "GPIO Utility"
cd ../gpio
make
${PFX}make install-static
else
make -j `nproc`
check_make_ok
${PFX}make install
fi
check_make_ok
echo
echo "WiringPi Devices Library"
cd ../devLib
${PFX}make uninstall
if [ x$1 = "xstatic" ]; then
make -j `nproc` static
check_make_ok
${PFX}make install-static
else
make -j `nproc`
check_make_ok
${PFX}make install
fi
check_make_ok
echo
echo "GPIO Utility"
cd ../gpio
make -j `nproc`
check_make_ok
${PFX}make install
check_make_ok
# echo
# echo "Examples"

View File

@ -1084,7 +1084,6 @@ static void doPwmClock (int argc, char *argv [])
int main (int argc, char *argv [])
{
int i ;
int model, rev, mem, maker, overVolted ;
if (getenv ("WIRINGPI_DEBUG") != NULL)
{
@ -1129,19 +1128,30 @@ int main (int argc, char *argv [])
printf ("This is free software with ABSOLUTELY NO WARRANTY.\n") ;
printf ("For details type: %s -warranty\n", argv [0]) ;
printf ("\n") ;
piBoardId (&model, &rev, &mem, &maker, &overVolted) ;
if (model == PI_MODEL_UNKNOWN)
{
printf ("Your Raspberry Pi has an unknown model type. Please report this to\n") ;
printf (" projects@drogon.net\n") ;
BoardHardwareInfo* retBoardInfo;
int ret = getBoardType(&retBoardInfo);
if (ret >= 0) {
if (retBoardInfo->boardTypeId > ALLWINNER_BASE && retBoardInfo->boardTypeId <= ALLWINNER_MAX
&& retBoardInfo->boardTypeId != NanoPi_A64) {
printf ("NanoPi Details:\n") ;
printf (" Type: %s, Revision: %d, Maker: FriednlyELEC\n\n",
retBoardInfo->boardDisplayName, retBoardInfo->kernelRevision) ;
} else {
if (retBoardInfo->boardTypeId == NanoPC_T3) {
printf(
"This NanoPi-T3 is only supported GPIO input and GPIO outpu. "
"Please Careful! ");
} 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") ;
}
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 ;
}

View File

@ -42,6 +42,8 @@ extern int wpMode ;
# define FALSE (1==2)
#endif
#define DEBUG_READALL 0
/*
* doReadallExternal:
* A relatively crude way to read the pins on an external device.
@ -80,42 +82,9 @@ static char *alts [] =
"IN", "OUT", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "OFF"
} ;
/* guenter static int physToWpi [64] =
{
-1, // 0
-1, -1, // 1, 2
8, -1,
9, -1,
7, 15,
-1, 16,
0, 1,
2, -1,
3, 4,
-1, 5,
12, -1,
13, 6,
14, 10,
-1, 11, // 25, 26
30, 31, // Actually I2C, but not used
21, -1,
22, 26,
23, -1,
24, 27,
25, 28,
-1, 29,
-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 */
#define MAX_PIN_COUNT 74
// guenter anfang
static int physToWpi [64] =
static int physToWpi_m1 [MAX_PIN_COUNT] =
{
-1, // 0
-1, -1, // 1, 2
@ -138,48 +107,15 @@ static int physToWpi [64] =
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
-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,
} ;
//guenter ende
/* guenter static char *physNames [64] =
{
NULL,
" 3.3v", "5v ",
" SDA.1", "5V ",
" SCL.1", "0v ",
"GPIO. 7", "TxD ",
" 0v", "RxD ",
"GPIO. 0", "GPIO. 1",
"GPIO. 2", "0v ",
"GPIO. 3", "GPIO. 4",
" 3.3v", "GPIO. 5",
" MOSI", "0v ",
" MISO", "GPIO. 6",
" SCLK", "CE0 ",
" 0v", "CE1 ",
" SDA.0", "SCL.0 ",
"GPIO.21", "0v ",
"GPIO.22", "GPIO.26",
"GPIO.23", "0v ",
"GPIO.24", "GPIO.27",
"GPIO.25", "GPIO.28",
" 0v", "GPIO.29",
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
"GPIO.17", "GPIO.18",
"GPIO.19", "GPIO.20",
NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
} ; guenter ende */
//guenter orange pi
static char *physNames [64] =
static char *physNames_m1 [MAX_PIN_COUNT] =
{
NULL,
@ -202,19 +138,455 @@ static char *physNames [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
} ;
// guenter ende
static int physToWpi_neo [MAX_PIN_COUNT] =
{
-1, // 0
/* 24pins */
-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
/* 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,
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
} ;
static char *physNames_neo [MAX_PIN_COUNT] =
{
NULL,
/* 24 Pin */
" 3.3V", "5V ",
" GPIOA12", "5V ",
" GPIOA11", "0v ",
" GPIOG11", "GPIOG6 ",
" 0v", "GPIOG7 ",
" GPIOA0", "GPIOA6 ",
" GPIOA2", "0v ",
" GPIOA3", "GPIOG8 ",
" 3.3v", "GPIOG9 ",
" GPIOC0", "0v ",
" GPIOC1", "GPIOA1 ",
" GPIOC2", "GPIOC3 ",
/* 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,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, //63
//64 ~ 73
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
} ;
static int physToWpi_duo [MAX_PIN_COUNT] =
{
-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, 18, //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,
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
} ;
static char *physNames_duo [MAX_PIN_COUNT] =
{
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", "GPIOL11 ",
" 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, //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, //71, 72
NULL //73
} ;
static int physToWpi_duo2 [MAX_PIN_COUNT] =
{
-1, // 0
-1, 15, // 1, 2
-1, 14, // 3, 4
-1, -1, // 5, 6
-1, 13, // 7, 8
18, 12, // 9, 10
16, 3, //11, 12
-1, 2, //13, 14
-1, 0, //15, 16
-1, 7, //17, 18
-1, 9, //19, 20
-1, 8, //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
-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,
} ;
static char *physNames_duo2 [MAX_PIN_COUNT] =
{
NULL,
// 32 Pin
" 5v", "GPIOA5 ",
" 5v", "GPIOA4 ",
" 3.3v", "0v ",
" 0v", "GPIOA11 ",
" GPIOL11", "GPIOA12 ",
" GPIOG11", "GPIOA13 ",
" USB-DM3", "GPIOA14 ", //13, 14
" USB-DP3", "GPIOA16 ",
" USB-DM2", "GPIOA15 ",
" USB-DP2", "GPIOG7 ",
" EPhyRXN", "GPIOG6 ",
" EPhyRXP", "CVBS ",
" EPhyTXN", "LineOutL", //25, 26
" EPhyTXP", "LineOutR",
"EPhyLinK", "MIC_P ",
" EPhySPD", "MIC_N ",
/* ---------nanopi duo end----------- */
NULL, NULL,
NULL, NULL,
/* 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, //71, 72
NULL //73
} ;
static int physToWpi_t3 [MAX_PIN_COUNT] =
{
-1, // 0
-1, -1, // 1, 2
3, 4, // 3, 4
-1, -1, // 5, 6
7, 8, // 7, 8
9, 10, // 9, 10
11, 12, //11, 12
13, 14, //13, 14
15, 16, //15, 16
17, 18, //17, 18
19, 20, //19, 20
21, 22, //21, 22
23, 24, //23, 24
25, -1, //25, 26
27, -1, //27, 28
-1, -1, //29, 30
-1, -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,
/* 64~73 */
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
} ;
static char *physNames_t3 [MAX_PIN_COUNT] =
{
NULL,
// 32 Pin
" 3.3v", "0v ",
" GPIOD20", "GPIOD16 ",
"I2C0_SCL", "I2C0_SDA",
" GPIOC31", "GPIOD0 ",
" GPIOC29", "GPIOC30 ",
" GPIOD21", "GPIOD17 ",
" GPIOB29", "GPIOB28 ", //13, 14
" GPIOB31", "GPIOB30 ",
" GPIOC4", "GPIOC7 ",
" GPIOC8", "GPIOC24 ",
" GPIOC28", "GPIOB26 ",
" GPIOD1", "GPIOD8 ",
" GPIOC13", "AliGPIO3", //25, 26
" GPIOC14", "AliGPIO5",
" 5v", "0v ",
/* ---------nanopc t3 end----------- */
NULL, NULL,
NULL, NULL,
NULL, NULL,
/* 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, //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
} ;
/*
@ -224,9 +596,33 @@ static char *physNames [64] =
*********************************************************************************
*/
static void readallPhys (int physPin, int pair)
static void readallPhys (int faBoardId, int physPin, int pair)
{
int pin ;
int *physToWpi;
char **physNames;
if (faBoardId == NanoPi_M1 || faBoardId == NanoPi_K1_Plus || faBoardId == NanoPi_M1_Plus || faBoardId == NanoPi_M1_Plus2) {
physToWpi = physToWpi_m1;
physNames = physNames_m1;
} else if (faBoardId == NanoPi_NEO || faBoardId == NanoPi_NEO_Air || faBoardId == NanoPi_NEO2 || faBoardId == NanoPi_NEO_Plus2) {
physToWpi = physToWpi_neo;
physNames = physNames_neo;
} else if (faBoardId == NanoPi_Duo) {
physToWpi = physToWpi_duo;
physNames = physNames_duo;
} else if (faBoardId == NanoPi_Duo2) {
physToWpi = physToWpi_duo2;
physNames = physNames_duo2;
} else if (faBoardId == NanoPi_NEO_Core || faBoardId == NanoPi_NEO_Core2) {
physToWpi = physToWpi_neocore;
physNames = physNames_neocore;
} else if (faBoardId == NanoPC_T3) {
physToWpi = physToWpi_t3;
physNames = physNames_t3;
} else {
return ;
}
if (physPinToGpio (physPin) == -1)
printf (" | | ") ;
@ -239,15 +635,25 @@ static void readallPhys (int physPin, int pair)
printf (" | | ") ;
else
{
/**/ if (wpMode == WPI_MODE_GPIO)
pin = physPinToGpio (physPin) ;
else if (wpMode == WPI_MODE_PHYS)
pin = physPin ;
else
pin = physToWpi [physPin] ;
if (wpMode == WPI_MODE_GPIO) {
// printf("#### WPI_MODE_GPIO\n");
pin = physPinToGpio (physPin) ;
} else if (wpMode == WPI_MODE_PHYS) {
// printf("#### WPI_MODE_PHYS\n");
pin = physPin ;
} else {
// printf("#### Unknow Mode, physPin=%d, physToWpi [physPin] =%d\n", physPin, physToWpi [physPin]);
pin = physToWpi [physPin] ;
}
printf (" | %4s", alts [getAlt (pin)]) ;
printf (" | %d", digitalRead (pin)) ;
int alt = getAltSilence (pin);
if (alt >= 0) {
printf (" | %4s", alts [alt]) ;
} else {
printf (" | ") ;
}
printf (" | %d", digitalReadSilence (pin)) ;
}
// Pin numbers:
@ -257,29 +663,40 @@ static void readallPhys (int physPin, int pair)
printf (" |\n") ;
return;
}
++physPin ;
printf (" || %-2d", physPin) ;
// Same, reversed
if (physToWpi [physPin] == -1)
printf (" | | ") ;
else
{
/**/ if (wpMode == WPI_MODE_GPIO)
pin = physPinToGpio (physPin) ;
else if (wpMode == WPI_MODE_PHYS)
pin = physPin ;
else
pin = physToWpi [physPin] ;
if (wpMode == WPI_MODE_GPIO) {
// printf("#### WPI_MODE_GPIO\n");
pin = physPinToGpio (physPin) ;
} else if (wpMode == WPI_MODE_PHYS) {
// printf("#### WPI_MODE_PHYS\n");
pin = physPin ;
} else {
// printf("#### Unknow Mode, physPin=%d, physToWpi [physPin] =%d\n", physPin, physToWpi [physPin]);
pin = physToWpi [physPin] ;
}
printf (" | %d", digitalRead (pin)) ;
printf (" | %-4s", alts [getAlt (pin)]) ;
printf (" | %d", digitalReadSilence (pin)) ;
int alt = getAltSilence (pin);
if (alt >= 0) {
printf (" | %4s", alts [alt]) ;
} else {
printf (" | ") ;
}
}
printf (" | %-5s", physNames [physPin]) ;
if (physToWpi [physPin] == -1)
if (physToWpi[physPin] == -1)
printf (" | | ") ;
else
printf (" | %-3d | %-3d", physToWpi [physPin], physPinToGpio (physPin)) ;
@ -287,46 +704,217 @@ static void readallPhys (int physPin, int pair)
printf (" |\n") ;
}
//guenter
void NanoPiReadAll(void)
static void debugReadallPhys (int faBoardId, int physPin)
{
int pin ;
int *physToWpi;
char **physNames;
printf (" +-----+-----+----------+------+---+-NanoPI M1+---+------+----------+-----+-----+\n") ;
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf (" +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+\n") ;
for (pin = 1 ; pin <= 40 ; pin += 2)
readallPhys (pin, 1) ;
printf (" +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+\n") ;
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf (" +-----+-----+----------+------+---+-NanoPI M1+---+------+----------+-----+-----+\n") ;
printf ("\n");
printf (" +-----+----NanoPI M1 Debug UART---+----+\n") ;
printf (" | BCM | wPi | Name | Mode | V | Ph |\n") ;
printf (" +-----+-----+----------+------+---+----+\n") ;
for (pin = 41 ; pin < 45 ; pin++) {
readallPhys (pin, 0) ;
if (faBoardId == NanoPi_M1 || faBoardId == NanoPi_K1_Plus || faBoardId == NanoPi_M1_Plus || faBoardId == NanoPi_M1_Plus2) {
physToWpi = physToWpi_m1;
physNames = physNames_m1;
} else if (faBoardId == NanoPi_NEO || faBoardId == NanoPi_NEO_Air || faBoardId == NanoPi_NEO2 || faBoardId == NanoPi_NEO_Plus2) {
physToWpi = physToWpi_neo;
physNames = physNames_neo;
} else if (faBoardId == NanoPi_Duo) {
physToWpi = physToWpi_duo;
physNames = physNames_duo;
} else if (faBoardId == NanoPi_Duo2) {
physToWpi = physToWpi_duo2;
physNames = physNames_duo2;
} else if (faBoardId == NanoPi_NEO_Core || faBoardId == NanoPi_NEO_Core2) {
physToWpi = physToWpi_neocore;
physNames = physNames_neocore;
} else if (faBoardId == NanoPC_T3) {
physToWpi = physToWpi_t3;
physNames = physNames_t3;
} else {
return ;
}
printf("## physPin: %d, %s\n", physPin, physNames [physPin]);
if (physPinToGpio (physPin) == -1)
printf("\tnot gpio\n");
else
printf("\tphysPinToGpio=%d, physToWpi=%d\n", physPinToGpio (physPin), physToWpi [physPin]);
if (physToWpi [physPin] == -1) {
printf("\t\tnot Wpi pin\n");
} else {
if (wpMode == WPI_MODE_GPIO) {
pin = physPinToGpio (physPin) ;
printf("\t\tWPI_MODE_GPIO, physPinToGpio (physPin) = %d\n", pin);
} else if (wpMode == WPI_MODE_PHYS) {
pin = physPin ;
printf("\t\tWPI_MODE_PHYS, pin = physPin = %d\n", pin);
} else {
printf("\t\tUnknow Mode, physPin=%d, physToWpi [physPin] =%d\n", physPin, physToWpi [physPin]);
pin = physToWpi [physPin] ;
}
printf ("\t\t\talts = %4s\n", alts [getAltSilence (pin)]) ;
printf ("\t\t\tdigitalRead = %d\n", digitalReadSilence (pin)) ;
}
}
void NanoPiReadAll()
{
int pin ;
BoardHardwareInfo* retBoardInfo;
int ret = getBoardType(&retBoardInfo);
if (ret >= 0) {
if (retBoardInfo->boardTypeId > ALLWINNER_BASE
&& retBoardInfo->boardTypeId <= ALLWINNER_MAX
&& retBoardInfo->boardTypeId != NanoPi_A64) {
// nothing to do.
} else if(retBoardInfo->boardTypeId == NanoPC_T3) {
printf ("This NanoPC-T3 is only supported GPIO input and GPIO out. \n") ;
printf("Please becareful to use this !!! \n");
} else {
printf ("This NanoPi model is currently not supported. \n") ;
printf ("This NanoPi's boardTypeId is %d .\n",retBoardInfo->boardTypeId);
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 ;
}
int pinCount;
if (retBoardInfo->boardTypeId == NanoPi_M1
|| retBoardInfo->boardTypeId == NanoPi_K1_Plus
|| retBoardInfo->boardTypeId == NanoPi_M1_Plus
|| retBoardInfo->boardTypeId == NanoPi_M1_Plus2) {
pinCount = 40;
} else if (retBoardInfo->boardTypeId == NanoPi_NEO
|| retBoardInfo->boardTypeId == NanoPi_NEO_Air
|| retBoardInfo->boardTypeId == NanoPi_NEO2
|| retBoardInfo->boardTypeId == NanoPi_NEO_Plus2
|| retBoardInfo->boardTypeId == NanoPi_NEO_Core
|| retBoardInfo->boardTypeId == NanoPi_NEO_Core2
) {
pinCount = 24;
} else if (retBoardInfo->boardTypeId == NanoPi_Duo
|| retBoardInfo->boardTypeId == NanoPi_Duo2) {
pinCount = 32;
} else if (retBoardInfo->boardTypeId == NanoPC_T3) {
pinCount = 30;
} else {
printf ("This NanoPi model(id: %d) is currently not supported. \n", retBoardInfo->boardTypeId) ;
return ;
}
if (getenv("WIRINGPI_DEBUG") != NULL)
printf("This pinCount num is %d .\nDEBUG_READALL is %d.\nwpMode is %d .\n",
pinCount, DEBUG_READALL, wpMode);
if (DEBUG_READALL) {
printf (" +-----+-----+----------+------+---+-%s--+------+----------+-----+-----+\n", retBoardInfo->boardDisplayName) ;
for (pin = 1 ; pin <= pinCount ; pin++) {
debugReadallPhys (retBoardInfo->boardTypeId, pin) ;
}
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") ;
for (pin = 1 ; pin <= pinCount ; pin += 2)
readallPhys (retBoardInfo->boardTypeId, pin, 1) ;
printf (" +-----+-----+----------+------+---+----++----+---+------+----------+-----+-----+\n") ;
printf (" | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |\n") ;
printf (" +-----+-----+----------+------+---+-%s--+------+----------+-----+-----+\n", retBoardInfo->boardDisplayName) ;
printf ("\n");
/* Print Second 1 ~ 12/24 pins */
if (retBoardInfo->boardTypeId == NanoPi_M1
|| retBoardInfo->boardTypeId == NanoPi_K1_Plus
|| retBoardInfo->boardTypeId == NanoPi_M1_Plus
|| retBoardInfo->boardTypeId == NanoPi_M1_Plus2) {
// nothing to do.
} else if (retBoardInfo->boardTypeId == NanoPi_NEO
|| retBoardInfo->boardTypeId == NanoPi_NEO_Air
|| retBoardInfo->boardTypeId == NanoPi_NEO2
|| retBoardInfo->boardTypeId == 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 (retBoardInfo->boardTypeId, pin, 0) ;
}
printf (" +-----+-----+----------+------+---+----+\n") ;
printf ("\n");
} else if (retBoardInfo->boardTypeId == NanoPi_Duo
|| retBoardInfo->boardTypeId == NanoPi_Duo2
|| retBoardInfo->boardTypeId == NanoPi_NEO_Core
|| retBoardInfo->boardTypeId == NanoPi_NEO_Core2) {
// nothing to do.
}
if (retBoardInfo->boardTypeId == NanoPi_NEO_Core
|| retBoardInfo->boardTypeId == 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 (retBoardInfo->boardTypeId, 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 (retBoardInfo->boardTypeId, 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 (retBoardInfo->boardTypeId == NanoPi_M1
|| retBoardInfo->boardTypeId == NanoPi_K1_Plus
|| retBoardInfo->boardTypeId == NanoPi_M1_Plus
|| retBoardInfo->boardTypeId == NanoPi_M1_Plus2) {
printf (" +-----+----%s Debug UART-+----+\n", retBoardInfo->boardDisplayName) ;
printf (" | BCM | wPi | Name | Mode | V | Ph |\n") ;
printf (" +-----+-----+----------+------+---+----+\n") ;
for (pin = 41 ; pin < 45 ; pin++) {
readallPhys (retBoardInfo->boardTypeId, pin, 0) ;
}
printf (" +-----+-----+----------+------+---+----+\n") ;
printf ("\n");
} else if (retBoardInfo->boardTypeId == NanoPi_NEO
|| retBoardInfo->boardTypeId == NanoPi_NEO_Air
|| retBoardInfo->boardTypeId == NanoPi_NEO2
|| retBoardInfo->boardTypeId == 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 (retBoardInfo->boardTypeId, pin, 0) ;
}
printf (" +-----+-----+----------+------+---+----+\n") ;
printf ("\n");
} else if (retBoardInfo->boardTypeId == NanoPi_Duo
|| retBoardInfo->boardTypeId == NanoPi_Duo2
|| retBoardInfo->boardTypeId == NanoPi_NEO_Core
|| retBoardInfo->boardTypeId == NanoPi_NEO_Core2) {
// nothing to do.
}
printf (" +-----+-----+----------+------+---+----+\n") ;
}
//guenter ende
void doReadall (void)
{
int model, rev, mem, maker, overVolted ;
if (wiringPiNodes != NULL) // External readall
if (wiringPiNodes != NULL) // External readall
{
doReadallExternal () ;
return ;
}
piBoardId (&model, &rev, &mem, &maker, &overVolted) ;
if (model == PI_MODEL_M1) {
NanoPiReadAll();
}
else
printf ("Oops - unable to determine board type... model: %d\n", model) ;
NanoPiReadAll();
}

View File

@ -36,7 +36,7 @@ DEBUG = -O2
CC = gcc
INCLUDE = -I.
DEFS = -D_GNU_SOURCE
CFLAGS = $(DEBUG) $(DEFS) -Wformat=2 -Wall -Winline $(INCLUDE) -pipe -fPIC
CFLAGS = $(DEBUG) $(DEFS) -Wformat=2 -Wall -Winline $(INCLUDE) -pipe -fPIC -Wpointer-to-int-cast
LIBS =
@ -47,7 +47,7 @@ SRC = wiringPi.c \
wiringSerial.c wiringShift.c \
piHiPri.c piThread.c \
wiringPiSPI.c wiringPiI2C.c \
softPwm.c softTone.c softServo.c \
softPwm.c softTone.c softServo.c \
mcp23008.c mcp23016.c mcp23017.c \
mcp23s08.c mcp23s17.c \
sr595.c \
@ -55,7 +55,8 @@ SRC = wiringPi.c \
mcp3002.c mcp3004.c mcp4802.c mcp3422.c \
max31855.c max5322.c \
sn3218.c \
drcSerial.c
drcSerial.c \
boardtype_friendlyelec.c
OBJ = $(SRC:.c=.o)
@ -116,6 +117,7 @@ install-headers:
@install -m 0644 pcf8574.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 pcf8591.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 sn3218.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 boardtype_friendlyelec.h $(DESTDIR)$(PREFIX)/include
.PHONEY: install
install: $(DYNAMIC) install-headers
@ -135,6 +137,7 @@ install-static: $(STATIC) install-headers
uninstall:
@echo "[UnInstall]"
@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/wiringShift.h
@rm -f $(DESTDIR)$(PREFIX)/include/softPwm.h
@ -169,6 +172,7 @@ depend:
# DO NOT DELETE
wiringPi.o: softPwm.h softTone.h wiringPi.h
boardtype_friendlyelec.o: boardtype_friendlyelec.h
wiringSerial.o: wiringSerial.h
wiringShift.o: wiringPi.h wiringShift.h
piHiPri.o: wiringPi.h

View File

@ -0,0 +1,311 @@
#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_M3B, "NanoPi-M3B", ""},
{"nanopi3", 3, Smart6818, "Smart6818", ""},
{"nanopi3", 4, NanoPC_T3T, "NanoPC-T3T", ""},
{"nanopi3", 5, NanoPi_Fire3, "NanoPi-Fire3", ""},
{"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)"},
{"sun8i", 0, NanoPi_K1, "NanoPi-K1", "6(0)"},
{"sun8i", 0, NanoPi_Hero, "NanoPi-Hero", "7(0)"},
{"sun8i", 0, NanoPi_Duo2, "NanoPi-Duo2", "8(0)"},
{"sun8i", 0, NanoPi_R1, "NanoPi-R1", "9(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)"},
{"Allwinnersun8iFamily", 0, NanoPi_K1, "NanoPi-K1", "6(0)"},
{"Allwinnersun8iFamily", 0, NanoPi_Hero, "NanoPi-Hero", "7(0)"},
{"Allwinnersun8iFamily", 0, NanoPi_Duo2, "NanoPi-Duo2", "8(0)"},
{"Allwinnersun8iFamily", 0, NanoPi_R1, "NanoPi-R1", "9(0)"},
// a64
// {"sun50iw1p1", 0, NanoPi_A64, "NanoPi-A64", "0"},
// armbian+Neo2
{"sun50iw1p1", 4, NanoPi_NEO2, "NanoPi-NEO2", "1(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)"},
{"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", ""},
//t4
{"nanopi4", 0, NanoPC_T4, "NanoPC-T4", ""},
{"nanopi4", 1, NanoPi_M4, "NanoPi-M4", ""},
{"nanopi4", 2, NanoPC_T4, "NanoPC-T4", ""},
{"nanopi4", 4, NanoPi_NEO4, "NanoPi-NEO4", ""},
};
static int getFieldValueInCpuInfo(char* hardware, int hardwareMaxLen, char* revision, int revisionMaxLen)
{
unsigned long n, i, j;
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)) {
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);
#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;
}
}
}
}
fclose(f);
return isGotHardware + isGotRevision;
}
static int getAllwinnerBoardID(char* boardId, int boardIdMaxLen )
{
unsigned long 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("/etc/sys_info", "r"))) {
LOGE("open /etc/sys_info 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{{ enum, start compare[%d]: %s <--> %s\n", i, gAllBoardHardwareInfo[i].kernelHardware, hardware);
if (strncasecmp(gAllBoardHardwareInfo[i].kernelHardware,
hardware,
strlen(gAllBoardHardwareInfo[i].kernelHardware)) == 0) {
//LOGD("\t\tMATCH %s\n", hardware);
if (strncasecmp(gAllBoardHardwareInfo[i].allwinnerBoardID,
allwinnerBoardID,
strlen(gAllBoardHardwareInfo[i].allwinnerBoardID)) == 0) {
if (retBoardInfo != 0) {
*retBoardInfo = &gAllBoardHardwareInfo[i];
}
//LOGD("\t\t\tMATCH board id: %s\n", allwinnerBoardID);
return gAllBoardHardwareInfo[i].boardTypeId;
} else {
//LOGD("\t\t\tnot match board id: %s\n", allwinnerBoardID);
}
} else {
//LOGD("\t\tnot match %s\n", hardware);
}
//LOGD("\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);
long 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;
}
*/

View File

@ -0,0 +1,86 @@
#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_M3B (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
//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 NanoPi_NEO_Core2 (ALLWINNER_BASE+11)
#define NanoPi_K1 (ALLWINNER_BASE+12)
#define NanoPi_K1_Plus (ALLWINNER_BASE+13)
#define NanoPi_Hero (ALLWINNER_BASE+14)
#define NanoPi_Duo2 (ALLWINNER_BASE+15)
#define NanoPi_R1 (ALLWINNER_BASE+16)
#define ALLWINNER_MAX NanoPi_R1
//amlogic
#define AMLOGIC_BASE (8000)
#define NanoPi_K2 (AMLOGIC_BASE+1)
//rk3399
#define RK3399_BASE (9000)
#define NanoPC_T4 (RK3399_BASE+1)
#define NanoPi_M4 (RK3399_BASE+2)
#define NanoPi_NEO4 (RK3399_BASE+3)
extern int getBoardType(BoardHardwareInfo** retBoardInfo);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -72,7 +72,6 @@
// Intended for the GPIO program Use at your own risk.
#define PI_MODEL_UNKNOWN 0
#define PI_MODEL_M1 1
#define PI_VERSION_UNKNOWN 0
#define PI_VERSION_1 1
@ -84,17 +83,12 @@
#define PI_MAKER_EGOMAN 1
#define PI_MAKER_SONY 2
#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
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.
// Threads
#define PI_THREAD(X) void *X (void *dummy)
@ -148,11 +142,7 @@ extern "C" {
// Data
//extern const char *piModelNames [] ;
//extern const char *piRevisionNames[] ;
// Internal
extern int wiringPiFailure (int fatal, const char *message, ...) ;
// Core wiringPi functions
@ -219,6 +209,8 @@ extern void delayMicroseconds (unsigned int howLong) ;
extern unsigned int millis (void) ;
extern unsigned int micros (void) ;
#include "boardtype_friendlyelec.h"
#ifdef __cplusplus
}
#endif

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