Statistics
| Branch: | Revision:

ddr4s / fw / wiringPi / wiringPi / wiringPi.h @ 32:cadb9025f1e0

History | View | Annotate | Download (8 KB)

1
/*
2
 * wiringPi.h:
3
 *        Arduino like Wiring library for the Raspberry Pi.
4
 *        Copyright (c) 2012-2017 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
// C doesn't have true/false by default and I can never remember which
28
//        way round they are, so ...
29
//        (and yes, I know about stdbool.h but I like capitals for these and I'm old)
30

    
31
#ifndef        TRUE
32
#  define        TRUE        (1==1)
33
#  define        FALSE        (!TRUE)
34
#endif
35

    
36
// GCC warning suppressor
37

    
38
#define        UNU        __attribute__((unused))
39

    
40
// Mask for the bottom 64 pins which belong to the Raspberry Pi
41
//        The others are available for the other devices
42

    
43
#define        PI_GPIO_MASK        (0xFFFFFFC0)
44

    
45
// Handy defines
46

    
47
// wiringPi modes
48

    
49
#define        WPI_MODE_PINS                 0
50
#define        WPI_MODE_GPIO                 1
51
#define        WPI_MODE_GPIO_SYS         2
52
#define        WPI_MODE_PHYS                 3
53
#define        WPI_MODE_PIFACE                 4
54
#define        WPI_MODE_UNINITIALISED        -1
55

    
56
// Pin modes
57

    
58
#define        INPUT                         0
59
#define        OUTPUT                         1
60
#define        PWM_OUTPUT                 2
61
#define        GPIO_CLOCK                 3
62
#define        SOFT_PWM_OUTPUT                 4
63
#define        SOFT_TONE_OUTPUT         5
64
#define        PWM_TONE_OUTPUT                 6
65

    
66
#define        LOW                         0
67
#define        HIGH                         1
68

    
69
// Pull up/down/none
70

    
71
#define        PUD_OFF                         0
72
#define        PUD_DOWN                 1
73
#define        PUD_UP                         2
74

    
75
// PWM
76

    
77
#define        PWM_MODE_MS                0
78
#define        PWM_MODE_BAL                1
79

    
80
// Interrupt levels
81

    
82
#define        INT_EDGE_SETUP                0
83
#define        INT_EDGE_FALLING        1
84
#define        INT_EDGE_RISING                2
85
#define        INT_EDGE_BOTH                3
86

    
87
// Pi model types and version numbers
88
//        Intended for the GPIO program Use at your own risk.
89

    
90
#define        PI_MODEL_A                 0
91
#define        PI_MODEL_B                 1
92
#define        PI_MODEL_AP                 2
93
#define        PI_MODEL_BP                 3
94
#define        PI_MODEL_2                 4
95
#define        PI_ALPHA                 5
96
#define        PI_MODEL_CM                 6
97
#define        PI_MODEL_07                 7
98
#define        PI_MODEL_3B                 8
99
#define        PI_MODEL_ZERO                 9
100
#define        PI_MODEL_CM3                10
101
#define        PI_MODEL_ZERO_W                12
102
#define        PI_MODEL_3BP                 13
103
#define        PI_MODEL_3AP                 14
104
#define        PI_MODEL_CM3P                 16
105

    
106
#define        PI_VERSION_1                0
107
#define        PI_VERSION_1_1                1
108
#define        PI_VERSION_1_2                2
109
#define        PI_VERSION_2                3
110

    
111
#define        PI_MAKER_SONY                0
112
#define        PI_MAKER_EGOMAN                1
113
#define        PI_MAKER_EMBEST                2
114
#define        PI_MAKER_UNKNOWN        3
115

    
116
extern const char *piModelNames    [20] ;
117
extern const char *piRevisionNames [16] ;
118
extern const char *piMakerNames    [16] ;
119
extern const int   piMemorySize    [ 8] ;
120

    
121

    
122
//        Intended for the GPIO program Use at your own risk.
123

    
124
// Threads
125

    
126
#define        PI_THREAD(X)        void *X (UNU void *dummy)
127

    
128
// Failure modes
129

    
130
#define        WPI_FATAL        (1==1)
131
#define        WPI_ALMOST        (1==2)
132

    
133

    
134
// wiringPiNodeStruct:
135
//        This describes additional device nodes in the extended wiringPi
136
//        2.0 scheme of things.
137
//        It's a simple linked list for now, but will hopefully migrate to 
138
//        a binary tree for efficiency reasons - but then again, the chances
139
//        of more than 1 or 2 devices being added are fairly slim, so who
140
//        knows....
141

    
142
struct wiringPiNodeStruct
143
{
144
  int     pinBase ;
145
  int     pinMax ;
146

    
147
  int          fd ;        // Node specific
148
  unsigned int data0 ;        //  ditto
149
  unsigned int data1 ;        //  ditto
150
  unsigned int data2 ;        //  ditto
151
  unsigned int data3 ;        //  ditto
152

    
153
           void   (*pinMode)          (struct wiringPiNodeStruct *node, int pin, int mode) ;
154
           void   (*pullUpDnControl)  (struct wiringPiNodeStruct *node, int pin, int mode) ;
155
           int    (*digitalRead)      (struct wiringPiNodeStruct *node, int pin) ;
156
//unsigned int    (*digitalRead8)     (struct wiringPiNodeStruct *node, int pin) ;
157
           void   (*digitalWrite)     (struct wiringPiNodeStruct *node, int pin, int value) ;
158
//         void   (*digitalWrite8)    (struct wiringPiNodeStruct *node, int pin, int value) ;
159
           void   (*pwmWrite)         (struct wiringPiNodeStruct *node, int pin, int value) ;
160
           int    (*analogRead)       (struct wiringPiNodeStruct *node, int pin) ;
161
           void   (*analogWrite)      (struct wiringPiNodeStruct *node, int pin, int value) ;
162

    
163
  struct wiringPiNodeStruct *next ;
164
} ;
165

    
166
extern struct wiringPiNodeStruct *wiringPiNodes ;
167

    
168
// Export variables for the hardware pointers
169

    
170
extern volatile unsigned int *_wiringPiGpio ;
171
extern volatile unsigned int *_wiringPiPwm ;
172
extern volatile unsigned int *_wiringPiClk ;
173
extern volatile unsigned int *_wiringPiPads ;
174
extern volatile unsigned int *_wiringPiTimer ;
175
extern volatile unsigned int *_wiringPiTimerIrqRaw ;
176

    
177

    
178
// Function prototypes
179
//        c++ wrappers thanks to a comment by Nick Lott
180
//        (and others on the Raspberry Pi forums)
181

    
182
#ifdef __cplusplus
183
extern "C" {
184
#endif
185

    
186
// Data
187

    
188
// Internal
189

    
190
extern int wiringPiFailure (int fatal, const char *message, ...) ;
191

    
192
// Core wiringPi functions
193

    
194
extern struct wiringPiNodeStruct *wiringPiFindNode (int pin) ;
195
extern struct wiringPiNodeStruct *wiringPiNewNode  (int pinBase, int numPins) ;
196

    
197
extern void wiringPiVersion        (int *major, int *minor) ;
198
extern int  wiringPiSetup       (void) ;
199
extern int  wiringPiSetupSys    (void) ;
200
extern int  wiringPiSetupGpio   (void) ;
201
extern int  wiringPiSetupPhys   (void) ;
202

    
203
extern          void pinModeAlt          (int pin, int mode) ;
204
extern          void pinMode             (int pin, int mode) ;
205
extern          void pullUpDnControl     (int pin, int pud) ;
206
extern          int  digitalRead         (int pin) ;
207
extern          void digitalWrite        (int pin, int value) ;
208
extern unsigned int  digitalRead8        (int pin) ;
209
extern          void digitalWrite8       (int pin, int value) ;
210
extern          void pwmWrite            (int pin, int value) ;
211
extern          int  analogRead          (int pin) ;
212
extern          void analogWrite         (int pin, int value) ;
213

    
214
// PiFace specifics 
215
//        (Deprecated)
216

    
217
extern int  wiringPiSetupPiFace (void) ;
218
extern int  wiringPiSetupPiFaceForGpioProg (void) ;        // Don't use this - for gpio program only
219

    
220
// On-Board Raspberry Pi hardware specific stuff
221

    
222
extern          int  piGpioLayout        (void) ;
223
extern          int  piBoardRev          (void) ;        // Deprecated
224
extern          void piBoardId           (int *model, int *rev, int *mem, int *maker, int *overVolted) ;
225
extern          int  wpiPinToGpio        (int wpiPin) ;
226
extern          int  physPinToGpio       (int physPin) ;
227
extern          void setPadDrive         (int group, int value) ;
228
extern          int  getAlt              (int pin) ;
229
extern          void pwmToneWrite        (int pin, int freq) ;
230
extern          void pwmSetMode          (int mode) ;
231
extern          void pwmSetRange         (unsigned int range) ;
232
extern          void pwmSetClock         (int divisor) ;
233
extern          void gpioClockSet        (int pin, int freq) ;
234
extern unsigned int  digitalReadByte     (void) ;
235
extern unsigned int  digitalReadByte2    (void) ;
236
extern          void digitalWriteByte    (int value) ;
237
extern          void digitalWriteByte2   (int value) ;
238

    
239
// Interrupts
240
//        (Also Pi hardware specific)
241

    
242
extern int  waitForInterrupt    (int pin, int mS) ;
243
extern int  wiringPiISR         (int pin, int mode, void (*function)(void)) ;
244

    
245
// Threads
246

    
247
extern int  piThreadCreate      (void *(*fn)(void *)) ;
248
extern void piLock              (int key) ;
249
extern void piUnlock            (int key) ;
250

    
251
// Schedulling priority
252

    
253
extern int piHiPri (const int pri) ;
254

    
255
// Extras from arduino land
256

    
257
extern void         delay             (unsigned int howLong) ;
258
extern void         delayMicroseconds (unsigned int howLong) ;
259
extern unsigned int millis            (void) ;
260
extern unsigned int micros            (void) ;
261

    
262
#ifdef __cplusplus
263
}
264
#endif
265

    
266
#endif