-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvm_api.h
272 lines (256 loc) · 13.3 KB
/
vm_api.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/*
* vm_api.h
* Functions exposed by PIGPIO's PIGS VM.
*
* For documentation, see:
* https://abyz.me.uk/rpi/pigpio/cif.html
* https://abyz.me.uk/rpi/pigpio/pigs.html
*/
enum {
/* stdbool.h */
false = 0,
true = 1,
};
enum {
/* Error Codes */
PI_INIT_FAILED = -1, // gpioInitialise failed
PI_BAD_USER_GPIO = -2, // GPIO not 0-31
PI_BAD_GPIO = -3, // GPIO not 0-53
PI_BAD_MODE = -4, // mode not 0-7
PI_BAD_LEVEL = -5, // level not 0-1
PI_BAD_PUD = -6, // pud not 0-2
PI_BAD_PULSEWIDTH = -7, // pulsewidth not 0 or 500-2500
PI_BAD_DUTYCYCLE = -8, // dutycycle outside set range
PI_BAD_TIMER = -9, // timer not 0-9
PI_BAD_MS = -10, // ms not 10-60000
PI_BAD_TIMETYPE = -11, // timetype not 0-1
PI_BAD_SECONDS = -12, // seconds < 0
PI_BAD_MICROS = -13, // micros not 0-999999
PI_TIMER_FAILED = -14, // gpioSetTimerFunc failed
PI_BAD_WDOG_TIMEOUT = -15, // timeout not 0-60000
PI_NO_ALERT_FUNC = -16, // DEPRECATED
PI_BAD_CLK_PERIPH = -17, // clock peripheral not 0-1
PI_BAD_CLK_SOURCE = -18, // DEPRECATED
PI_BAD_CLK_MICROS = -19, // clock micros not 1, 2, 4, 5, 8, or 10
PI_BAD_BUF_MILLIS = -20, // buf millis not 100-10000
PI_BAD_DUTYRANGE = -21, // dutycycle range not 25-40000
PI_BAD_DUTY_RANGE = -21, // DEPRECATED (use PI_BAD_DUTYRANGE)
PI_BAD_SIGNUM = -22, // signum not 0-63
PI_BAD_PATHNAME = -23, // can't open pathname
PI_NO_HANDLE = -24, // no handle available
PI_BAD_HANDLE = -25, // unknown handle
PI_BAD_IF_FLAGS = -26, // ifFlags > 4
PI_BAD_CHANNEL = -27, // DMA channel not 0-15
PI_BAD_PRIM_CHANNEL = -27, // DMA primary channel not 0-15
PI_BAD_SOCKET_PORT = -28, // socket port not 1024-32000
PI_BAD_FIFO_COMMAND = -29, // unrecognized fifo command
PI_BAD_SECO_CHANNEL = -30, // DMA secondary channel not 0-15
PI_NOT_INITIALISED = -31, // function called before gpioInitialise
PI_INITIALISED = -32, // function called after gpioInitialise
PI_BAD_WAVE_MODE = -33, // waveform mode not 0-3
PI_BAD_CFG_INTERNAL = -34, // bad parameter in gpioCfgInternals call
PI_BAD_WAVE_BAUD = -35, // baud rate not 50-250K(RX)/50-1M(TX)
PI_TOO_MANY_PULSES = -36, // waveform has too many pulses
PI_TOO_MANY_CHARS = -37, // waveform has too many chars
PI_NOT_SERIAL_GPIO = -38, // no bit bang serial read on GPIO
PI_BAD_SERIAL_STRUC = -39, // bad (null) serial structure parameter
PI_BAD_SERIAL_BUF = -40, // bad (null) serial buf parameter
PI_NOT_PERMITTED = -41, // GPIO operation not permitted
PI_SOME_PERMITTED = -42, // one or more GPIO not permitted
PI_BAD_WVSC_COMMND = -43, // bad WVSC subcommand
PI_BAD_WVSM_COMMND = -44, // bad WVSM subcommand
PI_BAD_WVSP_COMMND = -45, // bad WVSP subcommand
PI_BAD_PULSELEN = -46, // trigger pulse length not 1-100
PI_BAD_SCRIPT = -47, // invalid script
PI_BAD_SCRIPT_ID = -48, // unknown script id
PI_BAD_SER_OFFSET = -49, // add serial data offset > 30 minutes
PI_GPIO_IN_USE = -50, // GPIO already in use
PI_BAD_SERIAL_COUNT = -51, // must read at least a byte at a time
PI_BAD_PARAM_NUM = -52, // script parameter id not 0-9
PI_DUP_TAG = -53, // script has duplicate tag
PI_TOO_MANY_TAGS = -54, // script has too many tags
PI_BAD_SCRIPT_CMD = -55, // illegal script command
PI_BAD_VAR_NUM = -56, // script variable id not 0-149
PI_NO_SCRIPT_ROOM = -57, // no more room for scripts
PI_NO_MEMORY = -58, // can't allocate temporary memory
PI_SOCK_READ_FAILED = -59, // socket read failed
PI_SOCK_WRIT_FAILED = -60, // socket write failed
PI_TOO_MANY_PARAM = -61, // too many script parameters (> 10)
PI_NOT_HALTED = -62, // DEPRECATED
PI_SCRIPT_NOT_READY = -62, // script initialising
PI_BAD_TAG = -63, // script has unresolved tag
PI_BAD_MICS_DELAY = -64, // bad MICS delay (too large)
PI_BAD_MILS_DELAY = -65, // bad MILS delay (too large)
PI_BAD_WAVE_ID = -66, // non existent wave id
PI_TOO_MANY_CBS = -67, // No more CBs for waveform
PI_TOO_MANY_OOL = -68, // No more OOL for waveform
PI_EMPTY_WAVEFORM = -69, // attempt to create an empty waveform
PI_NO_WAVEFORM_ID = -70, // no more waveforms
PI_I2C_OPEN_FAILED = -71, // can't open I2C device
PI_SER_OPEN_FAILED = -72, // can't open serial device
PI_SPI_OPEN_FAILED = -73, // can't open SPI device
PI_BAD_I2C_BUS = -74, // bad I2C bus
PI_BAD_I2C_ADDR = -75, // bad I2C address
PI_BAD_SPI_CHANNEL = -76, // bad SPI channel
PI_BAD_FLAGS = -77, // bad i2c/spi/ser open flags
PI_BAD_SPI_SPEED = -78, // bad SPI speed
PI_BAD_SER_DEVICE = -79, // bad serial device name
PI_BAD_SER_SPEED = -80, // bad serial baud rate
PI_BAD_PARAM = -81, // bad i2c/spi/ser parameter
PI_I2C_WRITE_FAILED = -82, // i2c write failed
PI_I2C_READ_FAILED = -83, // i2c read failed
PI_BAD_SPI_COUNT = -84, // bad SPI count
PI_SER_WRITE_FAILED = -85, // ser write failed
PI_SER_READ_FAILED = -86, // ser read failed
PI_SER_READ_NO_DATA = -87, // ser read no data available
PI_UNKNOWN_COMMAND = -88, // unknown command
PI_SPI_XFER_FAILED = -89, // spi xfer/read/write failed
PI_BAD_POINTER = -90, // bad (NULL) pointer
PI_NO_AUX_SPI = -91, // no auxiliary SPI on Pi A or B
PI_NOT_PWM_GPIO = -92, // GPIO is not in use for PWM
PI_NOT_SERVO_GPIO = -93, // GPIO is not in use for servo pulses
PI_NOT_HCLK_GPIO = -94, // GPIO has no hardware clock
PI_NOT_HPWM_GPIO = -95, // GPIO has no hardware PWM
PI_BAD_HPWM_FREQ = -96, // invalid hardware PWM frequency
PI_BAD_HPWM_DUTY = -97, // hardware PWM dutycycle not 0-1M
PI_BAD_HCLK_FREQ = -98, // invalid hardware clock frequency
PI_BAD_HCLK_PASS = -99, // need password to use hardware clock 1
PI_HPWM_ILLEGAL = -100, // illegal, PWM in use for main clock
PI_BAD_DATABITS = -101, // serial data bits not 1-32
PI_BAD_STOPBITS = -102, // serial (half) stop bits not 2-8
PI_MSG_TOOBIG = -103, // socket/pipe message too big
PI_BAD_MALLOC_MODE = -104, // bad memory allocation mode
PI_TOO_MANY_SEGS = -105, // too many I2C transaction segments
PI_BAD_I2C_SEG = -106, // an I2C transaction segment failed
PI_BAD_SMBUS_CMD = -107, // SMBus command not supported by driver
PI_NOT_I2C_GPIO = -108, // no bit bang I2C in progress on GPIO
PI_BAD_I2C_WLEN = -109, // bad I2C write length
PI_BAD_I2C_RLEN = -110, // bad I2C read length
PI_BAD_I2C_CMD = -111, // bad I2C command
PI_BAD_I2C_BAUD = -112, // bad I2C baud rate, not 50-500k
PI_CHAIN_LOOP_CNT = -113, // bad chain loop count
PI_BAD_CHAIN_LOOP = -114, // empty chain loop
PI_CHAIN_COUNTER = -115, // too many chain counters
PI_BAD_CHAIN_CMD = -116, // bad chain command
PI_BAD_CHAIN_DELAY = -117, // bad chain delay micros
PI_CHAIN_NESTING = -118, // chain counters nested too deeply
PI_CHAIN_TOO_BIG = -119, // chain is too long
PI_DEPRECATED = -120, // deprecated function removed
PI_BAD_SER_INVERT = -121, // bit bang serial invert not 0 or 1
PI_BAD_EDGE = -122, // bad ISR edge value, not 0-2
PI_BAD_ISR_INIT = -123, // bad ISR initialisation
PI_BAD_FOREVER = -124, // loop forever must be last command
PI_BAD_FILTER = -125, // bad filter parameter
PI_BAD_PAD = -126, // bad pad number
PI_BAD_STRENGTH = -127, // bad pad drive strength
PI_FIL_OPEN_FAILED = -128, // file open failed
PI_BAD_FILE_MODE = -129, // bad file mode
PI_BAD_FILE_FLAG = -130, // bad file flag
PI_BAD_FILE_READ = -131, // bad file read
PI_BAD_FILE_WRITE = -132, // bad file write
PI_FILE_NOT_ROPEN = -133, // file not open for read
PI_FILE_NOT_WOPEN = -134, // file not open for write
PI_BAD_FILE_SEEK = -135, // bad file seek
PI_NO_FILE_MATCH = -136, // no files match pattern
PI_NO_FILE_ACCESS = -137, // no permission to access file
PI_FILE_IS_A_DIR = -138, // file is a directory
PI_BAD_SHELL_STATUS = -139, // bad shell return status
PI_BAD_SCRIPT_NAME = -140, // bad script name
PI_BAD_SPI_BAUD = -141, // bad SPI baud rate, not 50-500k
PI_NOT_SPI_GPIO = -142, // no bit bang SPI in progress on GPIO
PI_BAD_EVENT_ID = -143, // bad event id
PI_CMD_INTERRUPTED = -144, // Used by Python
PI_NOT_ON_BCM2711 = -145, // not available on BCM2711
PI_ONLY_ON_BCM2711 = -146, // only available on BCM2711
};
enum {
/* gpioSetMode(): defined constant values for argument "unsigned mode" */
PI_INPUT = 0, // use GPIO as an input (for reading)
PI_OUTPUT = 1, // use GPIO as an output (for writing)
PI_ALT0 = 4, // use GPIO's alternate function 0
PI_ALT1 = 5, // use GPIO's alternate function 1
PI_ALT2 = 6, // use GPIO's alternate function 2
PI_ALT3 = 7, // use GPIO's alternate function 3
PI_ALT4 = 3, // use GPIO's alternate function 4
PI_ALT5 = 2, // use GPIO's alternate function 5
};
enum {
/* gpioSetPullUpDown(): defined constant values for argument "unsigned pud" */
PI_PUD_OFF = 0, // disable GPIO's pull-up/down (floating)
PI_PUD_DOWN = 1, // enable GPIO's pull-down
PI_PUD_UP = 2, // enable GPIO's pull-up
};
enum {
/* gpioCfgSetInternals(): defined constant values for argument "unsigned cfgVal" */
PI_CFG_DBG_LEVEL = 0x0, // bits 0-3
PI_CFG_ALERT_FREQ = 0x4, // bits 4-7
PI_CFG_RT_PRIORITY = 0x100, // (1<<8)
PI_CFG_STATS = 0x200, // (1<<9)
PI_CFG_NOSIGHANDLER = 0x400, // (1<<10)
};
/* Basic commands */
extern int gpioSetMode(unsigned gpio, unsigned mode);
extern int gpioGetMode(unsigned gpio);
extern int gpioSetPullUpDown(unsigned gpio, unsigned pud);
extern int gpioRead(unsigned gpio);
extern int gpioWrite(unsigned gpio, unsigned level);
/* PWM commands */
extern int gpioPWM(unsigned user_gpio, unsigned dutycycle);
extern int gpioSetPWMfrequency(unsigned user_gpio, unsigned frequency);
extern int gpioSetPWMrange(unsigned user_gpio, unsigned range);
extern int gpioGetPWMdutycycle(unsigned user_gpio);
extern int gpioGetPWMfrequency(unsigned user_gpio);
extern int gpioGetPWMrange(unsigned user_gpio);
extern int gpioGetPWMrealRange(unsigned user_gpio);
/* Servo commands */
extern int gpioServo(unsigned user_gpio, unsigned pulsewidth);
extern int gpioGetServoPulsewidth(unsigned user_gpio);
/* Intermediate commands */
extern int gpioTrigger(unsigned user_gpio, unsigned pulseLen, unsigned level);
extern int gpioSetWatchdog(unsigned user_gpio, unsigned timeout);
extern unsigned gpioRead_Bits_0_31(void);
extern unsigned gpioRead_Bits_32_53(void);
extern int gpioWrite_Bits_0_31_Clear(unsigned bits);
extern int gpioWrite_Bits_32_53_Clear(unsigned bits);
extern int gpioWrite_Bits_0_31_Set(unsigned bits);
extern int gpioWrite_Bits_32_53_Set(unsigned bits);
/* Advanced commands */
extern int gpioNotifyOpen(void);
extern int gpioNotifyClose(unsigned handle);
extern int gpioNotifyBegin(unsigned handle, unsigned bits);
extern int gpioNotifyPause(unsigned handle);
extern int gpioHardwareClock(unsigned gpio, unsigned clkfreq);
extern int gpioHardwarePWM(unsigned gpio, unsigned PWMfreq, unsigned PWMduty);
extern int gpioGlitchFilter(unsigned user_gpio, unsigned steady);
extern int gpioNoiseFilter(unsigned user_gpio, unsigned steady, unsigned active);
extern int gpioSetPad(unsigned pad, unsigned padStrength);
extern int gpioGetPad(unsigned pad);
/* Event commands */
extern int eventMonitor(unsigned handle, unsigned bits);
extern int eventTrigger(unsigned event);
/* I2C commands */
extern int i2cOpen(unsigned i2cBus, unsigned i2cAddr, unsigned i2cFlags);
extern int i2cClose(unsigned handle);
extern int i2cWriteQuick(unsigned handle, unsigned bit);
extern int i2cReadByte(unsigned handle);
extern int i2cWriteByte(unsigned handle, unsigned bVal);
extern int i2cReadByteData(unsigned handle, unsigned i2cReg);
extern int i2cWriteByteData(unsigned handle, unsigned i2cReg, unsigned bVal);
extern int i2cReadWordData(unsigned handle, unsigned i2cReg);
extern int i2cWriteWordData(unsigned handle, unsigned i2cReg, unsigned wVal);
extern int i2cProcessCall(unsigned handle, unsigned i2cReg, unsigned wVal);
/* Utility commands */
extern unsigned gpioHardwareRevision(void);
extern unsigned gpioDelay_us(unsigned micros);
extern unsigned gpioDelay_ms(unsigned millis);
extern unsigned gpioVersion(void);
extern unsigned gpioTick(void);
/* Configuration commands */
extern unsigned gpioCfgGetInternals(void);
extern int gpioCfgSetInternals(unsigned cfgVal);
/* Script exclusive commands */
extern unsigned gpioWait(unsigned gpioBits); // WAIT x
extern unsigned eventWait(unsigned eventBits); // EVTWT x
extern void exit(void); // HALT
/* Script I/O parameter */
extern int p0, p1, p2, p3, p4, p5, p6, p7, p8, p9;