chiark / gitweb /
Updated a technicality in softPwm, and added a suggested memset to zero
[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 and version numbers
71 //      Intended for the GPIO program Use at your own risk.
72
73 #define PI_MODEL_UNKNOWN        0
74 #define PI_MODEL_A              1
75 #define PI_MODEL_B              2
76 #define PI_MODEL_BP             3
77 #define PI_MODEL_CM             4
78 #define PI_MODEL_AP             5
79
80 #define PI_VERSION_UNKNOWN      0
81 #define PI_VERSION_1            1
82 #define PI_VERSION_1_1          2
83 #define PI_VERSION_1_2          3
84 #define PI_VERSION_2            4
85
86 #define PI_MAKER_UNKNOWN        0
87 #define PI_MAKER_EGOMAN         1
88 #define PI_MAKER_SONY           2
89 #define PI_MAKER_QISDA          3
90 #define PI_MAKER_MBEST          4
91
92 extern const char *piModelNames    [6] ;
93 extern const char *piRevisionNames [5] ;
94 extern const char *piMakerNames    [5] ;
95
96
97 //      Intended for the GPIO program Use at your own risk.
98
99 // Threads
100
101 #define PI_THREAD(X)    void *X (void *dummy)
102
103 // Failure modes
104
105 #define WPI_FATAL       (1==1)
106 #define WPI_ALMOST      (1==2)
107
108
109 // wiringPiNodeStruct:
110 //      This describes additional device nodes in the extended wiringPi
111 //      2.0 scheme of things.
112 //      It's a simple linked list for now, but will hopefully migrate to 
113 //      a binary tree for efficiency reasons - but then again, the chances
114 //      of more than 1 or 2 devices being added are fairly slim, so who
115 //      knows....
116
117 struct wiringPiNodeStruct
118 {
119   int     pinBase ;
120   int     pinMax ;
121
122   int          fd ;     // Node specific
123   unsigned int data0 ;  //  ditto
124   unsigned int data1 ;  //  ditto
125   unsigned int data2 ;  //  ditto
126   unsigned int data3 ;  //  ditto
127
128   void   (*pinMode)         (struct wiringPiNodeStruct *node, int pin, int mode) ;
129   void   (*pullUpDnControl) (struct wiringPiNodeStruct *node, int pin, int mode) ;
130   int    (*digitalRead)     (struct wiringPiNodeStruct *node, int pin) ;
131   void   (*digitalWrite)    (struct wiringPiNodeStruct *node, int pin, int value) ;
132   void   (*pwmWrite)        (struct wiringPiNodeStruct *node, int pin, int value) ;
133   int    (*analogRead)      (struct wiringPiNodeStruct *node, int pin) ;
134   void   (*analogWrite)     (struct wiringPiNodeStruct *node, int pin, int value) ;
135
136   struct wiringPiNodeStruct *next ;
137 } ;
138
139 extern struct wiringPiNodeStruct *wiringPiNodes ;
140
141
142 // Function prototypes
143 //      c++ wrappers thanks to a comment by Nick Lott
144 //      (and others on the Raspberry Pi forums)
145
146 #ifdef __cplusplus
147 extern "C" {
148 #endif
149
150 // Data
151
152 //extern const char *piModelNames [] ;
153 //extern const char *piRevisionNames[] ;
154
155 // Internal
156
157 extern int wiringPiFailure (int fatal, const char *message, ...) ;
158
159 // Core wiringPi functions
160
161 extern struct wiringPiNodeStruct *wiringPiFindNode (int pin) ;
162 extern struct wiringPiNodeStruct *wiringPiNewNode  (int pinBase, int numPins) ;
163
164 extern int  wiringPiSetup       (void) ;
165 extern int  wiringPiSetupSys    (void) ;
166 extern int  wiringPiSetupGpio   (void) ;
167 extern int  wiringPiSetupPhys   (void) ;
168
169 extern void pinModeAlt          (int pin, int mode) ;
170 extern void pinMode             (int pin, int mode) ;
171 extern void pullUpDnControl     (int pin, int pud) ;
172 extern int  digitalRead         (int pin) ;
173 extern void digitalWrite        (int pin, int value) ;
174 extern void pwmWrite            (int pin, int value) ;
175 extern int  analogRead          (int pin) ;
176 extern void analogWrite         (int pin, int value) ;
177
178 // PiFace specifics 
179 //      (Deprecated)
180
181 extern int  wiringPiSetupPiFace (void) ;
182 extern int  wiringPiSetupPiFaceForGpioProg (void) ;     // Don't use this - for gpio program only
183
184 // On-Board Raspberry Pi hardware specific stuff
185
186 extern int  piBoardRev          (void) ;
187 extern void piBoardId           (int *model, int *rev, int *mem, int *maker, int *overVolted) ;
188 extern int  wpiPinToGpio        (int wpiPin) ;
189 extern int  physPinToGpio       (int physPin) ;
190 extern void setPadDrive         (int group, int value) ;
191 extern int  getAlt              (int pin) ;
192 extern void pwmToneWrite        (int pin, int freq) ;
193 extern void digitalWriteByte    (int value) ;
194 extern void pwmSetMode          (int mode) ;
195 extern void pwmSetRange         (unsigned int range) ;
196 extern void pwmSetClock         (int divisor) ;
197 extern void gpioClockSet        (int pin, int freq) ;
198
199 // Interrupts
200 //      (Also Pi hardware specific)
201
202 extern int  waitForInterrupt    (int pin, int mS) ;
203 extern int  wiringPiISR         (int pin, int mode, void (*function)(void)) ;
204
205 // Threads
206
207 extern int  piThreadCreate      (void *(*fn)(void *)) ;
208 extern void piLock              (int key) ;
209 extern void piUnlock            (int key) ;
210
211 // Schedulling priority
212
213 extern int piHiPri (const int pri) ;
214
215 // Extras from arduino land
216
217 extern void         delay             (unsigned int howLong) ;
218 extern void         delayMicroseconds (unsigned int howLong) ;
219 extern unsigned int millis            (void) ;
220 extern unsigned int micros            (void) ;
221
222 #ifdef __cplusplus
223 }
224 #endif
225
226 #endif