chiark / gitweb /
18c6da51733e89aa12995b21447555147859b8ab
[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_PIFACE          3
33 #define WPI_MODE_UNINITIALISED  -1
34
35 // Pin modes
36
37 #define INPUT                    0
38 #define OUTPUT                   1
39 #define PWM_OUTPUT               2
40 #define GPIO_CLOCK               3
41
42 #define LOW                      0
43 #define HIGH                     1
44
45 // Pull up/down/none
46
47 #define PUD_OFF                  0
48 #define PUD_DOWN                 1
49 #define PUD_UP                   2
50
51 // PWM
52
53 #define PWM_MODE_MS             0
54 #define PWM_MODE_BAL            1
55
56 // Interrupt levels
57
58 #define INT_EDGE_SETUP          0
59 #define INT_EDGE_FALLING        1
60 #define INT_EDGE_RISING         2
61 #define INT_EDGE_BOTH           3
62
63 // Threads
64
65 #define PI_THREAD(X)    void *X (void *dummy)
66
67
68 // Function prototypes
69 //      c++ wrappers thanks to a comment by Nick Lott
70 //      (and others on the Raspberry Pi forums)
71
72 #ifdef __cplusplus
73 extern "C" {
74 #endif
75
76 // Basic wiringPi functions
77
78 extern int  wiringPiSetup       (void) ;
79 extern int  wiringPiSetupSys    (void) ;
80 extern int  wiringPiSetupGpio   (void) ;
81 extern int  wiringPiSetupPiFace (void) ;
82
83 extern int  piBoardRev          (void) ;
84 extern int  wpiPinToGpio        (int wpiPin) ;
85
86 extern int  wiringPiSetupPiFaceForGpioProg (void) ;     // Don't use this - for gpio program only
87
88 extern void (*pinMode)           (int pin, int mode) ;
89 extern int  (*getAlt)            (int pin) ;
90 extern void (*pullUpDnControl)   (int pin, int pud) ;
91 extern void (*digitalWrite)      (int pin, int value) ;
92 extern void (*digitalWriteByte)  (int value) ;
93 extern void (*gpioClockSet)      (int pin, int freq) ;
94 extern void (*pwmWrite)          (int pin, int value) ;
95 extern void (*setPadDrive)       (int group, int value) ;
96 extern int  (*digitalRead)       (int pin) ;
97 extern void (*pwmSetMode)        (int mode) ;
98 extern void (*pwmSetRange)       (unsigned int range) ;
99 extern void (*pwmSetClock)       (int divisor) ;
100
101 // Interrupts
102
103 extern int  (*waitForInterrupt) (int pin, int mS) ;
104 extern int  wiringPiISR         (int pin, int mode, void (*function)(void)) ;
105
106 // Threads
107
108 extern int  piThreadCreate (void *(*fn)(void *)) ;
109 extern void piLock         (int key) ;
110 extern void piUnlock       (int key) ;
111
112 // Schedulling priority
113
114 extern int piHiPri (int pri) ;
115
116
117 // Extras from arduino land
118
119 extern void         delay             (unsigned int howLong) ;
120 extern void         delayMicroseconds (unsigned int howLong) ;
121 extern unsigned int millis            (void) ;
122 extern unsigned int micros            (void) ;
123
124 #ifdef __cplusplus
125 }
126 #endif