3 * Arduino compatable (ish) Wiring library for the Raspberry Pi
4 * Copyright (c) 2012 Gordon Henderson
5 ***********************************************************************
6 * This file is part of wiringPi:
7 * https://projects.drogon.net/raspberry-pi/wiringpi/
9 * wiringPi is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * wiringPi is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with wiringPi. If not, see <http://www.gnu.org/licenses/>.
21 ***********************************************************************
24 #ifndef __WIRING_PI_H__
25 #define __WIRING_PI_H__
32 #define WPI_MODE_PINS 0
33 #define WPI_MODE_GPIO 1
34 #define WPI_MODE_GPIO_SYS 2
35 #define WPI_MODE_PHYS 3
36 #define WPI_MODE_PIFACE 4
37 #define WPI_MODE_UNINITIALISED -1
58 #define PWM_MODE_BAL 1
62 #define INT_EDGE_SETUP 0
63 #define INT_EDGE_FALLING 1
64 #define INT_EDGE_RISING 2
65 #define INT_EDGE_BOTH 3
69 #define PI_THREAD(X) void *X (void *dummy)
73 #define WPI_FATAL (1==1)
74 #define WPI_ALMOST (1==2)
77 // wiringPiNodeStruct:
78 // This describes additional device nodes in the extended wiringPi
79 // 2.0 scheme of things.
80 // It's a simple linked list for now, but will hopefully migrate to
81 // a binary tree for efficiency reasons - but then again, the chances
82 // of more than 1 or 2 devices being added are fairly slim, so who
85 struct wiringPiNodeStruct
90 int fd ; // Node specific
91 unsigned int data0 ; // ditto
92 unsigned int data1 ; // ditto
93 unsigned int data2 ; // ditto
94 unsigned int data3 ; // ditto
96 void (*pinMode) (struct wiringPiNodeStruct *node, int pin, int mode) ;
97 void (*pullUpDnControl) (struct wiringPiNodeStruct *node, int pin, int mode) ;
98 int (*digitalRead) (struct wiringPiNodeStruct *node, int pin) ;
99 void (*digitalWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
100 void (*pwmWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
101 int (*analogRead) (struct wiringPiNodeStruct *node, int pin) ;
102 void (*analogWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
104 struct wiringPiNodeStruct *next ;
107 extern struct wiringPiNodeStruct *wiringPiNodes ;
110 // Function prototypes
111 // c++ wrappers thanks to a comment by Nick Lott
112 // (and others on the Raspberry Pi forums)
120 extern int wiringPiFailure (int fatal, const char *message, ...) ;
122 // Core wiringPi functions
124 extern struct wiringPiNodeStruct *wiringPiFindNode (int pin) ;
125 extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) ;
127 extern int wiringPiSetup (void) ;
128 extern int wiringPiSetupSys (void) ;
129 extern int wiringPiSetupGpio (void) ;
130 extern int wiringPiSetupPhys (void) ;
132 extern void pinMode (int pin, int mode) ;
133 extern void pullUpDnControl (int pin, int pud) ;
134 extern int digitalRead (int pin) ;
135 extern void digitalWrite (int pin, int value) ;
136 extern void pwmWrite (int pin, int value) ;
137 extern int analogRead (int pin) ;
138 extern void analogWrite (int pin, int value) ;
143 extern int wiringPiSetupPiFace (void) ;
144 extern int wiringPiSetupPiFaceForGpioProg (void) ; // Don't use this - for gpio program only
146 // On-Board Raspberry Pi hardware specific stuff
148 extern int piBoardRev (void) ;
149 extern int wpiPinToGpio (int wpiPin) ;
150 extern int physPinToGpio (int physPin) ;
151 extern void setPadDrive (int group, int value) ;
152 extern int getAlt (int pin) ;
153 extern void digitalWriteByte (int value) ;
154 extern void pwmSetMode (int mode) ;
155 extern void pwmSetRange (unsigned int range) ;
156 extern void pwmSetClock (int divisor) ;
157 extern void gpioClockSet (int pin, int freq) ;
160 // (Also Pi hardware specific)
162 extern int waitForInterrupt (int pin, int mS) ;
163 extern int wiringPiISR (int pin, int mode, void (*function)(void)) ;
167 extern int piThreadCreate (void *(*fn)(void *)) ;
168 extern void piLock (int key) ;
169 extern void piUnlock (int key) ;
171 // Schedulling priority
173 extern int piHiPri (const int pri) ;
175 // Extras from arduino land
177 extern void delay (unsigned int howLong) ;
178 extern void delayMicroseconds (unsigned int howLong) ;
179 extern unsigned int millis (void) ;
180 extern unsigned int micros (void) ;