Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Development

notro edited this page Aug 25, 2013 · 35 revisions

This is a step-by-step guide showing how to add and compile a new FBTFT driver in 30 minutes.

This doesn't work with the rpi-update release

This guide can also be used to get the latest driver update, if a new image hasn't been released yet. Follow the guide and skip the example driver.

If you want to contribute code, see Submitting patches

Boot with latest FBTFT image.

Expand root file system size.

sudo raspi-config
# expand_rootfs

Install dependencies

sudo apt-get update
sudo apt-get -y install git libncurses5-dev

Samba (optional)

Samba can be used to aid development on the Pi.

sudo apt-get -y install samba samba-common-bin

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.org


sudo sed -i '/ Share Definitions /q' /etc/samba/smb.conf
cat <<EOF | sudo tee -a /etc/samba/smb.conf

[homes]
   comment = Home Directories
   browseable = no
   read only = no
   create mask = 0644
   directory mask = 0755
   valid users = %S

EOF
sudo service samba restart
sudo smbpasswd -a pi

Home directory for user pi will be available at \\xxx.xxx.xxx.xxx\pi

Source

We don't need the complete git history (--depth 1). This will speed things up considerly.

cd
git clone --depth 1 git://github.com/raspberrypi/linux.git

fbtft source

cd ~/linux/drivers/video/
git clone https://github.com/notro/fbtft.git

# Let make/kbuild see the directory and config options.
echo "obj-y += fbtft/" >> Makefile
sed -i 's/endmenu/source "drivers\/video\/fbtft\/Kconfig"\n\nendmenu/' Kconfig

Preparation

cp ~/extra/{.config,Module.symvers} ~/linux/
cd ~/linux
make prepare scripts

Build

Lets make sure it builds before we start changing things.

This can be run from any directory

make -C /lib/modules/$(uname -r)/build SUBDIRS=drivers/video/fbtft modules

If config asks if it should build FB drivers, answer m for module.

If you are just building the latest source and not adding a driver or display, skip to Install

Example driver: fb_hello

This shows how to add a new driver for the Hello LCD Controller.

Add to ~/linux/drivers/video/fbtft/Kconfig

config FB_TFT_HELLO
        tristate "Example FBTFT driver"
        depends on FB_TFT

Add to ~/linux/drivers/video/fbtft/Makefile

obj-$(CONFIG_FB_TFT_HELLO)       += fb_hello.o

Create ~/linux/drivers/video/fbtft/fb_hello.c

/*
 * Copyright and GPL statement
*/
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/delay.h>

#include "fbtft.h"

#define DRVNAME		"fb_hello"
#define WIDTH		128
#define HEIGHT		128

static int init_display(struct fbtft_par *par)
{
	fbtft_par_dbg(DEBUG_INIT_DISPLAY, par, "%s()\n", __func__);

	printk("Hello World");

	return 0;
}

static void set_addr_win(struct fbtft_par *par, int xs, int ys, int xe, int ye)
{
	fbtft_par_dbg(DEBUG_SET_ADDR_WIN, par,
		"%s(xs=%d, ys=%d, xe=%d, ye=%d)\n", __func__, xs, ys, xe, ye);

}

static struct fbtft_display display = {
	.regwidth = 8,
	.width = WIDTH,
	.height = HEIGHT,
	.fbtftops = {
		.init_display = init_display,
		.set_addr_win = set_addr_win,
	},
};
FBTFT_REGISTER_DRIVER(DRVNAME, &display);

/*
    This makes the driver autoload if the device is present
    modprobe will load it from /lib/modules and not the build directory
	If your driver changes doesn't come into effect, this could be why
*/
MODULE_ALIAS("spi:" DRVNAME);
MODULE_ALIAS("platform:" DRVNAME);

MODULE_DESCRIPTION("FB driver for the Hello LCD Controller");
MODULE_AUTHOR("Me");
MODULE_LICENSE("GPL");

Example display: hello

This shows how to add a device for the Hello 1.5 inch display, which uses the SPI bus.

Add to static struct fbtft_device_display displays[] in file ~/linux/drivers/video/fbtft/fbtft_device.c

	}, {
		.name = "hello15",
		.spi = &(struct spi_board_info) {
			.modalias = "fb_hello",
			.max_speed_hz = 32000000,
			.mode = SPI_MODE_0,
			.platform_data = &(struct fbtft_platform_data) {
				.display = {
					.buswidth = 8,
				},
				.bgr = true,
				.gpios = (const struct fbtft_gpio []) {
					{ "reset", 25 },
					{ "dc", 24 },
					{},
				},
			}
		}

Configure

Start kernel configuration program

cd ~/linux
make menuconfig

Enable fb_hello

Device Drivers  ---> Graphics support  --->  Support for small TFT LCD display modules  --->

<M>   Example FBTFT driver
make prepare

Now rerun the previous build step.

Test

sudo dmesg -C
sudo modprobe fbtft
sudo insmod ~/linux/drivers/video/fbtft/fb_hello.ko
sudo insmod ~/linux/drivers/video/fbtft/fbtft_device.ko name=hello15 debug=3
dmesg
fbtft_device:  SPI devices registered:
fbtft_device:      spidev spi0.1 500kHz 8 bits mode=0x00
fbtft_device:  'fb' Platform devices registered:
fbtft_device:      bcm2708_fb id=-1 pdata? no

fb_hello spi0.0: fbtft_request_gpios: 'reset' = GPIO25
fb_hello spi0.0: fbtft_request_gpios: 'dc' = GPIO24
fb_hello spi0.0: fbtft_verify_gpios()
fb_hello spi0.0: init_display()
Hello World
fb_hello spi0.0: Elapsed time for display update:   21.914092 ms (fps: 45, lines=128)
graphics fb1: fb_hello frame buffer, 128x128, 32 KiB video memory, 4 KiB buffer memory, fps=20, spi0.0 at 32 MHz

fbtft_device:  GPIOS used by 'hello15':
fbtft_device:    'reset' = GPIO25
fbtft_device:    'dc' = GPIO24
fbtft_device:  SPI devices registered:
fbtft_device:      spidev spi0.1 500kHz 8 bits mode=0x00
fbtft_device:      fb_hello spi0.0 32000kHz 8 bits mode=0x00
sudo rmmod fb_hello fbtft_device fbtft

Install

# install the new driver
sudo cp /lib/modules/$(uname -r)/build/drivers/video/fbtft/{fbtft_device.ko,fb_hello.ko} /lib/modules/$(uname -r)/kernel/drivers/video/fbtft/
sudo depmod

# update all drivers/modules
sudo cp -v /lib/modules/$(uname -r)/build/drivers/video/fbtft/*.ko /lib/modules/$(uname -r)/kernel/drivers/video/fbtft/
sudo depmod
sudo modprobe fbtft_device name=hello15 debug=3

Submitting patches

I you want me to include your driver, follow these rules:

  • The license the code is released under has to be GPL version 2 or later. Add this information at the top of the file.

  • Agree with the Developer's Certificate of Origin 1.1 (12. Sign your work)

  • Follow the Linux kernel coding style
    Use linux/scripts/checkpatch.pl --file fb_xxx.c to verify your code.
    Lines can exceed 80 columns if the meaning is hard to grasp when breaking up the line. Never exceed 132 columns.

  • Make an issue and include your driver in a code block for review.

  • When the driver is approved, I can just copy the code from the issue, or you can make a pull request with just one commit in it. If I commit the driver directly from the issue, a Signed-off-by line will be added to the commit message to credit the author.

Except for trivial patches, make an issue first before making a pull request too see if I agree with you. Only one fix/feature per commit and vice versa. I can commit simple changes directly from an issue, a pull request is not needed.

Kernel messages in SSH session

When doing development and testing from a SSH session, it's nice to see the that kernel panic message before everything freezes.

Make file /etc/rsyslog.d/kern_pi.conf with contents:

kern.err  pi

This will show kernel error messages and worse when user pi is logged in.

service rsyslog restart

piwik

Clone this wiki locally