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