5
5
from pathlib import Path
6
6
import lgpio
7
7
8
+
8
9
def _get_gpiochip ():
9
10
"""
10
11
Determines the handle of the GPIO chip device to access.
11
12
12
13
iterate through sysfs to find a GPIO chip device with a driver known to be
13
14
used for userspace GPIO access.
14
15
"""
15
- for dev in Path (' /sys/bus/gpio/devices' ).glob (' gpiochip*' ):
16
- drivers = set ((dev / ' of_node/compatible' ).read_text ().split (' \0 ' ))
16
+ for dev in Path (" /sys/bus/gpio/devices" ).glob (" gpiochip*" ):
17
+ drivers = set ((dev / " of_node/compatible" ).read_text ().split (" \0 " ))
17
18
# check if driver names are intended for userspace control
18
- if drivers & {'raspberrypi,rp1-gpio' ,
19
- 'raspberrypi,bcm2835-gpio' ,
20
- 'raspberrypi,bcm2711-gpio' }:
19
+ if drivers & {
20
+ "raspberrypi,rp1-gpio" ,
21
+ "raspberrypi,bcm2835-gpio" ,
22
+ "raspberrypi,bcm2711-gpio" ,
23
+ }:
21
24
return lgpio .gpiochip_open (int (dev .name [- 1 ]))
22
25
# return chip0 as a fallback
23
26
return lgpio .gpiochip_open (0 )
@@ -60,7 +63,7 @@ class Pin:
60
63
lgpio .exceptions = True
61
64
62
65
def __init__ (self , bcm_number ):
63
- self .id = bcm_number # pylint: disable=invalid-name
66
+ self .id = bcm_number # pylint: disable=invalid-name
64
67
65
68
def __repr__ (self ):
66
69
return str (self .id )
@@ -76,8 +79,7 @@ def init(self, mode=IN, pull=None):
76
79
self ._set_gpio_mode_in ()
77
80
elif mode == self .OUT :
78
81
self ._mode = Pin .OUT
79
- Pin ._check_result (lgpio .gpio_claim_output (CHIP , self .id ,
80
- Pin .LOW ))
82
+ Pin ._check_result (lgpio .gpio_claim_output (CHIP , self .id , Pin .LOW ))
81
83
else :
82
84
raise RuntimeError (f"Invalid mode for pin: { self .id } " )
83
85
if pull is not None :
0 commit comments