Updated the Debian build system thanks to Ian Jackson for the

help.
This commit is contained in:
Gordon Henderson 2015-09-20 19:30:38 +01:00
parent a776e6b0e8
commit 170dce5f19
8 changed files with 132 additions and 47 deletions

View File

@ -1 +1 @@
2.25 2.27

View File

@ -1,5 +1,5 @@
Package: wiringpi Package: wiringpi
Version: 2.24 Version: 2.27
Section: libraries Section: libraries
Priority: optional Priority: optional
Architecture: armhf Architecture: armhf

View File

@ -49,7 +49,7 @@ OBJ = $(SRC:.c=.o)
all: gpio all: gpio
version.h: ../VERSION version.h: ../VERSION
./newVersion $Q echo Need to run newVersion above.
gpio: $(OBJ) gpio: $(OBJ)
$Q echo [Link] $Q echo [Link]
@ -97,3 +97,5 @@ depend:
makedepend -Y $(SRC) makedepend -Y $(SRC)
# DO NOT DELETE # DO NOT DELETE
gpio.o: version.h

View File

@ -1194,6 +1194,17 @@ int main (int argc, char *argv [])
printf ("Raspberry Pi Details:\n") ; printf ("Raspberry Pi Details:\n") ;
printf (" Type: %s, Revision: %s, Memory: %dMB, Maker: %s %s\n", printf (" Type: %s, Revision: %s, Memory: %dMB, Maker: %s %s\n",
piModelNames [model], piRevisionNames [rev], mem, piMakerNames [maker], overVolted ? "[OV]" : "") ; piModelNames [model], piRevisionNames [rev], mem, piMakerNames [maker], overVolted ? "[OV]" : "") ;
// Quick check for /dev/gpiomem
if ((i = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) >= 0)
printf (" This Raspberry Pi supports user-level GPIO access via /dev/gpiomem.\n") ;
else
{
printf (" You need to run your programs as root for GPIO access\n") ;
printf (" (Old /dev/mem method - consider upgrading)\n") ;
}
} }
return 0 ; return 0 ;
} }

View File

@ -1 +1 @@
#define VERSION "2.26" #define VERSION "2.27"

View File

@ -2,6 +2,7 @@
# #
# newVersion: # newVersion:
# Utility to create the version.h include file for the gpio command. # Utility to create the version.h include file for the gpio command.
# and the Debian package
# #
# Copyright (c) 2012-2015 Gordon Henderson # Copyright (c) 2012-2015 Gordon Henderson
################################################################################# #################################################################################
@ -22,5 +23,21 @@
# along with wiringPi. If not, see <http://www.gnu.org/licenses/>. # along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
################################################################################# #################################################################################
rm -f version.h echo Updating to version: `cat VERSION`
echo "#define VERSION \"`cat ../VERSION`\"" > version.h
rm -f gpio/version.h
echo "#define VERSION \"`cat VERSION`\"" > gpio/version.h
rm -f debian-template/wiringPi/DEBIAN/control
cat > debian-template/wiringPi/DEBIAN/control <<EOF
Package: wiringpi
Version: `cat VERSION`
Section: libraries
Priority: optional
Architecture: armhf
Depends: libc6
Maintainer: Gordon Henderson <projects@drogon.net>
Description: The wiringPi libraries, headers and gpio command
Libraries to allow GPIO access on a Raspberry Pi from C and C++
programs as well as from the command-line
EOF

View File

@ -22,39 +22,58 @@
*********************************************************************** ***********************************************************************
*/ */
#include <byteswap.h>
#include <stdint.h>
#include <math.h>
#include <wiringPi.h> #include <wiringPi.h>
#include <wiringPiSPI.h> #include <wiringPiSPI.h>
#include "max31855.h" #include "max31855.h"
/*
* myAnalogRead:
* Return the analog value of the given pin
* Note: The chip really only has one read "channel", but we're faking it
* here so we can read the error registers. Channel 0 will be the data
* channel, and 1 is the error register code.
* Note: Temperature returned is temp in C * 4, so divide result by 4
*********************************************************************************
*/
static int myAnalogRead (struct wiringPiNodeStruct *node, int pin) static int myAnalogRead (struct wiringPiNodeStruct *node, int pin)
{ {
unsigned int spiData ; uint32_t spiData ;
int temp ; int temp ;
int chan = pin - node->pinBase ; int chan = pin - node->pinBase ;
wiringPiSPIDataRW (node->fd, (unsigned char *)&spiData, 4) ; wiringPiSPIDataRW (node->fd, (unsigned char *)&spiData, 4) ;
if (chan == 0) // Read temp in C spiData = __bswap_32(spiData) ;
switch (chan)
{ {
spiData >>= 18 ; case 0: // Existing read - return raw value * 4
temp = spiData & 0x3FFF ; // Bottom 13 bits spiData >>= 18 ;
if ((spiData & 0x2000) != 0) // Negative temp = spiData & 0x1FFF ; // Bottom 13 bits
temp = -temp ; if ((spiData & 0x2000) != 0) // Negative
return temp ; temp = -temp ;
return temp ;
case 1: // Return error bits
return spiData & 0x7 ;
case 2: // Return temp in C * 10
spiData >>= 18 ;
temp = spiData & 0x1FFF ; // Bottom 13 bits
if ((spiData & 0x2000) != 0) // Negative
temp = -temp ;
return (int)rint ((double)temp * 2.5) ;
case 3: // Return temp in F * 10
spiData >>= 18 ;
temp = spiData & 0x1FFF ; // Bottom 13 bits
if ((spiData & 0x2000) != 0) // Negative
temp = -temp ;
return (int)rint ((((double)temp * 0.25 * 9.0 / 5.0) + 32.0) * 10.0) ;
default: // Who knows...
return 0 ;
} }
else // Return error bits
return spiData & 0x7 ;
} }
@ -72,7 +91,7 @@ int max31855Setup (const int pinBase, int spiChannel)
if (wiringPiSPISetup (spiChannel, 5000000) < 0) // 5MHz - prob 4 on the Pi if (wiringPiSPISetup (spiChannel, 5000000) < 0) // 5MHz - prob 4 on the Pi
return -1 ; return -1 ;
node = wiringPiNewNode (pinBase, 2) ; node = wiringPiNewNode (pinBase, 4) ;
node->fd = spiChannel ; node->fd = spiChannel ;
node->analogRead = myAnalogRead ; node->analogRead = myAnalogRead ;

View File

@ -130,13 +130,16 @@ struct wiringPiNodeStruct *wiringPiNodes = NULL ;
// Access from ARM Running Linux // Access from ARM Running Linux
// Taken from Gert/Doms code. Some of this is not in the manual // Taken from Gert/Doms code. Some of this is not in the manual
// that I can find )-: // that I can find )-:
//
// Updates in September 2015 - all now static variables (and apologies for the caps)
// due to the Pi v2 and the new /dev/gpiomem interface
static volatile unsigned int BCM2708_PERI_BASE = 0x20000000 ; // Variable for Pi2 static volatile unsigned int RASPBERRY_PI_PERI_BASE ;
#define GPIO_PADS (BCM2708_PERI_BASE + 0x00100000) static volatile unsigned int GPIO_PADS ;
#define CLOCK_BASE (BCM2708_PERI_BASE + 0x00101000) static volatile unsigned int GPIO_CLOCK_BASE ;
#define GPIO_BASE (BCM2708_PERI_BASE + 0x00200000) static volatile unsigned int GPIO_BASE ;
#define GPIO_TIMER (BCM2708_PERI_BASE + 0x0000B000) static volatile unsigned int GPIO_TIMER ;
#define GPIO_PWM (BCM2708_PERI_BASE + 0x0020C000) static volatile unsigned int GPIO_PWM ;
#define PAGE_SIZE (4*1024) #define PAGE_SIZE (4*1024)
#define BLOCK_SIZE (4*1024) #define BLOCK_SIZE (4*1024)
@ -628,6 +631,7 @@ int wiringPiFailure (int fatal, const char *message, ...)
* 0011 - Pi CM, Rev 1.2, 512MB, Sony * 0011 - Pi CM, Rev 1.2, 512MB, Sony
* 0012 - Model A+ Rev 1.2, 256MB, Sony * 0012 - Model A+ Rev 1.2, 256MB, Sony
* 0014 - Pi CM, Rev 1.1, 512MB, Sony (Actual Revision might be different) * 0014 - Pi CM, Rev 1.1, 512MB, Sony (Actual Revision might be different)
* 0015 - Model A+ Rev 1.1, 256MB, Sony
* *
* For the Pi 2: * For the Pi 2:
* 0010 - Model 2, Rev 1.1, Quad Core, 1GB, Sony * 0010 - Model 2, Rev 1.1, Quad Core, 1GB, Sony
@ -685,7 +689,11 @@ int piBoardRev (void)
else if (strstr (line, "BCM2708") == NULL) else if (strstr (line, "BCM2708") == NULL)
{ {
fprintf (stderr, "Unable to determine hardware version. I see: %s,\n", line) ; fprintf (stderr, "Unable to determine hardware version. I see: %s,\n", line) ;
fprintf (stderr, " - expecting BCM2708 or BCM2709. Please report this to projects@drogon.net\n") ; fprintf (stderr, " - expecting BCM2708 or BCM2709.\n") ;
fprintf (stderr, "If this is a genuine Raspberry Pi then please report this\n") ;
fprintf (stderr, "to projects@drogon.net. If this is not a Raspberry Pi then you\n") ;
fprintf (stderr, "are on your own as wiringPi is designed to support the\n") ;
fprintf (stderr, "Raspberry Pi ONLY.\n") ;
exit (EXIT_FAILURE) ; exit (EXIT_FAILURE) ;
} }
@ -860,6 +868,7 @@ void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted)
else if (strcmp (c, "0012") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; } else if (strcmp (c, "0012") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_2 ; *mem = 256 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0013") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_MBEST ; } else if (strcmp (c, "0013") == 0) { *model = PI_MODEL_BP ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_MBEST ; }
else if (strcmp (c, "0014") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; } else if (strcmp (c, "0014") == 0) { *model = PI_MODEL_CM ; *rev = PI_VERSION_1_2 ; *mem = 512 ; *maker = PI_MAKER_SONY ; }
else if (strcmp (c, "0015") == 0) { *model = PI_MODEL_AP ; *rev = PI_VERSION_1_1 ; *mem = 256 ; *maker = PI_MAKER_SONY ; }
else { *model = 0 ; *rev = 0 ; *mem = 0 ; *maker = 0 ; } else { *model = 0 ; *rev = 0 ; *mem = 0 ; *maker = 0 ; }
} }
} }
@ -1829,9 +1838,6 @@ int wiringPiSetup (void)
if (getenv (ENV_CODES) != NULL) if (getenv (ENV_CODES) != NULL)
wiringPiReturnCodes = TRUE ; wiringPiReturnCodes = TRUE ;
if (geteuid () != 0)
(void)wiringPiFailure (WPI_FATAL, "wiringPiSetup: Must be root. (Did you forget sudo?)\n") ;
if (wiringPiDebug) if (wiringPiDebug)
printf ("wiringPi: wiringPiSetup called\n") ; printf ("wiringPi: wiringPiSetup called\n") ;
@ -1844,43 +1850,73 @@ int wiringPiSetup (void)
} }
else // A, B, Rev 2, B+, CM, Pi2 else // A, B, Rev 2, B+, CM, Pi2
{ {
if (piModel2)
BCM2708_PERI_BASE = 0x3F000000 ;
pinToGpio = pinToGpioR2 ; pinToGpio = pinToGpioR2 ;
physToGpio = physToGpioR2 ; physToGpio = physToGpioR2 ;
} }
// Open the master /dev/memory device if (piModel2)
RASPBERRY_PI_PERI_BASE = 0x3F000000 ;
else
RASPBERRY_PI_PERI_BASE = 0x20000000 ;
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0) // Open the master /dev/ memory control device
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Unable to open /dev/mem: %s\n", strerror (errno)) ;
// GPIO: // See if /dev/gpiomem exists and we can open it...
if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) >= 0)
RASPBERRY_PI_PERI_BASE = 0 ;
// ... otherwise fall back to the original /dev/mem which requires root level access
else
{
// This check is here because people are too stupid to check for themselves or read
// error messages.
if (geteuid () != 0)
(void)wiringPiFailure (WPI_FATAL, "wiringPiSetup: Must be root. (Did you forget sudo?)\n") ;
if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0)
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Unable to open /dev/mem: %s\n", strerror (errno)) ;
}
// Set the offsets into the memory interface.
GPIO_PADS = RASPBERRY_PI_PERI_BASE + 0x00100000 ;
GPIO_CLOCK_BASE = RASPBERRY_PI_PERI_BASE + 0x00101000 ;
GPIO_BASE = RASPBERRY_PI_PERI_BASE + 0x00200000 ;
GPIO_TIMER = RASPBERRY_PI_PERI_BASE + 0x0000B000 ;
GPIO_PWM = RASPBERRY_PI_PERI_BASE + 0x0020C000 ;
// Map the individual hardware components
// GPIO:
gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_BASE) ; gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_BASE) ;
if ((int32_t)gpio == -1) if ((int32_t)gpio == -1)
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror (errno)) ; return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (GPIO) failed: %s\n", strerror (errno)) ;
// PWM // PWM
pwm = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PWM) ; pwm = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PWM) ;
if ((int32_t)pwm == -1) if ((int32_t)pwm == -1)
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (PWM) failed: %s\n", strerror (errno)) ; return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (PWM) failed: %s\n", strerror (errno)) ;
// Clock control (needed for PWM) // Clock control (needed for PWM)
clk = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, CLOCK_BASE) ; clk = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_CLOCK_BASE) ;
if ((int32_t)clk == -1) if ((int32_t)clk == -1)
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (CLOCK) failed: %s\n", strerror (errno)) ; return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (CLOCK) failed: %s\n", strerror (errno)) ;
// The drive pads // The drive pads
pads = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PADS) ; pads = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PADS) ;
if ((int32_t)pads == -1) if ((int32_t)pads == -1)
return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (PADS) failed: %s\n", strerror (errno)) ; return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: mmap (PADS) failed: %s\n", strerror (errno)) ;
#ifdef USE_TIMER #ifdef USE_TIMER
// The system timer // The system timer
timer = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_TIMER) ; timer = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_TIMER) ;
if ((int32_t)timer == -1) if ((int32_t)timer == -1)