wiringpi 2.0.0 → 2.32.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/wiringpi/WiringPi/devLib/maxdetect.c +100 -27
- data/ext/wiringpi/WiringPi/devLib/maxdetect.h +0 -0
- data/ext/wiringpi/WiringPi/devLib/scrollPhat.c +430 -0
- data/ext/wiringpi/WiringPi/devLib/scrollPhat.h +39 -0
- data/ext/wiringpi/WiringPi/devLib/scrollPhatFont.h +544 -0
- data/ext/wiringpi/WiringPi/examples/PiFace/ladder.c +0 -0
- data/ext/wiringpi/WiringPi/examples/max31855.c +60 -0
- data/ext/wiringpi/WiringPi/examples/rht03.c +32 -15
- data/ext/wiringpi/WiringPi/examples/scrollPhat/scphat.c +230 -0
- data/ext/wiringpi/WiringPi/examples/scrollPhat/test.c +115 -0
- data/ext/wiringpi/WiringPi/gpio/gpio.c +88 -37
- data/ext/wiringpi/WiringPi/gpio/readall.c +41 -9
- data/ext/wiringpi/WiringPi/gpio/version.h +1 -1
- data/ext/wiringpi/WiringPi/wiringPi/ads1115.c +293 -0
- data/ext/wiringpi/WiringPi/wiringPi/ads1115.h +55 -0
- data/ext/wiringpi/WiringPi/wiringPi/drcSerial.c +4 -9
- data/ext/wiringpi/WiringPi/wiringPi/max31855.c +41 -23
- data/ext/wiringpi/WiringPi/wiringPi/max5322.c +2 -2
- data/ext/wiringpi/WiringPi/wiringPi/mcp23008.c +2 -2
- data/ext/wiringpi/WiringPi/wiringPi/mcp23016.c +2 -2
- data/ext/wiringpi/WiringPi/wiringPi/mcp23017.c +2 -2
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s08.c +3 -4
- data/ext/wiringpi/WiringPi/wiringPi/mcp23s17.c +3 -4
- data/ext/wiringpi/WiringPi/wiringPi/mcp3002.c +2 -2
- data/ext/wiringpi/WiringPi/wiringPi/mcp3004.c +2 -2
- data/ext/wiringpi/WiringPi/wiringPi/mcp3422.c +33 -18
- data/ext/wiringpi/WiringPi/wiringPi/mcp3422.h +6 -6
- data/ext/wiringpi/WiringPi/wiringPi/mcp4802.c +2 -2
- data/ext/wiringpi/WiringPi/wiringPi/pcf8574.c +2 -2
- data/ext/wiringpi/WiringPi/wiringPi/pcf8591.c +2 -2
- data/ext/wiringpi/WiringPi/wiringPi/sn3218.c +2 -2
- data/ext/wiringpi/WiringPi/wiringPi/sr595.c +1 -1
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.c +418 -132
- data/ext/wiringpi/WiringPi/wiringPi/wiringPi.h +47 -37
- data/ext/wiringpi/WiringPi/wiringPi/wpiExtensions.c +38 -9
- data/ext/wiringpi/extconf.rb +26 -2
- data/ext/wiringpi/wiringpi_wrap.c +3456 -981
- metadata +9 -1
@@ -1,6 +1,6 @@
|
|
1
1
|
/*
|
2
|
-
* mcp3422.
|
3
|
-
* Extend wiringPi with the MCP3422 I2C ADC chip
|
2
|
+
* mcp3422.h:
|
3
|
+
* Extend wiringPi with the MCP3422/3/4 I2C ADC chip
|
4
4
|
***********************************************************************
|
5
5
|
* This file is part of wiringPi:
|
6
6
|
* https://projects.drogon.net/raspberry-pi/wiringpi/
|
@@ -21,10 +21,10 @@
|
|
21
21
|
***********************************************************************
|
22
22
|
*/
|
23
23
|
|
24
|
-
#define
|
25
|
-
#define
|
26
|
-
#define
|
27
|
-
#define
|
24
|
+
#define MCP3422_SR_240 0
|
25
|
+
#define MCP3422_SR_60 1
|
26
|
+
#define MCP3422_SR_15 2
|
27
|
+
#define MCP3422_SR_3_75 3
|
28
28
|
|
29
29
|
#define MCP3422_GAIN_1 0
|
30
30
|
#define MCP3422_GAIN_2 1
|
@@ -65,12 +65,12 @@ int mcp4802Setup (const int pinBase, int spiChannel)
|
|
65
65
|
struct wiringPiNodeStruct *node ;
|
66
66
|
|
67
67
|
if (wiringPiSPISetup (spiChannel, 1000000) < 0)
|
68
|
-
return
|
68
|
+
return FALSE ;
|
69
69
|
|
70
70
|
node = wiringPiNewNode (pinBase, 2) ;
|
71
71
|
|
72
72
|
node->fd = spiChannel ;
|
73
73
|
node->analogWrite = myAnalogWrite ;
|
74
74
|
|
75
|
-
return
|
75
|
+
return TRUE ;
|
76
76
|
}
|
@@ -112,7 +112,7 @@ int pcf8574Setup (const int pinBase, const int i2cAddress)
|
|
112
112
|
struct wiringPiNodeStruct *node ;
|
113
113
|
|
114
114
|
if ((fd = wiringPiI2CSetup (i2cAddress)) < 0)
|
115
|
-
return
|
115
|
+
return FALSE ;
|
116
116
|
|
117
117
|
node = wiringPiNewNode (pinBase, 8) ;
|
118
118
|
|
@@ -122,5 +122,5 @@ int pcf8574Setup (const int pinBase, const int i2cAddress)
|
|
122
122
|
node->digitalWrite = myDigitalWrite ;
|
123
123
|
node->data2 = wiringPiI2CRead (fd) ;
|
124
124
|
|
125
|
-
return
|
125
|
+
return TRUE ;
|
126
126
|
}
|
@@ -78,7 +78,7 @@ int pcf8591Setup (const int pinBase, const int i2cAddress)
|
|
78
78
|
struct wiringPiNodeStruct *node ;
|
79
79
|
|
80
80
|
if ((fd = wiringPiI2CSetup (i2cAddress)) < 0)
|
81
|
-
return
|
81
|
+
return FALSE ;
|
82
82
|
|
83
83
|
node = wiringPiNewNode (pinBase, 4) ;
|
84
84
|
|
@@ -86,5 +86,5 @@ int pcf8591Setup (const int pinBase, const int i2cAddress)
|
|
86
86
|
node->analogRead = myAnalogRead ;
|
87
87
|
node->analogWrite = myAnalogWrite ;
|
88
88
|
|
89
|
-
return
|
89
|
+
return TRUE ;
|
90
90
|
}
|
@@ -55,7 +55,7 @@ int sn3218Setup (const int pinBase)
|
|
55
55
|
struct wiringPiNodeStruct *node ;
|
56
56
|
|
57
57
|
if ((fd = wiringPiI2CSetup (0x54)) < 0)
|
58
|
-
return
|
58
|
+
return FALSE ;
|
59
59
|
|
60
60
|
// Setup the chip - initialise all 18 LEDs to off
|
61
61
|
|
@@ -71,5 +71,5 @@ int sn3218Setup (const int pinBase)
|
|
71
71
|
node->fd = fd ;
|
72
72
|
node->analogWrite = myAnalogWrite ;
|
73
73
|
|
74
|
-
return
|
74
|
+
return TRUE ;
|
75
75
|
}
|
@@ -69,21 +69,18 @@
|
|
69
69
|
#include <sys/stat.h>
|
70
70
|
#include <sys/wait.h>
|
71
71
|
#include <sys/ioctl.h>
|
72
|
+
#include <asm/ioctl.h>
|
72
73
|
|
73
74
|
#include "softPwm.h"
|
74
75
|
#include "softTone.h"
|
75
76
|
|
76
77
|
#include "wiringPi.h"
|
77
78
|
|
78
|
-
#ifndef TRUE
|
79
|
-
#define TRUE (1==1)
|
80
|
-
#define FALSE (1==2)
|
81
|
-
#endif
|
82
|
-
|
83
79
|
// Environment Variables
|
84
80
|
|
85
81
|
#define ENV_DEBUG "WIRINGPI_DEBUG"
|
86
82
|
#define ENV_CODES "WIRINGPI_CODES"
|
83
|
+
#define ENV_GPIOMEM "WIRINGPI_GPIOMEM"
|
87
84
|
|
88
85
|
|
89
86
|
// Mask for the bottom 64 pins which belong to the Raspberry Pi
|
@@ -130,13 +127,16 @@ struct wiringPiNodeStruct *wiringPiNodes = NULL ;
|
|
130
127
|
// Access from ARM Running Linux
|
131
128
|
// Taken from Gert/Doms code. Some of this is not in the manual
|
132
129
|
// that I can find )-:
|
130
|
+
//
|
131
|
+
// Updates in September 2015 - all now static variables (and apologies for the caps)
|
132
|
+
// due to the Pi v2 and the new /dev/gpiomem interface
|
133
133
|
|
134
|
-
static volatile unsigned int
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
134
|
+
static volatile unsigned int RASPBERRY_PI_PERI_BASE ;
|
135
|
+
static volatile unsigned int GPIO_PADS ;
|
136
|
+
static volatile unsigned int GPIO_CLOCK_BASE ;
|
137
|
+
static volatile unsigned int GPIO_BASE ;
|
138
|
+
static volatile unsigned int GPIO_TIMER ;
|
139
|
+
static volatile unsigned int GPIO_PWM ;
|
140
140
|
|
141
141
|
#define PAGE_SIZE (4*1024)
|
142
142
|
#define BLOCK_SIZE (4*1024)
|
@@ -205,35 +205,77 @@ static volatile uint32_t *timerIrqRaw ;
|
|
205
205
|
|
206
206
|
static int piModel2 = FALSE ;
|
207
207
|
|
208
|
-
const char *piModelNames [
|
208
|
+
const char *piModelNames [16] =
|
209
209
|
{
|
210
|
-
"
|
211
|
-
"Model
|
212
|
-
"Model
|
213
|
-
"Model B+",
|
214
|
-
"
|
215
|
-
"
|
216
|
-
"
|
210
|
+
"Model A", // 0
|
211
|
+
"Model B", // 1
|
212
|
+
"Model A+", // 2
|
213
|
+
"Model B+", // 3
|
214
|
+
"Pi 2", // 4
|
215
|
+
"Alpha", // 5
|
216
|
+
"CM", // 6
|
217
|
+
"Unknown07", // 07
|
218
|
+
"Pi 3", // 08
|
219
|
+
"Pi Zero", // 09
|
220
|
+
"Unknown10", // 10
|
221
|
+
"Unknown11", // 11
|
222
|
+
"Unknown12", // 12
|
223
|
+
"Unknown13", // 13
|
224
|
+
"Unknown14", // 14
|
225
|
+
"Unknown15", // 15
|
217
226
|
} ;
|
218
227
|
|
219
|
-
const char *piRevisionNames [
|
228
|
+
const char *piRevisionNames [16] =
|
220
229
|
{
|
221
|
-
"
|
222
|
-
"
|
223
|
-
"
|
224
|
-
"
|
225
|
-
"
|
230
|
+
"00",
|
231
|
+
"01",
|
232
|
+
"02",
|
233
|
+
"03",
|
234
|
+
"04",
|
235
|
+
"05",
|
236
|
+
"06",
|
237
|
+
"07",
|
238
|
+
"08",
|
239
|
+
"09",
|
240
|
+
"10",
|
241
|
+
"11",
|
242
|
+
"12",
|
243
|
+
"13",
|
244
|
+
"14",
|
245
|
+
"15",
|
226
246
|
} ;
|
227
247
|
|
228
|
-
const char *piMakerNames [
|
248
|
+
const char *piMakerNames [16] =
|
229
249
|
{
|
230
|
-
"
|
231
|
-
"Egoman",
|
232
|
-
"
|
233
|
-
"
|
234
|
-
"
|
250
|
+
"Sony", // 0
|
251
|
+
"Egoman", // 1
|
252
|
+
"Embest", // 2
|
253
|
+
"Unknown", // 3
|
254
|
+
"Embest", // 4
|
255
|
+
"Unknown05", // 5
|
256
|
+
"Unknown06", // 6
|
257
|
+
"Unknown07", // 7
|
258
|
+
"Unknown08", // 8
|
259
|
+
"Unknown09", // 9
|
260
|
+
"Unknown10", // 10
|
261
|
+
"Unknown11", // 11
|
262
|
+
"Unknown12", // 12
|
263
|
+
"Unknown13", // 13
|
264
|
+
"Unknown14", // 14
|
265
|
+
"Unknown15", // 15
|
235
266
|
} ;
|
236
267
|
|
268
|
+
const int piMemorySize [8] =
|
269
|
+
{
|
270
|
+
256, // 0
|
271
|
+
512, // 1
|
272
|
+
1024, // 2
|
273
|
+
0, // 3
|
274
|
+
0, // 4
|
275
|
+
0, // 5
|
276
|
+
0, // 6
|
277
|
+
0, // 7
|
278
|
+
} ;
|
237
279
|
|
238
280
|
// Time for easy calculations
|
239
281
|
|
@@ -250,6 +292,10 @@ static pthread_mutex_t pinMutex ;
|
|
250
292
|
int wiringPiDebug = FALSE ;
|
251
293
|
int wiringPiReturnCodes = FALSE ;
|
252
294
|
|
295
|
+
// Use /dev/gpiomem ?
|
296
|
+
|
297
|
+
int wiringPiTryGpioMem = FALSE ;
|
298
|
+
|
253
299
|
// sysFds:
|
254
300
|
// Map a file descriptor from the /sys/class/gpio/gpioX/value
|
255
301
|
|
@@ -411,6 +457,7 @@ static uint8_t gpioToShift [] =
|
|
411
457
|
0,3,6,9,12,15,18,21,24,27,
|
412
458
|
0,3,6,9,12,15,18,21,24,27,
|
413
459
|
0,3,6,9,12,15,18,21,24,27,
|
460
|
+
0,3,6,9,12,15,18,21,24,27,
|
414
461
|
} ;
|
415
462
|
|
416
463
|
|
@@ -604,42 +651,20 @@ int wiringPiFailure (int fatal, const char *message, ...)
|
|
604
651
|
/*
|
605
652
|
* piBoardRev:
|
606
653
|
* Return a number representing the hardware revision of the board.
|
654
|
+
* This is not strictly the board revision but is used to check the
|
655
|
+
* layout of the GPIO connector - and there are 2 types that we are
|
656
|
+
* really interested in here. The very earliest Pi's and the
|
657
|
+
* ones that came after that which switched some pins ....
|
607
658
|
*
|
608
|
-
* Revision 1 really means the early Model B's.
|
659
|
+
* Revision 1 really means the early Model A and B's.
|
609
660
|
* Revision 2 is everything else - it covers the B, B+ and CM.
|
610
661
|
* ... and the Pi 2 - which is a B+ ++ ...
|
662
|
+
* ... and the Pi 0 - which is an A+ ...
|
611
663
|
*
|
612
|
-
*
|
613
|
-
*
|
614
|
-
*
|
615
|
-
*
|
616
|
-
* 0002 - Model B, Rev 1, 256MB, Egoman
|
617
|
-
* 0003 - Model B, Rev 1.1, 256MB, Egoman, Fuses/D14 removed.
|
618
|
-
* 0004 - Model B, Rev 2, 256MB, Sony
|
619
|
-
* 0005 - Model B, Rev 2, 256MB, Qisda
|
620
|
-
* 0006 - Model B, Rev 2, 256MB, Egoman
|
621
|
-
* 0007 - Model A, Rev 2, 256MB, Egoman
|
622
|
-
* 0008 - Model A, Rev 2, 256MB, Sony
|
623
|
-
* 0009 - Model A, Rev 2, 256MB, Qisda
|
624
|
-
* 000d - Model B, Rev 2, 512MB, Egoman
|
625
|
-
* 000e - Model B, Rev 2, 512MB, Sony
|
626
|
-
* 000f - Model B, Rev 2, 512MB, Qisda
|
627
|
-
* 0010 - Model B+, Rev 1.2, 512MB, Sony
|
628
|
-
* 0011 - Pi CM, Rev 1.2, 512MB, Sony
|
629
|
-
* 0012 - Model A+ Rev 1.2, 256MB, Sony
|
630
|
-
* 0014 - Pi CM, Rev 1.1, 512MB, Sony (Actual Revision might be different)
|
631
|
-
*
|
632
|
-
* For the Pi 2:
|
633
|
-
* 0010 - Model 2, Rev 1.1, Quad Core, 1GB, Sony
|
634
|
-
*
|
635
|
-
* A small thorn is the olde style overvolting - that will add in
|
636
|
-
* 1000000
|
637
|
-
*
|
638
|
-
* The Pi compute module has an revision of 0011 - since we only check the
|
639
|
-
* last digit, then it's 1, therefore it'll default to not 2 or 3 for a
|
640
|
-
* Rev 1, so will appear as a Rev 2. This is fine for the most part, but
|
641
|
-
* we'll properly detect the Compute Module later and adjust accordingly.
|
642
|
-
* And the next rev of the CN is 0014 ...
|
664
|
+
* The main difference between the revision 1 and 2 system that I use here
|
665
|
+
* is the mapping of the GPIO pins. From revision 2, the Pi Foundation changed
|
666
|
+
* 3 GPIO pins on the (original) 26-way header - BCM_GPIO 22 was dropped and
|
667
|
+
* replaced with 27, and 0 + 1 - I2C bus 0 was changed to 2 + 3; I2C bus 1.
|
643
668
|
*
|
644
669
|
*********************************************************************************
|
645
670
|
*/
|
@@ -666,33 +691,45 @@ int piBoardRev (void)
|
|
666
691
|
if ((cpuFd = fopen ("/proc/cpuinfo", "r")) == NULL)
|
667
692
|
piBoardRevOops ("Unable to open /proc/cpuinfo") ;
|
668
693
|
|
669
|
-
// Start by looking for the Architecture
|
694
|
+
// Start by looking for the Architecture to make sure we're really running
|
695
|
+
// on a Pi. I'm getting fed-up with people whinging at me because
|
696
|
+
// they can't get it to work on weirdFruitPi boards...
|
670
697
|
|
671
698
|
while (fgets (line, 120, cpuFd) != NULL)
|
672
699
|
if (strncmp (line, "Hardware", 8) == 0)
|
673
700
|
break ;
|
674
701
|
|
675
702
|
if (strncmp (line, "Hardware", 8) != 0)
|
676
|
-
piBoardRevOops ("No
|
703
|
+
piBoardRevOops ("No hardware line") ;
|
677
704
|
|
678
705
|
if (wiringPiDebug)
|
679
706
|
printf ("piboardRev: Hardware: %s\n", line) ;
|
680
707
|
|
681
708
|
// See if it's BCM2708 or BCM2709
|
682
709
|
|
683
|
-
if (strstr (line, "BCM2709") != NULL)
|
710
|
+
if (strstr (line, "BCM2709") != NULL) // Pi v2 - no point doing anything more at this point
|
711
|
+
{
|
684
712
|
piModel2 = TRUE ;
|
713
|
+
fclose (cpuFd) ;
|
714
|
+
return boardRev = 2 ;
|
715
|
+
}
|
685
716
|
else if (strstr (line, "BCM2708") == NULL)
|
686
717
|
{
|
687
718
|
fprintf (stderr, "Unable to determine hardware version. I see: %s,\n", line) ;
|
688
|
-
fprintf (stderr, " - expecting BCM2708 or BCM2709
|
719
|
+
fprintf (stderr, " - expecting BCM2708 or BCM2709.\n") ;
|
720
|
+
fprintf (stderr, "If this is a genuine Raspberry Pi then please report this\n") ;
|
721
|
+
fprintf (stderr, "to projects@drogon.net. If this is not a Raspberry Pi then you\n") ;
|
722
|
+
fprintf (stderr, "are on your own as wiringPi is designed to support the\n") ;
|
723
|
+
fprintf (stderr, "Raspberry Pi ONLY.\n") ;
|
689
724
|
exit (EXIT_FAILURE) ;
|
690
725
|
}
|
691
726
|
|
692
|
-
// Now do the rest of it as before
|
727
|
+
// Now do the rest of it as before - we just need to see if it's an older
|
728
|
+
// Rev 1 as anything else is rev 2.
|
693
729
|
|
694
|
-
|
730
|
+
// Isolate the Revision line
|
695
731
|
|
732
|
+
rewind (cpuFd) ;
|
696
733
|
while (fgets (line, 120, cpuFd) != NULL)
|
697
734
|
if (strncmp (line, "Revision", 8) == 0)
|
698
735
|
break ;
|
@@ -710,28 +747,43 @@ int piBoardRev (void)
|
|
710
747
|
if (wiringPiDebug)
|
711
748
|
printf ("piboardRev: Revision string: %s\n", line) ;
|
712
749
|
|
713
|
-
// Scan to first
|
750
|
+
// Scan to the first character of the revision number
|
714
751
|
|
715
752
|
for (c = line ; *c ; ++c)
|
716
|
-
if (
|
753
|
+
if (*c == ':')
|
717
754
|
break ;
|
718
755
|
|
719
|
-
if (
|
720
|
-
piBoardRevOops ("
|
756
|
+
if (*c != ':')
|
757
|
+
piBoardRevOops ("Bogus \"Revision\" line (no colon)") ;
|
758
|
+
|
759
|
+
// Chomp spaces
|
760
|
+
|
761
|
+
++c ;
|
762
|
+
while (isspace (*c))
|
763
|
+
++c ;
|
764
|
+
|
765
|
+
if (!isxdigit (*c))
|
766
|
+
piBoardRevOops ("Bogus \"Revision\" line (no hex digit at start of revision)") ;
|
721
767
|
|
722
768
|
// Make sure its long enough
|
723
769
|
|
724
770
|
if (strlen (c) < 4)
|
725
|
-
piBoardRevOops ("Bogus
|
726
|
-
|
771
|
+
piBoardRevOops ("Bogus revision line (too small)") ;
|
772
|
+
|
727
773
|
// If you have overvolted the Pi, then it appears that the revision
|
728
774
|
// has 100000 added to it!
|
729
775
|
// The actual condition for it being set is:
|
730
776
|
// (force_turbo || current_limit_override || temp_limit>85) && over_voltage>0
|
731
777
|
|
778
|
+
|
779
|
+
// This test is not correct for the new encoding scheme, so we'll remove it here as
|
780
|
+
// we don't really need it at this point.
|
781
|
+
|
782
|
+
/********************
|
732
783
|
if (wiringPiDebug)
|
733
784
|
if (strlen (c) != 4)
|
734
785
|
printf ("piboardRev: This Pi has/is (force_turbo || current_limit_override || temp_limit>85) && over_voltage>0\n") ;
|
786
|
+
*******************/
|
735
787
|
|
736
788
|
// Isolate last 4 characters:
|
737
789
|
|
@@ -754,12 +806,49 @@ int piBoardRev (void)
|
|
754
806
|
|
755
807
|
/*
|
756
808
|
* piBoardId:
|
757
|
-
*
|
758
|
-
*
|
809
|
+
* Return the real details of the board we have.
|
810
|
+
*
|
759
811
|
* This is undocumented and really only intended for the GPIO command.
|
760
812
|
* Use at your own risk!
|
761
813
|
*
|
762
|
-
*
|
814
|
+
* Seems there are some boards with 0000 in them (mistake in manufacture)
|
815
|
+
* So the distinction between boards that I can see is:
|
816
|
+
*
|
817
|
+
* 0000 - Error
|
818
|
+
* 0001 - Not used
|
819
|
+
*
|
820
|
+
* Original Pi boards:
|
821
|
+
* 0002 - Model B, Rev 1, 256MB, Egoman
|
822
|
+
* 0003 - Model B, Rev 1.1, 256MB, Egoman, Fuses/D14 removed.
|
823
|
+
*
|
824
|
+
* Newer Pi's with remapped GPIO:
|
825
|
+
* 0004 - Model B, Rev 2, 256MB, Sony
|
826
|
+
* 0005 - Model B, Rev 2, 256MB, Qisda
|
827
|
+
* 0006 - Model B, Rev 2, 256MB, Egoman
|
828
|
+
* 0007 - Model A, Rev 2, 256MB, Egoman
|
829
|
+
* 0008 - Model A, Rev 2, 256MB, Sony
|
830
|
+
* 0009 - Model A, Rev 2, 256MB, Qisda
|
831
|
+
* 000d - Model B, Rev 2, 512MB, Egoman (Red Pi, Blue Pi?)
|
832
|
+
* 000e - Model B, Rev 2, 512MB, Sony
|
833
|
+
* 000f - Model B, Rev 2, 512MB, Qisda
|
834
|
+
* 0010 - Model B+, Rev 1.2, 512MB, Sony
|
835
|
+
* 0011 - Pi CM, Rev 1.2, 512MB, Sony
|
836
|
+
* 0012 - Model A+ Rev 1.2, 256MB, Sony
|
837
|
+
* 0014 - Pi CM, Rev 1.1, 512MB, Sony (Actual Revision might be different)
|
838
|
+
* 0015 - Model A+ Rev 1.1, 256MB, Sony
|
839
|
+
*
|
840
|
+
* A small thorn is the olde style overvolting - that will add in
|
841
|
+
* 1000000
|
842
|
+
*
|
843
|
+
* The Pi compute module has an revision of 0011 or 0014 - since we only
|
844
|
+
* check the last digit, then it's 1, therefore it'll default to not 2 or
|
845
|
+
* 3 for a Rev 1, so will appear as a Rev 2. This is fine for the most part, but
|
846
|
+
* we'll properly detect the Compute Module later and adjust accordingly.
|
847
|
+
*
|
848
|
+
* And then things changed with the introduction of the v2...
|
849
|
+
*
|
850
|
+
* For Pi v2 and subsequent models - e.g. the Zero:
|
851
|
+
*
|
763
852
|
* [USER:8] [NEW:1] [MEMSIZE:3] [MANUFACTURER:4] [PROCESSOR:4] [TYPE:8] [REV:4]
|
764
853
|
* NEW 23: will be 1 for the new scheme, 0 for the old scheme
|
765
854
|
* MEMSIZE 20: 0=256M 1=512M 2=1G
|
@@ -770,11 +859,13 @@ int piBoardRev (void)
|
|
770
859
|
*********************************************************************************
|
771
860
|
*/
|
772
861
|
|
773
|
-
void piBoardId (int *model, int *rev, int *mem, int *maker, int *
|
862
|
+
void piBoardId (int *model, int *rev, int *mem, int *maker, int *warranty)
|
774
863
|
{
|
775
864
|
FILE *cpuFd ;
|
776
865
|
char line [120] ;
|
777
866
|
char *c ;
|
867
|
+
unsigned int revision ;
|
868
|
+
int bRev, bType, bProc, bMfg, bMem, bWarranty ;
|
778
869
|
|
779
870
|
// Will deal with the properly later on - for now, lets just get it going...
|
780
871
|
// unsigned int modelNum ;
|
@@ -799,35 +890,61 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted)
|
|
799
890
|
*c = 0 ;
|
800
891
|
|
801
892
|
if (wiringPiDebug)
|
802
|
-
printf ("
|
893
|
+
printf ("piBoardId: Revision string: %s\n", line) ;
|
803
894
|
|
804
|
-
|
805
|
-
|
895
|
+
// Need to work out if it's using the new or old encoding scheme:
|
896
|
+
|
897
|
+
// Scan to the first character of the revision number
|
898
|
+
|
899
|
+
for (c = line ; *c ; ++c)
|
900
|
+
if (*c == ':')
|
901
|
+
break ;
|
902
|
+
|
903
|
+
if (*c != ':')
|
904
|
+
piBoardRevOops ("Bogus \"Revision\" line (no colon)") ;
|
806
905
|
|
807
|
-
//
|
906
|
+
// Chomp spaces
|
808
907
|
|
809
|
-
|
810
|
-
|
811
|
-
|
908
|
+
++c ;
|
909
|
+
while (isspace (*c))
|
910
|
+
++c ;
|
812
911
|
|
813
|
-
|
814
|
-
|
912
|
+
if (!isxdigit (*c))
|
913
|
+
piBoardRevOops ("Bogus \"Revision\" line (no hex digit at start of revision)") ;
|
815
914
|
|
816
|
-
|
915
|
+
revision = (unsigned int)strtol (c, NULL, 16) ; // Hex number with no leading 0x
|
916
|
+
|
917
|
+
// Check for new way:
|
918
|
+
|
919
|
+
if ((revision & (1 << 23)) != 0) // New way
|
920
|
+
{
|
921
|
+
if (wiringPiDebug)
|
922
|
+
printf ("piBoardId: New Way: revision is: 0x%08X\n", revision) ;
|
923
|
+
|
924
|
+
bRev = (revision & (0x0F << 0)) >> 0 ;
|
925
|
+
bType = (revision & (0xFF << 4)) >> 4 ;
|
926
|
+
bProc = (revision & (0x0F << 12)) >> 12 ; // Not used for now.
|
927
|
+
bMfg = (revision & (0x0F << 16)) >> 16 ;
|
928
|
+
bMem = (revision & (0x07 << 20)) >> 20 ;
|
929
|
+
bWarranty = (revision & (0x03 << 24)) != 0 ;
|
817
930
|
|
818
|
-
*model
|
819
|
-
*rev
|
820
|
-
*mem
|
821
|
-
*maker
|
931
|
+
*model = bType ;
|
932
|
+
*rev = bRev ;
|
933
|
+
*mem = bMem ;
|
934
|
+
*maker = bMfg ;
|
935
|
+
*warranty = bWarranty ;
|
936
|
+
|
937
|
+
if (wiringPiDebug)
|
938
|
+
printf ("piboardId: rev: %d, type: %d, proc: %d, mfg: %d, mem: %d, warranty: %d\n",
|
939
|
+
bRev, bType, bProc, bMfg, bMem, bWarranty) ;
|
822
940
|
}
|
823
|
-
else
|
941
|
+
else // Old way
|
824
942
|
{
|
943
|
+
if (wiringPiDebug)
|
944
|
+
printf ("piBoardId: Old Way: revision is: %s\n", c) ;
|
825
945
|
|
826
|
-
|
827
|
-
|
828
|
-
for (c = line ; *c ; ++c)
|
829
|
-
if (isdigit (*c))
|
830
|
-
break ;
|
946
|
+
if (!isdigit (*c))
|
947
|
+
piBoardRevOops ("Bogus \"Revision\" line (no digit at start of revision)") ;
|
831
948
|
|
832
949
|
// Make sure its long enough
|
833
950
|
|
@@ -836,7 +953,7 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted)
|
|
836
953
|
|
837
954
|
// If longer than 4, we'll assume it's been overvolted
|
838
955
|
|
839
|
-
*
|
956
|
+
*warranty = strlen (c) > 4 ;
|
840
957
|
|
841
958
|
// Extract last 4 characters:
|
842
959
|
|
@@ -844,22 +961,23 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted)
|
|
844
961
|
|
845
962
|
// Fill out the replys as appropriate
|
846
963
|
|
847
|
-
/**/ if (strcmp (c, "0002") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1 ; *mem =
|
848
|
-
else if (strcmp (c, "0003") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1_1 ; *mem =
|
849
|
-
else if (strcmp (c, "0004") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem =
|
850
|
-
else if (strcmp (c, "0005") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem =
|
851
|
-
else if (strcmp (c, "0006") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem =
|
852
|
-
else if (strcmp (c, "0007") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_2 ; *mem =
|
853
|
-
else if (strcmp (c, "0008") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_2 ; *mem =
|
854
|
-
else if (strcmp (c, "0009") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem =
|
855
|
-
else if (strcmp (c, "000d") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem =
|
856
|
-
else if (strcmp (c, "000e") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem =
|
857
|
-
else if (strcmp (c, "000f") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem =
|
858
|
-
else if (strcmp (c, "0010") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem =
|
859
|
-
else if (strcmp (c, "0011") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_2 ; *mem =
|
860
|
-
else if (strcmp (c, "0012") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_2 ; *mem =
|
861
|
-
else if (strcmp (c, "0013") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem =
|
862
|
-
else if (strcmp (c, "0014") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_2 ; *mem =
|
964
|
+
/**/ if (strcmp (c, "0002") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; }
|
965
|
+
else if (strcmp (c, "0003") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_1_1 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; }
|
966
|
+
else if (strcmp (c, "0004") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 0 ; *maker = PI_MAKER_SONY ; }
|
967
|
+
else if (strcmp (c, "0005") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 0 ; *maker = PI_MAKER_UNKNOWN ; }
|
968
|
+
else if (strcmp (c, "0006") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; }
|
969
|
+
else if (strcmp (c, "0007") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_2 ; *mem = 0 ; *maker = PI_MAKER_EGOMAN ; }
|
970
|
+
else if (strcmp (c, "0008") == 0) { *model = PI_MODEL_A ; *rev = PI_VERSION_2 ; *mem = 0 ; *maker = PI_MAKER_SONY ; ; }
|
971
|
+
else if (strcmp (c, "0009") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 0 ; *maker = PI_MAKER_UNKNOWN ; }
|
972
|
+
else if (strcmp (c, "000d") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 1 ; *maker = PI_MAKER_EGOMAN ; }
|
973
|
+
else if (strcmp (c, "000e") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 1 ; *maker = PI_MAKER_SONY ; }
|
974
|
+
else if (strcmp (c, "000f") == 0) { *model = PI_MODEL_B ; *rev = PI_VERSION_2 ; *mem = 1 ; *maker = PI_MAKER_EGOMAN ; }
|
975
|
+
else if (strcmp (c, "0010") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_SONY ; }
|
976
|
+
else if (strcmp (c, "0011") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_SONY ; }
|
977
|
+
else if (strcmp (c, "0012") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_2 ; *mem = 0 ; *maker = PI_MAKER_SONY ; }
|
978
|
+
else if (strcmp (c, "0013") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_EGOMAN ; }
|
979
|
+
else if (strcmp (c, "0014") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_2 ; *mem = 1 ; *maker = PI_MAKER_SONY ; }
|
980
|
+
else if (strcmp (c, "0015") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_1 ; *mem = 0 ; *maker = PI_MAKER_SONY ; }
|
863
981
|
else { *model = 0 ; *rev = 0 ; *mem = 0 ; *maker = 0 ; }
|
864
982
|
}
|
865
983
|
}
|
@@ -904,6 +1022,9 @@ void setPadDrive (int group, int value)
|
|
904
1022
|
|
905
1023
|
if ((wiringPiMode == WPI_MODE_PINS) || (wiringPiMode == WPI_MODE_PHYS) || (wiringPiMode == WPI_MODE_GPIO))
|
906
1024
|
{
|
1025
|
+
if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now
|
1026
|
+
return ;
|
1027
|
+
|
907
1028
|
if ((group < 0) || (group > 2))
|
908
1029
|
return ;
|
909
1030
|
|
@@ -977,6 +1098,9 @@ void pwmSetRange (unsigned int range)
|
|
977
1098
|
{
|
978
1099
|
if ((wiringPiMode == WPI_MODE_PINS) || (wiringPiMode == WPI_MODE_PHYS) || (wiringPiMode == WPI_MODE_GPIO))
|
979
1100
|
{
|
1101
|
+
if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now
|
1102
|
+
return ;
|
1103
|
+
|
980
1104
|
*(pwm + PWM0_RANGE) = range ; delayMicroseconds (10) ;
|
981
1105
|
*(pwm + PWM1_RANGE) = range ; delayMicroseconds (10) ;
|
982
1106
|
}
|
@@ -998,6 +1122,9 @@ void pwmSetClock (int divisor)
|
|
998
1122
|
|
999
1123
|
if ((wiringPiMode == WPI_MODE_PINS) || (wiringPiMode == WPI_MODE_PHYS) || (wiringPiMode == WPI_MODE_GPIO))
|
1000
1124
|
{
|
1125
|
+
if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now
|
1126
|
+
return ;
|
1127
|
+
|
1001
1128
|
if (wiringPiDebug)
|
1002
1129
|
printf ("Setting to: %d. Current: 0x%08X\n", divisor, *(clk + PWMCLK_DIV)) ;
|
1003
1130
|
|
@@ -1050,6 +1177,9 @@ void gpioClockSet (int pin, int freq)
|
|
1050
1177
|
else if (wiringPiMode != WPI_MODE_GPIO)
|
1051
1178
|
return ;
|
1052
1179
|
|
1180
|
+
if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now
|
1181
|
+
return ;
|
1182
|
+
|
1053
1183
|
divi = 19200000 / freq ;
|
1054
1184
|
divr = 19200000 % freq ;
|
1055
1185
|
divf = (int)((double)divr * 4096.0 / 19200000.0) ;
|
@@ -1222,11 +1352,17 @@ void pinMode (int pin, int mode)
|
|
1222
1352
|
softToneCreate (origPin) ;
|
1223
1353
|
else if (mode == PWM_TONE_OUTPUT)
|
1224
1354
|
{
|
1355
|
+
if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now
|
1356
|
+
return ;
|
1357
|
+
|
1225
1358
|
pinMode (origPin, PWM_OUTPUT) ; // Call myself to enable PWM mode
|
1226
1359
|
pwmSetMode (PWM_MODE_MS) ;
|
1227
1360
|
}
|
1228
1361
|
else if (mode == PWM_OUTPUT)
|
1229
1362
|
{
|
1363
|
+
if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now
|
1364
|
+
return ;
|
1365
|
+
|
1230
1366
|
if ((alt = gpioToPwmALT [pin]) == 0) // Not a hardware capable PWM pin
|
1231
1367
|
return ;
|
1232
1368
|
|
@@ -1241,6 +1377,9 @@ void pinMode (int pin, int mode)
|
|
1241
1377
|
}
|
1242
1378
|
else if (mode == GPIO_CLOCK)
|
1243
1379
|
{
|
1380
|
+
if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now
|
1381
|
+
return ;
|
1382
|
+
|
1244
1383
|
if ((alt = gpioToGpClkALT0 [pin]) == 0) // Not a GPIO_CLOCK pin
|
1245
1384
|
return ;
|
1246
1385
|
|
@@ -1395,6 +1534,9 @@ void pwmWrite (int pin, int value)
|
|
1395
1534
|
|
1396
1535
|
if ((pin & PI_GPIO_MASK) == 0) // On-Board Pin
|
1397
1536
|
{
|
1537
|
+
if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now
|
1538
|
+
return ;
|
1539
|
+
|
1398
1540
|
/**/ if (wiringPiMode == WPI_MODE_PINS)
|
1399
1541
|
pin = pinToGpio [pin] ;
|
1400
1542
|
else if (wiringPiMode == WPI_MODE_PHYS)
|
@@ -1461,6 +1603,9 @@ void pwmToneWrite (int pin, int freq)
|
|
1461
1603
|
{
|
1462
1604
|
int range ;
|
1463
1605
|
|
1606
|
+
if (RASPBERRY_PI_PERI_BASE == 0) // Ignore for now
|
1607
|
+
return ;
|
1608
|
+
|
1464
1609
|
if (freq == 0)
|
1465
1610
|
pwmWrite (pin, 0) ; // Off
|
1466
1611
|
else
|
@@ -1475,16 +1620,21 @@ void pwmToneWrite (int pin, int freq)
|
|
1475
1620
|
|
1476
1621
|
/*
|
1477
1622
|
* digitalWriteByte:
|
1623
|
+
* digitalReadByte:
|
1478
1624
|
* Pi Specific
|
1479
1625
|
* Write an 8-bit byte to the first 8 GPIO pins - try to do it as
|
1480
1626
|
* fast as possible.
|
1481
1627
|
* However it still needs 2 operations to set the bits, so any external
|
1482
1628
|
* hardware must not rely on seeing a change as there will be a change
|
1483
1629
|
* to set the outputs bits to zero, then another change to set the 1's
|
1630
|
+
* Reading is just bit fiddling.
|
1631
|
+
* These are wiringPi pin numbers 0..7, or BCM_GPIO pin numbers
|
1632
|
+
* 17, 18, 22, 23, 24, 24, 4 on a Pi v1 rev 0-3
|
1633
|
+
* 17, 18, 27, 23, 24, 24, 4 on a Pi v1 rev 3 onwards or B+, 2, zero
|
1484
1634
|
*********************************************************************************
|
1485
1635
|
*/
|
1486
1636
|
|
1487
|
-
void digitalWriteByte (int value)
|
1637
|
+
void digitalWriteByte (const int value)
|
1488
1638
|
{
|
1489
1639
|
uint32_t pinSet = 0 ;
|
1490
1640
|
uint32_t pinClr = 0 ;
|
@@ -1495,7 +1645,7 @@ void digitalWriteByte (int value)
|
|
1495
1645
|
{
|
1496
1646
|
for (pin = 0 ; pin < 8 ; ++pin)
|
1497
1647
|
{
|
1498
|
-
digitalWrite (pin, value & mask) ;
|
1648
|
+
digitalWrite (pinToGpio [pin], value & mask) ;
|
1499
1649
|
mask <<= 1 ;
|
1500
1650
|
}
|
1501
1651
|
return ;
|
@@ -1517,6 +1667,83 @@ void digitalWriteByte (int value)
|
|
1517
1667
|
}
|
1518
1668
|
}
|
1519
1669
|
|
1670
|
+
unsigned int digitalReadByte (void)
|
1671
|
+
{
|
1672
|
+
int pin, x ;
|
1673
|
+
uint32_t raw ;
|
1674
|
+
uint32_t data = 0 ;
|
1675
|
+
|
1676
|
+
/**/ if (wiringPiMode == WPI_MODE_GPIO_SYS)
|
1677
|
+
{
|
1678
|
+
for (pin = 0 ; pin < 8 ; ++pin)
|
1679
|
+
{
|
1680
|
+
x = digitalRead (pinToGpio [pin]) ;
|
1681
|
+
data = (data << 1) | x ;
|
1682
|
+
}
|
1683
|
+
}
|
1684
|
+
else
|
1685
|
+
{
|
1686
|
+
raw = *(gpio + gpioToGPLEV [0]) ; // First bank for these pins
|
1687
|
+
for (pin = 0 ; pin < 8 ; ++pin)
|
1688
|
+
{
|
1689
|
+
x = pinToGpio [pin] ;
|
1690
|
+
data = (data << 1) | (((raw & (1 << x)) == 0) ? 0 : 1) ;
|
1691
|
+
}
|
1692
|
+
}
|
1693
|
+
return data ;
|
1694
|
+
}
|
1695
|
+
|
1696
|
+
|
1697
|
+
/*
|
1698
|
+
* digitalWriteByte2:
|
1699
|
+
* digitalReadByte2:
|
1700
|
+
* Pi Specific
|
1701
|
+
* Write an 8-bit byte to the second set of 8 GPIO pins. This is marginally
|
1702
|
+
* faster than the first lot as these are consecutive BCM_GPIO pin numbers.
|
1703
|
+
* However they overlap with the original read/write bytes.
|
1704
|
+
*********************************************************************************
|
1705
|
+
*/
|
1706
|
+
|
1707
|
+
void digitalWriteByte2 (const int value)
|
1708
|
+
{
|
1709
|
+
register int mask = 1 ;
|
1710
|
+
register int pin ;
|
1711
|
+
|
1712
|
+
/**/ if (wiringPiMode == WPI_MODE_GPIO_SYS)
|
1713
|
+
{
|
1714
|
+
for (pin = 20 ; pin < 28 ; ++pin)
|
1715
|
+
{
|
1716
|
+
digitalWrite (pin, value & mask) ;
|
1717
|
+
mask <<= 1 ;
|
1718
|
+
}
|
1719
|
+
return ;
|
1720
|
+
}
|
1721
|
+
else
|
1722
|
+
{
|
1723
|
+
*(gpio + gpioToGPCLR [0]) = 0x0FF00000 ;
|
1724
|
+
*(gpio + gpioToGPSET [0]) = (value & 0xFF) << 20 ;
|
1725
|
+
}
|
1726
|
+
}
|
1727
|
+
|
1728
|
+
unsigned int digitalReadByte2 (void)
|
1729
|
+
{
|
1730
|
+
int pin, x ;
|
1731
|
+
uint32_t data = 0 ;
|
1732
|
+
|
1733
|
+
/**/ if (wiringPiMode == WPI_MODE_GPIO_SYS)
|
1734
|
+
{
|
1735
|
+
for (pin = 20 ; pin < 28 ; ++pin)
|
1736
|
+
{
|
1737
|
+
x = digitalRead (pin) ;
|
1738
|
+
data = (data << 1) | x ;
|
1739
|
+
}
|
1740
|
+
}
|
1741
|
+
else
|
1742
|
+
data = ((*(gpio + gpioToGPLEV [0])) >> 20) & 0xFF ; // First bank for these pins
|
1743
|
+
|
1744
|
+
return data ;
|
1745
|
+
}
|
1746
|
+
|
1520
1747
|
|
1521
1748
|
/*
|
1522
1749
|
* waitForInterrupt:
|
@@ -1822,6 +2049,16 @@ int wiringPiSetup (void)
|
|
1822
2049
|
int fd ;
|
1823
2050
|
int boardRev ;
|
1824
2051
|
int model, rev, mem, maker, overVolted ;
|
2052
|
+
static int alreadyCalled = FALSE ;
|
2053
|
+
|
2054
|
+
// This is here to trap the unwary - those who's program appears to work then fails some
|
2055
|
+
// time later with a weird error message because you run out of file-handles.
|
2056
|
+
|
2057
|
+
if (alreadyCalled)
|
2058
|
+
(void)wiringPiFailure (WPI_FATAL, "wiringPiSetup*: You must only call this once per program run. This is a fatal error. Please fix your code.\n") ;
|
2059
|
+
|
2060
|
+
alreadyCalled = TRUE ;
|
2061
|
+
|
1825
2062
|
|
1826
2063
|
if (getenv (ENV_DEBUG) != NULL)
|
1827
2064
|
wiringPiDebug = TRUE ;
|
@@ -1829,11 +2066,15 @@ int wiringPiSetup (void)
|
|
1829
2066
|
if (getenv (ENV_CODES) != NULL)
|
1830
2067
|
wiringPiReturnCodes = TRUE ;
|
1831
2068
|
|
1832
|
-
if (
|
1833
|
-
|
2069
|
+
if (getenv (ENV_GPIOMEM) != NULL)
|
2070
|
+
wiringPiTryGpioMem = TRUE ;
|
1834
2071
|
|
1835
2072
|
if (wiringPiDebug)
|
2073
|
+
{
|
1836
2074
|
printf ("wiringPi: wiringPiSetup called\n") ;
|
2075
|
+
if (wiringPiTryGpioMem)
|
2076
|
+
printf ("wiringPi: Using /dev/gpiomem\n") ;
|
2077
|
+
}
|
1837
2078
|
|
1838
2079
|
boardRev = piBoardRev () ;
|
1839
2080
|
|
@@ -1842,45 +2083,81 @@ int wiringPiSetup (void)
|
|
1842
2083
|
pinToGpio = pinToGpioR1 ;
|
1843
2084
|
physToGpio = physToGpioR1 ;
|
1844
2085
|
}
|
1845
|
-
else // A, B, Rev 2, B+, CM, Pi2
|
2086
|
+
else // A, B, Rev 2, B+, CM, Pi2, Zero
|
1846
2087
|
{
|
1847
|
-
if (piModel2)
|
1848
|
-
BCM2708_PERI_BASE = 0x3F000000 ;
|
1849
2088
|
pinToGpio = pinToGpioR2 ;
|
1850
2089
|
physToGpio = physToGpioR2 ;
|
1851
2090
|
}
|
1852
2091
|
|
1853
|
-
//
|
2092
|
+
// Note that a Zero is a model 1
|
1854
2093
|
|
1855
|
-
if (
|
1856
|
-
|
2094
|
+
if (piModel2)
|
2095
|
+
RASPBERRY_PI_PERI_BASE = 0x3F000000 ;
|
2096
|
+
else
|
2097
|
+
RASPBERRY_PI_PERI_BASE = 0x20000000 ;
|
1857
2098
|
|
1858
|
-
//
|
2099
|
+
// Open the master /dev/ memory control device
|
2100
|
+
|
2101
|
+
// See if /dev/gpiomem exists and we can open it...
|
2102
|
+
|
2103
|
+
if (wiringPiTryGpioMem)
|
2104
|
+
{
|
2105
|
+
if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
|
2106
|
+
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Unable to open /dev/gpiomem: %s\n", strerror (errno)) ;
|
2107
|
+
RASPBERRY_PI_PERI_BASE = 0 ;
|
2108
|
+
}
|
2109
|
+
|
2110
|
+
// ... otherwise fall back to the original /dev/mem which requires root level access
|
2111
|
+
|
2112
|
+
else
|
2113
|
+
{
|
2114
|
+
|
2115
|
+
// This check is here because people are too stupid to check for themselves or read
|
2116
|
+
// error messages.
|
2117
|
+
|
2118
|
+
if (geteuid () != 0)
|
2119
|
+
(void)wiringPiFailure (WPI_FATAL, "wiringPiSetup: Must be root. (Did you forget sudo?)\n") ;
|
2120
|
+
|
2121
|
+
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
|
2122
|
+
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Unable to open /dev/mem: %s\n", strerror (errno)) ;
|
2123
|
+
}
|
2124
|
+
|
2125
|
+
// Set the offsets into the memory interface.
|
2126
|
+
|
2127
|
+
GPIO_PADS = RASPBERRY_PI_PERI_BASE + 0x00100000 ;
|
2128
|
+
GPIO_CLOCK_BASE = RASPBERRY_PI_PERI_BASE + 0x00101000 ;
|
2129
|
+
GPIO_BASE = RASPBERRY_PI_PERI_BASE + 0x00200000 ;
|
2130
|
+
GPIO_TIMER = RASPBERRY_PI_PERI_BASE + 0x0000B000 ;
|
2131
|
+
GPIO_PWM = RASPBERRY_PI_PERI_BASE + 0x0020C000 ;
|
2132
|
+
|
2133
|
+
// Map the individual hardware components
|
2134
|
+
|
2135
|
+
// GPIO:
|
1859
2136
|
|
1860
2137
|
gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_BASE) ;
|
1861
2138
|
if ((int32_t)gpio == -1)
|
1862
2139
|
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror (errno)) ;
|
1863
2140
|
|
1864
|
-
//
|
2141
|
+
// PWM
|
1865
2142
|
|
1866
2143
|
pwm = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PWM) ;
|
1867
2144
|
if ((int32_t)pwm == -1)
|
1868
2145
|
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (PWM) failed: %s\n", strerror (errno)) ;
|
1869
2146
|
|
1870
|
-
//
|
2147
|
+
// Clock control (needed for PWM)
|
1871
2148
|
|
1872
|
-
clk = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd,
|
2149
|
+
clk = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_CLOCK_BASE) ;
|
1873
2150
|
if ((int32_t)clk == -1)
|
1874
2151
|
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (CLOCK) failed: %s\n", strerror (errno)) ;
|
1875
2152
|
|
1876
|
-
//
|
2153
|
+
// The drive pads
|
1877
2154
|
|
1878
2155
|
pads = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PADS) ;
|
1879
2156
|
if ((int32_t)pads == -1)
|
1880
2157
|
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (PADS) failed: %s\n", strerror (errno)) ;
|
1881
2158
|
|
1882
2159
|
#ifdef USE_TIMER
|
1883
|
-
//
|
2160
|
+
// The system timer
|
1884
2161
|
|
1885
2162
|
timer = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_TIMER) ;
|
1886
2163
|
if ((int32_t)timer == -1)
|
@@ -1967,6 +2244,15 @@ int wiringPiSetupSys (void)
|
|
1967
2244
|
int boardRev ;
|
1968
2245
|
int pin ;
|
1969
2246
|
char fName [128] ;
|
2247
|
+
static int alreadyCalled = FALSE ;
|
2248
|
+
|
2249
|
+
// This is here to trap the unwary - those who's program appears to work then fails some
|
2250
|
+
// time later with a weird error message because you run out of file-handles.
|
2251
|
+
|
2252
|
+
if (alreadyCalled)
|
2253
|
+
(void)wiringPiFailure (WPI_FATAL, "wiringPiSetupSys: You must only call this once per program run. This is a fatal error. Please fix your code.\n") ;
|
2254
|
+
|
2255
|
+
alreadyCalled = TRUE ;
|
1970
2256
|
|
1971
2257
|
if (getenv (ENV_DEBUG) != NULL)
|
1972
2258
|
wiringPiDebug = TRUE ;
|