FBTFT on Raspian - notro/fbtft GitHub Wiki

These are some recommendations when using FBTFT on Raspian

Where to display X windows

Raspian is hardwired to use /dev/fb0 for X windows.

Options:

Install custom configuration:

sudo mkdir -p /etc/X11/xorg.conf.d/
sudo wget https://gist.github.com/notro/63fc8f563b5f85010d30/raw/5e68d6c6df9471f973b3da5305e73a5017590a69/fbtft.conf -O /etc/X11/xorg.conf.d/fbtft.conf

Some more xorg config related info: https://github.com/notro/fbtft-spindle/wiki/Appendix

Displays with a touchpanel

Some displays have a touchpanel which needs some configuration.

X windows touch calibration

xinput-calibrator provides a way to calibrate the touchpanel for X windows use.

Install

cd /tmp
wget http://tronnes.org/downloads/xinput-calibrator_0.7.5-1_armhf.deb
sudo dpkg -i -B xinput-calibrator_0.7.5-1_armhf.deb
rm xinput-calibrator_0.7.5-1_armhf.deb

Configure xinput-calibrator to autostart with X windows.

sudo wget -O /etc/X11/Xsession.d/xinput_calibrator_pointercal https://raw.github.com/tias/xinput_calibrator/master/scripts/xinput_calibrator_pointercal.sh
echo "sudo /bin/sh /etc/X11/Xsession.d/xinput_calibrator_pointercal" | sudo tee -a /etc/xdg/lxsession/LXDE-pi/autostart

On first start of X windows a calibration window will be displayed.

startx

Delete /etc/pointercal.xinput to recalibrate.

Touch panel rotation
xinput-calibrator doesn't handle touchpanels with X/Y swapped.
If your calibration results in swapped axis, add the config file that matches your touch controller.

/etc/X11/xorg.conf.d/99-ads7846-cal.conf

Section "InputClass"
        Identifier      "calibration"
        MatchProduct    "ADS7846 Touchscreen"
        Option  "SwapAxes"      "1"
EndSection

/etc/X11/xorg.conf.d/99-stmpe-cal.conf

Section "InputClass"
        Identifier      "calibration"
        MatchProduct    "stmpe-ts"
        Option  "SwapAxes"      "1"
EndSection

Ref:

tslib (SDL, pygame)

tslib is used by some non X windows applications and frameworks.

Input devices get a device name which depends on the order of detection (/dev/input/eventX).

These udev rules will create a symlink /dev/input/touchscreen pointing to the touch controller device. Use the one matching your touch controller. There is no harm in adding both. Reloading the driver or rebooting is necessary for the change to take effect.

/etc/udev/rules.d/95-ads7846.rules

SUBSYSTEM=="input", KERNEL=="event[0-9]*", ATTRS{name}=="ADS7846*", SYMLINK+="input/touchscreen"

/etc/udev/rules.d/95-stmpe.rules

SUBSYSTEM=="input", ATTRS{name}=="stmpe-ts", ENV{DEVNAME}=="*event*", SYMLINK+="input/touchscreen"

Install tslib

sudo apt-get install -y tslib libts-bin

# install ts_test with Quit button
sudo wget -O /usr/bin/ts_test http://tronnes.org/downloads/ts_test
sudo chmod +x /usr/bin/ts_test

Set environment variables and let them pass through when using sudo

# tslib environment variables

cat <<EOF | sudo tee /etc/profile.d/tslib.sh
export TSLIB_TSDEVICE=/dev/input/touchscreen
export TSLIB_FBDEVICE=/dev/fb1
EOF

cat <<EOF | sudo tee /etc/sudoers.d/tslib
Defaults env_keep += "TSLIB_TSDEVICE TSLIB_FBDEVICE"
EOF

sudo chmod 0440 /etc/sudoers.d/tslib


# SDL environment variables

cat <<EOF | sudo tee /etc/profile.d/sdl.sh
export SDL_VIDEODRIVER=fbcon
export SDL_FBDEV=/dev/fb1
if [ -e /dev/input/touchscreen ](/notro/fbtft/wiki/--e-/dev/input/touchscreen-); then
	export SDL_MOUSEDRV=TSLIB
	export SDL_MOUSEDEV=/dev/input/touchscreen
fi
EOF

cat <<EOF | sudo tee /etc/sudoers.d/sdl
Defaults env_keep += "SDL_VIDEODRIVER SDL_FBDEV SDL_MOUSEDRV SDL_MOUSEDEV"
EOF

sudo chmod 0440 /etc/sudoers.d/tslib

Re-login to set the environment variables.

Calibrate

sudo ts_calibrate

Test

sudo ts_test

Framebuffer copy

The FBTFT drivers does not provide any hardware accelaration. It is possible to let the application use /dev/fb0 and then sync this framebuffer with /dev/fb1 using tasanakorn's rpi-fbcp.

Build and install

sudo apt-get install -y cmake
git clone https://github.com/tasanakorn/rpi-fbcp
mkdir -p rpi-fbcp/build
cd rpi-fbcp/build
cmake ..
make
sudo install fbcp /usr/local/bin/fbcp

Install service

sudo wget -O /etc/init.d/fbcp https://gist.github.com/notro/eac0fec51cac67bb99c7/raw/4804a36459db10b17d35451d98d4573a045084be/fbcp
sudo chmod +x /etc/init.d/fbcp
sudo update-rc.d fbcp defaults

More: https://github.com/notro/fbtft-spindle/wiki/FBTFT-image#fbcp---framebuffer-copy

Troubleshooting

evtest can be used to see lowlevel touch events (and keyboard/mouse)

sudo apt-get install -y evtest

Some more info can be gleaned from this: https://github.com/notro/fbtft-spindle/wiki/FBTFT-image