forked from joan2937/pigpio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pigpiod_if.h
2996 lines (2238 loc) · 72.8 KB
/
pigpiod_if.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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
For more information, please refer to <http://unlicense.org/>
*/
#ifndef PIGPIOD_IF_H
#define PIGPIOD_IF_H
#include "pigpio.h"
#define PIGPIOD_IF_VERSION 28
/*TEXT
THIS LIBRARY IS DEPRECATED. NEW CODE SHOULD BE WRITTEN TO
USE THE MORE VERSATILE pigpiod_if2 LIBRARY.
pigpiod_if is a C library for the Raspberry which allows control
of the GPIO via the socket interface to the pigpio daemon.
*Features*
o hardware timed PWM on any of GPIO 0-31
o hardware timed servo pulses on any of GPIO 0-31
o callbacks when any of GPIO 0-31 change state
o callbacks at timed intervals
o reading/writing all of the GPIO in a bank as one operation
o individually setting GPIO modes, reading and writing
o notifications when any of GPIO 0-31 change state
o the construction of output waveforms with microsecond timing
o rudimentary permission control over GPIO
o a simple interface to start and stop new threads
o I2C, SPI, and serial link wrappers
o creating and running scripts on the pigpio daemon
*GPIO*
ALL GPIO are identified by their Broadcom number.
*Notes*
The PWM and servo pulses are timed using the DMA and PWM/PCM peripherals.
*Usage*
Include <pigpiod_if.h> in your source files.
Assuming your source is in prog.c use the following command to build
. .
gcc -Wall -pthread -o prog prog.c -lpigpiod_if -lrt
. .
to run make sure the pigpio daemon is running
. .
sudo pigpiod
./prog # sudo is not required to run programs linked to pigpiod_if
. .
For examples see x_pigpiod_if.c within the pigpio archive file.
*Notes*
All the functions which return an int return < 0 on error
TEXT*/
/*OVERVIEW
ESSENTIAL
pigpio_start Connects to the pigpio daemon
pigpio_stop Disconnects from the pigpio daemon
BEGINNER
set_mode Set a GPIO mode
get_mode Get a GPIO mode
set_pull_up_down Set/clear GPIO pull up/down resistor
gpio_read Read a GPIO
gpio_write Write a GPIO
set_PWM_dutycycle Start/stop PWM pulses on a GPIO
get_PWM_dutycycle Get the PWM dutycycle in use on a GPIO
set_servo_pulsewidth Start/stop servo pulses on a GPIO
get_servo_pulsewidth Get the servo pulsewidth in use on a GPIO
callback Create GPIO level change callback
callback_ex Create GPIO level change callback
callback_cancel Cancel a callback
wait_for_edge Wait for GPIO level change
INTERMEDIATE
gpio_trigger Send a trigger pulse to a GPIO.
set_watchdog Set a watchdog on a GPIO.
set_PWM_range Configure PWM range for a GPIO
get_PWM_range Get configured PWM range for a GPIO
set_PWM_frequency Configure PWM frequency for a GPIO
get_PWM_frequency Get configured PWM frequency for a GPIO
read_bank_1 Read all GPIO in bank 1
read_bank_2 Read all GPIO in bank 2
clear_bank_1 Clear selected GPIO in bank 1
clear_bank_2 Clear selected GPIO in bank 2
set_bank_1 Set selected GPIO in bank 1
set_bank_2 Set selected GPIO in bank 2
start_thread Start a new thread
stop_thread Stop a previously started thread
ADVANCED
get_PWM_real_range Get underlying PWM range for a GPIO
notify_open Request a notification handle
notify_begin Start notifications for selected GPIO
notify_pause Pause notifications
notify_close Close a notification
bb_serial_read_open Opens a GPIO for bit bang serial reads
bb_serial_read Reads bit bang serial data from a GPIO
bb_serial_read_close Closes a GPIO for bit bang serial reads
bb_serial_invert Invert serial logic (1 invert, 0 normal)
hardware_clock Start hardware clock on supported GPIO
hardware_PWM Start hardware PWM on supported GPIO
set_glitch_filter Set a glitch filter on a GPIO
set_noise_filter Set a noise filter on a GPIO
SCRIPTS
store_script Store a script
run_script Run a stored script
script_status Get script status and parameters
stop_script Stop a running script
delete_script Delete a stored script
WAVES
wave_clear Deletes all waveforms
wave_add_new Starts a new waveform
wave_add_generic Adds a series of pulses to the waveform
wave_add_serial Adds serial data to the waveform
wave_create Creates a waveform from added data
wave_delete Deletes one or more waveforms
wave_send_once Transmits a waveform once
wave_send_repeat Transmits a waveform repeatedly
wave_chain Transmits a chain of waveforms
wave_tx_busy Checks to see if the waveform has ended
wave_tx_stop Aborts the current waveform
wave_get_micros Length in microseconds of the current waveform
wave_get_high_micros Length of longest waveform so far
wave_get_max_micros Absolute maximum allowed micros
wave_get_pulses Length in pulses of the current waveform
wave_get_high_pulses Length of longest waveform so far
wave_get_max_pulses Absolute maximum allowed pulses
wave_get_cbs Length in cbs of the current waveform
wave_get_high_cbs Length of longest waveform so far
wave_get_max_cbs Absolute maximum allowed cbs
I2C
i2c_open Opens an I2C device
i2c_close Closes an I2C device
i2c_write_quick smbus write quick
i2c_write_byte smbus write byte
i2c_read_byte smbus read byte
i2c_write_byte_data smbus write byte data
i2c_write_word_data smbus write word data
i2c_read_byte_data smbus read byte data
i2c_read_word_data smbus read word data
i2c_process_call smbus process call
i2c_write_block_data smbus write block data
i2c_read_block_data smbus read block data
i2c_block_process_call smbus block process call
i2c_write_i2c_block_data smbus write I2C block data
i2c_read_i2c_block_data smbus read I2C block data
i2c_read_device Reads the raw I2C device
i2c_write_device Writes the raw I2C device
i2c_zip Performs multiple I2C transactions
bb_i2c_open Opens GPIO for bit banging I2C
bb_i2c_close Closes GPIO for bit banging I2C
bb_i2c_zip Performs multiple bit banged I2C transactions
SPI
spi_open Opens a SPI device
spi_close Closes a SPI device
spi_read Reads bytes from a SPI device
spi_write Writes bytes to a SPI device
spi_xfer Transfers bytes with a SPI device
SERIAL
serial_open Opens a serial device
serial_close Closes a serial device
serial_write_byte Writes a byte to a serial device
serial_read_byte Reads a byte from a serial device
serial_write Writes bytes to a serial device
serial_read Reads bytes from a serial device
serial_data_available Returns number of bytes ready to be read
CUSTOM
custom_1 User custom function 1
custom_2 User custom function 2
UTILITIES
get_current_tick Get current tick (microseconds)
get_hardware_revision Get hardware revision
get_pigpio_version Get the pigpio version
pigpiod_if_version Get the pigpiod_if version
pigpio_error Get a text description of an error code.
time_sleep Sleeps for a float number of seconds
time_time Float number of seconds since the epoch
OVERVIEW*/
#ifdef __cplusplus
extern "C" {
#endif
typedef void (*CBFunc_t) (unsigned user_gpio, unsigned level, uint32_t tick);
typedef void (*CBFuncEx_t)
(unsigned user_gpio, unsigned level, uint32_t tick, void * user);
typedef struct callback_s callback_t;
/*F*/
double time_time(void);
/*D
Return the current time in seconds since the Epoch.
D*/
/*F*/
void time_sleep(double seconds);
/*D
Delay execution for a given number of seconds.
. .
seconds: the number of seconds to delay.
. .
D*/
/*F*/
char *pigpio_error(int errnum);
/*D
Return a text description for an error code.
. .
errnum: the error code.
. .
D*/
/*F*/
unsigned pigpiod_if_version(void);
/*D
Return the pigpiod_if version.
D*/
/*F*/
pthread_t *start_thread(gpioThreadFunc_t thread_func, void *userdata);
/*D
Starts a new thread of execution with thread_func as the main routine.
. .
thread_func: the main function for the new thread.
userdata: a pointer to an arbitrary argument.
. .
Returns a pointer to pthread_t if OK, otherwise NULL.
The function is passed the single argument userdata.
The thread can be cancelled by passing the pointer to pthread_t to
[*stop_thread*].
D*/
/*F*/
void stop_thread(pthread_t *pth);
/*D
Cancels the thread pointed at by pth.
. .
pth: the thread to be stopped.
. .
No value is returned.
The thread to be stopped should have been started with [*start_thread*].
D*/
/*F*/
int pigpio_start(char *addrStr, char *portStr);
/*D
Connect to the pigpio daemon. Reserving command and
notification streams.
. .
addrStr: specifies the host or IP address of the Pi running the
pigpio daemon. It may be NULL in which case localhost
is used unless overridden by the PIGPIO_ADDR environment
variable.
portStr: specifies the port address used by the Pi running the
pigpio daemon. It may be NULL in which case "8888"
is used unless overridden by the PIGPIO_PORT environment
variable.
. .
D*/
/*F*/
void pigpio_stop(void);
/*D
Terminates the connection to the pigpio daemon and releases
resources used by the library.
D*/
/*F*/
int set_mode(unsigned gpio, unsigned mode);
/*D
Set the GPIO mode.
. .
gpio: 0-53.
mode: PI_INPUT, PI_OUTPUT, PI_ALT0, PI_ALT1,
PI_ALT2, PI_ALT3, PI_ALT4, PI_ALT5.
. .
Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_MODE,
or PI_NOT_PERMITTED.
D*/
/*F*/
int get_mode(unsigned gpio);
/*D
Get the GPIO mode.
. .
gpio: 0-53.
. .
Returns the GPIO mode if OK, otherwise PI_BAD_GPIO.
D*/
/*F*/
int set_pull_up_down(unsigned gpio, unsigned pud);
/*D
Set or clear the GPIO pull-up/down resistor.
. .
gpio: 0-53.
pud: PI_PUD_UP, PI_PUD_DOWN, PI_PUD_OFF.
. .
Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_PUD,
or PI_NOT_PERMITTED.
D*/
/*F*/
int gpio_read(unsigned gpio);
/*D
Read the GPIO level.
. .
gpio:0-53.
. .
Returns the GPIO level if OK, otherwise PI_BAD_GPIO.
D*/
/*F*/
int gpio_write(unsigned gpio, unsigned level);
/*D
Write the GPIO level.
. .
gpio: 0-53.
level: 0, 1.
. .
Returns 0 if OK, otherwise PI_BAD_GPIO, PI_BAD_LEVEL,
or PI_NOT_PERMITTED.
Notes
If PWM or servo pulses are active on the GPIO they are switched off.
D*/
/*F*/
int set_PWM_dutycycle(unsigned user_gpio, unsigned dutycycle);
/*D
Start (non-zero dutycycle) or stop (0) PWM pulses on the GPIO.
. .
user_gpio: 0-31.
dutycycle: 0-range (range defaults to 255).
. .
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYCYCLE,
or PI_NOT_PERMITTED.
Notes
The [*set_PWM_range*] function may be used to change the
default range of 255.
D*/
/*F*/
int get_PWM_dutycycle(unsigned user_gpio);
/*D
Return the PWM dutycycle in use on a GPIO.
. .
user_gpio: 0-31.
. .
Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_PWM_GPIO.
For normal PWM the dutycycle will be out of the defined range
for the GPIO (see [*get_PWM_range*]).
If a hardware clock is active on the GPIO the reported dutycycle
will be 500000 (500k) out of 1000000 (1M).
If hardware PWM is active on the GPIO the reported dutycycle
will be out of a 1000000 (1M).
D*/
/*F*/
int set_PWM_range(unsigned user_gpio, unsigned range);
/*D
Set the range of PWM values to be used on the GPIO.
. .
user_gpio: 0-31.
range: 25-40000.
. .
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_DUTYRANGE,
or PI_NOT_PERMITTED.
Notes
If PWM is currently active on the GPIO its dutycycle will be
scaled to reflect the new range.
The real range, the number of steps between fully off and fully on
for each of the 18 available GPIO frequencies is
. .
25(#1), 50(#2), 100(#3), 125(#4), 200(#5), 250(#6),
400(#7), 500(#8), 625(#9), 800(#10), 1000(#11), 1250(#12),
2000(#13), 2500(#14), 4000(#15), 5000(#16), 10000(#17), 20000(#18)
. .
The real value set by set_PWM_range is (dutycycle * real range) / range.
D*/
/*F*/
int get_PWM_range(unsigned user_gpio);
/*D
Get the range of PWM values being used on the GPIO.
. .
user_gpio: 0-31.
. .
Returns the dutycycle range used for the GPIO if OK,
otherwise PI_BAD_USER_GPIO.
If a hardware clock or hardware PWM is active on the GPIO the
reported range will be 1000000 (1M).
D*/
/*F*/
int get_PWM_real_range(unsigned user_gpio);
/*D
Get the real underlying range of PWM values being used on the GPIO.
. .
user_gpio: 0-31.
. .
Returns the real range used for the GPIO if OK,
otherwise PI_BAD_USER_GPIO.
If a hardware clock is active on the GPIO the reported
real range will be 1000000 (1M).
If hardware PWM is active on the GPIO the reported real range
will be approximately 250M divided by the set PWM frequency.
D*/
/*F*/
int set_PWM_frequency(unsigned user_gpio, unsigned frequency);
/*D
Set the frequency (in Hz) of the PWM to be used on the GPIO.
. .
user_gpio: 0-31.
frequency: >=0 (Hz).
. .
Returns the numerically closest frequency if OK, otherwise
PI_BAD_USER_GPIO or PI_NOT_PERMITTED.
If PWM is currently active on the GPIO it will be switched
off and then back on at the new frequency.
Each GPIO can be independently set to one of 18 different
PWM frequencies.
The selectable frequencies depend upon the sample rate which
may be 1, 2, 4, 5, 8, or 10 microseconds (default 5). The
sample rate is set when the pigpio daemon is started.
The frequencies for each sample rate are:
. .
Hertz
1: 40000 20000 10000 8000 5000 4000 2500 2000 1600
1250 1000 800 500 400 250 200 100 50
2: 20000 10000 5000 4000 2500 2000 1250 1000 800
625 500 400 250 200 125 100 50 25
4: 10000 5000 2500 2000 1250 1000 625 500 400
313 250 200 125 100 63 50 25 13
sample
rate
(us) 5: 8000 4000 2000 1600 1000 800 500 400 320
250 200 160 100 80 50 40 20 10
8: 5000 2500 1250 1000 625 500 313 250 200
156 125 100 63 50 31 25 13 6
10: 4000 2000 1000 800 500 400 250 200 160
125 100 80 50 40 25 20 10 5
. .
D*/
/*F*/
int get_PWM_frequency(unsigned user_gpio);
/*D
Get the frequency of PWM being used on the GPIO.
. .
user_gpio: 0-31.
. .
For normal PWM the frequency will be that defined for the GPIO by
[*set_PWM_frequency*].
If a hardware clock is active on the GPIO the reported frequency
will be that set by [*hardware_clock*].
If hardware PWM is active on the GPIO the reported frequency
will be that set by [*hardware_PWM*].
Returns the frequency (in hertz) used for the GPIO if OK,
otherwise PI_BAD_USER_GPIO.
D*/
/*F*/
int set_servo_pulsewidth(unsigned user_gpio, unsigned pulsewidth);
/*D
Start (500-2500) or stop (0) servo pulses on the GPIO.
. .
user_gpio: 0-31.
pulsewidth: 0 (off), 500 (anti-clockwise) - 2500 (clockwise).
. .
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, PI_BAD_PULSEWIDTH or
PI_NOT_PERMITTED.
The selected pulsewidth will continue to be transmitted until
changed by a subsequent call to set_servo_pulsewidth.
The pulsewidths supported by servos varies and should probably be
determined by experiment. A value of 1500 should always be safe and
represents the mid-point of rotation.
You can DAMAGE a servo if you command it to move beyond its limits.
OTHER UPDATE RATES:
This function updates servos at 50Hz. If you wish to use a different
update frequency you will have to use the PWM functions.
. .
Update Rate (Hz) 50 100 200 400 500
1E6/Hz 20000 10000 5000 2500 2000
. .
Firstly set the desired PWM frequency using [*set_PWM_frequency*].
Then set the PWM range using [*set_PWM_range*] to 1E6/Hz.
Doing this allows you to use units of microseconds when setting
the servo pulsewidth.
E.g. If you want to update a servo connected to GPIO 25 at 400Hz
. .
set_PWM_frequency(25, 400);
set_PWM_range(25, 2500);
. .
Thereafter use the [*set_PWM_dutycycle*] function to move the servo,
e.g. set_PWM_dutycycle(25, 1500) will set a 1500 us pulse.
D*/
/*F*/
int get_servo_pulsewidth(unsigned user_gpio);
/*D
Return the servo pulsewidth in use on a GPIO.
. .
user_gpio: 0-31.
. .
Returns 0 if OK, otherwise PI_BAD_USER_GPIO or PI_NOT_SERVO_GPIO.
D*/
/*F*/
int notify_open(void);
/*D
Get a free notification handle.
Returns a handle greater than or equal to zero if OK,
otherwise PI_NO_HANDLE.
A notification is a method for being notified of GPIO state
changes via a pipe.
Pipes are only accessible from the local machine so this function
serves no purpose if you are using the library from a remote machine.
The in-built (socket) notifications provided by [*callback*]
should be used instead.
Notifications for handle x will be available at the pipe
named /dev/pigpiox (where x is the handle number).
E.g. if the function returns 15 then the notifications must be
read from /dev/pigpio15.
D*/
/*F*/
int notify_begin(unsigned handle, uint32_t bits);
/*D
Start notifications on a previously opened handle.
. .
handle: 0-31 (as returned by [*notify_open*])
bits: a mask indicating the GPIO to be notified.
. .
Returns 0 if OK, otherwise PI_BAD_HANDLE.
The notification sends state changes for each GPIO whose
corresponding bit in bits is set.
Each notification occupies 12 bytes in the fifo as follows:
. .
typedef struct
{
uint16_t seqno;
uint16_t flags;
uint32_t tick;
uint32_t level;
} gpioReport_t;
. .
seqno: starts at 0 each time the handle is opened and then increments
by one for each report.
flags: two flags are defined, PI_NTFY_FLAGS_WDOG and PI_NTFY_FLAGS_ALIVE.
PI_NTFY_FLAGS_WDOG, if bit 5 is set then bits 0-4 of the flags
indicate a GPIO which has had a watchdog timeout.
PI_NTFY_FLAGS_ALIVE, if bit 6 is set this indicates a keep alive
signal on the pipe/socket and is sent once a minute in the absence
of other notification activity.
tick: the number of microseconds since system boot. It wraps around
after 1h12m.
level: indicates the level of each GPIO. If bit 1<<x is set then
GPIO x is high.
D*/
/*F*/
int notify_pause(unsigned handle);
/*D
Pause notifications on a previously opened handle.
. .
handle: 0-31 (as returned by [*notify_open*])
. .
Returns 0 if OK, otherwise PI_BAD_HANDLE.
Notifications for the handle are suspended until
[*notify_begin*] is called again.
D*/
/*F*/
int notify_close(unsigned handle);
/*D
Stop notifications on a previously opened handle and
release the handle for reuse.
. .
handle: 0-31 (as returned by [*notify_open*])
. .
Returns 0 if OK, otherwise PI_BAD_HANDLE.
D*/
/*F*/
int set_watchdog(unsigned user_gpio, unsigned timeout);
/*D
Sets a watchdog for a GPIO.
. .
user_gpio: 0-31.
timeout: 0-60000.
. .
Returns 0 if OK, otherwise PI_BAD_USER_GPIO
or PI_BAD_WDOG_TIMEOUT.
The watchdog is nominally in milliseconds.
Only one watchdog may be registered per GPIO.
The watchdog may be cancelled by setting timeout to 0.
Once a watchdog has been started callbacks for the GPIO will be
triggered every timeout interval after the last GPIO activity.
The callback will receive the special level PI_TIMEOUT.
D*/
/*F*/
int set_glitch_filter(unsigned user_gpio, unsigned steady);
/*D
Sets a glitch filter on a GPIO.
Level changes on the GPIO are not reported unless the level
has been stable for at least [*steady*] microseconds. The
level is then reported. Level changes of less than [*steady*]
microseconds are ignored.
. .
user_gpio: 0-31
steady: 0-300000
. .
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
This filter affects the GPIO samples returned to callbacks set up
with [*callback*], [*callback_ex*] and [*wait_for_edge*].
It does not affect levels read by [*gpio_read*],
[*read_bank_1*], or [*read_bank_2*].
Each (stable) edge will be timestamped [*steady*] microseconds
after it was first detected.
D*/
/*F*/
int set_noise_filter(unsigned user_gpio, unsigned steady, unsigned active);
/*D
Sets a noise filter on a GPIO.
Level changes on the GPIO are ignored until a level which has
been stable for [*steady*] microseconds is detected. Level changes
on the GPIO are then reported for [*active*] microseconds after
which the process repeats.
. .
user_gpio: 0-31
steady: 0-300000
active: 0-1000000
. .
Returns 0 if OK, otherwise PI_BAD_USER_GPIO, or PI_BAD_FILTER.
This filter affects the GPIO samples returned to callbacks set up
with [*callback*], [*callback_ex*] and [*wait_for_edge*].
It does not affect levels read by [*gpio_read*],
[*read_bank_1*], or [*read_bank_2*].
Level changes before and after the active period may
be reported. Your software must be designed to cope with
such reports.
D*/
/*F*/
uint32_t read_bank_1(void);
/*D
Read the levels of the bank 1 GPIO (GPIO 0-31).
The returned 32 bit integer has a bit set if the corresponding
GPIO is logic 1. GPIO n has bit value (1<<n).
D*/
/*F*/
uint32_t read_bank_2(void);
/*D
Read the levels of the bank 2 GPIO (GPIO 32-53).
The returned 32 bit integer has a bit set if the corresponding
GPIO is logic 1. GPIO n has bit value (1<<(n-32)).
D*/
/*F*/
int clear_bank_1(uint32_t bits);
/*D
Clears GPIO 0-31 if the corresponding bit in bits is set.
. .
bits: a bit mask with 1 set if the corresponding GPIO is
to be cleared.
. .
Returns 0 if OK, otherwise PI_SOME_PERMITTED.
A status of PI_SOME_PERMITTED indicates that the user is not
allowed to write to one or more of the GPIO.
D*/
/*F*/
int clear_bank_2(uint32_t bits);
/*D
Clears GPIO 32-53 if the corresponding bit (0-21) in bits is set.
. .
bits: a bit mask with 1 set if the corresponding GPIO is
to be cleared.
. .
Returns 0 if OK, otherwise PI_SOME_PERMITTED.
A status of PI_SOME_PERMITTED indicates that the user is not
allowed to write to one or more of the GPIO.
D*/
/*F*/
int set_bank_1(uint32_t bits);
/*D
Sets GPIO 0-31 if the corresponding bit in bits is set.
. .
bits: a bit mask with 1 set if the corresponding GPIO is
to be set.
. .
Returns 0 if OK, otherwise PI_SOME_PERMITTED.
A status of PI_SOME_PERMITTED indicates that the user is not
allowed to write to one or more of the GPIO.
D*/
/*F*/
int set_bank_2(uint32_t bits);
/*D
Sets GPIO 32-53 if the corresponding bit (0-21) in bits is set.
. .
bits: a bit mask with 1 set if the corresponding GPIO is
to be set.
. .
Returns 0 if OK, otherwise PI_SOME_PERMITTED.
A status of PI_SOME_PERMITTED indicates that the user is not
allowed to write to one or more of the GPIO.
D*/
/*F*/
int hardware_clock(unsigned gpio, unsigned clkfreq);
/*D
Starts a hardware clock on a GPIO at the specified frequency.
Frequencies above 30MHz are unlikely to work.
. .
gpio: see description
frequency: 0 (off) or 4689-250000000 (250M)
. .
Returns 0 if OK, otherwise PI_NOT_PERMITTED, PI_BAD_GPIO,
PI_NOT_HCLK_GPIO, PI_BAD_HCLK_FREQ,or PI_BAD_HCLK_PASS.
The same clock is available on multiple GPIO. The latest
frequency setting will be used by all GPIO which share a clock.
The GPIO must be one of the following.
. .
4 clock 0 All models
5 clock 1 All models but A and B (reserved for system use)
6 clock 2 All models but A and B
20 clock 0 All models but A and B
21 clock 1 All models but A and Rev.2 B (reserved for system use)
32 clock 0 Compute module only
34 clock 0 Compute module only
42 clock 1 Compute module only (reserved for system use)
43 clock 2 Compute module only
44 clock 1 Compute module only (reserved for system use)
. .
Access to clock 1 is protected by a password as its use will likely
crash the Pi. The password is given by or'ing 0x5A000000 with the
GPIO number.
D*/
/*F*/
int hardware_PWM(unsigned gpio, unsigned PWMfreq, uint32_t PWMduty);
/*D
Starts hardware PWM on a GPIO at the specified frequency and dutycycle.
Frequencies above 30MHz are unlikely to work.
NOTE: Any waveform started by [*wave_send_once*], [*wave_send_repeat*],
or [*wave_chain*] will be cancelled.
This function is only valid if the pigpio main clock is PCM. The