CPC GPIO Driver#
The CPC GPIO Driver is a component part of the CPC GPIO Expander and acts as a backend for the Linux GPIO subsystem and as a frontend for the CPC GPIO Bridge.
Table of Contents#
Installation
Kernel headers
Raspbian
Ubuntu
Other distributions
Building
Loading (Manual)
Loading (Automatic)
Debugging
Enable logging
Installation#
Kernel headers#
This driver has been tested under v5.10 - v6.1 and may or may not be compatible with newer releases of the Linux Kernel.
Raspbian#
On Raspbian, the package manager only fetches the latest kernel headers.
This means you must keep your OS up to date to match the running kernel version:
sudo apt update, sudo apt dist-upgrade -y and reboot.
And then fetch the latest kernel headers:
sudo apt install raspberrypi-kernel-headers
If you do not wish to update your OS, you can manually download old kernel headers and install them:
sudo apt install raspberrypi-kernel-headers_xxxx_xxxx.deb
The matching tag release/kernel version can be determined in different ways.
Ubuntu#
On Ubuntu, you can fetch the current kernel headers matching your currently running kernel:
sudo apt install linux-headers-$(uname -r)
Other distributions#
Other distributions should have similar ways of acquiring their kernel headers but might use different package managers.
Building#
Invoke make to build the driver:
make
This generates a kernel module (cpc_gpio.ko) which can then be loaded manually (see Loading (Manual) below) or automatically (see Loading (Automatic) below).
Loading (Manual)#
This step manually loads the driver, meaning it will not be running after a reboot:
sudo insmod cpc_gpio.ko
You may then unload the driver:
sudo rmmod cpc-gpio
Or simply reboot.
Loading (Automatic)#
These steps ensures the driver loads on subsequent boots:
Copy driver to appropriate folder:
cp `pwd`/cpc_gpio.ko /lib/modules/`uname -r`/kernel/drivers/gpio
Generate dependencies:
sudo depmod
Add the driver to be loaded at boot time and reboot:
echo "cpc-gpio" | sudo tee -a /etc/modules
You may then unload the driver and remove it from subsequents boots:
sudo rmmod cpc-gpio
Then remove cpc-gpio from /etc/modules and reboot.
Optionally, you may also remove cpc_gpio.ko from /lib/modules/`uname -r`/kernel/drivers/gpio but it is not required.
Debugging#
Enable logging#
In the Kbuild file, add the following DEBUG flag:
EXTRA_CFLAGS := -DDEBUG
Rebuild and reload the driver.
Run dmesg.
You should see debugging logs during GPIO transactions.