This is a GPIO Driver for Raspberry Pi 4 with Direct Memory Access to GPIO register and turning it ON/OFF. It is a /proc based driver. This is an experimental driver for controlling GPIO pins and is free to modify and distribute under GPL-2 License.
Install dependencies before compilation: (following command is for debian, use the respective package manager for your distro)
sudo apt install -y build-essential linux-headers-$(uname -r) kmod
The Makefile provided in the files. Use the command make
to build the driver file.
Use make clean
for cleaning the project repository with all the files generated with make
command.
After compilation, gpio_driver.ko
file would be generated, which is the Kernel Object file.
To load the driver into the Kernel, use the following command:
sudo insmod gpio_driver.ko
This will load the driver into the Kernel. For ensuring the driver is connected properly, verify it by these two commands:
sudo lsmod
sudo dmesg
If the driver is loaded, it will be listed by the lsmod
command. It is also recommended to check the output of the dmesg
command. The dmesg
prints the content of the Kernel Buffer which contains logs of messages generated by the drivers loaded into the kernel.
This driver is a char category of driver and works with system calls like read() and write(). For out purpose, write() system call is enough to get the command reach to the driver from user space, which can be easily attended by echo
command. The source code of echo
command the write() system call. It is recommended to use echo
with root privilages since your commands would be going into Kernel Space and hence, you require root privilages.
echo "<gpio_pin>,<state>" > /proc/maverick
where gpio_pin
is the GPIO number and state
is either 1 or 0 (ON and OFF).
The Raspberry Pi 4 is powered by BCM2711 ARM Processor. The memory address mapped with these range of processor is 0xfe200000. This drivers manipulates the values stored in this memory location and controls the GPIO Pin.
This project is licensed under GPL-2.0 License.