adafruit / Adafruit_Blinka

Add CircuitPython hardware API and libraries to MicroPython & CPython devices
https://learn.adafruit.com/circuitpython-on-raspberrypi-linux
MIT License
438 stars 328 forks source link

GPIO Access Support for linux (kernel > 4.7) #795

Closed sriram-rs closed 3 months ago

sriram-rs commented 3 months ago

Board Name

RockPiS

Steps

  1. SSH into the board
  2. install adafruit_blinka library
  3. open python and try to configure any gpio

Adafruit blinka OSError

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.11/dist-packages/digitalio.py", line 187, in init self.direction = Direction.INPUT ^^^^^^^^^^^^^^ File "/usr/local/lib/python3.11/dist-packages/digitalio.py", line 217, in direction self._pin.init(mode=Pin.IN) File "/usr/local/lib/python3.11/dist-packages/adafruit_blinka/microcontroller/generic_linux/sysfs_pin.py", line 94, in init self._open(self.IN) File "/usr/local/lib/python3.11/dist-packages/adafruit_blinka/microcontroller/generic_linux/sysfs_pin.py", line 142, in _open raise GPIOError(e.errno, "Exporting GPIO: " + e.strerror) from IOError adafruit_blinka.microcontroller.generic_linux.sysfs_pin.GPIOError: [Errno 2] Exporting GPIO: No such file or directory

Description

Error while using digitialio to configure GPIO with linux 6.1

Since the /sys/class/gpio is deprecated since kernel 4.8, Adafruit_Blinka cannot be used to configure and control gpios on the upstream kernel.

Now there is access only to /dev/gpiochip{x} instead of /sys/class/gpio/{x}.

Any help would be greatly appreciated.

Additional information

No response

makermelissa commented 3 months ago

Sounds like it needs to be updated to use libgpiod. If I recall correctly, I'm the one who added this board and at the time libgpiod wasn't available, but if they are updating the kernel, perhaps it is now.

sriram-rs commented 3 months ago

Thanks very much @makermelissa for the revert. Looking forward to the inclusion. So that I can use Adafruit_Blinka alone for all peripheral access with busio and IO access with digitalio.

makermelissa commented 3 months ago

Got my RockPi S out and have now re-familiarized myself with it. Which image are you running? The official Rock Pi S Buster image is still on kernel 4.4.

makermelissa commented 3 months ago

Ok, the official buster image is kinda terrible. It's kernel 4.4 and although libgpiod is available, there are no /dev/gpiochipX devices, so it's pointless. I'm going to update for Armbian.

sriram-rs commented 3 months ago

Thanks @makermelissa again for seamlessly pointing out to the issue 👍🏽 .

I am running 6.1.68 rc image provided by radxa.

sriram-rs commented 3 months ago

Ok, the official buster image is kinda terrible. It's kernel 4.4 and although libgpiod is available, there are no /dev/gpiochipX devices, so it's pointless. I'm going to update for Armbian.

That's the core of the issue.

I have got Adafruit_blinka to work with 4.4.143. It is fully functional.

Seems /sys/class/gpio approach had been deprecated since kernel 4.8 and changed to /dev/gpiochipX

sriram-rs commented 3 months ago

Thanks a lot, @makermelissa and @tekktrik for the support.

I will give the library a try and let know in case of queries. !!