-
Notifications
You must be signed in to change notification settings - Fork 495
Development
This is a step-by-step guide showing how to add and compile a new FBTFT driver in 30 minutes.
First check if flexfb can be used.
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.
Boot with latest FBTFT image.
Expand root file system size.
sudo raspi-config
# expand_rootfs
sudo apt-get update
sudo apt-get -y install git libncurses5-dev
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
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
cp ~/extra/.config ~/linux/
cp ~/extra/Module.symvers ~/linux/
cd ~/linux
make prepare scripts
This shows how to add a new driver.
Add to ~/linux/drivers/video/fbtft/Kconfig
config FB_HELLO
tristate "Example FBTFT driver"
depends on FB_TFT
Add to ~/linux/drivers/video/fbtft/Makefile
obj-$(CONFIG_FB_HELLO) += hellofb.o
Add to static struct spi_board_info fbtft_device_spi_displays[] in file ~/linux/drivers/video/fbtft/fbtft_device.c
}, {
.modalias = "hellofb",
.max_speed_hz = 32000000,
.mode = SPI_MODE_0,
.platform_data = &(struct fbtft_platform_data) {
.gpios = (const struct fbtft_gpio []) {
{ "reset", 25 },
{},
},
}
Create ~/linux/drivers/video/fbtft/hellofb.c
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/gpio.h>
#include <linux/spi/spi.h>
#include <linux/delay.h>
#include "fbtft.h"
#define DRVNAME "hellofb"
#define WIDTH 128
#define HEIGHT 160
/* Module Parameter: debug (also available through sysfs) */
MODULE_PARM_DEBUG;
static int hellofb_init_display(struct fbtft_par *par)
{
fbtft_dev_dbg(DEBUG_INIT_DISPLAY, par->info->device, "%s()\n", __func__);
printk("Hello World");
return 0;
}
struct fbtft_display hellofb_display = {
.width = WIDTH,
.height = HEIGHT,
};
static int hellofb_probe(struct spi_device *spi)
{
struct fb_info *info;
struct fbtft_par *par;
int ret;
fbtft_dev_dbg(DEBUG_DRIVER_INIT_FUNCTIONS, &spi->dev, "%s()\n", __func__);
info = fbtft_framebuffer_alloc(&hellofb_display, &spi->dev);
if (!info)
return -ENOMEM;
par = info->par;
par->spi = spi;
fbtft_debug_init(par);
par->fbtftops.init_display = hellofb_init_display;
ret = fbtft_register_framebuffer(info);
if (ret < 0)
goto out_release;
return 0;
out_release:
fbtft_framebuffer_release(info);
return ret;
}
static int hellofb_remove(struct spi_device *spi)
{
struct fb_info *info = spi_get_drvdata(spi);
fbtft_dev_dbg(DEBUG_DRIVER_INIT_FUNCTIONS, &spi->dev, "%s()\n", __func__);
if (info) {
fbtft_unregister_framebuffer(info);
fbtft_framebuffer_release(info);
}
return 0;
}
static struct spi_driver hellofb_driver = {
.driver = {
.name = DRVNAME,
.owner = THIS_MODULE,
},
.probe = hellofb_probe,
.remove = hellofb_remove,
};
static int __init hellofb_init(void)
{
fbtft_pr_debug("\n\n"DRVNAME": %s()\n", __func__);
return spi_register_driver(&hellofb_driver);
}
static void __exit hellofb_exit(void)
{
fbtft_pr_debug(DRVNAME": %s()\n", __func__);
spi_unregister_driver(&hellofb_driver);
}
/* ------------------------------------------------------------------------- */
module_init(hellofb_init);
module_exit(hellofb_exit);
MODULE_DESCRIPTION("Example FBTFT driver");
MODULE_AUTHOR("Noralf Tronnes");
MODULE_LICENSE("GPL");
Start kernel configuration program
cd ~/linux
make menuconfig
Enable hellofb
Device Drivers ---> Graphics support ---> Support for small TFT LCD display modules --->
<M> Example FBTFT driver
make prepare
This can be run from any directory
make -C /lib/modules/$(uname -r)/build SUBDIRS=drivers/video/fbtft modules
sudo dmesg -C
sudo modprobe fbtft
sudo insmod ~/linux/drivers/video/fbtft/fbtft_device.ko name=hellofb
sudo insmod ~/linux/drivers/video/fbtft/hellofb.ko 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
fbtft_device: GPIOS used by 'hellofb':
fbtft_device: 'reset' = GPIO25
fbtft_device: SPI devices registered:
fbtft_device: spidev spi0.1 500kHz 8 bits mode=0x00
fbtft_device: hellofb spi0.0 32000kHz 8 bits mode=0x00
hellofb: hellofb_init()
hellofb spi0.0: hellofb_probe()
hellofb spi0.0: fbtft_request_gpios: 'reset' = GPIO25
hellofb spi0.0: hellofb_init_display()
hellofb spi0.0: Elapsed time for display update: 16.561898 ms (fps: 60, lines=160)
graphics fb1: hellofb frame buffer, 40 KiB video memory, 4 KiB buffer memory, fps=20, spi0.0 at 32 MHz
sudo rmmod hellofb fbtft_device
# install the new driver
sudo cp /lib/modules/$(uname -r)/build/drivers/video/fbtft/fbtft_device.ko /lib/modules/$(uname -r)/kernel/drivers/video/fbtft/
sudo cp /lib/modules/$(uname -r)/build/drivers/video/fbtft/hellofb.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=hellofb
sudo modprobe hellofb debug=3
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