Join the Ben Heck team every week for amazing hacks! Watch them build and mod community-inspired projects using electronics!
|The Learning Circuit|
|See All Episodes|
Felix takes us to a site (blog.gegg.us/category/foss/) that explains how you can enable the GIO matrix. To check to see if the keyboard matrix is already enabled use: $ sudo mod info matrix-keypad If you get an error, that mean s you need to recompile the kernel with it enabled. Felix demonstrates the steps how to cross compile the Linux kernel for the Raspberry Pi on an Arch Linux system. He starts by opening up the Kate program. It’s a plain text editor with a terminal attached to it. He utilizes the terminal to connect to the Raspberry Pi via SSH. The notes on are on the top pane and the terminal at the bottom is connected to the Raspberry Pi via SSH. You’ll need to download the cross-compile tools ($ git clone https://github.com/raspberry pi/tools ./tools) You’ll alsoneed to update the environment path and add the location of the compiled tools ($echo $PATH) which will add the tools path to the path variable. After adding the new path to the .bashrc file its necessary to source the .bashrc file that will refresh and update the path variable. You can view the path again to see the updated changes. Download the Linux source ($ git clone –depth=1 https://github.com/raspberrypi/linux). Felix runs through a list of things you can do while you wait for it to download.
As this is a Arch Linux system you need the ncurses installed ($ sudo pacman –S ncurses). Next, you’ll create the variable kernel to reflex the name of the desired new kernel ($ cd linux/ $ KERNAL=kernal). From the Linux source directory prepare the .config file. After preparing the .config file, you will need to open up the mini config and select the proper modules to compile. Make the menu config and select the proper options. Enable the keypad GPIO matrix and enable USB drivers. Navigate to: device drivers >> input device drivers >> keyboards >> GPIO driven matrix keypad support Save and exit. You’ll also need to enable some USB modules. He goes into the USB options and checks some of those. After checking the USB drives he saves and completes the configuration file. Felix starts the compile ($ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf - zImage modules dtbs –j 8). The magic argument in this sauce is -j 8. The –j 8 flag enables multi-thread compiling to reduce compile time. Next, Felix takes the newly compiled kernel and all the support files and transfers them over to the SD card. He’ll need to mount the SD card and then copy the files over. He lists the block devices ($ lsblk) and then mounts the sd card ($sudo mount /dev/ssd1 ../../Mount/boot) which is boot partition to the mount point he’s created in the filesystem. Once the boot partition is mounted you can list the directory ($ ls ../../Mount/boot/ ) and does the same for the root ($ ls ../Mount/root/). Next, he installs the modules with the make instruction ($sudo make ARCH=arm CROSS_COMPILE=arm -linux -gnueabihf – INSTALL_MOD_PATH=../ ../ ../Mount / root modules_install). Felix makes a backup of the stock image that came with the operating system ($ sudo cp ../../ ../Mount/boot/$KERNEL.img ../../ ../Mount/boot/$KERNEL -backup.img). He then copies the Z image to the boot directory.
He names the kernel he wants to boot into($ sudo cp ../ ../ ../Mount/boot/$KERNEL.img ../ ../ ../Mount/boot/$KERNEL-backup.img). He then copies the compiled device tree files to the boot directory. He also modifies the .config file so that when the Raspberry Pi boots, it loads the modified kernel. He does this by adding a line (kernel=kernel –gpio-matrix.img). Once you unmount the partitions you’ll be able to boot into the Raspberry Pi with the new kernel without getting an error. Felix shows you how to create the GPIO matix .DTS file and compile it. You can do this by referencing the TFT connections and finding the GPIO pins to use. He also shows you a reference to all the connections that have been made. She shows you the lines that define the GPIO rows and columns to use for the matrix. The next section defines the key map. It has a hex code that relates to a column, a row, and a Linux key code that we want it to represent. The code of the input key comes from the Linux keyboard.h file or the input-event-codes .h file. Felix transfers the source file and a compile script onto the Raspberry Pi. He compiles into the device tree overlay directory. He adds the device tree overlay to the config.txt file. He reboots to check to see if the button matrix is functional. He’ll need to invoke LS input which requires installing the input utilities package ($ sudo apt –get install input -utils). This will list the devices connected to the GPIO matrix. You can now see the results of key presses with input events and the event number zero. Now events happen when the key is pressed. Felix creates a UDEV rule to prevent the GPIO kernel matrix from conflicting with the SDL library used to make the emulator.