vsergeev / lua-periphery

A Lua library for peripheral I/O (GPIO, LED, PWM, SPI, I2C, MMIO, Serial) in Linux.
MIT License
181 stars 38 forks source link

Support for Raspberry Pi 5 #31

Open nashafa opened 2 months ago

nashafa commented 2 months ago

I'm having trouble getting this library to work on a Raspberry Pi 5. My understanding is that GPIO support has a few breaking changes on the Pi 5; this may or may not be related to my issue.

I've installed lua-periphery with luarocks and am using Lua 5.1. I'm on Bookworm and Linux kernel 6.6.

When using the sysfs GPIO mode I get the following error:

Opening GPIO: writing 'export': Invalid argument [errno 22]

When attempting to use the character device GPIO mode (to target /dev/gpiochip4), I get the following error.

c-periphery library built without character device GPIO support.

Let me know if there's any further information I can provide or any additional tests to run. Thanks for the help!

vsergeev commented 1 month ago

Hmm, strange that it wasn't built with character device GPIO support. It could be a bug with the GPIO cdev support tests in the c-periphery Makefile. Do you happen to have a log of the LuaRocks build?

nashafa commented 1 month ago

I ended up trying with different Lua versions to no avail. The following log is with Lua 5.4.

LuaRocks log ``` Installing https://luarocks.org/lua-periphery-2.4.2-1.src.rock lua-periphery 2.4.2-1 depends on luarocks-fetch-gitrec >= 0.2 (0.2-2 installed: success) lua-periphery 2.4.2-1 depends on lua >= 5.1 (5.4-1 provided by VM: success) Warning: variable CFLAGS was not passed in build_variables cd c-periphery; make make[1]: Entering directory '/tmp/luarocks_lua-periphery-2.4.2-1-5101674/lua-periphery/c-periphery' mkdir obj gcc -std=gnu99 -pedantic -O3 -Wall -Wextra -Wno-stringop-truncation -fPIC -DPERIPHERY_VERSION_COMMIT=\"\" -DPERIPHERY_GPIO_CDEV_SUPPORT=0 -c src/gpio.c -o obj/gpio.o gcc -std=gnu99 -pedantic -O3 -Wall -Wextra -Wno-stringop-truncation -fPIC -DPERIPHERY_VERSION_COMMIT=\"\" -DPERIPHERY_GPIO_CDEV_SUPPORT=0 -c src/gpio_cdev_v2.c -o obj/gpio_cdev_v2.o gcc -std=gnu99 -pedantic -O3 -Wall -Wextra -Wno-stringop-truncation -fPIC -DPERIPHERY_VERSION_COMMIT=\"\" -DPERIPHERY_GPIO_CDEV_SUPPORT=0 -c src/gpio_cdev_v1.c -o obj/gpio_cdev_v1.o gcc -std=gnu99 -pedantic -O3 -Wall -Wextra -Wno-stringop-truncation -fPIC -DPERIPHERY_VERSION_COMMIT=\"\" -DPERIPHERY_GPIO_CDEV_SUPPORT=0 -c src/gpio_sysfs.c -o obj/gpio_sysfs.o gcc -std=gnu99 -pedantic -O3 -Wall -Wextra -Wno-stringop-truncation -fPIC -DPERIPHERY_VERSION_COMMIT=\"\" -DPERIPHERY_GPIO_CDEV_SUPPORT=0 -c src/led.c -o obj/led.o gcc -std=gnu99 -pedantic -O3 -Wall -Wextra -Wno-stringop-truncation -fPIC -DPERIPHERY_VERSION_COMMIT=\"\" -DPERIPHERY_GPIO_CDEV_SUPPORT=0 -c src/pwm.c -o obj/pwm.o gcc -std=gnu99 -pedantic -O3 -Wall -Wextra -Wno-stringop-truncation -fPIC -DPERIPHERY_VERSION_COMMIT=\"\" -DPERIPHERY_GPIO_CDEV_SUPPORT=0 -c src/spi.c -o obj/spi.o gcc -std=gnu99 -pedantic -O3 -Wall -Wextra -Wno-stringop-truncation -fPIC -DPERIPHERY_VERSION_COMMIT=\"\" -DPERIPHERY_GPIO_CDEV_SUPPORT=0 -c src/i2c.c -o obj/i2c.o gcc -std=gnu99 -pedantic -O3 -Wall -Wextra -Wno-stringop-truncation -fPIC -DPERIPHERY_VERSION_COMMIT=\"\" -DPERIPHERY_GPIO_CDEV_SUPPORT=0 -c src/mmio.c -o obj/mmio.o gcc -std=gnu99 -pedantic -O3 -Wall -Wextra -Wno-stringop-truncation -fPIC -DPERIPHERY_VERSION_COMMIT=\"\" -DPERIPHERY_GPIO_CDEV_SUPPORT=0 -c src/serial.c -o obj/serial.o gcc -std=gnu99 -pedantic -O3 -Wall -Wextra -Wno-stringop-truncation -fPIC -DPERIPHERY_VERSION_COMMIT=\"\" -DPERIPHERY_GPIO_CDEV_SUPPORT=0 -c src/version.c -o obj/version.o ar rcs periphery.a obj/gpio.o obj/gpio_cdev_v2.o obj/gpio_cdev_v1.o obj/gpio_sysfs.o obj/led.o obj/pwm.o obj/spi.o obj/i2c.o obj/mmio.o obj/serial.o obj/version.o make[1]: Leaving directory '/tmp/luarocks_lua-periphery-2.4.2-1-5101674/lua-periphery/c-periphery' gcc -std=c99 -pedantic -D_XOPEN_SOURCE=700 -Wall -Wextra -Wno-unused-parameter -fPIC -I. -I/usr/local/include -shared src/lua_periphery.c src/lua_mmio.c src/lua_gpio.c src/lua_led.c src/lua_pwm.c src/lua_spi.c src/lua_i2c.c src/lua_serial.c c-periphery/periphery.a -o periphery.so mkdir -p /usr/local/lib/luarocks/rocks-5.4/lua-periphery/2.4.2-1/lib cp periphery.so /usr/local/lib/luarocks/rocks-5.4/lua-periphery/2.4.2-1/lib/periphery.so lua-periphery 2.4.2-1 is now installed in /usr/local (license: MIT/X11) ```

It's clear that DPERIPHERY_GPIO_CDEV_SUPPORT in the Makefile is evaluating to 0, but I'm not sure why. I do appear to have a gpio.h file in /usr/include/linux/ with the macro and enum that are being checked for.