File tree Expand file tree Collapse file tree 4 files changed +89
-22
lines changed
src/adafruit_blinka/microcontroller Expand file tree Collapse file tree 4 files changed +89
-22
lines changed Original file line number Diff line number Diff line change 15
15
from adafruit_blinka .agnostic import detector
16
16
from adafruit_blinka .microcontroller .alias import get_dts_alias , get_pwm_chipid
17
17
from adafruit_blinka .microcontroller .generic_linux .libgpiod_pin import Pin
18
+ from adafruit_blinka .microcontroller .generic_linux .libgpiod_chip import Chip
18
19
19
- try :
20
- import gpiod
21
- except ImportError :
22
- raise ImportError (
23
- "libgpiod Python bindings not found, please install and try again!"
24
- ) from ImportError
20
+ chip0 = Chip ("0" )
21
+ chip1 = Chip ("1" )
25
22
26
- if hasattr (gpiod , "Chip" ):
27
- chip0 = gpiod .Chip ("0" )
28
- chip1 = gpiod .Chip ("1" )
29
- else :
30
- chip0 = gpiod .chip ("0" )
31
- chip1 = gpiod .chip ("1" )
32
-
33
- if callable (chip0 .num_lines ):
34
- chip0lines = chip0 .num_lines ()
35
- else :
36
- chip0lines = chip0 .num_lines
37
-
38
- if callable (chip1 .num_lines ):
39
- chip1lines = chip1 .num_lines ()
40
- else :
41
- chip1lines = chip1 .num_lines
23
+ chip0lines = chip0 .num_lines
24
+ chip1lines = chip1 .num_lines
42
25
43
26
if chip0lines < 20 :
44
27
aobus = 0
Original file line number Diff line number Diff line change
1
+ # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """A Chip class for use with libgpiod 1.x."""
5
+ import gpiod
6
+
7
+
8
+ # pylint: disable=too-many-branches,too-many-statements
9
+ class Chip :
10
+ """Abstraction for handling all breaking changes over the lifecycle of gpiod"""
11
+
12
+ _CONSUMER = "adafruit_blinka"
13
+
14
+ id : str = None
15
+ num_lines : int
16
+
17
+ def __init__ (self , chip_id : str ):
18
+ self .id = chip_id
19
+ if hasattr (gpiod , "Chip" ):
20
+ self ._chip = gpiod .Chip (self .id )
21
+ else :
22
+ self ._chip = gpiod .chip (self .id )
23
+
24
+ if callable (self ._chip .num_lines ):
25
+ self .num_lines = self ._chip .num_lines ()
26
+ else :
27
+ self .num_lines = self .num_lines
28
+
29
+ def __repr__ (self ):
30
+ return self .id
31
+
32
+ def __eq__ (self , other ):
33
+ return self .id == other
Original file line number Diff line number Diff line change
1
+ # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """A Chip class for use with libgpiod 2.x."""
5
+ import gpiod
6
+
7
+
8
+ # pylint: disable=too-many-branches,too-many-statements
9
+ class Chip :
10
+ """Abstraction for handling all breaking changes over the lifecycle of gpiod"""
11
+
12
+ _CONSUMER = "adafruit_blinka"
13
+
14
+ id : str = None
15
+ num_lines : int
16
+
17
+ def __init__ (self , chip_id : str ):
18
+ self .id = chip_id
19
+ path = f"/dev/gpiochip{ self .id } "
20
+ self ._chip = gpiod .Chip (path )
21
+
22
+ info = self ._chip .get_info ()
23
+ self .num_lines = info .num_lines
24
+
25
+ def __repr__ (self ):
26
+ return self .id
27
+
28
+ def __eq__ (self , other ):
29
+ return self .id == other
Original file line number Diff line number Diff line change
1
+ # SPDX-FileCopyrightText: 2021 Melissa LeBlanc-Williams for Adafruit Industries
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """A Chip class for use with libgpiod."""
5
+ try :
6
+ import gpiod
7
+ except ImportError :
8
+ raise ImportError (
9
+ "libgpiod Python bindings not found, please install and try again! See "
10
+ "https://github.com/adafruit/Raspberry-Pi-Installer-Scripts/blob/main/libgpiod.py"
11
+ ) from ImportError
12
+
13
+ # Versions 1.5.4 and earlier have no __version__ attribute
14
+ if hasattr (gpiod , "__version__" ):
15
+ version = gpiod .__version__
16
+ else :
17
+ version = "1.x"
18
+
19
+ if version .startswith ("1." ):
20
+ from .libgpiod .libgpiod_chip_1_x import Chip # pylint: disable=unused-import
21
+ else :
22
+ from .libgpiod .libgpiod_chip_2_x import Chip # pylint: disable=unused-import
You can’t perform that action at this time.
0 commit comments