Skip to content

Commit

Permalink
Use gpiochip API 2 instead of API 1.
Browse files Browse the repository at this point in the history
  • Loading branch information
joan2937 committed Aug 15, 2021
1 parent 9ebaf58 commit dcabc9b
Show file tree
Hide file tree
Showing 19 changed files with 674 additions and 401 deletions.
9 changes: 9 additions & 0 deletions DOC/bin/dmakdoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ def nostar(k):
if line == "":
break

while line.find("[&") != -1 and line.find("&]") != -1:
(b, s, e) = line.partition("[&")
(l, s, e) = e.partition("&]")

if man:
line = "{}\\fB{}\\fP{}".format(b, l, e)
else:
line = "{}<a href=\"{}\">{}</a>".format(b, l, e)

while line.find("[*") != -1 and line.find("*]") != -1:
(b, s, e) = line.partition("[*")
(l, s, e) = e.partition("*]")
Expand Down
Binary file modified DOC/dbase/lg.sqlite
Binary file not shown.
13 changes: 13 additions & 0 deletions DOC/src/defs/index.def
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,16 @@ ALL GPIO are identified by their gpiochip device number.

TEXT*/

/*TEXT Other Languages

There are several third party projects which provide wrappers for lg.

Some are listed here:

[ul]
NodeJS (thanks to Dan Kadera) [&https://github.com/jahudka/node-lgpio&]NodeJS bindings
NodeJS (thanks to Dan Kadera) [&https://www.npmjs.com/package/lgpio&]NPM package
[ul]

TEXT*/

95 changes: 51 additions & 44 deletions DOC/src/defs/rgs.def
Original file line number Diff line number Diff line change
Expand Up @@ -445,54 +445,54 @@ $ rgs c 1 gic 1
GIL ::

This command gets information for GPIO [#g#] of an opened gpiochip.
In particular it gets the GPIO number, kernel usage flags, its user,
In particular it gets the GPIO number, line flags, its user,
and its purpose.

The usage flags are bits.

Bit value @ Bit meaning
1 @ GPIO in use by the kernel
2 @ GPIO is an output
4 @ GPIO is active low
8 @ GPIO is open drain
16 @ GPIO is open source
The meaning of the line flags bits are as given for the mode by [*GMODE*].

The user and purpose fields are filled in by the software which has
claimed the GPIO and may be blank.

...
$ for ((i=2; i<10; i++)); do rgs c 1 gil 1 $i; done
2 0 "" ""
3 0 "" ""
4 11 "" "onewire.0"
5 0 "" ""
6 0 "" ""
7 7 "" "spi0 CS1"
8 7 "" "spi0 CS0"
9 0 "" ""
2 65536 "SDA1" ""
3 65536 "SCL1" ""
4 65536 "GPIO_GCLK" ""
5 65536 "GPIO5" ""
6 65536 "GPIO6" ""
7 7 "SPI_CE1_N" "spi0 CS1"
8 7 "SPI_CE0_N" "spi0 CS0"
9 65536 "SPI_MISO" ""
...

GMODE ::

This command gets the mode for GPIO [#g#] of an opened gpiochip.

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: ---
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: Pull up set
6 @ 64 @ Kernel: Pull down set
7 @ 128 @ Kernel: Pulls off set
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: ---
16 @ 65536 @ Kernel: Input
17 @ 1<<17 @ Kernel: Rising edge alert
18 @ 1<<18 @ Kernel: Falling edge alert
19 @ 1<<19 @ Kernel: Realtime clock alert

The LG bits are only set if the query was made by the process that
owns the GPIO.

GSI ::

Expand All @@ -507,7 +507,8 @@ GSIX ::
This command claims GPIO [#g#] for input.

The line flags [#lf#] may be used to set the GPIO
as active low, open drain, or open source.
as active low, open drain, open source,
pull up, pull down, pull off.

...
$ rgs c 1 gsi 1 0 23 # claim GPIO 23 for input.
Expand All @@ -529,7 +530,8 @@ GSOX ::
This command claims GPIO [#g#] for output.

The line flags [#lf#] may be used to set the GPIO
as active low, open drain, or open source.
as active low, open drain, open source,
pull up, pull down, pull off.

If [#v#] is zero the GPIO will be initialised low. If any other
value is used the GPIO will be initialised high.
Expand All @@ -551,7 +553,8 @@ GSAX ::
This command claims GPIO [#g#] for alerts.

The line flags [#lf#] may be used to set the GPIO
as active low, open drain, or open source.
as active low, open drain, open source,
pull up, pull down, pull off.

The event flags [#ef#] specify whether alerts should be
generated on a rising edge, falling edge, or both edges.
Expand Down Expand Up @@ -580,7 +583,8 @@ This command claims a group of GPIO for inputs. All the GPIO
share the same line flag setting.

The line flags [#lf#] may be used to set the GPIO
as active low, open drain, or open source.
as active low, open drain, open source,
pull up, pull down, pull off.

[#g*#] is a list of one or more GPIO. The first GPIO in the list is
called the group leader and is used to reference the group as a whole.
Expand Down Expand Up @@ -608,7 +612,8 @@ This command claims a group of GPIO for outputs. All the GPIO
and share the same line flag setting.

The line flags [#lf#] may be used to set the GPIO
as active low, open drain, or open source.
as active low, open drain, open source,
pull up, pull down, pull off.

[#g*#] is a list of one or more GPIO. The first GPIO in the list is
called the group leader and is used to reference the group as a whole.
Expand Down Expand Up @@ -1889,6 +1894,9 @@ Value @ Meaning
4 @ Active low
8 @ Open drain
16 @ Open source
32 @ Pull up
64 @ Pull down
128 @ Pull none

mode :: lgFile open mode
One of the following values.
Expand Down Expand Up @@ -1944,12 +1952,11 @@ pat :: a file name pattern
A file path which may contain wildcards. To be accessible the path
must match an entry in the [files] section of the permits file.

pdc :: thousandths of %
PWM duty cycle between 0 % (0) and 100 % (100000).
pdc :: %
PWM duty cycle between 0.0 % and 100 % inclusive.

pf :: thousandths of Hz
PWM frequency between 0.1 Hz (100) and 10000 Hz (10000000).
Use 0 for off.
pf :: Hz
PWM frequency between 0.1 Hz and 10000 Hz inclusive. Use 0 for off.

r :: register (0-255)
The command expects an I2C register number.
Expand Down
67 changes: 44 additions & 23 deletions PY_LGPIO/lgpio_extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import threading
import time

LGPIO_PY_VERSION = 0x00010700
LGPIO_PY_VERSION = 0x00020000

exceptions = True

Expand All @@ -28,6 +28,9 @@
SET_ACTIVE_LOW = 4
SET_OPEN_DRAIN = 8
SET_OPEN_SOURCE = 16
SET_PULL_UP = 32
SET_PULL_DOWN = 64
SET_PULL_NONE = 128

# GPIO event flags

Expand Down Expand Up @@ -451,6 +454,9 @@ def gpio_get_line_info(handle, gpio):
If OK returns a list of okay status, GPIO number,
line flags, name, and user.
The meaning of the line flags bits are as given for the mode
by [*gpio_get_mode*].
On failure returns a negative error code.
"""
return _u2i_list(_lgpio._gpio_get_line_info(handle&0xffff, gpio))
Expand All @@ -467,23 +473,30 @@ def gpio_get_mode(handle, 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: ---
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: Pull up set
6 @ 64 @ Kernel: Pull down set
7 @ 128 @ Kernel: Pulls off set
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: ---
16 @ 65536 @ Kernel: Input
17 @ 1<<17 @ Kernel: Rising edge alert
18 @ 1<<18 @ Kernel: Falling edge alert
19 @ 1<<19 @ Kernel: Realtime clock alert
The LG bits are only set if the query was made by the process
that owns the GPIO.
"""
return _u2i(_lgpio._gpio_get_mode(handle&0xffff, gpio))

Expand All @@ -501,7 +514,8 @@ def gpio_claim_input(handle, gpio, lFlags=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.
as active low, open drain, open source,
pull up, pull down, pull off.
...
sbc.gpio_claim_input(h, 23) # open GPIO 23 for input.
Expand All @@ -523,7 +537,8 @@ def gpio_claim_output(handle, gpio, level=0, lFlags=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.
as active low, open drain, open source,
pull up, pull down, pull off.
If level is zero the GPIO will be initialised low (0). If any other
value is used the GPIO will be initialised high (1).
Expand Down Expand Up @@ -563,7 +578,8 @@ def group_claim_input(handle, gpio, lFlags=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.
as active low, open drain, open source,
pull up, pull down, pull off.
gpio is a list of one or more GPIO. The first GPIO in the
list is called the group leader and is used to reference the
Expand Down Expand Up @@ -592,7 +608,8 @@ def group_claim_output(handle, gpio, levels=[0], lFlags=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.
as active low, open drain, open source,
pull up, pull down, pull off.
gpio is a list of one or more GPIO. The first GPIO in the list is
called the group leader and is used to reference the group as a whole.
Expand Down Expand Up @@ -1034,7 +1051,8 @@ def gpio_claim_alert(
falling edge, or both edges.
The line flags may be used to set the GPIO
as active low, open drain, or open source.
as active low, open drain, open source,
pull up, pull down, pull off.
Use the default notification handle of None unless you plan
to read the alerts from a notification pipe you have opened.
Expand Down Expand Up @@ -2176,6 +2194,9 @@ def xref():
SET_ACTIVE_LOW
SET_OPEN_DRAIN
SET_OPEN_SOURCE
SET_PULL_UP
SET_PULL_DOWN
SET_PULL_NONE
. .
notify_handle:
Expand Down
2 changes: 1 addition & 1 deletion PY_LGPIO/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
lgpio_module = Extension('_lgpio', sources=['lgpio_wrap.c',], libraries=['lgpio',],)

setup (name = 'lgpio',
version = '0.1.7.0',
version = '0.2.0.0',
zip_safe=False,
author='joan',
author_email='[email protected]',
Expand Down
Loading

0 comments on commit dcabc9b

Please sign in to comment.