#!/bin/bash
+i2c-install()
+{
+ echo "* wiringPi needs the I2C Development Libraires installing."
+ echo ""
+ echo "If using Debian/Raspbian, then type this command:"
+ echo " sudo apt-get install libi2c-dev"
+ echo "then run ./build again."
+ echo ""
+ echo "If using another Linux distribution, then you will have to"
+ echo "work out how to install the I2C Developmen Libraries for your"
+ echo "system. (Sorry - I don't know - do let me know though!)"
+ echo ""
+ exit 1
+}
+
+check-make-ok()
+{
+ if [ $? != 0 ]; then
+ echo ""
+ echo "Make Failed..."
+ echo "Please check the messages and fix any problems. If you're still stuck,"
+ echo "then please email all the output and as many details as you can to"
+ echo " projects@drogon.net"
+ echo ""
+ exit 1
+ fi
+}
+
+
if [ x$1 = "xclean" ]; then
echo Cleaning
echo
cd ..
else
echo wiringPi Build script - please wait...
-
echo
+
+# Check for I2C being installed...
+
if [ ! -f /usr/include/linux/i2c-dev.h ]; then
- echo "* wiringPi needs the I2C Development Libraires installing."
- echo ""
- echo "If using Debian/Raspbian, then type this command:"
- echo " sudo apt-get install libi2c-dev"
- echo "then run ./build again."
- echo ""
- echo "If using another Linux distribution, then you will have to"
- echo "work out how to install the I2C Developmen Libraries for your"
- echo "system."
- echo ""
- exit 1
+ i2c-install
+ fi
+ grep -q i2c_smbus_read_byte /usr/include/linux/i2c-dev.h
+ if [ $? = 1 ]; then
+ i2c-install
fi
echo "WiringPi library"
cd wiringPi
sudo make uninstall
- make
+ make
+ check-make-ok
sudo make install
+ check-make-ok
echo
echo "GPIO Utility"
cd ../gpio
make
+ check-make-ok
sudo make install
+ check-make-ok
echo
echo "Examples"
cd ../examples
{
int fd ;
int boardRev ;
- uint8_t *gpioMem, *pwmMem, *clkMem, *padsMem, *timerMem ;
+ //uint8_t *gpioMem, *pwmMem, *clkMem, *padsMem, *timerMem ;
struct timeval tv ;
if (geteuid () != 0)
// GPIO:
-// Allocate 2 pages - 1 ...
-
- if ((gpioMem = malloc (BLOCK_SIZE + (PAGE_SIZE-1))) == NULL)
- {
- if (wiringPiDebug)
- fprintf (stderr, "wiringPiSetup: malloc failed: %s\n", strerror (errno)) ;
- return -1 ;
- }
-
-// ... presumably to make sure we can round it up to a whole page size
-
- if (((uint32_t)gpioMem % PAGE_SIZE) != 0)
- gpioMem += PAGE_SIZE - ((uint32_t)gpioMem % PAGE_SIZE) ;
-
- gpio = (uint32_t *)mmap((caddr_t)gpioMem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd, GPIO_BASE) ;
-
- if ((int32_t)gpio < 0)
+ gpio = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_BASE) ;
+ if ((int32_t)gpio == -1)
{
if (wiringPiDebug)
fprintf (stderr, "wiringPiSetup: mmap failed: %s\n", strerror (errno)) ;
// PWM
- if ((pwmMem = malloc (BLOCK_SIZE + (PAGE_SIZE-1))) == NULL)
- {
- if (wiringPiDebug)
- fprintf (stderr, "wiringPiSetup: pwmMem malloc failed: %s\n", strerror (errno)) ;
- return -1 ;
- }
-
- if (((uint32_t)pwmMem % PAGE_SIZE) != 0)
- pwmMem += PAGE_SIZE - ((uint32_t)pwmMem % PAGE_SIZE) ;
-
- pwm = (uint32_t *)mmap(pwmMem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd, GPIO_PWM) ;
-
- if ((int32_t)pwm < 0)
+ pwm = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PWM) ;
+ if ((int32_t)pwm == -1)
{
if (wiringPiDebug)
fprintf (stderr, "wiringPiSetup: mmap failed (pwm): %s\n", strerror (errno)) ;
// Clock control (needed for PWM)
- if ((clkMem = malloc (BLOCK_SIZE + (PAGE_SIZE-1))) == NULL)
- {
- if (wiringPiDebug)
- fprintf (stderr, "wiringPiSetup: clkMem malloc failed: %s\n", strerror (errno)) ;
- return -1 ;
- }
-
- if (((uint32_t)clkMem % PAGE_SIZE) != 0)
- clkMem += PAGE_SIZE - ((uint32_t)clkMem % PAGE_SIZE) ;
-
- clk = (uint32_t *)mmap(clkMem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd, CLOCK_BASE) ;
-
+ clk = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, CLOCK_BASE) ;
if ((int32_t)clk < 0)
{
if (wiringPiDebug)
// The drive pads
- if ((padsMem = malloc (BLOCK_SIZE + (PAGE_SIZE-1))) == NULL)
- {
- if (wiringPiDebug)
- fprintf (stderr, "wiringPiSetup: padsMem malloc failed: %s\n", strerror (errno)) ;
- return -1 ;
- }
-
- if (((uint32_t)padsMem % PAGE_SIZE) != 0)
- padsMem += PAGE_SIZE - ((uint32_t)padsMem % PAGE_SIZE) ;
-
- pads = (uint32_t *)mmap(padsMem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd, GPIO_PADS) ;
-
+ pads = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_PADS) ;
if ((int32_t)pads < 0)
{
if (wiringPiDebug)
// The system timer
- if ((timerMem = malloc (BLOCK_SIZE + (PAGE_SIZE-1))) == NULL)
- {
- if (wiringPiDebug)
- fprintf (stderr, "wiringPiSetup: timerMem malloc failed: %s\n", strerror (errno)) ;
- return -1 ;
- }
-
- if (((uint32_t)timerMem % PAGE_SIZE) != 0)
- timerMem += PAGE_SIZE - ((uint32_t)timerMem % PAGE_SIZE) ;
-
- timer = (uint32_t *)mmap(timerMem, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd, GPIO_TIMER) ;
-
+ timer = (uint32_t *)mmap(0, BLOCK_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, fd, GPIO_TIMER) ;
if ((int32_t)timer < 0)
{
if (wiringPiDebug)