chiark / gitweb /
Updated mostly to the gpio readall command to support the Raspberry Pi B+
[wiringPi.git] / wiringPi / wiringPi.h
1 /*
2  * wiringPi:
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/
8  *
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.
13  *
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.
18  *
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  ***********************************************************************
22  */
23
24 #ifndef __WIRING_PI_H__
25 #define __WIRING_PI_H__
26
27 // Handy defines
28
29 // Deprecated
30 #define NUM_PINS        17
31
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
38
39 // Pin modes
40
41 #define INPUT                    0
42 #define OUTPUT                   1
43 #define PWM_OUTPUT               2
44 #define GPIO_CLOCK               3
45 #define SOFT_PWM_OUTPUT          4
46 #define SOFT_TONE_OUTPUT         5
47 #define PWM_TONE_OUTPUT          6
48
49 #define LOW                      0
50 #define HIGH                     1
51
52 // Pull up/down/none
53
54 #define PUD_OFF                  0
55 #define PUD_DOWN                 1
56 #define PUD_UP                   2
57
58 // PWM
59
60 #define PWM_MODE_MS             0
61 #define PWM_MODE_BAL            1
62
63 // Interrupt levels
64
65 #define INT_EDGE_SETUP          0
66 #define INT_EDGE_FALLING        1
67 #define INT_EDGE_RISING         2
68 #define INT_EDGE_BOTH           3
69
70 // Pi model types
71
72 #define PI_MODEL_A              0
73 #define PI_MODEL_B              1
74 #define PI_MODEL_BPLUS          2
75 #define PI_MODEL_CM             3
76
77
78 // Threads
79
80 #define PI_THREAD(X)    void *X (void *dummy)
81
82 // Failure modes
83
84 #define WPI_FATAL       (1==1)
85 #define WPI_ALMOST      (1==2)
86
87
88 // wiringPiNodeStruct:
89 //      This describes additional device nodes in the extended wiringPi
90 //      2.0 scheme of things.
91 //      It's a simple linked list for now, but will hopefully migrate to 
92 //      a binary tree for efficiency reasons - but then again, the chances
93 //      of more than 1 or 2 devices being added are fairly slim, so who
94 //      knows....
95
96 struct wiringPiNodeStruct
97 {
98   int     pinBase ;
99   int     pinMax ;
100
101   int          fd ;     // Node specific
102   unsigned int data0 ;  //  ditto
103   unsigned int data1 ;  //  ditto
104   unsigned int data2 ;  //  ditto
105   unsigned int data3 ;  //  ditto
106
107   void   (*pinMode)         (struct wiringPiNodeStruct *node, int pin, int mode) ;
108   void   (*pullUpDnControl) (struct wiringPiNodeStruct *node, int pin, int mode) ;
109   int    (*digitalRead)     (struct wiringPiNodeStruct *node, int pin) ;
110   void   (*digitalWrite)    (struct wiringPiNodeStruct *node, int pin, int value) ;
111   void   (*pwmWrite)        (struct wiringPiNodeStruct *node, int pin, int value) ;
112   int    (*analogRead)      (struct wiringPiNodeStruct *node, int pin) ;
113   void   (*analogWrite)     (struct wiringPiNodeStruct *node, int pin, int value) ;
114
115   struct wiringPiNodeStruct *next ;
116 } ;
117
118 extern struct wiringPiNodeStruct *wiringPiNodes ;
119
120
121 // Function prototypes
122 //      c++ wrappers thanks to a comment by Nick Lott
123 //      (and others on the Raspberry Pi forums)
124
125 #ifdef __cplusplus
126 extern "C" {
127 #endif
128
129 // Data
130
131 extern const char *piModelNames [] ;
132 extern const char *piRevisionNames[] ;
133
134 // Internal
135
136 extern int wiringPiFailure (int fatal, const char *message, ...) ;
137
138 // Core wiringPi functions
139
140 extern struct wiringPiNodeStruct *wiringPiFindNode (int pin) ;
141 extern struct wiringPiNodeStruct *wiringPiNewNode  (int pinBase, int numPins) ;
142
143 extern int  wiringPiSetup       (void) ;
144 extern int  wiringPiSetupSys    (void) ;
145 extern int  wiringPiSetupGpio   (void) ;
146 extern int  wiringPiSetupPhys   (void) ;
147
148 extern void pinModeAlt          (int pin, int mode) ;
149 extern void pinMode             (int pin, int mode) ;
150 extern void pullUpDnControl     (int pin, int pud) ;
151 extern int  digitalRead         (int pin) ;
152 extern void digitalWrite        (int pin, int value) ;
153 extern void pwmWrite            (int pin, int value) ;
154 extern int  analogRead          (int pin) ;
155 extern void analogWrite         (int pin, int value) ;
156
157 // PiFace specifics 
158 //      (Deprecated)
159
160 extern int  wiringPiSetupPiFace (void) ;
161 extern int  wiringPiSetupPiFaceForGpioProg (void) ;     // Don't use this - for gpio program only
162
163 // On-Board Raspberry Pi hardware specific stuff
164
165 extern int  piBoardRev          (void) ;
166 extern void piBoardId           (int *model, int *rev, int *mem, char **maker) ;
167 extern int  wpiPinToGpio        (int wpiPin) ;
168 extern int  physPinToGpio       (int physPin) ;
169 extern void setPadDrive         (int group, int value) ;
170 extern int  getAlt              (int pin) ;
171 extern void pwmToneWrite        (int pin, int freq) ;
172 extern void digitalWriteByte    (int value) ;
173 extern void pwmSetMode          (int mode) ;
174 extern void pwmSetRange         (unsigned int range) ;
175 extern void pwmSetClock         (int divisor) ;
176 extern void gpioClockSet        (int pin, int freq) ;
177
178 // Interrupts
179 //      (Also Pi hardware specific)
180
181 extern int  waitForInterrupt    (int pin, int mS) ;
182 extern int  wiringPiISR         (int pin, int mode, void (*function)(void)) ;
183
184 // Threads
185
186 extern int  piThreadCreate      (void *(*fn)(void *)) ;
187 extern void piLock              (int key) ;
188 extern void piUnlock            (int key) ;
189
190 // Schedulling priority
191
192 extern int piHiPri (const int pri) ;
193
194 // Extras from arduino land
195
196 extern void         delay             (unsigned int howLong) ;
197 extern void         delayMicroseconds (unsigned int howLong) ;
198 extern unsigned int millis            (void) ;
199 extern unsigned int micros            (void) ;
200
201 #ifdef __cplusplus
202 }
203 #endif
204
205 #endif