- Notifications
You must be signed in to change notification settings - Fork1
GPIO Driver Code in C for Raspberry Pi 4 Linux Kernel with Bit Manipulation of Values in Special Registers mapped to GPIO Pins
License
PythonHacker24/rpi-gpio-driver
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
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) kmodThe Makefile provided in the files. Use the commandmake to build the driver file.
Usemake clean for cleaning the project repository with all the files generated withmake 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.koThis will load the driver into the Kernel. For ensuring the driver is connected properly, verify it by these two commands:
sudo lsmodsudo dmesgIf the driver is loaded, it will be listed by thelsmod command. It is also recommended to check the output of thedmesg command. Thedmesg 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 byecho command. The source code ofecho command the write() system call. It is recommended to useecho with root privilages since your commands would be going into Kernel Space and hence, you require root privilages.
echo "<gpio_pin>,<state>" > /proc/maverickwheregpio_pin is the GPIO number andstate 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 underGPL-2.0 License.
About
GPIO Driver Code in C for Raspberry Pi 4 Linux Kernel with Bit Manipulation of Values in Special Registers mapped to GPIO Pins
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
