parent
98bcb20d93
commit
567ee0027e
@ -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/
|
||||||
|
|
||||||
@ -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 |
@ -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}
|
||||||
@ -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
|
||||||
@ -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 ;
|
||||||
|
}
|
||||||
@ -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
|
||||||
@ -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
@ -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
|
||||||
@ -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…
Reference in new issue