forked from joan2937/lg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rgpio.h
2937 lines (2160 loc) · 66.9 KB
/
rgpio.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 RGPIO_H
#define RGPIO_H
#include <inttypes.h>
#include <pthread.h>
#include "lgpio.h"
#define RGPIO_VERSION 0x00010700
/*TEXT
rgpio is a C library which allows remote control of the GPIO and
other functions of Linux SBCs running the rgpiod daemon.
The rgpiod daemon must be running on the SBCs you wish to control.
*Features*
o reading and writing GPIO singly and in groups
o software timed PWM and waves
o GPIO callbacks
o pipe notification of GPIO alerts
o I2C wrapper
o SPI wrapper
o serial link wrapper
o simple file handling
o creating and running scripts on the rgpiod daemon
o a simple interface to start and stop new threads
*Usage*
Include <rgpio.h> in your source files.
Assuming your source is in prog.c use the following command to build
. .
gcc -Wall -o prog prog.c -lrgpio
. .
to run make sure the rgpiod daemon is running
. .
rgpiod&
./prog
. .
For examples see the lg archive file.
*Notes*
All the functions which return an int return < 0 on error
TEXT*/
/*OVERVIEW
ESSENTIAL
rgpiod_start Connects to a rgpiod daemon
rgpiod_stop Disconnects from a rgpiod daemon
FILES
file_open Opens a file
file_close Closes a file
file_read Reads bytes from a file
file_write Writes bytes to a file
file_seek Seeks to a position within a file
file_list List files which match a pattern
GPIO
gpiochip_open Opens a gpiochip device
gpiochip_close Closes a gpiochip device
gpio_get_chip_info Gets gpiochip information
gpio_get_line_info Gets gpiochip line information
gpio_get_mode Gets the mode of a GPIO
gpio_claim_input Claims a GPIO for input
gpio_claim_output Claims a GPIO for output
gpio_claim_alert Claims a GPIO for alerts
gpio_free Frees a GPIO
group_claim_input Claims a group of GPIO for inputs
group_claim_output Claims a group of GPIO for outputs
group_free Frees a group of GPIO
gpio_read Reads a GPIO
gpio_write Writes a GPIO
group_read Reads a group of GPIO
group_write Writes a group of GPIO
tx_pulse Starts pulses on a GPIO
tx_pwm Starts PWM on a GPIO
tx_servo Starts servo pulses on a GPIO.
tx_wave Starts a wave on a group of GPIO
tx_busy See if tx is active on a GPIO or group
tx_room See if more room for tx on a GPIO or group
gpio_set_debounce_time Sets the debounce time for a GPIO
gpio_set_watchdog_time Sets the watchdog time for a GPIO
callback Starts a GPIO callback
callback_cancel Stops a GPIO callback
I2C
i2c_open Opens an I2C device
i2c_close Closes an I2C device
i2c_write_quick smbus write quick
i2c_read_byte smbus read byte
i2c_write_byte smbus write byte
i2c_read_byte_data smbus read byte data
i2c_write_byte_data smbus write byte data
i2c_read_word_data smbus read word data
i2c_write_word_data smbus write word data
i2c_read_block_data smbus read block data
i2c_write_block_data smbus write block data
i2c_read_i2c_block_data smbus read I2C block data
i2c_write_i2c_block_data smbus write I2C block data
i2c_read_device Reads the raw I2C device
i2c_write_device Writes the raw I2C device
i2c_process_call smbus process call
i2c_block_process_call smbus block process call
i2c_zip Performs multiple I2C transactions
NOTIFICATIONS
notify_open Request a notification handle
notify_close Close a notification
notify_pause Pause notifications
notify_resume Start notifications for selected GPIO
SCRIPTS
script_store Store a script
script_run Run a stored script
script_update Set a scripts parameters
script_status Get script status and parameters
script_stop Stop a running script
script_delete Delete a stored script
SERIAL
serial_open Opens a serial device
serial_close Closes a serial device
serial_read_byte Reads a byte from a serial device
serial_write_byte Writes a byte to a serial device
serial_read Reads bytes from a serial device
serial_write Writes bytes to a serial device
serial_data_available Returns number of bytes ready to be read
SHELL
shell Executes a shell command
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
THREADS
thread_start Start a new thread
thread_stop Stop a previously started thread
UTILITIES
lgu_get_sbc_name Get the SBC name
lgu_get_internal Get a SBC configuration value
lgu_set_internal Set a SBC configuration value
lgu_time Returns the number of seconds since the epoch
lgu_timestamp Returns the number of nanoseconds since the epoch
lgu_sleep Sleeps for a number of seconds
lgu_set_user Set the user (and associated permissions)
lgu_set_share_id Set the share id for a resource
lgu_use_share_id Use this share id when asking for a resource
lgu_rgpio_version Get the rgpio library version
lgu_error_text Get the error text for an error code
OVERVIEW*/
#ifdef __cplusplus
extern "C" {
#endif
#define RISING_EDGE 1
#define FALLING_EDGE 2
#define BOTH_EDGES 3
typedef void (*CBFunc_t)
(int sbc, int chip, int gpio,
int level, uint64_t tick, void *userdata);
typedef struct callback_s callback_t;
typedef void *(lgThreadFunc_t) (void *);
/* --------------------------------------------------------- ESSENTIAL API
*/
/*F*/
int rgpiod_start(const char *addrStr, const char *portStr);
/*D
Connect to the rgpiod daemon. Reserving command and
notification streams.
. .
addrStr: specifies the host or IP address of the SBC running the
rgpiod daemon. It may be NULL in which case localhost
is used unless overridden by the LG_ADDR environment
variable.
portStr: specifies the port address used by the SBC running the
rgpiod daemon. It may be NULL in which case "8889"
is used unless overridden by the LG_PORT environment
variable.
. .
If OK returns a sbc (>= 0).
On failure returns a negative error code.
This sbc value is passed to the other functions to specify
the SBC to be used.
If the LG_USER environment variable exists that user will be
"logged in" using [*lgu_set_user*]. This only has an effect if
the rgpiod daemon is running with access control enabled.
D*/
/*F*/
void rgpiod_stop(int sbc);
/*D
Terminates the connection to a rgpiod daemon and frees
resources used by the library.
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
. .
D*/
/* -------------------------------------------------------------- FILE API
*/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcomment"
/*F*/
int file_open(int sbc, const char *file, int mode);
/*D
This function returns a handle to a file opened in a specified mode.
This is a privileged command. See [+permits+].
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
file: the file to open.
mode: the file open mode.
. .
If OK returns a handle (>= 0).
On failure returns a negative error code.
File
A file may only be opened if permission is granted by an entry in
the [files] section of the permits file. This is intended to allow
remote access to files in a controlled manner.
Mode
The mode may have the following values.
Macro @ Value @ Meaning
LG_FILE_READ @ 1 @ open file for reading
LG_FILE_WRITE @ 2 @ open file for writing
LG_FILE_RW @ 3 @ open file for reading and writing
The following values may be or'd into the mode.
Macro @ Value @ Meaning
LG_FILE_APPEND @ 4 @ Writes append data to the end of the file
LG_FILE_CREATE @ 8 @ The file is created if it doesn't exist
LG_FILE_TRUNC @ 16 @ The file is truncated
Newly created files are owned by the user who launched the daemon
with permissions owner read and write.
...
#include <stdio.h>
#include <rgpio.h>
int main(int argc, char *argv[])
{
int sbc, handle, c;
char buf[60000];
sbc = rgpiod_start(NULL, NULL);
if (sbc < 0) return 1;
handle = file_open(sbc, "/ram/lg.c", LG_FILE_READ);
if (handle >= 0)
{
while ((c=file_read(sbc, handle, buf, sizeof(buf)-1)))
{
buf[c] = 0;
printf("%s", buf);
}
file_close(sbc, handle);
}
rgpiod_stop(sbc);
}
...
D*/
#pragma GCC diagnostic pop
/*F*/
int file_close(int sbc, int handle);
/*D
This function closes the file.
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
handle: >= 0 (as returned by [*file_open*]).
. .
If OK returns 0.
On failure returns a negative error code.
...
file_close(sbc, handle);
...
D*/
/*F*/
int file_write(int sbc, int handle, const char *buf, int count);
/*D
This function writes count bytes from buf to the the file.
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
handle: >= 0 (as returned by [*file_open*]).
buf: the array of bytes to write.
count: the number of bytes to write.
. .
If OK returns 0.
On failure returns a negative error code.
...
if (file_write(sbc, handle, buf, 100) == 0)
{
// file written okay
}
else
{
// error
}
...
D*/
/*F*/
int file_read(int sbc, int handle, char *buf, int count);
/*D
This function reads up to count bytes from the the file.
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
handle: >= 0 (as returned by [*file_open*]).
buf: an array to receive the read data.
count: the maximum number of bytes to read.
. .
If OK returns the count of bytes read and updates buf.
On failure returns a negative error code.
...
bytes = file_read(sbc, handle, buf, sizeof(buf));
if (bytes >= 0)
{
// process read data
}
...
D*/
/*F*/
int file_seek(int sbc, int handle, int32_t seekOffset, int seekFrom);
/*D
This function seeks to a position within the file.
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
handle: >= 0 (as returned by [*file_open*]).
seekOffset: the number of bytes to move. Positive offsets
move forward, negative offsets backwards.
seekFrom: one of LG_FROM_START (0), LG_FROM_CURRENT (1),
or LG_FROM_END (2).
. .
If OK returns the new file position.
On failure returns a negative error code.
...
file_seek(sbc, handle, 123, LG_FROM_START); // Start plus 123
size = file_seek(sbc, handle, 0, LG_FROM_END); // End, return size
pos = file_seek(sbc, handle, 0, LG_FROM_CURRENT); // Current position
...
D*/
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wcomment"
/*F*/
int file_list(int sbc, const char *fpat, char *buf, int count);
/*D
This function returns a list of files which match a pattern.
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
fpat: file pattern to match.
buf: an array to receive the matching file names.
count: the maximum number of bytes to read.
. .
If OK returns the count of bytes read and updates buf with
the matching filenames (the filenames are separated by newline
characters).
On failure returns a negative error code.
...
#include <stdio.h>
#include <rgpio.h>
int main(int argc, char *argv[])
{
int sbc, handle, c;
char buf[60000];
sbc = rgpiod_start(NULL, NULL);
if (sbc < 0) return 1;
c = file_list(sbc, "/ram/p*.c", buf, sizeof(buf));
if (c >= 0)
{
buf[c] = 0;
printf("%s", buf);
}
rgpiod_stop(sbc);
}
...
D*/
#pragma GCC diagnostic pop
/* -------------------------------------------------------------- GPIO API
*/
/*F*/
int gpiochip_open(int sbc, int gpioDev);
/*D
This returns a handle to a gpiochip device.
This is a privileged command. See [+permits+].
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
gpioDev: >= 0
. .
If OK returns a handle (>= 0).
On failure returns a negative error code.
...
h = gpiochip_open(sbc, 0); // open gpiochip0
if (h >= 0)
{
// open ok
}
else
{
// open error
}
...
D*/
/*F*/
int gpiochip_close(int sbc, int handle);
/*D
This closes a gpiochip device.
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
handle: >= 0 (as returned by [*gpiochip_open*]).
. .
If OK returns 0.
On failure returns a negative error code.
...
status = gpiochip_close(sbc, h); // close gpiochip
if (status < 0)
{
// close failed
}
...
D*/
/*F*/
int gpio_get_chip_info(int sbc, int handle, lgChipInfo_p chipInfo);
/*D
This returns summary information of an opened gpiochip.
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
handle: >= 0 (as returned by [*gpiochip_open*]).
chipInfo: address to store returned chip info.
. .
If OK returns a list of okay status, number of
lines, name, and label.
On failure returns a negative error code.
D*/
/*F*/
int gpio_get_line_info(int sbc, int handle, int gpio, lgLineInfo_p lineInfo);
/*D
This returns detailed information of a GPIO of
an opened gpiochip.
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
handle: >= 0 (as returned by [*gpiochip_open*]).
gpio: the GPIO.
lineInfo: address to store returned line info.
. .
If OK returns a list of okay status, offset,
line flags, name, and user.
On failure returns a negative error code.
D*/
/*F*/
int gpio_get_mode(int sbc, int handle, int gpio);
/*D
This returns the mode of a GPIO.
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
handle: >= 0 (as returned by [*gpiochip_open*]).
gpio: the GPIO to be read.
. .
If OK returns the mode of the GPIO.
On failure returns a negative error code.
Mode bit @ Value @ Meaning
0 @ 1 @ Kernel: In use by the kernel
1 @ 2 @ Kernel: Output
2 @ 4 @ Kernel: Active low
3 @ 8 @ Kernel: Open drain
4 @ 16 @ Kernel: Open source
5 @ 32 @ Kernel: ---
6 @ 64 @ Kernel: ---
7 @ 128 @ Kernel: ---
8 @ 256 @ LG: Input
9 @ 512 @ LG: Output
10 @ 1024 @ LG: Alert
11 @ 2048 @ LG: Group
12 @ 4096 @ LG: ---
13 @ 8192 @ LG: ---
14 @ 16384 @ LG: ---
15 @ 32768 @ LG: ---
D*/
/*F*/
int gpio_claim_input(int sbc, int handle, int lFlags, int gpio);
/*D
This claims a GPIO for input.
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
handle: >= 0 (as returned by [*gpiochip_open*]).
lFlags: line flags for the GPIO.
gpio: the GPIO to be claimed.
. .
If OK returns 0.
On failure returns a negative error code.
The line flags may be used to set the GPIO
as active low, open drain, or open source.
...
status = gpio_claim_input(sbc, h, 0, 23); // open GPIO 23 for input
...
D*/
/*F*/
int gpio_claim_output(
int sbc, int handle, int lFlags, int gpio, int value);
/*D
This claims a GPIO for output.
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
handle: >= 0 (as returned by [*gpiochip_open*]).
lFlags: line flags for the GPIO.
gpio: the GPIO to be claimed.
value: the initial value for the GPIO.
. .
If OK returns 0.
On failure returns a negative error code.
The line flags may be used to set the GPIO
as active low, open drain, or open source.
If value is zero the GPIO will be initialised low (0). If any other
value is used the GPIO will be initialised high (1).
...
status = gpio_claim_output(sbc, h, 0, 35, 1); // open GPIO 35 for high output
...
D*/
/*F*/
int gpio_free(int sbc, int handle, int gpio);
/*D
This frees a GPIO.
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
handle: >= 0 (as returned by [*gpiochip_open*]).
gpio: the GPIO to be freed.
. .
If OK returns 0.
On failure returns a negative error code.
The GPIO may now be claimed by another user or for a different purpose.
D*/
/*F*/
int group_claim_input(
int sbc, int handle, int lFlags, int count, const int *gpios);
/*D
This claims a group of GPIO for inputs.
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
handle: >= 0 (as returned by [*gpiochip_open*]).
lFlags: line flags for each GPIO.
count: the number of GPIO to claim.
gpios: the group GPIO.
. .
If OK returns 0.
On failure returns a negative error code.
The line flags may be used to set the group as active low,
open drain, or open source.
gpios is an array of one or more GPIO. The first GPIO in the array
is called the group leader and is used to reference the group as a whole.
D*/
/*F*/
int group_claim_output(
int sbc, int handle, int lFlags,
int count, const int *gpios, const int *values);
/*D
This claims a group of GPIO to be used as outputs.
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
handle: >= 0 (as returned by [*gpiochip_open*]).
lFlags: line flags for each GPIO.
count: the number of GPIO to claim.
gpios: the group GPIO.
values: the initial value for each GPIO.
. .
If OK returns 0.
On failure returns a negative error code.
The line flags may be used to set the group as active low, open drain, or open source.
gpios is an array of one or more GPIO. The first GPIO in the array is
called the group leader and is used to reference the group as a whole.
values is a list of initialisation values for the GPIO. If a value
is zero the corresponding GPIO will be initialised low (0).
If any other value is used the corresponding GPIO will be
initialised high (1).
D*/
/*F*/
int group_free(int sbc, int handle, int gpio);
/*D
This frees all the group GPIO.
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
handle: >= 0 (as returned by [*gpiochip_open*]).
gpio: the group leader.
. .
If OK returns 0.
On failure returns a negative error code.
The GPIO may now be claimed by another user or for a different purpose.
D*/
/*F*/
int gpio_read(int sbc, int handle, int gpio);
/*D
This returns the level of a GPIO.
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
handle: >= 0 (as returned by [*gpiochip_open*]).
gpio: the GPIO to be read.
. .
If OK returns 0 (low) or 1 (high).
On failure returns a negative error code.
This command will work for any claimed GPIO (even if a member
of a group). For an output GPIO the value returned
will be that last written to the GPIO.
D*/
/*F*/
int gpio_write(int sbc, int handle, int gpio, int value);
/*D
This sets the level of an output GPIO.
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
handle: >= 0 (as returned by [*gpiochip_open*]).
gpio: the GPIO to be written.
value: the value to write.
. .
If OK returns 0.
On failure returns a negative error code.
This command will work for any GPIO claimed as an output (even if
a member of a group).
If level is zero the GPIO will be set low (0). If any other value
is used the GPIO will be set high (1).
D*/
/*F*/
int group_read(
int sbc, int handle, int gpio, uint64_t *groupBits);
/*D
This returns the levels read from a group.
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
handle: >= 0 (as returned by [*gpiochip_open*]).
gpio: the offset of a member of the GPIO group to be read.
groupBits: a pointer to a 64-bit memory area for the returned value.
. .
If OK returns the group size and updates groupBits.
On failure returns a negative error code.
This command will work for an output group as well as an input group. For an output group the value returned will be that last written to the group GPIO.
Note that this command will also work on an individual GPIO claimed as an input or output as that is treated as a group with one member.
After a successful read groupBits is set as follows.
Bit 0 is the level of the group leader.
Bit 1 is the level of the second GPIO in the group.
Bit x is the level of GPIO x+1 of the group.
D*/
/*F*/
int group_write(
int sbc, int handle, int gpio, uint64_t groupBits, uint64_t groupMask);
/*D
This sets the levels of an output output group.
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
handle: >= 0 (as returned by [*gpiochip_open*]).
gpio: the offset of a member of the GPIO group to be written.
groupBits: the level to set if the corresponding bit in groupMask is set.
groupMask: a mask indicating the group GPIO to be updated.
. .
If OK returns 0.
On failure returns a negative error code.
The values of each GPIO of the group are set according to the bits
of group_bits.
Bit 0 sets the level of the group leader.
Bit 1 sets the level of the second GPIO in the group.
Bit x sets the level of GPIO x+1 in the group.
However this may be overridden by the group_mask. A GPIO is only
updated if the corresponding bit in the mask is 1.
D*/
/*F*/
int tx_pulse(
int sbc, int handle, int gpio,
int pulse_on, int pulse_off,
int pulse_offset, int pulse_cycles);
/*D
This starts software timed pulses on an output GPIO.
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
handle: >= 0 (as returned by [*gpiochip_open*]).
gpio: GPIO to be written.
pulse_on: pulse high time in microseconds.
pulse_off: pulse low time in microseconds.
pulse_offset: offset from nominal pulse start position.
pulse_cycles: the number of pulses to be sent, 0 for infinite.
. .
If OK returns the number of entries left in the PWM queue for the GPIO.
On failure returns a negative error code.
If both pulse_on and pulse_off are zero pulses will be switched off
for that GPIO. The active pulse, if any, will be stopped and any
queued pulses will be deleted.
Each successful call to this function consumes one PWM queue entry.
pulse_cycles cycles are transmitted (0 means infinite).
Each cycle consists of pulse_on microseconds of GPIO high
followed by pulse_off microseconds of GPIO low.
PWM is characterised by two values, its frequency
(number of cycles per second) and its duty cycle
(percentage of high time per cycle).
The set frequency will be 1000000 / (pulse_on + pulse_off) Hz.
The set duty cycle will be pulse_on / (pulse_on + pulse_off) * 100 %.
E.g. if pulse_on is 50 and pulse_off is 100 the frequency will
be 6666.67 Hz and the duty cycle will be 33.33 %.
pulse_offset is a microsecond offset from the natural start
of the pulse cycle.
For instance if the PWM frequency is 10 Hz the natural start of
each cycle is at seconds 0, then 0.1, 0.2, 0.3 etc. In this case
if the offset is 20000 microseconds the cycle will start at
seconds 0.02, 0.12, 0.22, 0.32 etc.
Another pulse command may be issued to the GPIO before the last
has finished.
If the last pulse had infinite cycles then it will be replaced by
the new settings at the end of the current cycle. Otherwise it will
be replaced by the new settings when all its cycles are compete.
Multiple pulse settings may be queued in this way.
D*/
/*F*/
int tx_pwm(
int sbc,
int handle,
int gpio,
float pwmFrequency,
float pwmDutyCycle,
int pwmOffset,
int pwmCycles);
/*D
This starts software timed PWM on an output GPIO.
. .
sbc: >= 0 (as returned by [*rgpiod_start*]).
handle: >= 0 (as returned by [*gpiochip_open*])
gpio: the GPIO to be pulsed
pwmFrequency: PWM frequency in Hz (0=off, 0.1-10000)
pwmDutyCycle: PWM duty cycle in % (0-100)
pwmOffset: offset from nominal pulse start position
pwmCycles: the number of pulses to be sent, 0 for infinite
. .
If OK returns the number of entries left in the PWM queue for the GPIO.
On failure returns a negative error code.
Each successful call to this function consumes one PWM queue entry.
PWM is characterised by two values, its frequency (number of cycles