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