Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

GPIO Driver Code in C for Raspberry Pi 4 Linux Kernel with Bit Manipulation of Values in Special Registers mapped to GPIO Pins

License

NotificationsYou must be signed in to change notification settings

PythonHacker24/rpi-gpio-driver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

White Minimalist Profile LinkedIn Banner (1)

Introduction

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.

Compiling

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 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.

Loading the Driver

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 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.

Using the GPIO Driver

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/maverick

wheregpio_pin is the GPIO number andstate is either 1 or 0 (ON and OFF).

Theory: How it's Done

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.

License

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

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp