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