WiringPi V2.0 for Python2 & Python3

pull/6/head
Philip Howard 13 years ago
parent 98bcb20d93
commit 567ee0027e

2
.gitignore vendored

@ -0,0 +1,2 @@
build/
__pycache__

@ -0,0 +1,58 @@
WiringPi: An implementation of most of the Arduino Wiring
functions for the Raspberry Pi
Prerequisites:
You must have python-dev and python-setuptools installed
If you manually rebuild the bindings with swig -python wiringpi.i
then cat wiringpi_class.py >> wiringpi.py to get the class-based wrapper
Get/setup repo:
git clone https://github.com/WiringPi/WiringPi-Python.git
cd WiringPi-Python
git submodule update --init
Build & install with:
sudo python setup.py install
Class-based Usage:
import wiringpi
io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_PINS)
io.pinMode(1,io.OUTPUT)
io.digitalWrite(1,io.HIGH)
GPIO with /sys/class/gpio (You must first export the interfaces):
import wiringpi
io = wiringpi.GPIO(wiringpi.GPIO.WPI_MODE_SYS)
io.pinMode(1,io.OUTPUT)
io.digitalWrite(1,io.HIGH)
Serial:
serial = wiringpi.Serial('/dev/ttyAMA0',9600)
serial.puts("hello")
serial.close()
Usage:
import wiringpi
wiringpi.wiringPiSetup // For sequential pin numbering, one of these MUST be called before using IO functions
OR
wiringpi.wiringPiSetupSys // For /sys/class/gpio with GPIO pin numbering
OR
wiringpi.wiringPiSetupGpio // For GPIO pin numbering
General IO:
wiringpi.pinMode(1,1) // Set pin 1 to output
wiringpi.digitalWrite(1,1) // Write 1 HIGH to pin 1
wiringpi.digitalRead(1) // Read pin 1
Bit shifting:
wiringpi.shiftOut(1,2,0,123) // Shift out 123 (b1110110, byte 0-255) to data pin 1, clock pin 2
Serial:
serial = wiringpi.serialOpen('/dev/ttyAMA0',9600) // Requires device/baud and returns an ID
wiringpi.serialPuts(serial,"hello")
wiringpi.serialClose(serial) // Pass in ID
Full details at:
https://projects.drogon.net/raspberry-pi/wiringpi/

@ -38,7 +38,7 @@ LDLIBS = -lwiringPi -lpthread -lm
SRC = blink.c test1.c test2.c speed.c lcd.c wfi.c isr.c isr-osc.c \
piface.c gertboard.c nes.c \
pwm.c tone.c servo.c \
delayTest.c serialRead.c serialTest.c okLed.c
delayTest.c serialRead.c serialTest.c okLed.c ds1302.c
OBJ = $(SRC:.c=.o)
@ -123,6 +123,10 @@ servo: servo.o
@echo [link]
@$(CC) -o $@ servo.o $(LDFLAGS) $(LDLIBS)
ds1302: ds1302.o
@echo [link]
@$(CC) -o $@ ds1302.o $(LDFLAGS) $(LDLIBS)
.c.o:
@echo [CC] $<

@ -0,0 +1,238 @@
/*
* ds1302.c:
* Real Time clock
*
* Copyright (c) 2013 Gordon Henderson.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <time.h>
#include <wiringPi.h>
#include <ds1302.h>
// Register defines
#define RTC_SECS 0
#define RTC_MINS 1
#define RTC_HOURS 2
#define RTC_DATE 3
#define RTC_MONTH 4
#define RTC_DAY 5
#define RTC_YEAR 6
#define RTC_WP 7
#define RTC_TC 8
#define RTC_BM 31
static unsigned int masks [] = { 0x7F, 0x7F, 0x3F, 0x3F, 0x1F, 0x07, 0xFF } ;
/*
* bcdToD: dToBCD:
* BCD decode/encode
*********************************************************************************
*/
static int bcdToD (unsigned int byte, unsigned int mask)
{
unsigned int b1, b2 ;
byte &= mask ;
b1 = byte & 0x0F ;
b2 = ((byte >> 4) & 0x0F) * 10 ;
return b1 + b2 ;
}
static unsigned int dToBcd (unsigned int byte)
{
return ((byte / 10) << 4) + (byte % 10) ;
}
/*
* ramTest:
* Simple test of the 31 bytes of RAM inside the DS1302 chip
*********************************************************************************
*/
static int ramTestValues [] =
{ 0x00, 0xFF, 0xAA, 0x55, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00, 0xF0, 0x0F, -1 } ;
static int ramTest (void)
{
int addr ;
int got ;
int i = 0 ;
int errors = 0 ;
int testVal ;
printf ("DS1302 RAM TEST\n") ;
testVal = ramTestValues [i] ;
while (testVal != -1)
{
for (addr = 0 ; addr < 31 ; ++addr)
ds1302ramWrite (addr, testVal) ;
for (addr = 0 ; addr < 31 ; ++addr)
if ((got = ds1302ramRead (addr)) != testVal)
{
printf ("DS1302 RAM Failure: Address: %2d, Expected: 0x%02X, Got: 0x%02X\n",
addr, testVal, got) ;
++errors ;
}
testVal = ramTestValues [++i] ;
}
for (addr = 0 ; addr < 31 ; ++addr)
ds1302ramWrite (addr, addr) ;
for (addr = 0 ; addr < 31 ; ++addr)
if ((got = ds1302ramRead (addr)) != addr)
{
printf ("DS1302 RAM Failure: Address: %2d, Expected: 0x%02X, Got: 0x%02X\n",
addr, addr, got) ;
++errors ;
}
if (errors == 0)
printf ("-- DS1302 RAM TEST: OK\n") ;
else
printf ("-- DS1302 RAM TEST FAILURE. %d errors.\n", errors) ;
return 0 ;
}
/*
* setLinuxClock:
* Set the Linux clock from the hardware
*********************************************************************************
*/
static int setLinuxClock (void)
{
char dateTime [20] ;
char command [64] ;
int clock [8] ;
printf ("Setting the Linux Clock from the DS1302... ") ; fflush (stdout) ;
ds1302clockRead (clock) ;
// [MMDDhhmm[[CC]YY][.ss]]
sprintf (dateTime, "%02d%02d%02d%02d%02d%02d.%02d",
bcdToD (clock [RTC_MONTH], masks [RTC_MONTH]),
bcdToD (clock [RTC_DATE], masks [RTC_DATE]),
bcdToD (clock [RTC_HOURS], masks [RTC_HOURS]),
bcdToD (clock [RTC_MINS], masks [RTC_MINS]),
20,
bcdToD (clock [RTC_YEAR], masks [RTC_YEAR]),
bcdToD (clock [RTC_SECS], masks [RTC_SECS])) ;
sprintf (command, "/bin/date %s", dateTime) ;
system (command) ;
return 0 ;
}
/*
* setDSclock:
* Set the DS1302 block from Linux time
*********************************************************************************
*/
static int setDSclock (void)
{
struct tm t ;
time_t now ;
int clock [8] ;
printf ("Setting the clock in the DS1302 from Linux time... ") ;
now = time (NULL) ;
gmtime_r (&now, &t) ;
clock [ 0] = dToBcd (t.tm_sec) ; // seconds
clock [ 1] = dToBcd (t.tm_min) ; // mins
clock [ 2] = dToBcd (t.tm_hour) ; // hours
clock [ 3] = dToBcd (t.tm_mday) ; // date
clock [ 4] = dToBcd (t.tm_mon + 1) ; // months 0-11 --> 1-12
clock [ 5] = dToBcd (t.tm_wday + 1) ; // weekdays (sun 0)
clock [ 6] = dToBcd (t.tm_year - 100) ; // years
clock [ 7] = 0 ; // W-Protect off
ds1302clockWrite (clock) ;
printf ("OK\n") ;
return 0 ;
}
int main (int argc, char *argv [])
{
int i ;
int clock [8] ;
wiringPiSetup () ;
ds1302setup (0, 1, 2) ;
if (argc == 2)
{
/**/ if (strcmp (argv [1], "-slc") == 0)
return setLinuxClock () ;
else if (strcmp (argv [1], "-sdsc") == 0)
return setDSclock () ;
else if (strcmp (argv [1], "-rtest") == 0)
return ramTest () ;
else
{
printf ("Usage: ds1302 [-slc | -sdsc | -rtest]\n") ;
return EXIT_FAILURE ;
}
}
for (i = 0 ;; ++i)
{
printf ("%5d: ", i) ;
ds1302clockRead (clock) ;
printf (" %2d:%02d:%02d",
bcdToD (clock [2], masks [2]), bcdToD (clock [1], masks [1]), bcdToD (clock [0], masks [0])) ;
printf (" %2d/%02d/%04d",
bcdToD (clock [3], masks [3]), bcdToD (clock [4], masks [4]), bcdToD (clock [6], masks [6]) + 2000) ;
printf ("\n") ;
delay (200) ;
}
return 0 ;
}

Before

Width:  |  Height:  |  Size: 4.7 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

@ -25,6 +25,7 @@
*/
#include <wiringPi.h>
#include <piFace.h>
#include <stdio.h>
#include <stdlib.h>
@ -32,15 +33,17 @@
int outputs [4] = { 0,0,0,0 } ;
#define PIFACE_BASE 200
void scanButton (int button)
{
if (digitalRead (button) == LOW)
if (digitalRead (PIFACE_BASE + button) == LOW)
{
outputs [button] ^= 1 ;
digitalWrite (button, outputs [button]) ;
digitalWrite (PIFACE_BASE + button, outputs [button]) ;
}
while (digitalRead (button) == LOW)
while (digitalRead (PIFACE_BASE + button) == LOW)
delay (1) ;
}
@ -50,16 +53,16 @@ int main (void)
int pin, button ;
printf ("Raspberry Pi wiringPiFace test program\n") ;
printf ("======================================\n") ;
if (wiringPiSetupPiFace () == -1)
if (piFaceSetup (200) == -1)
exit (1) ;
// Enable internal pull-ups
for (pin = 0 ; pin < 8 ; ++pin)
for (pin = PIFACE_BASE ; pin < (PIFACE_BASE + 8) ; ++pin)
pullUpDnControl (pin, PUD_UP) ;
for (;;)
{
for (button = 0 ; button < 4 ; ++button)

@ -8,8 +8,8 @@ gpio \- Command-line access to Raspberry Pi and PiFace GPIO
.B \-v
.PP
.B gpio
.B [ \-g ]
.B read/write/wb/pwm/clock/mode ...
.B [ \-g | \-1 ]
.B read/write/aread/awrite/wb/pwm/clock/mode ...
.PP
.B gpio
.B [ \-p ]
@ -17,7 +17,7 @@ gpio \- Command-line access to Raspberry Pi and PiFace GPIO
.B ...
.PP
.B gpio
.B readall
.B readall/reset
.PP
.B gpio
.B unexportall/exports
@ -73,12 +73,21 @@ Output the current version including the board revision of the Raspberry Pi.
.TP
.B \-g
Use the BCM_GPIO pins numbers rather than wiringPi pin numbers.
\fINOTE:\fR The BCM_GPIO pin numbers are always used with the
\fINote:\fR The BCM_GPIO pin numbers are always used with the
export and edge commands.
.TP
.B \-1
Use the physical pin numbers rather than wiringPi pin numbers.
\fINote:\fR that this applies to the P1 connector only. It is not possible to
use pins on the Revision 2 P5 connector this way, and as with \-g the
BCM_GPIO pin numbers are always used with the export and edge commands.
.TP
.B \-p
Use the PiFace interface board and its corresponding pin numbers.
Use the PiFace interface board and its corresponding pin numbers. The PiFace
will always appear at pin number 200 in the gpio command. You can assign any
pin numbers you like in your own programs though.
.TP
.B read <pin>
@ -102,6 +111,11 @@ Output a table of all GPIO pins values. The values represent the actual values r
if the pin is in input mode, or the last value written if the pin is in output
mode.
.TP
.B reset
Resets the GPIO - As much as it's possible to do. All pins are set to input
mode and all the internal pull-up/down resistors are disconnected (tristate mode).
.TP
.B pwm <pin> <value>
Write a PWM value (0-1023) to the given pin. The pin needs to be put

@ -2,7 +2,7 @@
* gpio.c:
* Swiss-Army-Knife, Set-UID command-line interface to the Raspberry
* Pi's GPIO.
* Copyright (c) 2012 Gordon Henderson
* Copyright (c) 2012-2013 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
@ -26,6 +26,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
@ -33,7 +34,14 @@
#include <fcntl.h>
#include <wiringPi.h>
#include <gertboard.h>
#include <piFace.h>
#include <sr595.h>
#include <mcp23008.h>
#include <mcp23017.h>
#include <mcp23s08.h>
#include <mcp23s17.h>
extern int wiringPiDebug ;
@ -42,16 +50,17 @@ extern int wiringPiDebug ;
# define FALSE (1==2)
#endif
#define VERSION "1.12"
#define VERSION "2.00"
static int wpMode ;
char *usage = "Usage: gpio -v\n"
" gpio -h\n"
" gpio [-g] <read/write/wb/pwm/clock/mode> ...\n"
" gpio [-g|-1] [-x module:params] ...\n"
" gpio [-p] <read/write/wb> ...\n"
" gpio readall\n"
" gpio unexportall/exports ...\n"
" gpio <read/write/aread/awritewb/pwm/clock/mode> ...\n"
" gpio readall/reset\n"
" gpio unexportall/exports\n"
" gpio export/edge/unexport ...\n"
" gpio drive <group> <value>\n"
" gpio pwm-bal/pwm-ms \n"
@ -61,6 +70,193 @@ char *usage = "Usage: gpio -v\n"
" gpio gbr <channel>\n"
" gpio gbw <channel> <value>" ; // No trailing newline needed here.
struct moduleFunctionStruct
{
const char *name ;
int (*function)(char *progName, int pinBase, char *params) ;
} ;
static int doModuleMcp23008 (char *progName, int pinBase, char *params)
{
int i2c ;
// Extract the I2C address:
if (*params != ':')
{
fprintf (stderr, "%s: colon expected after pin-base number\n", progName) ;
return FALSE ;
}
++params ;
if (!isdigit (*params))
{
fprintf (stderr, "%s: digit expected after pin-base number\n", progName) ;
return FALSE ;
}
i2c = strtol (params, NULL, 0) ;
if ((i2c < 0x03) || (i2c > 0x77))
{
fprintf (stderr, "%s: i2c address (0x%X) out of range\n", progName, i2c) ;
return FALSE ;
}
mcp23008Setup (pinBase, i2c) ;
return TRUE ;
}
static int doModuleMcp23017 (char *progName, int pinBase, char *params)
{
int i2c ;
// Extract the I2C address:
if (*params != ':')
{
fprintf (stderr, "%s: colon expected after pin-base number\n", progName) ;
return FALSE ;
}
++params ;
if (!isdigit (*params))
{
fprintf (stderr, "%s: digit expected after pin-base number\n", progName) ;
return FALSE ;
}
i2c = strtol (params, NULL, 0) ;
if ((i2c < 0x03) || (i2c > 0x77))
{
fprintf (stderr, "%s: i2c address (0x%X) out of range\n", progName, i2c) ;
return FALSE ;
}
mcp23017Setup (pinBase, i2c) ;
return TRUE ;
}
static int doModuleMcp23s08 (char *progName, int pinBase, char *params)
{
int spi, port ;
// Extract the SPI address:
if (*params != ':')
{
fprintf (stderr, "%s: colon expected after pin-base number\n", progName) ;
return FALSE ;
}
++params ;
if (!isdigit (*params))
{
fprintf (stderr, "%s: digit expected after pin-base number\n", progName) ;
return FALSE ;
}
spi = *params - '0' ;
if ((spi < 0) || (spi > 1))
{
fprintf (stderr, "%s: SPI address (%d) out of range\n", progName, spi) ;
return FALSE ;
}
// Extract the port:
if (*++params != ':')
{
fprintf (stderr, "%s: colon expected after SPI address\n", progName) ;
return FALSE ;
}
++params ;
if (!isdigit (*params))
{
fprintf (stderr, "%s: digit expected after SPI address\n", progName) ;
return FALSE ;
}
port = strtol (params, NULL, 0) ;
if ((port < 0) || (port > 7))
{
fprintf (stderr, "%s: port address (%d) out of range\n", progName, port) ;
return FALSE ;
}
mcp23s08Setup (pinBase, spi, port) ;
return TRUE ;
}
static int doModuleMcp23s17 (char *progName, int pinBase, char *params)
{
int spi, port ;
// Extract the SPI address:
if (*params != ':')
{
fprintf (stderr, "%s: colon expected after pin-base number\n", progName) ;
return FALSE ;
}
++params ;
if (!isdigit (*params))
{
fprintf (stderr, "%s: digit expected after pin-base number\n", progName) ;
return FALSE ;
}
spi = *params - '0' ;
if ((spi < 0) || (spi > 1))
{
fprintf (stderr, "%s: SPI address (%d) out of range\n", progName, spi) ;
return FALSE ;
}
// Extract the port:
if (*++params != ':')
{
fprintf (stderr, "%s: colon expected after SPI address\n", progName) ;
return FALSE ;
}
++params ;
if (!isdigit (*params))
{
fprintf (stderr, "%s: digit expected after SPI address\n", progName) ;
return FALSE ;
}
port = strtol (params, NULL, 0) ;
if ((port < 0) || (port > 7))
{
fprintf (stderr, "%s: port address (%d) out of range\n", progName, port) ;
return FALSE ;
}
mcp23s17Setup (pinBase, spi, port) ;
return TRUE ;
}
struct moduleFunctionStruct moduleFunctions [] =
{
{ "mcp23008", &doModuleMcp23008 },
{ "mcp23017", &doModuleMcp23017 },
{ "mcp23s08", &doModuleMcp23s08 },
{ "mcp23s17", &doModuleMcp23s17 },
{ NULL, NULL },
} ;
/*
* changeOwner:
@ -215,27 +411,39 @@ static char *alts [] =
"IN ", "OUT ", "ALT5", "ALT4", "ALT0", "ALT1", "ALT2", "ALT3"
} ;
static int wpiToPhys [64] =
{
11, 12, 13, 15, 16, 18, 22, 7, // 0...7
3, 5, // 8...9
24, 26, 19, 21, 23, // 10..14
8, 10, // 15..16
3, 4, 5, 6, // 17..20
0,0,0,0,0,0,0,0,0,0,0, // 20..31
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 32..47
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, // 47..63
} ;
static void doReadall (void)
{
int pin ;
printf ("+----------+------+--------+------+-------+\n") ;
printf ("| wiringPi | GPIO | Name | Mode | Value |\n") ;
printf ("+----------+------+--------+------+-------+\n") ;
printf ("+----------+-Rev%d-+------+--------+------+-------+\n", piBoardRev ()) ;
printf ("| wiringPi | GPIO | Phys | Name | Mode | Value |\n") ;
printf ("+----------+------+------+--------+------+-------+\n") ;
for (pin = 0 ; pin < 64 ; ++pin)
{
if (wpiPinToGpio (pin) == -1)
continue ;
printf ("| %6d | %3d | %s | %s | %s |\n",
pin, wpiPinToGpio (pin),
printf ("| %6d | %3d | %3d | %s | %s | %s |\n",
pin, wpiPinToGpio (pin), wpiToPhys [pin],
pinNames [pin],
alts [getAlt (pin)],
digitalRead (pin) == HIGH ? "High" : "Low ") ;
}
printf ("+----------+------+--------+------+-------+\n") ;
printf ("+----------+------+------+--------+------+-------+\n") ;
}
@ -499,7 +707,7 @@ void doUnexport (int argc, char *argv [])
*********************************************************************************
*/
void doUnexportall (int argc, char *argv [])
void doUnexportall (char *progName)
{
FILE *fd ;
int pin ;
@ -508,7 +716,7 @@ void doUnexportall (int argc, char *argv [])
{
if ((fd = fopen ("/sys/class/gpio/unexport", "w")) == NULL)
{
fprintf (stderr, "%s: Unable to open GPIO export interface\n", argv [0]) ;
fprintf (stderr, "%s: Unable to open GPIO export interface\n", progName) ;
exit (1) ;
}
fprintf (fd, "%d\n", pin) ;
@ -517,6 +725,30 @@ void doUnexportall (int argc, char *argv [])
}
/*
* doReset:
* Reset the GPIO pins - as much as we can do
*********************************************************************************
*/
static void doReset (char *progName)
{
int pin ;
doUnexportall (progName) ;
for (pin = 0 ; pin < 64 ; ++pin)
{
if (wpiPinToGpio (pin) == -1)
continue ;
digitalWrite (pin, LOW) ;
pinMode (pin, INPUT) ;
pullUpDnControl (pin, PUD_OFF) ;
}
}
/*
* doMode:
* gpio mode pin mode ...
@ -536,9 +768,6 @@ void doMode (int argc, char *argv [])
pin = atoi (argv [2]) ;
if ((wpMode == WPI_MODE_PINS) && ((pin < 0) || (pin >= NUM_PINS)))
return ;
mode = argv [3] ;
/**/ if (strcasecmp (mode, "in") == 0) pinMode (pin, INPUT) ;
@ -623,13 +852,13 @@ static void doGbw (int argc, char *argv [])
exit (1) ;
}
if (gertboardSPISetup () == -1)
if (gertboardAnalogSetup (64) < 0)
{
fprintf (stderr, "Unable to initialise the Gertboard SPI interface: %s\n", strerror (errno)) ;
exit (1) ;
}
gertboardAnalogWrite (channel, value) ;
analogWrite (64 + channel, value) ;
}
@ -658,17 +887,16 @@ static void doGbr (int argc, char *argv [])
exit (1) ;
}
if (gertboardSPISetup () == -1)
if (gertboardAnalogSetup (64) < 0)
{
fprintf (stderr, "Unable to initialise the Gertboard SPI interface: %s\n", strerror (errno)) ;
exit (1) ;
}
printf ("%d\n",gertboardAnalogRead (channel)) ;
printf ("%d\n", analogRead (64 + channel)) ;
}
/*
* doWrite:
* gpio write pin value
@ -687,9 +915,6 @@ static void doWrite (int argc, char *argv [])
pin = atoi (argv [2]) ;
if ((wpMode == WPI_MODE_PINS) && ((pin < 0) || (pin >= NUM_PINS)))
return ;
/**/ if ((strcasecmp (argv [3], "up") == 0) || (strcasecmp (argv [3], "on") == 0))
val = 1 ;
else if ((strcasecmp (argv [3], "down") == 0) || (strcasecmp (argv [3], "off") == 0))
@ -703,6 +928,31 @@ static void doWrite (int argc, char *argv [])
digitalWrite (pin, HIGH) ;
}
/*
* doAwriterite:
* gpio awrite pin value
*********************************************************************************
*/
static void doAwrite (int argc, char *argv [])
{
int pin, val ;
if (argc != 4)
{
fprintf (stderr, "Usage: %s awrite pin value\n", argv [0]) ;
exit (1) ;
}
pin = atoi (argv [2]) ;
val = atoi (argv [3]) ;
analogWrite (pin, val) ;
}
/*
* doWriteByte:
* gpio write value
@ -743,13 +993,31 @@ void doRead (int argc, char *argv [])
pin = atoi (argv [2]) ;
if ((wpMode == WPI_MODE_PINS) && ((pin < 0) || (pin >= NUM_PINS)))
val = digitalRead (pin) ;
printf ("%s\n", val == 0 ? "0" : "1") ;
}
/*
* doAread:
* Read an analog pin and return the value
*********************************************************************************
*/
void doAread (int argc, char *argv [])
{
int pin, val ;
if (argc != 3)
{
printf ("0\n") ;
return ;
fprintf (stderr, "Usage: %s aread pin\n", argv [0]) ;
exit (1) ;
}
val = digitalRead (pin) ;
pin = atoi (argv [2]) ;
val = analogRead (pin) ;
printf ("%s\n", val == 0 ? "0" : "1") ;
}
@ -773,9 +1041,6 @@ void doClock (int argc, char *argv [])
pin = atoi (argv [2]) ;
if ((wpMode == WPI_MODE_PINS) && ((pin < 0) || (pin >= NUM_PINS)))
return ;
freq = atoi (argv [3]) ;
gpioClockSet (pin, freq) ;
@ -800,9 +1065,6 @@ void doPwm (int argc, char *argv [])
pin = atoi (argv [2]) ;
if ((wpMode == WPI_MODE_PINS) && ((pin < 0) || (pin >= NUM_PINS)))
return ;
val = atoi (argv [3]) ;
pwmWrite (pin, val) ;
@ -863,6 +1125,72 @@ static void doPwmClock (int argc, char *argv [])
}
/*
* doModule:
* Load in a wiringPi extension module
*********************************************************************************
*/
static int doModule (char *progName, char *moduleData)
{
char *p ;
char *module = moduleData ;
struct moduleFunctionStruct *modFn ;
int pinBase = 0 ;
// Get the module name by finding the first :
p = module ;
while (*p != ':')
{
if (!*p) // ran out of characters
{
fprintf (stderr, "%s: module name not terminated by a colon\n", progName) ;
return FALSE ;
}
++p ;
}
*p++ = 0 ;
if (!isdigit (*p))
{
fprintf (stderr, "%s: pinBase number expected after module name\n", progName) ;
return FALSE ;
}
while (isdigit (*p))
{
if (pinBase > 1000000000)
{
fprintf (stderr, "%s: pinBase too large\n", progName) ;
return FALSE ;
}
pinBase = pinBase * 10 + (*p - '0') ;
++p ;
}
if (pinBase < 64)
{
fprintf (stderr, "%s: pinBase (%d) too small. Minimum is 64.\n", progName, pinBase) ;
return FALSE ;
}
// Search for modules:
for (modFn = moduleFunctions ; modFn->name != NULL ; ++modFn)
{
if (strcmp (modFn->name, module) == 0)
return modFn->function (progName, pinBase, p) ;
}
fprintf (stderr, "%s: module %s not found\n", progName, module) ;
return FALSE ;
}
/*
* main:
* Start here
@ -894,7 +1222,7 @@ int main (int argc, char *argv [])
if (strcasecmp (argv [1], "-v") == 0)
{
printf ("gpio version: %s\n", VERSION) ;
printf ("Copyright (c) 2012 Gordon Henderson\n") ;
printf ("Copyright (c) 2012-2013 Gordon Henderson\n") ;
printf ("This is free software with ABSOLUTELY NO WARRANTY.\n") ;
printf ("For details type: %s -warranty\n", argv [0]) ;
printf ("\n") ;
@ -905,7 +1233,7 @@ int main (int argc, char *argv [])
if (strcasecmp (argv [1], "-warranty") == 0)
{
printf ("gpio version: %s\n", VERSION) ;
printf ("Copyright (c) 2012 Gordon Henderson\n") ;
printf ("Copyright (c) 2012-2013 Gordon Henderson\n") ;
printf ("\n") ;
printf (" This program is free software; you can redistribute it and/or modify\n") ;
printf (" it under the terms of the GNU Leser General Public License as published\n") ;
@ -934,8 +1262,8 @@ int main (int argc, char *argv [])
/**/ if (strcasecmp (argv [1], "exports" ) == 0) { doExports (argc, argv) ; return 0 ; }
else if (strcasecmp (argv [1], "export" ) == 0) { doExport (argc, argv) ; return 0 ; }
else if (strcasecmp (argv [1], "edge" ) == 0) { doEdge (argc, argv) ; return 0 ; }
else if (strcasecmp (argv [1], "unexportall") == 0) { doUnexportall (argc, argv) ; return 0 ; }
else if (strcasecmp (argv [1], "unexport" ) == 0) { doUnexport (argc, argv) ; return 0 ; }
else if (strcasecmp (argv [1], "unexportall") == 0) { doUnexportall (argv [0]) ; return 0 ; }
// Check for load command:
@ -948,13 +1276,9 @@ int main (int argc, char *argv [])
// Check for -g argument
if (strcasecmp (argv [1], "-g") == 0)
/**/ if (strcasecmp (argv [1], "-g") == 0)
{
if (wiringPiSetupGpio () == -1)
{
fprintf (stderr, "%s: Unable to initialise GPIO mode.\n", argv [0]) ;
exit (1) ;
}
wiringPiSetupGpio () ;
for (i = 2 ; i < argc ; ++i)
argv [i - 1] = argv [i] ;
@ -962,15 +1286,23 @@ int main (int argc, char *argv [])
wpMode = WPI_MODE_GPIO ;
}
// Check for -1 argument
else if (strcasecmp (argv [1], "-1") == 0)
{
wiringPiSetupPhys () ;
for (i = 2 ; i < argc ; ++i)
argv [i - 1] = argv [i] ;
--argc ;
wpMode = WPI_MODE_PHYS ;
}
// Check for -p argument for PiFace
else if (strcasecmp (argv [1], "-p") == 0)
{
if (wiringPiSetupPiFaceForGpioProg () == -1)
{
fprintf (stderr, "%s: Unable to initialise PiFace.\n", argv [0]) ;
exit (1) ;
}
piFaceSetup (200) ;
for (i = 2 ; i < argc ; ++i)
argv [i - 1] = argv [i] ;
@ -982,38 +1314,58 @@ int main (int argc, char *argv [])
else
{
if (wiringPiSetup () == -1)
{
fprintf (stderr, "%s: Unable to initialise wiringPi mode\n", argv [0]) ;
exit (1) ;
}
wiringPiSetup () ;
wpMode = WPI_MODE_PINS ;
}
// Check for PWM or Pad Drive operations
// Check for -x argument to load in a new module
if (wpMode != WPI_MODE_PIFACE)
if (strcasecmp (argv [1], "-x") == 0)
{
if (strcasecmp (argv [1], "pwm-bal") == 0) { doPwmMode (PWM_MODE_BAL) ; return 0 ; }
if (strcasecmp (argv [1], "pwm-ms") == 0) { doPwmMode (PWM_MODE_MS) ; return 0 ; }
if (strcasecmp (argv [1], "pwmr") == 0) { doPwmRange (argc, argv) ; return 0 ; }
if (strcasecmp (argv [1], "pwmc") == 0) { doPwmClock (argc, argv) ; return 0 ; }
if (strcasecmp (argv [1], "drive") == 0) { doPadDrive (argc, argv) ; return 0 ; }
if (argc < 3)
{
fprintf (stderr, "%s: -x missing module specification.\n", argv [0]) ;
exit (EXIT_FAILURE) ;
}
if (!doModule (argv [0], argv [2])) // Prints its own error messages
exit (EXIT_FAILURE) ;
for (i = 3 ; i < argc ; ++i)
argv [i - 2] = argv [i] ;
argc -= 2 ;
}
// Check for wiring commands
if (argc <= 1)
{
fprintf (stderr, "%s: no command given\n", argv [0]) ;
exit (EXIT_FAILURE) ;
}
/**/ if (strcasecmp (argv [1], "readall" ) == 0) doReadall () ;
else if (strcasecmp (argv [1], "read" ) == 0) doRead (argc, argv) ;
else if (strcasecmp (argv [1], "write") == 0) doWrite (argc, argv) ;
else if (strcasecmp (argv [1], "wb") == 0) doWriteByte (argc, argv) ;
else if (strcasecmp (argv [1], "pwm" ) == 0) doPwm (argc, argv) ;
else if (strcasecmp (argv [1], "clock") == 0) doClock (argc, argv) ;
else if (strcasecmp (argv [1], "mode" ) == 0) doMode (argc, argv) ;
// Core wiringPi functions
/**/ if (strcasecmp (argv [1], "mode" ) == 0) doMode (argc, argv) ;
else if (strcasecmp (argv [1], "read" ) == 0) doRead (argc, argv) ;
else if (strcasecmp (argv [1], "write" ) == 0) doWrite (argc, argv) ;
else if (strcasecmp (argv [1], "pwm" ) == 0) doPwm (argc, argv) ;
else if (strcasecmp (argv [1], "awrite" ) == 0) doAwrite (argc, argv) ;
else if (strcasecmp (argv [1], "aread" ) == 0) doAread (argc, argv) ;
// Pi Specifics
else if (strcasecmp (argv [1], "pwm-bal") == 0) doPwmMode (PWM_MODE_BAL) ;
else if (strcasecmp (argv [1], "pwm-ms" ) == 0) doPwmMode (PWM_MODE_MS) ;
else if (strcasecmp (argv [1], "pwmr" ) == 0) doPwmRange (argc, argv) ;
else if (strcasecmp (argv [1], "pwmc" ) == 0) doPwmClock (argc, argv) ;
else if (strcasecmp (argv [1], "drive" ) == 0) doPadDrive (argc, argv) ;
else if (strcasecmp (argv [1], "readall") == 0) doReadall () ;
else if (strcasecmp (argv [1], "reset" ) == 0) doReset (argv [0]) ;
else if (strcasecmp (argv [1], "wb" ) == 0) doWriteByte (argc, argv) ;
else if (strcasecmp (argv [1], "clock" ) == 0) doClock (argc, argv) ;
else
{
fprintf (stderr, "%s: Unknown command: %s.\n", argv [0], argv [1]) ;
exit (1) ;
exit (EXIT_FAILURE) ;
}
return 0 ;
}

@ -0,0 +1,18 @@
SRC = pins.tex
all: ${SRC}
@echo Generating DVI
@latex pins.tex
pins.dvi: pins.tex
@latex pins.tex
pdf: pins.dvi
@dvipdf pins.dvi
.PHONEY: clean
clean:
@rm -f *.dvi *.aux *.log *.ps *.toc *.bak *~

Binary file not shown.

@ -0,0 +1,116 @@
\documentclass[12pt,a4paper]{article}
\parskip 1ex
\parindent 0em
\thispagestyle{empty}
\pagestyle{plain}
\pagenumbering{arabic}
\setlength{\topmargin}{0pt}
\setlength{\headheight}{0pt}
\setlength{\headsep}{0pt}
\setlength{\topskip}{0pt}
\setlength{\textheight}{240mm}
\setlength{\footskip}{5ex}
\setlength{\oddsidemargin}{0pt}
\setlength{\evensidemargin}{0pt}
\setlength{\textwidth}{160mm}
\usepackage[dvips]{graphics,color}
\usepackage{helvet}
\renewcommand{\familydefault}{\sfdefault}
\begin{document}
\begin{sffamily}
\definecolor{rtb-black}{rgb} {0.0, 0.0, 0.0}
\definecolor{rtb-navy}{rgb} {0.0, 0.0, 0.5}
\definecolor{rtb-green}{rgb} {0.0, 0.5, 0.0}
\definecolor{rtb-teal}{rgb} {0.0, 0.5, 0.5}
\definecolor{rtb-maroon}{rgb} {0.5, 0.0, 0.0}
\definecolor{rtb-purple}{rgb} {0.5, 0.0, 0.5}
\definecolor{rtb-olive}{rgb} {0.5, 0.5, 0.0}
\definecolor{rtb-silver}{rgb} {0.7, 0.7, 0.7}
\definecolor{rtb-grey}{rgb} {0.5, 0.5, 0.5}
\definecolor{rtb-blue}{rgb} {0.0, 0.0, 1.0}
\definecolor{rtb-lime}{rgb} {0.0, 1.0, 0.0}
\definecolor{rtb-aqua}{rgb} {0.0, 1.0, 1.0}
\definecolor{rtb-red}{rgb} {1.0, 0.0, 0.0}
\definecolor{rtb-fuchsia}{rgb}{1.0, 0.0, 1.0}
\definecolor{rtb-yellow}{rgb} {1.0, 1.0, 0.0}
\definecolor{rtb-white}{rgb} {1.0, 1.0, 1.0}
\begin{center}
\bfseries{WiringPi: GPIO Pin Numbering Tables}\\
\tt{http://wiringpi.com/}
\end{center}
\begin{center}
\begin{tabular}{|c|c|c||p{8mm}|p{8mm}||c|c|c|c|}
\hline
\multicolumn{8}{|c|}{\bfseries{P1: The Main GPIO connector}}\\
\hline
\hline
WiringPi Pin & BCM GPIO & Name & \multicolumn{2}{|c||}{Header} & Name & BCM GPIO & WiringPi Pin\\
\hline
\hline
& & \textcolor{rtb-red}{3.3v} & \raggedleft{1} & 2 & \textcolor{rtb-maroon}{5v} & & \\
\hline
8 & Rv1:0 - Rv2:2 & \textcolor{rtb-aqua}{SDA} & \raggedleft{3} & 4 & \textcolor{rtb-maroon}{5v} & & \\
\hline
9 & Rv1:1 - Rv2:3 & \textcolor{rtb-aqua}{SCL} & \raggedleft{5} & 6 & \textcolor{rtb-black}{0v} & & \\
\hline
7 & 4 & \textcolor{rtb-green}{GPIO7} & \raggedleft{7} & 8 & \textcolor{rtb-yellow}{TxD} & 14 & 15\\
\hline
& & \textcolor{rtb-black}{0v} & \raggedleft{9} & 10 & \textcolor{rtb-yellow}{RxD} & 15 & 16\\
\hline
0 & 17 & \textcolor{rtb-green}{GPIO0} & \raggedleft{11} & 12 & \textcolor{rtb-green}{GPIO1} & 18 & 1\\
\hline
2 & Rv1:21 - Rv2:27 & \textcolor{rtb-green}{GPIO2} & \raggedleft{13} & 14 & \textcolor{rtb-black}{0v} & & \\
\hline
3 & 22 & \textcolor{rtb-green}{GPIO3} & \raggedleft{15} & 16 & \textcolor{rtb-green}{GPIO4} & 23 & 4\\
\hline
& & \textcolor{rtb-red}{3.3v} & \raggedleft{17} & 18 & \textcolor{rtb-green}{GPIO5} & 24 & 5\\
\hline
12 & 10 & \textcolor{rtb-teal}{MOSI} & \raggedleft{19} & 20 & \textcolor{rtb-black}{0v} & & \\
\hline
13 & 9 & \textcolor{rtb-teal}{MISO} & \raggedleft{21} & 22 & \textcolor{rtb-green}{GPIO6} & 25 & 6\\
\hline
14 & 11 & \textcolor{rtb-teal}{SCLK} & \raggedleft{23} & 24 & \textcolor{rtb-teal}{CE0} & 8 & 10\\
\hline
& & \textcolor{rtb-black}{0v} & \raggedleft{25} & 26 & \textcolor{rtb-teal}{CE1} & 7 & 11\\
\hline
\hline
WiringPi Pin & BCM GPIO & Name & \multicolumn{2}{|c||}{Header} & Name & BCM GPIO & WiringPi Pin\\
\hline
\end{tabular}
\end{center}
Note the differences between Revision 1 and Revision 2 Raspberry
Pi's. The Revision 2 is readily identifiable by the presence of the 2
mounting holes.
The revision 2 Raspberry Pi has an additional GPIO connector, P5, which is next to the main P1 GPIO
connector:
\begin{center}
\begin{tabular}{|c|c|c||p{8mm}|p{8mm}||c|c|c|c|}
\hline
\multicolumn{8}{|c|}{\bfseries{P5: Secondary GPIO connector (Rev. 2 Pi only)}}\\
\hline
\hline
WiringPi Pin & BCM GPIO & Name & \multicolumn{2}{|c||}{Header} & Name & BCM GPIO & WiringPi Pin\\
\hline
\hline
& & \textcolor{rtb-maroon}{5v} & \raggedleft{1} & 2 & \textcolor{rtb-red}{3.3v} & & \\
\hline
17 & 28 & \textcolor{rtb-green}{GPIO8} & \raggedleft{3} & 4 & \textcolor{rtb-green}{GPIO9} & 29 & 18 \\
\hline
19 & 30 & \textcolor{rtb-green}{GPIO10} & \raggedleft{5} & 6 & \textcolor{rtb-green}{GPIO11} & 31 & 20 \\
\hline
& & \textcolor{rtb-black}{0v} & \raggedleft{7} & 8 & \textcolor{rtb-black}{0v} & & \\
\hline
\hline
WiringPi Pin & BCM GPIO & Name & \multicolumn{2}{|c||}{Header} & Name & BCM GPIO & WiringPi Pin\\
\hline
\end{tabular}
\end{center}
\end{sffamily}
\end{document}

@ -21,7 +21,7 @@
# along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
#################################################################################
DYN_VERS_MAJ=1
DYN_VERS_MAJ=2
DYN_VERS_MIN=0
VERSION=$(DYN_VERS_MAJ).$(DYN_VERS_MIN)
@ -42,19 +42,18 @@ LIBS =
# Should not alter anything below this line
###############################################################################
SRC = wiringPi.c wiringPiFace.c wiringSerial.c wiringShift.c \
gertboard.c \
piNes.c \
lcd.c piHiPri.c piThread.c \
wiringPiSPI.c \
softPwm.c softServo.c softTone.c
SRC_I2C = wiringPiI2C.c
SRC = wiringPi.c \
wiringSerial.c wiringShift.c \
piHiPri.c piThread.c \
wiringPiSPI.c wiringPiI2C.c \
softPwm.c softTone.c \
mcp23s08.c mcp23008.c \
mcp23s17.c mcp23017.c sr595.c \
piFace.c gertboard.c \
piNes.c ds1302.c lcd.c
OBJ = $(SRC:.c=.o)
OBJ_I2C = $(SRC_I2C:.c=.o)
all: $(DYNAMIC)
static: $(STATIC)
@ -67,11 +66,7 @@ $(STATIC): $(OBJ)
$(DYNAMIC): $(OBJ)
@echo "[Link (Dynamic)]"
@$(CC) -shared -Wl,-soname,libwiringPi.so.1 -o libwiringPi.so.1.0 -lpthread $(OBJ)
i2c: $(OBJ) $(OBJ_I2C)
@echo "[Link (Dynamic + I2C)]"
@$(CC) -shared -Wl,-soname,libwiringPi.so.1 -o libwiringPi.so.1.0 -lpthread $(OBJ) $(OBJ_I2C)
@$(CC) -shared -Wl,-soname,libwiringPi.so -o libwiringPi.so.$(VERSION) -lpthread $(OBJ)
.c.o:
@echo [Compile] $<
@ -95,16 +90,21 @@ install: $(DYNAMIC)
@install -m 0644 wiringSerial.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 wiringShift.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 gertboard.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 piFace.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 piNes.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 ds1302.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 softPwm.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 softServo.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 softTone.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 lcd.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 wiringPiSPI.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 wiringPiI2C.h $(DESTDIR)$(PREFIX)/include
@install -m 0755 libwiringPi.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib
@ln -sf $(DESTDIR)$(PREFIX)/lib/libwiringPi.so.$(VERSION) $(DESTDIR)/lib/libwiringPi.so
@ln -sf $(DESTDIR)$(PREFIX)/lib/libwiringPi.so.$(VERSION) $(DESTDIR)/lib/libwiringPi.so.1
@install -m 0644 mcp23008.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 mcp23017.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 mcp23s08.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 mcp23s17.h $(DESTDIR)$(PREFIX)/include
@install -m 0644 sr595.h $(DESTDIR)$(PREFIX)/include
@install -m 0755 libwiringPi.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib/libwiringPi.so.$(VERSION)
@ln -sf $(DESTDIR)$(PREFIX)/lib/libwiringPi.so.$(VERSION) $(DESTDIR)/lib/libwiringPi.so
@ldconfig
.PHONEY: install-static
@ -119,13 +119,19 @@ uninstall:
@rm -f $(DESTDIR)$(PREFIX)/include/wiringSerial.h
@rm -f $(DESTDIR)$(PREFIX)/include/wiringShift.h
@rm -f $(DESTDIR)$(PREFIX)/include/gertboard.h
@rm -f $(DESTDIR)$(PREFIX)/include/piFace.h
@rm -f $(DESTDIR)$(PREFIX)/include/piNes.h
@rm -f $(DESTDIR)$(PREFIX)/include/ds1302.h
@rm -f $(DESTDIR)$(PREFIX)/include/softPwm.h
@rm -f $(DESTDIR)$(PREFIX)/include/softServo.h
@rm -f $(DESTDIR)$(PREFIX)/include/softTone.h
@rm -f $(DESTDIR)$(PREFIX)/include/lcd.h
@rm -f $(DESTDIR)$(PREFIX)/include/wiringPiSPI.h
@rm -f $(DESTDIR)$(PREFIX)/include/wiringPiI2C.h
@rm -f $(DESTDIR)$(PREFIX)/include/mcp23008.h
@rm -f $(DESTDIR)$(PREFIX)/include/mcp23017.h
@rm -f $(DESTDIR)$(PREFIX)/include/mcp23s08.h
@rm -f $(DESTDIR)$(PREFIX)/include/mcp23s17.h
@rm -f $(DESTDIR)$(PREFIX)/include/sr595.h
@rm -f $(DESTDIR)$(PREFIX)/lib/libwiringPi.*
@ldconfig
@ -137,16 +143,21 @@ depend:
# DO NOT DELETE
wiringPi.o: wiringPi.h
wiringPiFace.o: wiringPi.h
wiringSerial.o: wiringSerial.h
wiringShift.o: wiringPi.h wiringShift.h
gertboard.o: wiringPiSPI.h gertboard.h
piNes.o: wiringPi.h piNes.h
lcd.o: wiringPi.h lcd.h
piHiPri.o: wiringPi.h
piThread.o: wiringPi.h
wiringPiSPI.o: wiringPiSPI.h
wiringPiI2C.o: wiringPi.h wiringPiI2C.h
softPwm.o: wiringPi.h softPwm.h
softServo.o: wiringPi.h softServo.h
softTone.o: wiringPi.h softTone.h
wiringPiI2C.o: wiringPi.h wiringPiI2C.h
mcp23s08.o: wiringPi.h wiringPiSPI.h mcp23x0817.h mcp23s08.h
mcp23008.o: wiringPi.h wiringPiI2C.h mcp23x0817.h mcp23008.h
mcp23s17.o: wiringPi.h wiringPiSPI.h mcp23x0817.h mcp23s17.h
mcp23017.o: wiringPi.h wiringPiI2C.h mcp23x0817.h mcp23017.h
sr595.o: wiringPi.h sr595.h
piFace.o: wiringPi.h wiringPiSPI.h piFace.h mcp23x0817.h
gertboard.o: wiringPi.h wiringPiSPI.h gertboard.h
piNes.o: wiringPi.h piNes.h
ds1302.o: wiringPi.h ds1302.h
lcd.o: wiringPi.h lcd.h

@ -0,0 +1,239 @@
/*
* ds1302.c:
* Real Time clock
*
* Copyright (c) 2013 Gordon Henderson.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdarg.h>
#include "wiringPi.h"
#include "ds1302.h"
// Register defines
#define RTC_SECS 0
#define RTC_MINS 1
#define RTC_HOURS 2
#define RTC_DATE 3
#define RTC_MONTH 4
#define RTC_DAY 5
#define RTC_YEAR 6
#define RTC_WP 7
#define RTC_TC 8
#define RTC_BM 31
// Locals
static int dPin, cPin, sPin ;
/*
* dsShiftIn:
* Shift a number in from the chip, LSB first. Note that the data is
* sampled on the trailing edge of the last clock, so it's valid immediately.
*********************************************************************************
*/
unsigned int dsShiftIn (void)
{
uint8_t value = 0 ;
int i ;
pinMode (dPin, INPUT) ; delayMicroseconds (1) ;
for (i = 0 ; i < 8 ; ++i)
{
value |= (digitalRead (dPin) << i) ;
digitalWrite (cPin, HIGH) ; delayMicroseconds (1) ;
digitalWrite (cPin, LOW) ; delayMicroseconds (1) ;
}
return value;
}
/*
* dsShiftOut:
* A normal LSB-first shift-out, just slowed down a bit - the Pi is
* a bit faster than the chip can handle.
*********************************************************************************
*/
void dsShiftOut (unsigned int data)
{
int i ;
pinMode (dPin, OUTPUT) ;
for (i = 0 ; i < 8 ; ++i)
{
digitalWrite (dPin, data & (1 << i)) ; delayMicroseconds (1) ;
digitalWrite (cPin, HIGH) ; delayMicroseconds (1) ;
digitalWrite (cPin, LOW) ; delayMicroseconds (1) ;
}
}
/*
* ds1302regRead: ds1302regWrite:
* Read/Write a value to an RTC Register or RAM location on the chip
*********************************************************************************
*/
static unsigned int ds1302regRead (int reg)
{
unsigned int data ;
digitalWrite (sPin, HIGH) ; delayMicroseconds (1) ;
dsShiftOut (reg) ;
data = dsShiftIn () ;
digitalWrite (sPin, LOW) ; delayMicroseconds (1) ;
return data ;
}
static void ds1302regWrite (int reg, unsigned int data)
{
digitalWrite (sPin, HIGH) ; delayMicroseconds (1) ;
dsShiftOut (reg) ;
dsShiftOut (data) ;
digitalWrite (sPin, LOW) ; delayMicroseconds (1) ;
}
/*
* ds1302rtcWrite: ds1302rtcRead:
* Writes/Reads the data to/from the RTC register
*********************************************************************************
*/
unsigned int ds1302rtcRead (int reg)
{
return ds1302regRead (0x81 | ((reg & 0x1F) << 1)) ;
}
void ds1302rtcWrite (int reg, unsigned int data)
{
ds1302regWrite (0x80 | ((reg & 0x1F) << 1), data) ;
}
/*
* ds1302ramWrite: ds1302ramRead:
* Writes/Reads the data to/from the RTC register
*********************************************************************************
*/
unsigned int ds1302ramRead (int addr)
{
return ds1302regRead (0xC1 | ((addr & 0x1F) << 1)) ;
}
void ds1302ramWrite (int addr, unsigned int data)
{
ds1302regWrite ( 0xC0 | ((addr & 0x1F) << 1), data) ;
}
/*
* ds1302clockRead:
* Read all 8 bytes of the clock in a single operation
*********************************************************************************
*/
void ds1302clockRead (int clockData [8])
{
int i ;
unsigned int regVal = 0x81 | ((RTC_BM & 0x1F) << 1) ;
digitalWrite (sPin, HIGH) ; delayMicroseconds (1) ;
dsShiftOut (regVal) ;
for (i = 0 ; i < 8 ; ++i)
clockData [i] = dsShiftIn () ;
digitalWrite (sPin, LOW) ; delayMicroseconds (1) ;
}
/*
* ds1302clockWrite:
* Write all 8 bytes of the clock in a single operation
*********************************************************************************
*/
void ds1302clockWrite (int clockData [8])
{
int i ;
unsigned int regVal = 0x80 | ((RTC_BM & 0x1F) << 1) ;
digitalWrite (sPin, HIGH) ; delayMicroseconds (1) ;
dsShiftOut (regVal) ;
for (i = 0 ; i < 8 ; ++i)
dsShiftOut (clockData [i]) ;
digitalWrite (sPin, LOW) ; delayMicroseconds (1) ;
}
/*
* ds1302trickleCharge:
* Set the bits on the trickle charger.
* Probably best left alone...
*********************************************************************************
*/
void ds1302trickleCharge (int diodes, int resistors)
{
if (diodes + resistors == 0)
ds1302rtcWrite (RTC_TC, 0x5C) ; // Disabled
else
ds1302rtcWrite (RTC_TC, 0xA0 | ((diodes & 3) << 2) | (resistors & 3)) ;
}
/*
* ds1302setup:
* Initialise the chip & remember the pins we're using
*********************************************************************************
*/
void ds1302setup (int clockPin, int dataPin, int csPin)
{
dPin = dataPin ;
cPin = clockPin ;
sPin = csPin ;
digitalWrite (dPin, LOW) ;
digitalWrite (cPin, LOW) ;
digitalWrite (sPin, LOW) ;
pinMode (dPin, OUTPUT) ;
pinMode (cPin, OUTPUT) ;
pinMode (sPin, OUTPUT) ;
ds1302rtcWrite (RTC_WP, 0) ; // Remove write-protect
}

@ -0,0 +1,44 @@
/*
* ds1302.h:
* Real Time clock
*
* Copyright (c) 2013 Gordon Henderson.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#ifdef __cplusplus
extern "C" {
#endif
extern unsigned int ds1302rtcRead (int reg) ;
extern void ds1302rtcWrite (int reg, unsigned int data) ;
extern unsigned int ds1302ramRead (int addr) ;
extern void ds1302ramWrite (int addr, unsigned int data) ;
extern void ds1302clockRead (int clockData [8]) ;
extern void ds1302clockWrite (int clockData [8]) ;
extern void ds1302trickleCharge (int diodes, int resistors) ;
extern void ds1302setup (int clockPin, int dataPin, int csPin) ;
#ifdef __cplusplus
}
#endif

@ -38,16 +38,17 @@
#include <sys/ioctl.h>
#include <linux/spi/spidev.h>
#include "wiringPi.h"
#include "wiringPiSPI.h"
#include "gertboard.h"
// The A-D convertor won't run at more than 1MHz @ 3.3v
#define SPI_ADC_SPEED 1000000
#define SPI_DAC_SPEED 1000000
#define SPI_A2D 0
#define SPI_D2A 1
#define SPI_ADC_SPEED 1000000
#define SPI_DAC_SPEED 1000000
#define SPI_A2D 0
#define SPI_D2A 1
/*
@ -120,3 +121,46 @@ int gertboardSPISetup (void)
return 0 ;
}
/*
* New wiringPi node extension methods.
*********************************************************************************
*/
int gbWiringPiAnalogRead (struct wiringPiNodeStruct *node, int chan)
{
chan -= node->pinBase ;
return gertboardAnalogRead (chan) ;
}
void gbWiringPiAnalogWrite (struct wiringPiNodeStruct *node, int chan, int value)
{
chan -= node->pinBase ;
gertboardAnalogWrite (chan, value) ;
}
/*
* gertboardAnalogSetup:
* Create a new wiringPi device node for the analog devices on the
* Gertboard. We create one node with 2 pins - each pin being read
* and write - although the operations actually go to different
* hardware devices.
*********************************************************************************
*/
int gertboardAnalogSetup (int pinBase)
{
struct wiringPiNodeStruct *node ;
int x ;
if (( x = gertboardSPISetup ()) != 0)
return x;
node = wiringPiNewNode (pinBase, 2) ;
node->analogRead = gbWiringPiAnalogRead ;
node->analogWrite = gbWiringPiAnalogWrite ;
return 0 ;
}

@ -33,6 +33,7 @@ extern "C" {
extern void gertboardAnalogWrite (int chan, int value) ;
extern int gertboardAnalogRead (int chan) ;
extern int gertboardSPISetup (void) ;
extern int gertboardAnalogSetup (int pinBase) ;
#ifdef __cplusplus
}

@ -0,0 +1,155 @@
/*
* mcp23008.c:
* Extend wiringPi with the MCP 23008 I2C GPIO expander chip
* Copyright (c) 2013 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with wiringPi.
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <pthread.h>
#include "wiringPi.h"
#include "wiringPiI2C.h"
#include "mcp23x0817.h"
#include "mcp23008.h"
/*
* myPinMode:
*********************************************************************************
*/
static void myPinMode (struct wiringPiNodeStruct *node, int pin, int mode)
{
int mask, old, ddr ;
pin -= node->pinBase ;
ddr = MCP23x08_IODIR ;
mask = 1 << pin ;
old = wiringPiI2CReadReg8 (node->fd, ddr) ;
if (mode == OUTPUT)
old &= (~mask) ;
else
old |= mask ;
wiringPiI2CWriteReg8 (node->fd, ddr, old) ;
}
/*
* myPullUpDnControl:
*********************************************************************************
*/
static void myPullUpDnControl (struct wiringPiNodeStruct *node, int pin, int mode)
{
int mask, old, pud ;
pin -= node->pinBase ;
pud = MCP23x08_GPPU ;
mask = 1 << pin ;
old = wiringPiI2CReadReg8 (node->fd, pud) ;
if (mode == PUD_UP)
old |= mask ;
else
old &= (~mask) ;
wiringPiI2CWriteReg8 (node->fd, pud, old) ;
}
/*
* myDigitalWrite:
*********************************************************************************
*/
static void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value)
{
int bit, old ;
pin -= node->pinBase ;
bit = 1 << (pin & 7) ;
old = node->data2 ;
if (value == LOW)
old &= (~bit) ;
else
old |= bit ;
wiringPiI2CWriteReg8 (node->fd, MCP23x08_GPIO, old) ;
node->data2 = old ;
}
/*
* myDigitalRead:
*********************************************************************************
*/
static int myDigitalRead (struct wiringPiNodeStruct *node, int pin)
{
int mask, value, gpio ;
pin -= node->pinBase ;
gpio = MCP23x08_GPIO ;
mask = 1 << pin ;
value = wiringPiI2CReadReg8 (node->fd, gpio) ;
if ((value & mask) == 0)
return LOW ;
else
return HIGH ;
}
/*
* mcp23008Setup:
* Create a new instance of an MCP23008 I2C GPIO interface. We know it
* has 16 pins, so all we need to know here is the I2C address and the
* user-defined pin base.
*********************************************************************************
*/
int mcp23008Setup (int pinBase, int i2cAddress)
{
int fd ;
struct wiringPiNodeStruct *node ;
if ((fd = wiringPiI2CSetup (i2cAddress)) < 0)
return fd ;
wiringPiI2CWriteReg8 (fd, MCP23x08_IOCON, IOCON_INIT) ;
node = wiringPiNewNode (pinBase, 16) ;
node->fd = fd ;
node->pinMode = myPinMode ;
node->pullUpDnControl = myPullUpDnControl ;
node->digitalRead = myDigitalRead ;
node->digitalWrite = myDigitalWrite ;
node->data2 = wiringPiI2CReadReg8 (fd, MCP23x08_OLAT) ;
return 0 ;
}

@ -0,0 +1,33 @@
/*
* 23008.h:
* Extend wiringPi with the MCP 23008 I2C GPIO expander chip
* Copyright (c) 2013 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with wiringPi.
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#ifdef __cplusplus
extern "C" {
#endif
extern int mcp23008Setup (int pinBase, int i2cAddress) ;
#ifdef __cplusplus
}
#endif

@ -0,0 +1,195 @@
/*
* mcp23017.c:
* Extend wiringPi with the MCP 23017 I2C GPIO expander chip
* Copyright (c) 2013 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with wiringPi.
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <pthread.h>
#include "wiringPi.h"
#include "wiringPiI2C.h"
#include "mcp23x0817.h"
#include "mcp23017.h"
/*
* myPinMode:
*********************************************************************************
*/
static void myPinMode (struct wiringPiNodeStruct *node, int pin, int mode)
{
int mask, old, ddr ;
pin -= node->pinBase ;
if (pin < 8) // Bank A
ddr = MCP23x17_IODIRA ;
else
{
ddr = MCP23x17_IODIRB ;
pin &= 0x07 ;
}
mask = 1 << pin ;
old = wiringPiI2CReadReg8 (node->fd, ddr) ;
if (mode == OUTPUT)
old &= (~mask) ;
else
old |= mask ;
wiringPiI2CWriteReg8 (node->fd, ddr, old) ;
}
/*
* myPullUpDnControl:
*********************************************************************************
*/
static void myPullUpDnControl (struct wiringPiNodeStruct *node, int pin, int mode)
{
int mask, old, pud ;
pin -= node->pinBase ;
if (pin < 8) // Bank A
pud = MCP23x17_GPPUA ;
else
{
pud = MCP23x17_GPPUB ;
pin &= 0x07 ;
}
mask = 1 << pin ;
old = wiringPiI2CReadReg8 (node->fd, pud) ;
if (mode == PUD_UP)
old |= mask ;
else
old &= (~mask) ;
wiringPiI2CWriteReg8 (node->fd, pud, old) ;
}
/*
* myDigitalWrite:
*********************************************************************************
*/
static void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value)
{
int bit, old ;
pin -= node->pinBase ; // Pin now 0-15
bit = 1 << (pin & 7) ;
if (pin < 8) // Bank A
{
old = node->data2 ;
if (value == LOW)
old &= (~bit) ;
else
old |= bit ;
wiringPiI2CWriteReg8 (node->fd, MCP23x17_GPIOA, old) ;
node->data2 = old ;
}
else // Bank B
{
old = node->data3 ;
if (value == LOW)
old &= (~bit) ;
else
old |= bit ;
wiringPiI2CWriteReg8 (node->fd, MCP23x17_GPIOB, old) ;
node->data3 = old ;
}
}
/*
* myDigitalRead:
*********************************************************************************
*/
static int myDigitalRead (struct wiringPiNodeStruct *node, int pin)
{
int mask, value, gpio ;
pin -= node->pinBase ;
if (pin < 8) // Bank A
gpio = MCP23x17_GPIOA ;
else
{
gpio = MCP23x17_GPIOB ;
pin &= 0x07 ;
}
mask = 1 << pin ;
value = wiringPiI2CReadReg8 (node->fd, gpio) ;
if ((value & mask) == 0)
return LOW ;
else
return HIGH ;
}
/*
* mcp23017Setup:
* Create a new instance of an MCP23017 I2C GPIO interface. We know it
* has 16 pins, so all we need to know here is the I2C address and the
* user-defined pin base.
*********************************************************************************
*/
int mcp23017Setup (int pinBase, int i2cAddress)
{
int fd ;
struct wiringPiNodeStruct *node ;
if ((fd = wiringPiI2CSetup (i2cAddress)) < 0)
return fd ;
wiringPiI2CWriteReg8 (fd, MCP23x17_IOCON, IOCON_INIT) ;
node = wiringPiNewNode (pinBase, 16) ;
node->fd = fd ;
node->pinMode = myPinMode ;
node->pullUpDnControl = myPullUpDnControl ;
node->digitalRead = myDigitalRead ;
node->digitalWrite = myDigitalWrite ;
node->data2 = wiringPiI2CReadReg8 (fd, MCP23x17_OLATA) ;
node->data3 = wiringPiI2CReadReg8 (fd, MCP23x17_OLATB) ;
return 0 ;
}

@ -0,0 +1,33 @@
/*
* 23017.h:
* Extend wiringPi with the MCP 23017 I2C GPIO expander chip
* Copyright (c) 2013 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with wiringPi.
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#ifdef __cplusplus
extern "C" {
#endif
extern int mcp23017Setup (int pinBase, int i2cAddress) ;
#ifdef __cplusplus
}
#endif

@ -0,0 +1,195 @@
/*
* mcp23s08.c:
* Extend wiringPi with the MCP 23s08 SPI GPIO expander chip
* Copyright (c) 2013 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with wiringPi.
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <stdint.h>
#include "wiringPi.h"
#include "wiringPiSPI.h"
#include "mcp23x0817.h"
#include "mcp23s08.h"
#define MCP_SPEED 4000000
/*
* writeByte:
* Write a byte to a register on the MCP23s08 on the SPI bus.
*********************************************************************************
*/
static void writeByte (uint8_t spiPort, uint8_t devId, uint8_t reg, uint8_t data)
{
uint8_t spiData [4] ;
spiData [0] = CMD_WRITE | ((devId & 7) << 1) ;
spiData [1] = reg ;
spiData [2] = data ;
wiringPiSPIDataRW (spiPort, spiData, 3) ;
}
/*
* readByte:
* Read a byte from a register on the MCP23s08 on the SPI bus.
*********************************************************************************
*/
static uint8_t readByte (uint8_t spiPort, uint8_t devId, uint8_t reg)
{
uint8_t spiData [4] ;
spiData [0] = CMD_READ | ((devId & 7) << 1) ;
spiData [1] = reg ;
wiringPiSPIDataRW (spiPort, spiData, 3) ;
return spiData [2] ;
}
/*
* myPinMode:
*********************************************************************************
*/
static void myPinMode (struct wiringPiNodeStruct *node, int pin, int mode)
{
int mask, old, ddr ;
pin -= node->pinBase ;
ddr = MCP23x08_IODIR ;
mask = 1 << pin ;
old = readByte (node->data0, node->data1, ddr) ;
if (mode == OUTPUT)
old &= (~mask) ;
else
old |= mask ;
writeByte (node->data0, node->data1, ddr, old) ;
}
/*
* myPullUpDnControl:
*********************************************************************************
*/
static void myPullUpDnControl (struct wiringPiNodeStruct *node, int pin, int mode)
{
int mask, old, pud ;
pin -= node->pinBase ;
pud = MCP23x08_GPPU ;
mask = 1 << pin ;
old = readByte (node->data0, node->data1, pud) ;
if (mode == PUD_UP)
old |= mask ;
else
old &= (~mask) ;
writeByte (node->data0, node->data1, pud, old) ;
}
/*
* myDigitalWrite:
*********************************************************************************
*/
static void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value)
{
int bit, old ;
pin -= node->pinBase ;
bit = 1 << pin ;
old = node->data2 ;
if (value == LOW)
old &= (~bit) ;
else
old |= bit ;
writeByte (node->data0, node->data1, MCP23x08_GPIO, old) ;
node->data2 = old ;
}
/*
* myDigitalRead:
*********************************************************************************
*/
static int myDigitalRead (struct wiringPiNodeStruct *node, int pin)
{
int mask, value, gpio ;
pin -= node->pinBase ;
gpio = MCP23x08_GPIO ;
mask = 1 << pin ;
value = readByte (node->data0, node->data1, gpio) ;
if ((value & mask) == 0)
return LOW ;
else
return HIGH ;
}
/*
* mcp23s08Setup:
* Create a new instance of an MCP23s08 SPI GPIO interface. We know it
* has 16 pins, so all we need to know here is the SPI address and the
* user-defined pin base.
*********************************************************************************
*/
int mcp23s08Setup (int pinBase, int spiPort, int devId)
{
int x ;
struct wiringPiNodeStruct *node ;
if ((x = wiringPiSPISetup (spiPort, MCP_SPEED)) < 0)
return x ;
writeByte (spiPort, devId, MCP23x08_IOCON, IOCON_INIT) ;
node = wiringPiNewNode (pinBase, 16) ;
node->data0 = spiPort ;
node->data1 = devId ;
node->pinMode = myPinMode ;
node->pullUpDnControl = myPullUpDnControl ;
node->digitalRead = myDigitalRead ;
node->digitalWrite = myDigitalWrite ;
node->data2 = readByte (spiPort, devId, MCP23x08_OLAT) ;
return 0 ;
}

@ -1,6 +1,6 @@
/*
* wiringPiI2C.h:
* Simplified I2C access routines
* 23s08.h:
* Extend wiringPi with the MCP 23s08 SPI GPIO expander chip
* Copyright (c) 2013 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
@ -26,15 +26,7 @@
extern "C" {
#endif
extern int wiringPiI2CRead (int fd) ;
extern int wiringPiI2CReadReg8 (int fd, int reg) ;
extern int wiringPiI2CReadReg16 (int fd, int reg) ;
extern int wiringPiI2CWrite (int fd, int data) ;
extern int wiringPiI2CWriteReg8 (int fd, int reg, int data) ;
extern int wiringPiI2CWriteReg16 (int fd, int reg, int data) ;
int wiringPiI2CSetup (int devId) ;
extern int mcp23s08Setup (int pinBase, int spiPort, int devId) ;
#ifdef __cplusplus
}

@ -0,0 +1,236 @@
/*
* mcp23s17.c:
* Extend wiringPi with the MCP 23s17 SPI GPIO expander chip
* Copyright (c) 2013 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with wiringPi.
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <stdint.h>
#include "wiringPi.h"
#include "wiringPiSPI.h"
#include "mcp23x0817.h"
#include "mcp23s17.h"
#define MCP_SPEED 4000000
/*
* writeByte:
* Write a byte to a register on the MCP23s17 on the SPI bus.
*********************************************************************************
*/
static void writeByte (uint8_t spiPort, uint8_t devId, uint8_t reg, uint8_t data)
{
uint8_t spiData [4] ;
spiData [0] = CMD_WRITE | ((devId & 7) << 1) ;
spiData [1] = reg ;
spiData [2] = data ;
wiringPiSPIDataRW (spiPort, spiData, 3) ;
}
/*
* readByte:
* Read a byte from a register on the MCP23s17 on the SPI bus.
*********************************************************************************
*/
static uint8_t readByte (uint8_t spiPort, uint8_t devId, uint8_t reg)
{
uint8_t spiData [4] ;
spiData [0] = CMD_READ | ((devId & 7) << 1) ;
spiData [1] = reg ;
wiringPiSPIDataRW (spiPort, spiData, 3) ;
return spiData [2] ;
}
/*
* myPinMode:
*********************************************************************************
*/
static void myPinMode (struct wiringPiNodeStruct *node, int pin, int mode)
{
int mask, old, ddr ;
pin -= node->pinBase ;
if (pin < 8) // Bank A
ddr = MCP23x17_IODIRA ;
else
{
ddr = MCP23x17_IODIRB ;
pin &= 0x07 ;
}
mask = 1 << pin ;
old = readByte (node->data0, node->data1, ddr) ;
if (mode == OUTPUT)
old &= (~mask) ;
else
old |= mask ;
writeByte (node->data0, node->data1, ddr, old) ;
}
/*
* myPullUpDnControl:
*********************************************************************************
*/
static void myPullUpDnControl (struct wiringPiNodeStruct *node, int pin, int mode)
{
int mask, old, pud ;
pin -= node->pinBase ;
if (pin < 8) // Bank A
pud = MCP23x17_GPPUA ;
else
{
pud = MCP23x17_GPPUB ;
pin &= 0x07 ;
}
mask = 1 << pin ;
old = readByte (node->data0, node->data1, pud) ;
if (mode == PUD_UP)
old |= mask ;
else
old &= (~mask) ;
writeByte (node->data0, node->data1, pud, old) ;
}
/*
* myDigitalWrite:
*********************************************************************************
*/
static void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value)
{
int bit, old ;
pin -= node->pinBase ; // Pin now 0-15
bit = 1 << (pin & 7) ;
if (pin < 8) // Bank A
{
old = node->data2 ;
if (value == LOW)
old &= (~bit) ;
else
old |= bit ;
writeByte (node->data0, node->data1, MCP23x17_GPIOA, old) ;
node->data2 = old ;
}
else // Bank B
{
old = node->data3 ;
if (value == LOW)
old &= (~bit) ;
else
old |= bit ;
writeByte (node->data0, node->data1, MCP23x17_GPIOB, old) ;
node->data3 = old ;
}
}
/*
* myDigitalRead:
*********************************************************************************
*/
static int myDigitalRead (struct wiringPiNodeStruct *node, int pin)
{
int mask, value, gpio ;
pin -= node->pinBase ;
if (pin < 8) // Bank A
gpio = MCP23x17_GPIOA ;
else
{
gpio = MCP23x17_GPIOB ;
pin &= 0x07 ;
}
mask = 1 << pin ;
value = readByte (node->data0, node->data1, gpio) ;
if ((value & mask) == 0)
return LOW ;
else
return HIGH ;
}
/*
* mcp23s17Setup:
* Create a new instance of an MCP23s17 SPI GPIO interface. We know it
* has 16 pins, so all we need to know here is the SPI address and the
* user-defined pin base.
*********************************************************************************
*/
int mcp23s17Setup (int pinBase, int spiPort, int devId)
{
int x ;
struct wiringPiNodeStruct *node ;
if ((x = wiringPiSPISetup (spiPort, MCP_SPEED)) < 0)
return x ;
writeByte (spiPort, devId, MCP23x17_IOCON, IOCON_INIT | IOCON_HAEN) ;
writeByte (spiPort, devId, MCP23x17_IOCONB, IOCON_INIT | IOCON_HAEN) ;
node = wiringPiNewNode (pinBase, 16) ;
node->data0 = spiPort ;
node->data1 = devId ;
node->pinMode = myPinMode ;
node->pullUpDnControl = myPullUpDnControl ;
node->digitalRead = myDigitalRead ;
node->digitalWrite = myDigitalWrite ;
node->data2 = readByte (spiPort, devId, MCP23x17_OLATA) ;
node->data3 = readByte (spiPort, devId, MCP23x17_OLATB) ;
return 0 ;
}

@ -0,0 +1,33 @@
/*
* 23s17.h:
* Extend wiringPi with the MCP 23s17 SPI GPIO expander chip
* Copyright (c) 2013 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with wiringPi.
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#ifdef __cplusplus
extern "C" {
#endif
extern int mcp23s17Setup (int pinBase, int spiPort, int devId) ;
#ifdef __cplusplus
}
#endif

@ -0,0 +1,73 @@
/*
* mcp23x17:
* Copyright (c) 2012-2013 Gordon Henderson
*
* Header file for code using the MCP23x17 GPIO expander chip.
* This comes in 2 flavours: MCP23017 which has an I2C interface,
* an the MXP23S17 which has an SPI interface.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with wiringPi.
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
// MCP23x17 Registers
#define IODIRA 0x00
#define IPOLA 0x02
#define GPINTENA 0x04
#define DEFVALA 0x06
#define INTCONA 0x08
#define IOCON 0x0A
#define GPPUA 0x0C
#define INTFA 0x0E
#define INTCAPA 0x10
#define GPIOA 0x12
#define OLATA 0x14
#define IODIRB 0x01
#define IPOLB 0x03
#define GPINTENB 0x05
#define DEFVALB 0x07
#define INTCONB 0x09
#define IOCONB 0x0B
#define GPPUB 0x0D
#define INTFB 0x0F
#define INTCAPB 0x11
#define GPIOB 0x13
#define OLATB 0x15
// Bits in the IOCON register
#define IOCON_UNUSED 0x01
#define IOCON_INTPOL 0x02
#define IOCON_ODR 0x04
#define IOCON_HAEN 0x08
#define IOCON_DISSLW 0x10
#define IOCON_SEQOP 0x20
#define IOCON_MIRROR 0x40
#define IOCON_BANK_MODE 0x80
// Default initialisation mode
#define IOCON_INIT (IOCON_SEQOP)
// SPI Command codes
#define CMD_WRITE 0x40
#define CMD_READ 0x41

@ -0,0 +1,87 @@
/*
* mcp23xxx:
* Copyright (c) 2012-2013 Gordon Henderson
*
* Header file for code using the MCP23x08 and 17 GPIO expander
* chips.
* This comes in 2 flavours: MCP230xx (08/17) which has an I2C
* interface, and the MXP23Sxx (08/17) which has an SPI interface.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with wiringPi.
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
// MCP23x08 Registers
#define MCP23x08_IODIR 0x00
#define MCP23x08_IPOL 0x01
#define MCP23x08_GPINTEN 0x02
#define MCP23x08_DEFVAL 0x03
#define MCP23x08_INTCON 0x04
#define MCP23x08_IOCON 0x05
#define MCP23x08_GPPU 0x06
#define MCP23x08_INTF 0x07
#define MCP23x08_INTCAP 0x08
#define MCP23x08_GPIO 0x09
#define MCP23x08_OLAT 0x0A
// MCP23x17 Registers
#define MCP23x17_IODIRA 0x00
#define MCP23x17_IPOLA 0x02
#define MCP23x17_GPINTENA 0x04
#define MCP23x17_DEFVALA 0x06
#define MCP23x17_INTCONA 0x08
#define MCP23x17_IOCON 0x0A
#define MCP23x17_GPPUA 0x0C
#define MCP23x17_INTFA 0x0E
#define MCP23x17_INTCAPA 0x10
#define MCP23x17_GPIOA 0x12
#define MCP23x17_OLATA 0x14
#define MCP23x17_IODIRB 0x01
#define MCP23x17_IPOLB 0x03
#define MCP23x17_GPINTENB 0x05
#define MCP23x17_DEFVALB 0x07
#define MCP23x17_INTCONB 0x09
#define MCP23x17_IOCONB 0x0B
#define MCP23x17_GPPUB 0x0D
#define MCP23x17_INTFB 0x0F
#define MCP23x17_INTCAPB 0x11
#define MCP23x17_GPIOB 0x13
#define MCP23x17_OLATB 0x15
// Bits in the IOCON register
#define IOCON_UNUSED 0x01
#define IOCON_INTPOL 0x02
#define IOCON_ODR 0x04
#define IOCON_HAEN 0x08
#define IOCON_DISSLW 0x10
#define IOCON_SEQOP 0x20
#define IOCON_MIRROR 0x40
#define IOCON_BANK_MODE 0x80
// Default initialisation mode
#define IOCON_INIT (IOCON_SEQOP)
// SPI Command codes
#define CMD_WRITE 0x40
#define CMD_READ 0x41

@ -0,0 +1,179 @@
/*
* piFace.:
* Arduino compatable (ish) Wiring library for the Raspberry Pi
* Copyright (c) 2012-2013 Gordon Henderson
*
* This file to interface with the PiFace peripheral device which
* has an MCP23S17 GPIO device connected via the SPI bus.
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with wiringPi.
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <stdint.h>
#include "wiringPi.h"
#include "wiringPiSPI.h"
#include "piFace.h"
#define PIFACE_SPEED 4000000
#define PIFACE_DEVNO 0
#include "mcp23x0817.h"
/*
* writeByte:
* Write a byte to a register on the MCP23S17 on the SPI bus.
*********************************************************************************
*/
static void writeByte (uint8_t reg, uint8_t data)
{
uint8_t spiData [4] ;
spiData [0] = CMD_WRITE ;
spiData [1] = reg ;
spiData [2] = data ;
wiringPiSPIDataRW (PIFACE_DEVNO, spiData, 3) ;
}
/*
* readByte:
* Read a byte from a register on the MCP23S17 on the SPI bus.
*********************************************************************************
*/
static uint8_t readByte (uint8_t reg)
{
uint8_t spiData [4] ;
spiData [0] = CMD_READ ;
spiData [1] = reg ;
wiringPiSPIDataRW (PIFACE_DEVNO, spiData, 3) ;
return spiData [2] ;
}
/*
* digitalWrite:
* Perform the digitalWrite function on the PiFace board
*********************************************************************************
*/
void digitalWritePiFace (struct wiringPiNodeStruct *node, int pin, int value)
{
uint8_t mask, old ;
pin -= node->pinBase ;
mask = 1 << pin ;
old = readByte (MCP23x17_GPIOA) ;
if (value == 0)
old &= (~mask) ;
else
old |= mask ;
writeByte (MCP23x17_GPIOA, old) ;
}
/*
* digitalReadPiFace:
* Perform the digitalRead function on the PiFace board
*********************************************************************************
*/
int digitalReadPiFace (struct wiringPiNodeStruct *node, int pin)
{
uint8_t mask, reg ;
pin -= node->pinBase ;
mask = 1 << (pin & 7) ;
if (pin < 8)
reg = MCP23x17_GPIOB ; // Input regsiter
else
reg = MCP23x17_OLATA ; // Output latch regsiter
if ((readByte (reg) & mask) != 0)
return HIGH ;
else
return LOW ;
}
/*
* pullUpDnControlPiFace:
* Perform the pullUpDnControl function on the PiFace board
*********************************************************************************
*/
void pullUpDnControlPiFace (struct wiringPiNodeStruct *node, int pin, int pud)
{
uint8_t mask, old ;
pin -= node->pinBase ;
mask = 1 << pin ;
old = readByte (MCP23x17_GPPUB) ;
if (pud == 0)
old &= (~mask) ;
else
old |= mask ;
writeByte (MCP23x17_GPPUB, old) ;
}
/*
* piFaceSetup
* Setup the SPI interface and initialise the MCP23S17 chip
* We create one node with 16 pins - each if the first 8 pins being read
* and write - although the operations actually go to different
* hardware ports. The top 8 let you read the state of the output register.
*********************************************************************************
*/
int piFaceSetup (int pinBase)
{
int x ;
struct wiringPiNodeStruct *node ;
if ((x = wiringPiSPISetup (PIFACE_DEVNO, PIFACE_SPEED)) < 0)
return x ;
// Setup the MCP23S17
writeByte (MCP23x17_IOCON, IOCON_INIT) ;
writeByte (MCP23x17_IODIRA, 0x00) ; // Port A -> Outputs
writeByte (MCP23x17_IODIRB, 0xFF) ; // Port B -> Inputs
node = wiringPiNewNode (pinBase, 16) ;
node->digitalRead = digitalReadPiFace ;
node->digitalWrite = digitalWritePiFace ;
node->pullUpDnControl = pullUpDnControlPiFace ;
return 0 ;
}

@ -0,0 +1,32 @@
/*
* piFace.h:
* Control the PiFace Interface board for the Raspberry Pi
* Copyright (c) 2012-2013 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#ifdef __cplusplus
extern "C" {
#endif
extern int piFaceSetup (int pinBase) ;
#ifdef __cplusplus
}
#endif

@ -36,7 +36,7 @@
#define PULSE_TIME 100
static int frewqs [MAX_PINS] ;
static int freqs [MAX_PINS] ;
static int newPin = -1 ;
@ -49,7 +49,7 @@ static int newPin = -1 ;
static PI_THREAD (softToneThread)
{
int pin, frewq, halfPeriod ;
int pin, freq, halfPeriod ;
pin = newPin ;
newPin = -1 ;
@ -58,12 +58,12 @@ static PI_THREAD (softToneThread)
for (;;)
{
frewq = frewqs [pin] ;
if (frewq == 0)
freq = freqs [pin] ;
if (freq == 0)
delay (1) ;
else
{
halfPeriod = 500000 / frewq ;
halfPeriod = 500000 / freq ;
digitalWrite (pin, HIGH) ;
delayMicroseconds (halfPeriod) ;
@ -83,16 +83,16 @@ static PI_THREAD (softToneThread)
*********************************************************************************
*/
void softToneWrite (int pin, int frewq)
void softToneWrite (int pin, int freq)
{
pin &= 63 ;
/**/ if (frewq < 0)
frewq = 0 ;
else if (frewq > 5000) // Max 5KHz
frewq = 5000 ;
/**/ if (freq < 0)
freq = 0 ;
else if (freq > 5000) // Max 5KHz
freq = 5000 ;
frewqs [pin] = frewq ;
freqs [pin] = freq ;
}
@ -109,7 +109,7 @@ int softToneCreate (int pin)
pinMode (pin, OUTPUT) ;
digitalWrite (pin, LOW) ;
frewqs [pin] = 0 ;
freqs [pin] = 0 ;
newPin = pin ;
res = piThreadCreate (softToneThread) ;

@ -31,7 +31,7 @@ extern "C" {
#endif
extern int softToneCreate (int pin) ;
extern void softToneWrite (int pin, int frewq) ;
extern void softToneWrite (int pin, int freq) ;
#ifdef __cplusplus
}

@ -0,0 +1,108 @@
/*
* sr595.c:
* Extend wiringPi with the 74x595 shift register as a GPIO
* expander chip.
* Note that the code can cope with a number of 595's
* daisy-chained together - up to 4 for now as we're storing
* the output "register" in a single unsigned int.
*
* Copyright (c) 2013 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with wiringPi.
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <stdint.h>
#include "wiringPi.h"
#include "sr595.h"
/*
* myDigitalWrite:
*********************************************************************************
*/
static void myDigitalWrite (struct wiringPiNodeStruct *node, int pin, int value)
{
unsigned int mask ;
int dataPin, clockPin, latchPin ;
int bit, bits, output ;
pin -= node->pinBase ; // Normalise pin number
bits = node->pinMax - node->pinBase + 1 ; // ie. number of clock pulses
dataPin = node->data0 ;
clockPin = node->data1 ;
latchPin = node->data2 ;
output = node->data3 ;
mask = 1 << pin ;
if (value == LOW)
output &= (~mask) ;
else
output |= mask ;
node->data3 = output ;
// A low -> high latch transition copies the latch to the output pins
digitalWrite (latchPin, LOW) ; delayMicroseconds (1) ;
for (bit = bits - 1 ; bit >= 0 ; --bit)
{
digitalWrite (dataPin, output & (1 << bit)) ;
digitalWrite (clockPin, HIGH) ; delayMicroseconds (1) ;
digitalWrite (clockPin, LOW) ; delayMicroseconds (1) ;
}
digitalWrite (latchPin, HIGH) ; delayMicroseconds (1) ;
}
/*
* sr595Setup:
* Create a new instance of a 74x595 shift register GPIO expander.
*********************************************************************************
*/
int sr595Setup (int pinBase, int numPins, int dataPin, int clockPin, int latchPin)
{
struct wiringPiNodeStruct *node ;
node = wiringPiNewNode (pinBase, numPins) ;
node->data0 = dataPin ;
node->data1 = clockPin ;
node->data2 = latchPin ;
node->data3 = 0 ; // Output register
node->digitalWrite = myDigitalWrite ;
// Initialise the underlying hardware
digitalWrite (dataPin, LOW) ;
digitalWrite (clockPin, LOW) ;
digitalWrite (latchPin, HIGH) ;
pinMode (dataPin, OUTPUT) ;
pinMode (clockPin, OUTPUT) ;
pinMode (latchPin, OUTPUT) ;
return 0 ;
}

@ -0,0 +1,33 @@
/*
* sr595.h:
* Extend wiringPi with the 74x595 shift registers.
* Copyright (c) 2013 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with wiringPi.
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#ifdef __cplusplus
extern "C" {
#endif
extern int sr595Setup (int pinBase, int numPins, int dataPin, int clockPin, int latchPin) ;
#ifdef __cplusplus
}
#endif

File diff suppressed because it is too large Load Diff

@ -29,7 +29,8 @@
#define WPI_MODE_PINS 0
#define WPI_MODE_GPIO 1
#define WPI_MODE_GPIO_SYS 2
#define WPI_MODE_PIFACE 3
#define WPI_MODE_PHYS 3
#define WPI_MODE_PIFACE 4
#define WPI_MODE_UNINITIALISED -1
// Pin modes
@ -64,6 +65,36 @@
#define PI_THREAD(X) void *X (void *dummy)
// wiringPiNodeStruct:
// This describes additional device nodes in the extended wiringPi
// 2.0 scheme of things.
// It's a simple linked list for now, but will hopefully migrate to
// a binary tree for efficiency reasons - but then again, the chances
// of more than 1 or 2 devices being added are fairly slim, so who
// knows....
struct wiringPiNodeStruct
{
int pinBase ;
int pinMax ;
int fd ; // Node specific
unsigned int data0 ; // ditto
unsigned int data1 ; // ditto
unsigned int data2 ; // ditto
unsigned int data3 ; // ditto
void (*pinMode) (struct wiringPiNodeStruct *node, int pin, int mode) ;
void (*pullUpDnControl) (struct wiringPiNodeStruct *node, int pin, int mode) ;
int (*digitalRead) (struct wiringPiNodeStruct *node, int pin) ;
void (*digitalWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
void (*pwmWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
int (*analogRead) (struct wiringPiNodeStruct *node, int pin) ;
void (*analogWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
struct wiringPiNodeStruct *next ;
} ;
// Function prototypes
// c++ wrappers thanks to a comment by Nick Lott
@ -73,47 +104,58 @@
extern "C" {
#endif
// Basic wiringPi functions
// Core wiringPi functions
extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) ;
extern int wiringPiSetup (void) ;
extern int wiringPiSetupSys (void) ;
extern int wiringPiSetupGpio (void) ;
extern int wiringPiSetupPiFace (void) ;
extern int wiringPiSetupPhys (void) ;
extern int piBoardRev (void) ;
extern int wpiPinToGpio (int wpiPin) ;
extern void pinMode (int pin, int mode) ;
extern void pullUpDnControl (int pin, int pud) ;
extern int digitalRead (int pin) ;
extern void digitalWrite (int pin, int value) ;
extern void pwmWrite (int pin, int value) ;
extern int analogRead (int pin) ;
extern void analogWrite (int pin, int value) ;
// PiFace specifics
// (Deprecated)
extern int wiringPiSetupPiFace (void) ;
extern int wiringPiSetupPiFaceForGpioProg (void) ; // Don't use this - for gpio program only
extern void (*pinMode) (int pin, int mode) ;
extern int (*getAlt) (int pin) ;
extern void (*pullUpDnControl) (int pin, int pud) ;
extern void (*digitalWrite) (int pin, int value) ;
extern void (*digitalWriteByte) (int value) ;
extern void (*gpioClockSet) (int pin, int freq) ;
extern void (*pwmWrite) (int pin, int value) ;
extern void (*setPadDrive) (int group, int value) ;
extern int (*digitalRead) (int pin) ;
extern void (*pwmSetMode) (int mode) ;
extern void (*pwmSetRange) (unsigned int range) ;
extern void (*pwmSetClock) (int divisor) ;
// On-Board Raspberry Pi hardware specific stuff
extern int piBoardRev (void) ;
extern int wpiPinToGpio (int wpiPin) ;
extern void setPadDrive (int group, int value) ;
extern int getAlt (int pin) ;
extern void digitalWriteByte (int value) ;
extern void pwmSetMode (int mode) ;
extern void pwmSetRange (unsigned int range) ;
extern void pwmSetClock (int divisor) ;
extern void gpioClockSet (int pin, int freq) ;
// Interrupts
// (Also Pi hardware specific)
extern int (*waitForInterrupt) (int pin, int mS) ;
extern int waitForInterrupt (int pin, int mS) ;
extern int wiringPiISR (int pin, int mode, void (*function)(void)) ;
// Threads
extern int piThreadCreate (void *(*fn)(void *)) ;
extern void piLock (int key) ;
extern void piUnlock (int key) ;
extern int piThreadCreate (void *(*fn)(void *)) ;
extern void piLock (int key) ;
extern void piUnlock (int key) ;
// Schedulling priority
extern int piHiPri (int pri) ;
// Extras from arduino land
extern void delay (unsigned int howLong) ;

@ -0,0 +1,227 @@
/*
* wiringPiI2C.c:
* Simplified I2C access routines
* Copyright (c) 2013 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with wiringPi.
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
/*
* Notes:
* The Linux I2C code is actually the same (almost) as the SMBus code.
* SMBus is System Management Bus - and in essentially I2C with some
* additional functionality added, and stricter controls on the electrical
* specifications, etc. however I2C does work well with it and the
* protocols work over both.
*
* I'm directly including the SMBus functions here as some Linux distros
* lack the correct header files, and also some header files are GPLv2
* rather than the LGPL that wiringPi is released under - presumably because
* originally no-one expected I2C/SMBus to be used outside the kernel -
* however enter the Raspberry Pi with people now taking directly to I2C
* devices without going via the kernel...
*
* This may ultimately reduce the flexibility of this code, but it won't be
* hard to maintain it and keep it current, should things change.
*
* Information here gained from: kernel/Documentation/i2c/dev-interface
* as well as other online resources.
*********************************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include "wiringPi.h"
#include "wiringPiI2C.h"
// I2C definitions
#define I2C_SLAVE 0x0703
#define I2C_SMBUS 0x0720 /* SMBus-level access */
#define I2C_SMBUS_READ 1
#define I2C_SMBUS_WRITE 0
// SMBus transaction types
#define I2C_SMBUS_QUICK 0
#define I2C_SMBUS_BYTE 1
#define I2C_SMBUS_BYTE_DATA 2
#define I2C_SMBUS_WORD_DATA 3
#define I2C_SMBUS_PROC_CALL 4
#define I2C_SMBUS_BLOCK_DATA 5
#define I2C_SMBUS_I2C_BLOCK_BROKEN 6
#define I2C_SMBUS_BLOCK_PROC_CALL 7 /* SMBus 2.0 */
#define I2C_SMBUS_I2C_BLOCK_DATA 8
// SMBus messages
#define I2C_SMBUS_BLOCK_MAX 32 /* As specified in SMBus standard */
#define I2C_SMBUS_I2C_BLOCK_MAX 32 /* Not specified but we use same structure */
// Structures used in the ioctl() calls
union i2c_smbus_data
{
uint8_t byte ;
uint16_t word ;
uint8_t block [I2C_SMBUS_BLOCK_MAX + 2] ; // block [0] is used for length + one more for PEC
} ;
struct i2c_smbus_ioctl_data
{
char read_write ;
uint8_t command ;
int size ;
union i2c_smbus_data *data ;
} ;
static inline int i2c_smbus_access (int fd, char rw, uint8_t command, int size, union i2c_smbus_data *data)
{
struct i2c_smbus_ioctl_data args ;
args.read_write = rw ;
args.command = command ;
args.size = size ;
args.data = data ;
return ioctl (fd, I2C_SMBUS, &args) ;
}
/*
* wiringPiI2CRead:
* Simple device read
*********************************************************************************
*/
int wiringPiI2CRead (int fd)
{
union i2c_smbus_data data ;
if (i2c_smbus_access (fd, I2C_SMBUS_READ, 0, I2C_SMBUS_BYTE, &data))
return -1 ;
else
return data.byte & 0xFF ;
}
/*
* wiringPiI2CReadReg8: wiringPiI2CReadReg16:
* Read an 8 or 16-bit value from a regsiter on the device
*********************************************************************************
*/
int wiringPiI2CReadReg8 (int fd, int reg)
{
union i2c_smbus_data data;
if (i2c_smbus_access (fd, I2C_SMBUS_READ, reg, I2C_SMBUS_BYTE_DATA, &data))
return -1 ;
else
return data.byte & 0xFF ;
}
int wiringPiI2CReadReg16 (int fd, int reg)
{
union i2c_smbus_data data;
if (i2c_smbus_access (fd, I2C_SMBUS_READ, reg, I2C_SMBUS_WORD_DATA, &data))
return -1 ;
else
return data.byte & 0xFF ;
}
/*
* wiringPiI2CWrite:
* Simple device write
*********************************************************************************
*/
int wiringPiI2CWrite (int fd, int data)
{
return i2c_smbus_access (fd, I2C_SMBUS_WRITE, data, I2C_SMBUS_BYTE, NULL) ;
}
/*
* wiringPiI2CWriteReg8: wiringPiI2CWriteReg16:
* Write an 8 or 16-bit value to the given register
*********************************************************************************
*/
int wiringPiI2CWriteReg8 (int fd, int reg, int value)
{
union i2c_smbus_data data ;
data.byte = value ;
return i2c_smbus_access (fd, I2C_SMBUS_WRITE, reg, I2C_SMBUS_BYTE_DATA, &data) ;
}
int wiringPiI2CWriteReg16 (int fd, int reg, int value)
{
union i2c_smbus_data data ;
data.word = value ;
return i2c_smbus_access (fd, I2C_SMBUS_WRITE, reg, I2C_SMBUS_WORD_DATA, &data) ;
}
/*
* wiringPiI2CSetup:
* Open the I2C device, and regsiter the target device
*********************************************************************************
*/
int wiringPiI2CSetupInterface (char *device, int devId)
{
int fd ;
if ((fd = open (device, O_RDWR)) < 0)
return -1 ;
if (ioctl (fd, I2C_SLAVE, devId) < 0)
return -1 ;
return fd ;
}
int wiringPiI2CSetup (int devId)
{
int rev ;
char *device ;
if ((rev = piBoardRev ()) < 0)
{
fprintf (stderr, "wiringPiI2CSetup: Unable to determine Pi board revision\n") ;
exit (1) ;
}
if (rev == 1)
device = "/dev/i2c-0" ;
else
device = "/dev/i2c-1" ;
return wiringPiI2CSetupInterface (device, devId) ;
}

@ -0,0 +1,42 @@
/*
* wiringPiI2C.h:
* Simplified I2C access routines
* Copyright (c) 2013 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with wiringPi.
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#ifdef __cplusplus
extern "C" {
#endif
extern int wiringPiI2CRead (int fd) ;
extern int wiringPiI2CReadReg8 (int fd, int reg) ;
extern int wiringPiI2CReadReg16 (int fd, int reg) ;
extern int wiringPiI2CWrite (int fd, int data) ;
extern int wiringPiI2CWriteReg8 (int fd, int reg, int data) ;
extern int wiringPiI2CWriteReg16 (int fd, int reg, int data) ;
extern int wiringPiI2CSetupInterface (char *device, int devId) ;
extern int wiringPiI2CSetup (int devId) ;
#ifdef __cplusplus
}
#endif

@ -28,6 +28,8 @@
#include <sys/ioctl.h>
#include <linux/spi/spidev.h>
#include "wiringPi.h"
#include "wiringPiSPI.h"

@ -60,6 +60,7 @@ int serialOpen (char *device, int baud)
case 1200: myBaud = B1200 ; break ;
case 1800: myBaud = B1800 ; break ;
case 2400: myBaud = B2400 ; break ;
case 4800: myBaud = B4800 ; break ;
case 9600: myBaud = B9600 ; break ;
case 19200: myBaud = B19200 ; break ;
case 38400: myBaud = B38400 ; break ;

@ -56,7 +56,6 @@ uint8_t shiftIn (uint8_t dPin, uint8_t cPin, uint8_t order)
return value;
}
/*
* shiftOut:
* Shift data out to a clocked source

@ -33,8 +33,8 @@
extern "C" {
#endif
extern uint8_t shiftIn (uint8_t dPin, uint8_t cPin, uint8_t order) ;
extern void shiftOut (uint8_t dPin, uint8_t cPin, uint8_t order, uint8_t val) ;
extern uint8_t shiftIn (uint8_t dPin, uint8_t cPin, uint8_t order) ;
extern void shiftOut (uint8_t dPin, uint8_t cPin, uint8_t order, uint8_t val) ;
#ifdef __cplusplus
}

@ -0,0 +1,277 @@
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 2.0.7
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
from sys import version_info
if version_info >= (2,6,0):
def swig_import_helper():
from os.path import dirname
import imp
fp = None
try:
fp, pathname, description = imp.find_module('__wiringpi', [dirname(__file__)])
except ImportError:
import __wiringpi
return __wiringpi
if fp is not None:
try:
_mod = imp.load_module('__wiringpi', fp, pathname, description)
finally:
fp.close()
return _mod
__wiringpi = swig_import_helper()
del swig_import_helper
else:
import __wiringpi
del version_info
try:
_swig_property = property
except NameError:
pass # Python < 2.2 doesn't have 'property'.
def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
if (name == "thisown"): return self.this.own(value)
if (name == "this"):
if type(value).__name__ == 'SwigPyObject':
self.__dict__[name] = value
return
method = class_type.__swig_setmethods__.get(name,None)
if method: return method(self,value)
if (not static):
self.__dict__[name] = value
else:
raise AttributeError("You cannot add attributes to %s" % self)
def _swig_setattr(self,class_type,name,value):
return _swig_setattr_nondynamic(self,class_type,name,value,0)
def _swig_getattr(self,class_type,name):
if (name == "thisown"): return self.this.own()
method = class_type.__swig_getmethods__.get(name,None)
if method: return method(self)
raise AttributeError(name)
def _swig_repr(self):
try: strthis = "proxy of " + self.this.__repr__()
except: strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
try:
_object = object
_newclass = 1
except AttributeError:
class _object : pass
_newclass = 0
def wiringPiSetup():
return __wiringpi.wiringPiSetup()
wiringPiSetup = __wiringpi.wiringPiSetup
def wiringPiSetupSys():
return __wiringpi.wiringPiSetupSys()
wiringPiSetupSys = __wiringpi.wiringPiSetupSys
def wiringPiSetupGpio():
return __wiringpi.wiringPiSetupGpio()
wiringPiSetupGpio = __wiringpi.wiringPiSetupGpio
def piFaceSetup(*args):
return __wiringpi.piFaceSetup(*args)
piFaceSetup = __wiringpi.piFaceSetup
def piBoardRev():
return __wiringpi.piBoardRev()
piBoardRev = __wiringpi.piBoardRev
def wpiPinToGpio(*args):
return __wiringpi.wpiPinToGpio(*args)
wpiPinToGpio = __wiringpi.wpiPinToGpio
def pinMode(*args):
return __wiringpi.pinMode(*args)
pinMode = __wiringpi.pinMode
def getAlt(*args):
return __wiringpi.getAlt(*args)
getAlt = __wiringpi.getAlt
def pullUpDnControl(*args):
return __wiringpi.pullUpDnControl(*args)
pullUpDnControl = __wiringpi.pullUpDnControl
def digitalWrite(*args):
return __wiringpi.digitalWrite(*args)
digitalWrite = __wiringpi.digitalWrite
def digitalWriteByte(*args):
return __wiringpi.digitalWriteByte(*args)
digitalWriteByte = __wiringpi.digitalWriteByte
def gpioClockSet(*args):
return __wiringpi.gpioClockSet(*args)
gpioClockSet = __wiringpi.gpioClockSet
def pwmWrite(*args):
return __wiringpi.pwmWrite(*args)
pwmWrite = __wiringpi.pwmWrite
def setPadDrive(*args):
return __wiringpi.setPadDrive(*args)
setPadDrive = __wiringpi.setPadDrive
def digitalRead(*args):
return __wiringpi.digitalRead(*args)
digitalRead = __wiringpi.digitalRead
def pwmSetMode(*args):
return __wiringpi.pwmSetMode(*args)
pwmSetMode = __wiringpi.pwmSetMode
def pwmSetRange(*args):
return __wiringpi.pwmSetRange(*args)
pwmSetRange = __wiringpi.pwmSetRange
def pwmSetClock(*args):
return __wiringpi.pwmSetClock(*args)
pwmSetClock = __wiringpi.pwmSetClock
def wiringPiISR(*args):
return __wiringpi.wiringPiISR(*args)
wiringPiISR = __wiringpi.wiringPiISR
def piThreadCreate(*args):
return __wiringpi.piThreadCreate(*args)
piThreadCreate = __wiringpi.piThreadCreate
def piLock(*args):
return __wiringpi.piLock(*args)
piLock = __wiringpi.piLock
def piUnlock(*args):
return __wiringpi.piUnlock(*args)
piUnlock = __wiringpi.piUnlock
def delay(*args):
return __wiringpi.delay(*args)
delay = __wiringpi.delay
def delayMicroseconds(*args):
return __wiringpi.delayMicroseconds(*args)
delayMicroseconds = __wiringpi.delayMicroseconds
def millis():
return __wiringpi.millis()
millis = __wiringpi.millis
def micros():
return __wiringpi.micros()
micros = __wiringpi.micros
def serialOpen(*args):
return __wiringpi.serialOpen(*args)
serialOpen = __wiringpi.serialOpen
def serialClose(*args):
return __wiringpi.serialClose(*args)
serialClose = __wiringpi.serialClose
def serialFlush(*args):
return __wiringpi.serialFlush(*args)
serialFlush = __wiringpi.serialFlush
def serialPutchar(*args):
return __wiringpi.serialPutchar(*args)
serialPutchar = __wiringpi.serialPutchar
def serialPuts(*args):
return __wiringpi.serialPuts(*args)
serialPuts = __wiringpi.serialPuts
def serialPrintf(*args):
return __wiringpi.serialPrintf(*args)
serialPrintf = __wiringpi.serialPrintf
def serialDataAvail(*args):
return __wiringpi.serialDataAvail(*args)
serialDataAvail = __wiringpi.serialDataAvail
def serialGetchar(*args):
return __wiringpi.serialGetchar(*args)
serialGetchar = __wiringpi.serialGetchar
def shiftOut(*args):
return __wiringpi.shiftOut(*args)
shiftOut = __wiringpi.shiftOut
def shiftIn(*args):
return __wiringpi.shiftIn(*args)
shiftIn = __wiringpi.shiftIn
def wiringPiSPIGetFd(*args):
return __wiringpi.wiringPiSPIGetFd(*args)
wiringPiSPIGetFd = __wiringpi.wiringPiSPIGetFd
def wiringPiSPIDataRW(*args):
return __wiringpi.wiringPiSPIDataRW(*args)
wiringPiSPIDataRW = __wiringpi.wiringPiSPIDataRW
def wiringPiSPISetup(*args):
return __wiringpi.wiringPiSPISetup(*args)
wiringPiSPISetup = __wiringpi.wiringPiSPISetup
def wiringPiI2CRead(*args):
return __wiringpi.wiringPiI2CRead(*args)
wiringPiI2CRead = __wiringpi.wiringPiI2CRead
def wiringPiI2CReadReg8(*args):
return __wiringpi.wiringPiI2CReadReg8(*args)
wiringPiI2CReadReg8 = __wiringpi.wiringPiI2CReadReg8
def wiringPiI2CReadReg16(*args):
return __wiringpi.wiringPiI2CReadReg16(*args)
wiringPiI2CReadReg16 = __wiringpi.wiringPiI2CReadReg16
def wiringPiI2CWrite(*args):
return __wiringpi.wiringPiI2CWrite(*args)
wiringPiI2CWrite = __wiringpi.wiringPiI2CWrite
def wiringPiI2CWriteReg8(*args):
return __wiringpi.wiringPiI2CWriteReg8(*args)
wiringPiI2CWriteReg8 = __wiringpi.wiringPiI2CWriteReg8
def wiringPiI2CWriteReg16(*args):
return __wiringpi.wiringPiI2CWriteReg16(*args)
wiringPiI2CWriteReg16 = __wiringpi.wiringPiI2CWriteReg16
def softToneCreate(*args):
return __wiringpi.softToneCreate(*args)
softToneCreate = __wiringpi.softToneCreate
def softToneWrite(*args):
return __wiringpi.softToneWrite(*args)
softToneWrite = __wiringpi.softToneWrite
def softServoWrite(*args):
return __wiringpi.softServoWrite(*args)
softServoWrite = __wiringpi.softServoWrite
def softServoSetup(*args):
return __wiringpi.softServoSetup(*args)
softServoSetup = __wiringpi.softServoSetup
def softPwmCreate(*args):
return __wiringpi.softPwmCreate(*args)
softPwmCreate = __wiringpi.softPwmCreate
def softPwmWrite(*args):
return __wiringpi.softPwmWrite(*args)
softPwmWrite = __wiringpi.softPwmWrite
# This file is compatible with both classic and new-style classes.
cvar = __wiringpi.cvar

@ -0,0 +1,89 @@
#!/usr/bin/env python
from setuptools import setup, find_packages, Extension
wiringpi_module = Extension(
'_wiringpi',
headers=[
'WiringPi/wiringPi/ds1302.h',
'WiringPi/wiringPi/gertboard.h',
'WiringPi/wiringPi/lcd.h',
'WiringPi/wiringPi/mcp23008.h',
'WiringPi/wiringPi/mcp23017.h',
'WiringPi/wiringPi/mcp23s08.h',
'WiringPi/wiringPi/mcp23s17.h',
'WiringPi/wiringPi/mcp23x0817.h',
'WiringPi/wiringPi/mcp23x08.h',
'WiringPi/wiringPi/piFace.h',
'WiringPi/wiringPi/piNes.h',
'WiringPi/wiringPi/softPwm.h',
'WiringPi/wiringPi/softServo.h',
'WiringPi/wiringPi/softTone.h',
'WiringPi/wiringPi/sr595.h',
'WiringPi/wiringPi/wiringPi.h',
'WiringPi/wiringPi/wiringPiI2C.h',
'WiringPi/wiringPi/wiringPiSPI.h',
'WiringPi/wiringPi/wiringSerial.h',
'WiringPi/wiringPi/wiringShift.h'
],
sources=[
'WiringPi/wiringPi/ds1302.c',
'WiringPi/wiringPi/gertboard.c',
'WiringPi/wiringPi/lcd.c',
'WiringPi/wiringPi/mcp23008.c',
'WiringPi/wiringPi/mcp23017.c',
'WiringPi/wiringPi/mcp23s08.c',
'WiringPi/wiringPi/mcp23s17.c',
'WiringPi/wiringPi/piFace.c',
'WiringPi/wiringPi/piHiPri.c',
'WiringPi/wiringPi/piNes.c',
'WiringPi/wiringPi/piThread.c',
'WiringPi/wiringPi/softPwm.c',
'WiringPi/wiringPi/softServo.c',
'WiringPi/wiringPi/softTone.c',
'WiringPi/wiringPi/sr595.c',
'WiringPi/wiringPi/wiringPi.c',
'WiringPi/wiringPi/wiringPiI2C.c',
'WiringPi/wiringPi/wiringPiSPI.c',
'WiringPi/wiringPi/wiringSerial.c',
'WiringPi/wiringPi/wiringShift.c',
'wiringpi_wrap.c'
],
)
setup(
name = 'wiringpi',
version = '1.1.0',
author = "Philip Howard",
author_email = "phil@gadgetoid.com",
url = 'https://github.com/WiringPi/WiringPi-Python/',
description = """A python interface to WiringPi library which allows for
easily interfacing with the GPIO pins of the Raspberry Pi. Also supports
i2c and SPI""",
long_description=open('README').read(),
ext_modules = [wiringpi_module],
py_modules = ["wiringpi"],
install_requires=[],
headers=[
'WiringPi/wiringPi/ds1302.h',
'WiringPi/wiringPi/gertboard.h',
'WiringPi/wiringPi/lcd.h',
'WiringPi/wiringPi/mcp23008.h',
'WiringPi/wiringPi/mcp23017.h',
'WiringPi/wiringPi/mcp23s08.h',
'WiringPi/wiringPi/mcp23s17.h',
'WiringPi/wiringPi/mcp23x0817.h',
'WiringPi/wiringPi/mcp23x08.h',
'WiringPi/wiringPi/piFace.h',
'WiringPi/wiringPi/piNes.h',
'WiringPi/wiringPi/softPwm.h',
'WiringPi/wiringPi/softServo.h',
'WiringPi/wiringPi/softTone.h',
'WiringPi/wiringPi/sr595.h',
'WiringPi/wiringPi/wiringPi.h',
'WiringPi/wiringPi/wiringPiI2C.h',
'WiringPi/wiringPi/wiringPiSPI.h',
'WiringPi/wiringPi/wiringSerial.h',
'WiringPi/wiringPi/wiringShift.h'
]
)

@ -1,165 +0,0 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.

@ -1,362 +0,0 @@
/*
* wiringPiFace:
* Arduino compatable (ish) Wiring library for the Raspberry Pi
* Copyright (c) 2012 Gordon Henderson
*
* This file to interface with the PiFace peripheral device which
* has an MCP23S17 GPIO device connected via the SPI bus.
*
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with wiringPi.
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <stdint.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <linux/spi/spidev.h>
#include "wiringPi.h"
// The SPI bus parameters
// Variables as they need to be passed as pointers later on
static char *spiDevice = "/dev/spidev0.0" ;
static uint8_t spiMode = 0 ;
static uint8_t spiBPW = 8 ;
static uint32_t spiSpeed = 5000000 ;
static uint16_t spiDelay = 0;
// Locals here to keep track of everything
static int spiFd ;
// The MCP23S17 doesn't have bit-set operations, so it's
// cheaper to keep a copy here than to read/modify/write it
uint8_t dataOutRegister = 0 ;
uint8_t pudRegister = 0 ;
// MCP23S17 Registers
#define IOCON 0x0A
#define IODIRA 0x00
#define IPOLA 0x02
#define GPINTENA 0x04
#define DEFVALA 0x06
#define INTCONA 0x08
#define GPPUA 0x0C
#define INTFA 0x0E
#define INTCAPA 0x10
#define GPIOA 0x12
#define OLATA 0x14
#define IODIRB 0x01
#define IPOLB 0x03
#define GPINTENB 0x05
#define DEFVALB 0x07
#define INTCONB 0x09
#define GPPUB 0x0D
#define INTFB 0x0F
#define INTCAPB 0x11
#define GPIOB 0x13
#define OLATB 0x15
// Bits in the IOCON register
#define IOCON_BANK_MODE 0x80
#define IOCON_MIRROR 0x40
#define IOCON_SEQOP 0x20
#define IOCON_DISSLW 0x10
#define IOCON_HAEN 0x08
#define IOCON_ODR 0x04
#define IOCON_INTPOL 0x02
#define IOCON_UNUSED 0x01
// Default initialisation mode
#define IOCON_INIT (IOCON_SEQOP)
// Command codes
#define CMD_WRITE 0x40
#define CMD_READ 0x41
/*
* writeByte:
* Write a byte to a register on the MCP23S17 on the SPI bus.
* This is using the synchronous access mechanism.
*********************************************************************************
*/
static void writeByte (uint8_t reg, uint8_t data)
{
uint8_t spiBufTx [3] ;
uint8_t spiBufRx [3] ;
struct spi_ioc_transfer spi ;
spiBufTx [0] = CMD_WRITE ;
spiBufTx [1] = reg ;
spiBufTx [2] = data ;
spi.tx_buf = (unsigned long)spiBufTx ;
spi.rx_buf = (unsigned long)spiBufRx ;
spi.len = 3 ;
spi.delay_usecs = spiDelay ;
spi.speed_hz = spiSpeed ;
spi.bits_per_word = spiBPW ;
ioctl (spiFd, SPI_IOC_MESSAGE(1), &spi) ;
}
/*
* readByte:
* Read a byte from a register on the MCP23S17 on the SPI bus.
* This is the synchronous access mechanism.
* What appears to happen is that the data returned is at
* the same offset as the number of bytes written to the device. So if we
* write 2 bytes (e.g. command then register number), then the data returned
* will by at the 3rd byte...
*********************************************************************************
*/
static uint8_t readByte (uint8_t reg)
{
uint8_t tx [4] ;
uint8_t rx [4] ;
struct spi_ioc_transfer spi ;
tx [0] = CMD_READ ;
tx [1] = reg ;
tx [2] = 0 ;
spi.tx_buf = (unsigned long)tx ;
spi.rx_buf = (unsigned long)rx ;
spi.len = 3 ;
spi.delay_usecs = spiDelay ;
spi.speed_hz = spiSpeed ;
spi.bits_per_word = spiBPW ;
ioctl (spiFd, SPI_IOC_MESSAGE(1), &spi) ;
return rx [2] ;
}
/*
* digitalWritePiFace:
* Perform the digitalWrite function on the PiFace board
*********************************************************************************
*/
void digitalWritePiFace (int pin, int value)
{
uint8_t mask = 1 << pin ;
if (value == 0)
dataOutRegister &= (~mask) ;
else
dataOutRegister |= mask ;
writeByte (GPIOA, dataOutRegister) ;
}
void digitalWriteBytePiFace (int value)
{
writeByte (GPIOA, value) ;
}
void digitalWritePiFaceSpecial (int pin, int value)
{
uint8_t mask = 1 << pin ;
uint8_t old ;
old = readByte (GPIOA) ;
if (value == 0)
old &= (~mask) ;
else
old |= mask ;
writeByte (GPIOA, old) ;
}
/*
* digitalReadPiFace:
* Perform the digitalRead function on the PiFace board
*********************************************************************************
*/
int digitalReadPiFace (int pin)
{
uint8_t mask = 1 << pin ;
if ((readByte (GPIOB) & mask) != 0)
return HIGH ;
else
return LOW ;
}
/*
* pullUpDnControlPiFace:
* Perform the pullUpDnControl function on the PiFace board
*********************************************************************************
*/
void pullUpDnControlPiFace (int pin, int pud)
{
uint8_t mask = 1 << pin ;
if (pud == PUD_UP)
pudRegister |= mask ;
else
pudRegister &= (~mask) ;
writeByte (GPPUB, pudRegister) ;
}
void pullUpDnControlPiFaceSpecial (int pin, int pud)
{
uint8_t mask = 1 << pin ;
uint8_t old ;
old = readByte (GPPUB) ;
if (pud == PUD_UP)
old |= mask ;
else
old &= (~mask) ;
writeByte (GPPUB, old) ;
}
/*
* Dummy functions that are not used in this mode
*********************************************************************************
*/
void pinModePiFace (int pin, int mode) {}
void pwmWritePiFace (int pin, int value) {}
int waitForInterruptPiFace (int pin, int mS) { return 0 ; }
/*
* wiringPiSetupPiFace
* Setup the SPI interface and initialise the MCP23S17 chip
*********************************************************************************
*/
static int _wiringPiSetupPiFace (void)
{
if ((spiFd = open (spiDevice, O_RDWR)) < 0)
return -1 ;
// Set SPI parameters
// Why are we doing a read after write?
// I don't know - just blindliy copying an example elsewhere... -GH-
if (ioctl (spiFd, SPI_IOC_WR_MODE, &spiMode) < 0)
return -1 ;
if (ioctl (spiFd, SPI_IOC_RD_MODE, &spiMode) < 0)
return -1 ;
if (ioctl (spiFd, SPI_IOC_WR_BITS_PER_WORD, &spiBPW) < 0)
return -1 ;
if (ioctl (spiFd, SPI_IOC_RD_BITS_PER_WORD, &spiBPW) < 0)
return -1 ;
if (ioctl (spiFd, SPI_IOC_WR_MAX_SPEED_HZ, &spiSpeed) < 0)
return -1 ;
if (ioctl (spiFd, SPI_IOC_RD_MAX_SPEED_HZ, &spiSpeed) < 0)
return -1 ;
// Setup the MCP23S17
writeByte (IOCON, IOCON_INIT) ;
writeByte (IODIRA, 0x00) ; // Port A -> Outputs
writeByte (IODIRB, 0xFF) ; // Port B -> Inputs
return 0 ;
}
int wiringPiSetupPiFace (void)
{
int x = _wiringPiSetupPiFace () ;
if (x != 0)
return x ;
writeByte (GPIOA, 0x00) ; // Set all outptus off
writeByte (GPPUB, 0x00) ; // Disable any pull-ups on port B
pinMode = pinModePiFace ;
pullUpDnControl = pullUpDnControlPiFace ;
digitalWrite = digitalWritePiFace ;
digitalWriteByte = digitalWriteBytePiFace ;
pwmWrite = pwmWritePiFace ;
digitalRead = digitalReadPiFace ;
waitForInterrupt = waitForInterruptPiFace ;
return 0 ;
}
/*
* wiringPiSetupPiFaceForGpioProg:
* Setup the SPI interface and initialise the MCP23S17 chip
* Special version for the gpio program
*********************************************************************************
*/
int wiringPiSetupPiFaceForGpioProg (void)
{
int x = _wiringPiSetupPiFace () ;
if (x != 0)
return x ;
pinMode = pinModePiFace ;
pullUpDnControl = pullUpDnControlPiFaceSpecial ;
digitalWrite = digitalWritePiFaceSpecial ;
digitalWriteByte = digitalWriteBytePiFace ;
pwmWrite = pwmWritePiFace ;
digitalRead = digitalReadPiFace ;
waitForInterrupt = waitForInterruptPiFace ;
return 0 ;
}

@ -1,122 +0,0 @@
/*
* wiringPiI2C.c:
* Simplified I2C access routines
* Copyright (c) 2013 Gordon Henderson
***********************************************************************
* This file is part of wiringPi:
* https://projects.drogon.net/raspberry-pi/wiringpi/
*
* wiringPi is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* wiringPi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with wiringPi.
* If not, see <http://www.gnu.org/licenses/>.
***********************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/i2c-dev.h>
#include "wiringPi.h"
#include "wiringPiI2C.h"
/*
* wiringPiI2CRead:
* Simple device read
*********************************************************************************
*/
int wiringPiI2CRead (int fd)
{
return i2c_smbus_read_byte (fd) ;
}
/*
* wiringPiI2CReadReg8: wiringPiI2CReadReg16:
* Read an 8 or 16-bit value from a regsiter on the device
*********************************************************************************
*/
int wiringPiI2CReadReg8 (int fd, int reg)
{
return i2c_smbus_read_byte_data (fd, reg) ;
}
int wiringPiI2CReadReg16 (int fd, int reg)
{
return i2c_smbus_read_word_data (fd, reg) ;
}
/*
* wiringPiI2CWrite:
* Simple device write
*********************************************************************************
*/
int wiringPiI2CWrite (int fd, int data)
{
return i2c_smbus_write_byte (fd, data) ;
}
/*
* wiringPiI2CWriteReg8: wiringPiI2CWriteReg16:
* Write an 8 or 16-bit value to the given register
*********************************************************************************
*/
int wiringPiI2CWriteReg8 (int fd, int reg, int data)
{
return i2c_smbus_write_byte_data (fd, reg, data) ;
}
int wiringPiI2CWriteReg16 (int fd, int reg, int data)
{
return i2c_smbus_write_word_data (fd, reg, data) ;
}
/*
* wiringPiI2CSetup:
* Open the I2C device, and regsiter the target device
*********************************************************************************
*/
int wiringPiI2CSetup (int devId)
{
int rev, fd ;
char *device ;
if ((rev = piBoardRev ()) < 0)
{
fprintf (stderr, "wiringPiI2CSetup: Unable to determine Pi board revision\n") ;
exit (1) ;
}
if (rev == 1)
device = "/dev/i2c-0" ;
else
device = "/dev/i2c-1" ;
if ((fd = open (device, O_RDWR)) < 0)
return -1 ;
if (ioctl (fd, I2C_SLAVE, devId) < 0)
return -1 ;
return fd ;
}

@ -0,0 +1,127 @@
%module wiringpi
%{
#include "WiringPi/wiringPi/ds1302.h",
#include "WiringPi/wiringPi/gertboard.h",
#include "WiringPi/wiringPi/lcd.h",
#include "WiringPi/wiringPi/mcp23008.h",
#include "WiringPi/wiringPi/mcp23017.h",
#include "WiringPi/wiringPi/mcp23s08.h",
#include "WiringPi/wiringPi/mcp23s17.h",
#include "WiringPi/wiringPi/mcp23x0817.h",
#include "WiringPi/wiringPi/mcp23x08.h",
#include "WiringPi/wiringPi/piFace.h",
#include "WiringPi/wiringPi/piNes.h",
#include "WiringPi/wiringPi/softPwm.h",
#include "WiringPi/wiringPi/softServo.h",
#include "WiringPi/wiringPi/softTone.h",
#include "WiringPi/wiringPi/sr595.h",
#include "WiringPi/wiringPi/wiringPi.h",
#include "WiringPi/wiringPi/wiringPiI2C.h",
#include "WiringPi/wiringPi/wiringPiSPI.h",
#include "WiringPi/wiringPi/wiringSerial.h",
#include "WiringPi/wiringPi/wiringShift.h"
%}
%apply unsigned char { uint8_t };
extern int wiringPiSetup (void) ;
extern int wiringPiSetupSys (void) ;
extern int wiringPiSetupGpio (void) ;
extern int piFaceSetup (int pinbase) ;
extern int piBoardRev (void) ;
extern int wpiPinToGpio (int wpiPin) ;
extern void pinMode (int pin, int mode) ;
extern int getAlt (int pin) ;
extern void pullUpDnControl (int pin, int pud) ;
extern void digitalWrite (int pin, int value) ;
extern void digitalWriteByte (int value) ;
extern void gpioClockSet (int pin, int freq) ;
extern void pwmWrite (int pin, int value) ;
extern void setPadDrive (int group, int value) ;
extern int digitalRead (int pin) ;
extern void pwmSetMode (int mode) ;
extern void pwmSetRange (unsigned int range) ;
extern void pwmSetClock (int divisor) ;
// Interrupts
extern int (*waitForInterrupt) (int pin, int mS) ;
extern int wiringPiISR (int pin, int mode, void (*function)(void)) ;
// Threads
extern int piThreadCreate (void *(*fn)(void *)) ;
extern void piLock (int key) ;
extern void piUnlock (int key) ;
// Extras from arduino land
extern void delay (unsigned int howLong) ;
extern void delayMicroseconds (unsigned int howLong) ;
extern unsigned int millis (void) ;
extern unsigned int micros (void) ;
// WiringSerial
extern int serialOpen (char *device, int baud) ;
extern void serialClose (int fd) ;
extern void serialFlush (int fd) ;
extern void serialPutchar (int fd, unsigned char c) ;
extern void serialPuts (int fd, char *s) ;
extern void serialPrintf (int fd, char *message, ...) ;
extern int serialDataAvail (int fd) ;
extern int serialGetchar (int fd) ;
// Shifting
extern void shiftOut (uint8_t dPin, uint8_t cPin, uint8_t order, uint8_t val);
extern uint8_t shiftIn (uint8_t dPin, uint8_t cPin, uint8_t order);
// Spi
%typemap(in) (unsigned char *data, int len) {
$1 = (unsigned char *) PyString_AsString($input);
$2 = PyString_Size($input);
};
int wiringPiSPIGetFd (int channel) ;
int wiringPiSPIDataRW (int channel, unsigned char *data, int len) ;
int wiringPiSPISetup (int channel, int speed) ;
// i2c
extern int wiringPiI2CRead (int fd) ;
extern int wiringPiI2CReadReg8 (int fd, int reg) ;
extern int wiringPiI2CReadReg16 (int fd, int reg) ;
extern int wiringPiI2CWrite (int fd, int data) ;
extern int wiringPiI2CWriteReg8 (int fd, int reg, int data) ;
extern int wiringPiI2CWriteReg16 (int fd, int reg, int data) ;
// Soft Tone
extern int softToneCreate (int pin) ;
extern void softToneWrite (int pin, int frewq) ;
// Soft Servo
extern void softServoWrite (int pin, int value) ;
extern int softServoSetup (int p0, int p1, int p2, int p3, int p4, int p5, int p6, int p7) ;
// Soft PWM
extern int softPwmCreate (int pin, int value, int range) ;
extern void softPwmWrite (int pin, int value) ;
extern int mcp23s17Setup (int pinBase, int spiPort, int devId) ;
extern int mcp23017Setup (int pinBase, int i2cAddress) ;
extern int mcp23s08Setup (int pinBase, int spiPort, int devId) ;
extern int mcp23008Setup (int pinBase, int i2cAddress) ;
extern int sr595Setup (int pinBase, int numPins, int dataPin, int clockPin, int latchPin) ;

@ -0,0 +1,297 @@
# This file was automatically generated by SWIG (http://www.swig.org).
# Version 2.0.7
#
# Do not make changes to this file unless you know what you are doing--modify
# the SWIG interface file instead.
from sys import version_info
if version_info >= (2,6,0):
def swig_import_helper():
from os.path import dirname
import imp
fp = None
try:
fp, pathname, description = imp.find_module('_wiringpi', [dirname(__file__)])
except ImportError:
import _wiringpi
return _wiringpi
if fp is not None:
try:
_mod = imp.load_module('_wiringpi', fp, pathname, description)
finally:
fp.close()
return _mod
_wiringpi = swig_import_helper()
del swig_import_helper
else:
import _wiringpi
del version_info
try:
_swig_property = property
except NameError:
pass # Python < 2.2 doesn't have 'property'.
def _swig_setattr_nondynamic(self,class_type,name,value,static=1):
if (name == "thisown"): return self.this.own(value)
if (name == "this"):
if type(value).__name__ == 'SwigPyObject':
self.__dict__[name] = value
return
method = class_type.__swig_setmethods__.get(name,None)
if method: return method(self,value)
if (not static):
self.__dict__[name] = value
else:
raise AttributeError("You cannot add attributes to %s" % self)
def _swig_setattr(self,class_type,name,value):
return _swig_setattr_nondynamic(self,class_type,name,value,0)
def _swig_getattr(self,class_type,name):
if (name == "thisown"): return self.this.own()
method = class_type.__swig_getmethods__.get(name,None)
if method: return method(self)
raise AttributeError(name)
def _swig_repr(self):
try: strthis = "proxy of " + self.this.__repr__()
except: strthis = ""
return "<%s.%s; %s >" % (self.__class__.__module__, self.__class__.__name__, strthis,)
try:
_object = object
_newclass = 1
except AttributeError:
class _object : pass
_newclass = 0
def wiringPiSetup():
return _wiringpi.wiringPiSetup()
wiringPiSetup = _wiringpi.wiringPiSetup
def wiringPiSetupSys():
return _wiringpi.wiringPiSetupSys()
wiringPiSetupSys = _wiringpi.wiringPiSetupSys
def wiringPiSetupGpio():
return _wiringpi.wiringPiSetupGpio()
wiringPiSetupGpio = _wiringpi.wiringPiSetupGpio
def piFaceSetup(*args):
return _wiringpi.piFaceSetup(*args)
piFaceSetup = _wiringpi.piFaceSetup
def piBoardRev():
return _wiringpi.piBoardRev()
piBoardRev = _wiringpi.piBoardRev
def wpiPinToGpio(*args):
return _wiringpi.wpiPinToGpio(*args)
wpiPinToGpio = _wiringpi.wpiPinToGpio
def pinMode(*args):
return _wiringpi.pinMode(*args)
pinMode = _wiringpi.pinMode
def getAlt(*args):
return _wiringpi.getAlt(*args)
getAlt = _wiringpi.getAlt
def pullUpDnControl(*args):
return _wiringpi.pullUpDnControl(*args)
pullUpDnControl = _wiringpi.pullUpDnControl
def digitalWrite(*args):
return _wiringpi.digitalWrite(*args)
digitalWrite = _wiringpi.digitalWrite
def digitalWriteByte(*args):
return _wiringpi.digitalWriteByte(*args)
digitalWriteByte = _wiringpi.digitalWriteByte
def gpioClockSet(*args):
return _wiringpi.gpioClockSet(*args)
gpioClockSet = _wiringpi.gpioClockSet
def pwmWrite(*args):
return _wiringpi.pwmWrite(*args)
pwmWrite = _wiringpi.pwmWrite
def setPadDrive(*args):
return _wiringpi.setPadDrive(*args)
setPadDrive = _wiringpi.setPadDrive
def digitalRead(*args):
return _wiringpi.digitalRead(*args)
digitalRead = _wiringpi.digitalRead
def pwmSetMode(*args):
return _wiringpi.pwmSetMode(*args)
pwmSetMode = _wiringpi.pwmSetMode
def pwmSetRange(*args):
return _wiringpi.pwmSetRange(*args)
pwmSetRange = _wiringpi.pwmSetRange
def pwmSetClock(*args):
return _wiringpi.pwmSetClock(*args)
pwmSetClock = _wiringpi.pwmSetClock
def wiringPiISR(*args):
return _wiringpi.wiringPiISR(*args)
wiringPiISR = _wiringpi.wiringPiISR
def piThreadCreate(*args):
return _wiringpi.piThreadCreate(*args)
piThreadCreate = _wiringpi.piThreadCreate
def piLock(*args):
return _wiringpi.piLock(*args)
piLock = _wiringpi.piLock
def piUnlock(*args):
return _wiringpi.piUnlock(*args)
piUnlock = _wiringpi.piUnlock
def delay(*args):
return _wiringpi.delay(*args)
delay = _wiringpi.delay
def delayMicroseconds(*args):
return _wiringpi.delayMicroseconds(*args)
delayMicroseconds = _wiringpi.delayMicroseconds
def millis():
return _wiringpi.millis()
millis = _wiringpi.millis
def micros():
return _wiringpi.micros()
micros = _wiringpi.micros
def serialOpen(*args):
return _wiringpi.serialOpen(*args)
serialOpen = _wiringpi.serialOpen
def serialClose(*args):
return _wiringpi.serialClose(*args)
serialClose = _wiringpi.serialClose
def serialFlush(*args):
return _wiringpi.serialFlush(*args)
serialFlush = _wiringpi.serialFlush
def serialPutchar(*args):
return _wiringpi.serialPutchar(*args)
serialPutchar = _wiringpi.serialPutchar
def serialPuts(*args):
return _wiringpi.serialPuts(*args)
serialPuts = _wiringpi.serialPuts
def serialPrintf(*args):
return _wiringpi.serialPrintf(*args)
serialPrintf = _wiringpi.serialPrintf
def serialDataAvail(*args):
return _wiringpi.serialDataAvail(*args)
serialDataAvail = _wiringpi.serialDataAvail
def serialGetchar(*args):
return _wiringpi.serialGetchar(*args)
serialGetchar = _wiringpi.serialGetchar
def shiftOut(*args):
return _wiringpi.shiftOut(*args)
shiftOut = _wiringpi.shiftOut
def shiftIn(*args):
return _wiringpi.shiftIn(*args)
shiftIn = _wiringpi.shiftIn
def wiringPiSPIGetFd(*args):
return _wiringpi.wiringPiSPIGetFd(*args)
wiringPiSPIGetFd = _wiringpi.wiringPiSPIGetFd
def wiringPiSPIDataRW(*args):
return _wiringpi.wiringPiSPIDataRW(*args)
wiringPiSPIDataRW = _wiringpi.wiringPiSPIDataRW
def wiringPiSPISetup(*args):
return _wiringpi.wiringPiSPISetup(*args)
wiringPiSPISetup = _wiringpi.wiringPiSPISetup
def wiringPiI2CRead(*args):
return _wiringpi.wiringPiI2CRead(*args)
wiringPiI2CRead = _wiringpi.wiringPiI2CRead
def wiringPiI2CReadReg8(*args):
return _wiringpi.wiringPiI2CReadReg8(*args)
wiringPiI2CReadReg8 = _wiringpi.wiringPiI2CReadReg8
def wiringPiI2CReadReg16(*args):
return _wiringpi.wiringPiI2CReadReg16(*args)
wiringPiI2CReadReg16 = _wiringpi.wiringPiI2CReadReg16
def wiringPiI2CWrite(*args):
return _wiringpi.wiringPiI2CWrite(*args)
wiringPiI2CWrite = _wiringpi.wiringPiI2CWrite
def wiringPiI2CWriteReg8(*args):
return _wiringpi.wiringPiI2CWriteReg8(*args)
wiringPiI2CWriteReg8 = _wiringpi.wiringPiI2CWriteReg8
def wiringPiI2CWriteReg16(*args):
return _wiringpi.wiringPiI2CWriteReg16(*args)
wiringPiI2CWriteReg16 = _wiringpi.wiringPiI2CWriteReg16
def softToneCreate(*args):
return _wiringpi.softToneCreate(*args)
softToneCreate = _wiringpi.softToneCreate
def softToneWrite(*args):
return _wiringpi.softToneWrite(*args)
softToneWrite = _wiringpi.softToneWrite
def softServoWrite(*args):
return _wiringpi.softServoWrite(*args)
softServoWrite = _wiringpi.softServoWrite
def softServoSetup(*args):
return _wiringpi.softServoSetup(*args)
softServoSetup = _wiringpi.softServoSetup
def softPwmCreate(*args):
return _wiringpi.softPwmCreate(*args)
softPwmCreate = _wiringpi.softPwmCreate
def softPwmWrite(*args):
return _wiringpi.softPwmWrite(*args)
softPwmWrite = _wiringpi.softPwmWrite
def mcp23s17Setup(*args):
return _wiringpi.mcp23s17Setup(*args)
mcp23s17Setup = _wiringpi.mcp23s17Setup
def mcp23017Setup(*args):
return _wiringpi.mcp23017Setup(*args)
mcp23017Setup = _wiringpi.mcp23017Setup
def mcp23s08Setup(*args):
return _wiringpi.mcp23s08Setup(*args)
mcp23s08Setup = _wiringpi.mcp23s08Setup
def mcp23008Setup(*args):
return _wiringpi.mcp23008Setup(*args)
mcp23008Setup = _wiringpi.mcp23008Setup
def sr595Setup(*args):
return _wiringpi.sr595Setup(*args)
sr595Setup = _wiringpi.sr595Setup
# This file is compatible with both classic and new-style classes.
cvar = _wiringpi.cvar

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save