GPIO-Driver

What is GPIO?

A "General Purpose Input/Output" (GPIO) is a flexible software-controlled digital signal. They are provided from many kinds of chips and are familiar to Linux developers working with embedded and custom hardware.

Using GPIO Lines in Linux:-

The Linux kernel exists to abstract and present hardware to users. GPIO lines as such are normally not user-facing abstractions. The most obvious, natural, and preferred way to use GPIO lines is to let kernel hardware drivers deal with them.

Important

Key information users need to know to achieve their goals.

Raspberry Pi 3B Hardware Documentation:- image

Important

Key information users need to know to achieve their goals.

The Problem:-

When you are writing a code in user space, you are trying to access the GPIO pin you are trying to do two things illegally:-

1)Memory Boundary:- User space, we are accessing memory which is virtually translated to physical address either in RAM or physical interface. When we are accessing this without the permission of Kernel, this creates our first error.

2)Hardware Abstraction Layer:- Directly accessing the GPIO bus without talking to the hardware abstraction layer.

image

The Solution:-

We can use Drivers.

What is Driver?

Drivers are really an interface to legally cross memory boundary and legally cross hardware abstraction layer.

image

Now, we have a driver, but how does user space talk to driver to get access to kernel space?

The way to solve this is there are two types of filesystem

1)Device File:- Special file maps into the kernel.

2)Procfs File:- Meant to do more generic things, not only meant to map to particularly to single hardware interface.

Note

Useful information that users should know, even when skimming content.

So, for this project, we will use Procfs file.

In this project, I have written a code that finishes up the driver that allows a user to turn led on and off from user space via this driver's interface.

Output:-

VID-20240322-WA0000.mp4
VID-20240322-WA0001.mp4