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
45 #define SOFT_PWM_OUTPUT 4
46 #define SOFT_TONE_OUTPUT 5
47 #define PWM_TONE_OUTPUT 6
61 #define PWM_MODE_BAL 1
65 #define INT_EDGE_SETUP 0
66 #define INT_EDGE_FALLING 1
67 #define INT_EDGE_RISING 2
68 #define INT_EDGE_BOTH 3
70 // Pi model types and version numbers
71 // Intended for the GPIO program Use at your own risk.
73 #define PI_MODEL_UNKNOWN 0
79 #define PI_VERSION_UNKNOWN 0
80 #define PI_VERSION_1 1
81 #define PI_VERSION_1_1 2
82 #define PI_VERSION_1_2 3
83 #define PI_VERSION_2 4
85 #define PI_MAKER_UNKNOWN 0
86 #define PI_MAKER_EGOMAN 1
87 #define PI_MAKER_SONY 2
88 #define PI_MAKER_QISDA 3
90 extern const char *piModelNames [5] ;
91 extern const char *piRevisionNames [5] ;
92 extern const char *piMakerNames [4] ;
95 // Intended for the GPIO program Use at your own risk.
99 #define PI_THREAD(X) void *X (void *dummy)
103 #define WPI_FATAL (1==1)
104 #define WPI_ALMOST (1==2)
107 // wiringPiNodeStruct:
108 // This describes additional device nodes in the extended wiringPi
109 // 2.0 scheme of things.
110 // It's a simple linked list for now, but will hopefully migrate to
111 // a binary tree for efficiency reasons - but then again, the chances
112 // of more than 1 or 2 devices being added are fairly slim, so who
115 struct wiringPiNodeStruct
120 int fd ; // Node specific
121 unsigned int data0 ; // ditto
122 unsigned int data1 ; // ditto
123 unsigned int data2 ; // ditto
124 unsigned int data3 ; // ditto
126 void (*pinMode) (struct wiringPiNodeStruct *node, int pin, int mode) ;
127 void (*pullUpDnControl) (struct wiringPiNodeStruct *node, int pin, int mode) ;
128 int (*digitalRead) (struct wiringPiNodeStruct *node, int pin) ;
129 void (*digitalWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
130 void (*pwmWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
131 int (*analogRead) (struct wiringPiNodeStruct *node, int pin) ;
132 void (*analogWrite) (struct wiringPiNodeStruct *node, int pin, int value) ;
134 struct wiringPiNodeStruct *next ;
137 extern struct wiringPiNodeStruct *wiringPiNodes ;
140 // Function prototypes
141 // c++ wrappers thanks to a comment by Nick Lott
142 // (and others on the Raspberry Pi forums)
150 //extern const char *piModelNames [] ;
151 //extern const char *piRevisionNames[] ;
155 extern int wiringPiFailure (int fatal, const char *message, ...) ;
157 // Core wiringPi functions
159 extern struct wiringPiNodeStruct *wiringPiFindNode (int pin) ;
160 extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) ;
162 extern int wiringPiSetup (void) ;
163 extern int wiringPiSetupSys (void) ;
164 extern int wiringPiSetupGpio (void) ;
165 extern int wiringPiSetupPhys (void) ;
167 extern void pinModeAlt (int pin, int mode) ;
168 extern void pinMode (int pin, int mode) ;
169 extern void pullUpDnControl (int pin, int pud) ;
170 extern int digitalRead (int pin) ;
171 extern void digitalWrite (int pin, int value) ;
172 extern void pwmWrite (int pin, int value) ;
173 extern int analogRead (int pin) ;
174 extern void analogWrite (int pin, int value) ;
179 extern int wiringPiSetupPiFace (void) ;
180 extern int wiringPiSetupPiFaceForGpioProg (void) ; // Don't use this - for gpio program only
182 // On-Board Raspberry Pi hardware specific stuff
184 extern int piBoardRev (void) ;
185 extern void piBoardId (int *model, int *rev, int *mem, int *maker, int *overVolted) ;
186 extern int wpiPinToGpio (int wpiPin) ;
187 extern int physPinToGpio (int physPin) ;
188 extern void setPadDrive (int group, int value) ;
189 extern int getAlt (int pin) ;
190 extern void pwmToneWrite (int pin, int freq) ;
191 extern void digitalWriteByte (int value) ;
192 extern void pwmSetMode (int mode) ;
193 extern void pwmSetRange (unsigned int range) ;
194 extern void pwmSetClock (int divisor) ;
195 extern void gpioClockSet (int pin, int freq) ;
198 // (Also Pi hardware specific)
200 extern int waitForInterrupt (int pin, int mS) ;
201 extern int wiringPiISR (int pin, int mode, void (*function)(void)) ;
205 extern int piThreadCreate (void *(*fn)(void *)) ;
206 extern void piLock (int key) ;
207 extern void piUnlock (int key) ;
209 // Schedulling priority
211 extern int piHiPri (const int pri) ;
213 // Extras from arduino land
215 extern void delay (unsigned int howLong) ;
216 extern void delayMicroseconds (unsigned int howLong) ;
217 extern unsigned int millis (void) ;
218 extern unsigned int micros (void) ;