Optimize fbcp driver for raspberry pi handheld SPI display
What I use
I use a waveshare 2 inch spi display for my raspberry pi 3A+ text mode handheld computer, with 32bit raspberry pi os
as waveshare official document says I wired it to raspberry pi as this
I use FBCP driver with recommended install method
Problems
- default TX & RX channels not working
- the spi display will suspend / freeze in an interval of sometime
- the object has blur, when the object in display is moving
Solutions
solve TX & RX channels issue
2 inch display install script file: Waveshare_fbcp/shell/waveshare-2inch
j=$(uname -n)
b=$(getconf LONG_BIT)
echo "The operating system :$j $b bit"
if test "$j" = "raspberrypi";then
if [ -d "/home/pi/Waveshare_fbcp/build" ]; then
sudo rm -rf /home/pi/Waveshare_fbcp/build
fi
mkdir /home/pi/Waveshare_fbcp/build
sudo apt update
sudo apt install cmake -y
sudo apt install unzip -y
if test "$b" = "32";then
sudo cp /home/pi/Waveshare_fbcp/shell/boot/32/waveshare-2inch.txt /boot/config.txt
else
sudo cp /home/pi/Waveshare_fbcp/shell/boot/64/waveshare-2inch.txt /boot/config.txt
fi
sudo cp /home/pi/Waveshare_fbcp/shell/etc/rc.local /etc/rc.local
cd /home/pi/Waveshare_fbcp/build
sudo cmake -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_2INCH_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 ..
sudo make -j
if [ -x "/usr/local/bin/fbcp" ]; then
sudo rm -rf /usr/local/bin/fbcp
fi
sudo cp ./fbcp /usr/local/bin/fbcp
echo "The system is configured."
echo "The system will restart."
sudo reboot
else
echo "The shell only works with RaspberryPi"
fi
I change the sudo cmake line as below:
sudo cmake -DWAVESHARE_2INCH_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 -DDMA_TX_CHANNEL=10 -DDMA_RX_CHANNEL=5 ..
I add -DDMA_TX_CHANNEL=10 -DDMA_RX_CHANNEL=5, this will specify TX use channel 10, RX use channel 5.
solve display suspend / freeze
In the driver code file: Waveshare_fbcp/src/config/config.h
// If less than this much % of the screen changes per frame, the screen is considered to be inactive, and
// the display backlight can automatically turn off, if TURN_DISPLAY_OFF_AFTER_USECS_OF_INACTIVITY is
// defined.
#define DISPLAY_CONSIDERED_INACTIVE_PERCENTAGE (5 / 100.0)
this means, if the screen change pixels less than 5%, then the display back light will turn off, and, that will be often happened in a linux terminal situation.
so, I change it as below:
// If less than this much % of the screen changes per frame, the screen is considered to be inactive, and
// the display backlight can automatically turn off, if TURN_DISPLAY_OFF_AFTER_USECS_OF_INACTIVITY is
// defined.
#define DISPLAY_CONSIDERED_INACTIVE_PERCENTAGE (0.001 / 100.0)
this will keep the display always active.
solve moving object blur
2 inch display install script file: Waveshare_fbcp/shell/waveshare-2inch
j=$(uname -n)
b=$(getconf LONG_BIT)
echo "The operating system :$j $b bit"
if test "$j" = "raspberrypi";then
if [ -d "/home/pi/Waveshare_fbcp/build" ]; then
sudo rm -rf /home/pi/Waveshare_fbcp/build
fi
mkdir /home/pi/Waveshare_fbcp/build
sudo apt update
sudo apt install cmake -y
sudo apt install unzip -y
if test "$b" = "32";then
sudo cp /home/pi/Waveshare_fbcp/shell/boot/32/waveshare-2inch.txt /boot/config.txt
else
sudo cp /home/pi/Waveshare_fbcp/shell/boot/64/waveshare-2inch.txt /boot/config.txt
fi
sudo cp /home/pi/Waveshare_fbcp/shell/etc/rc.local /etc/rc.local
cd /home/pi/Waveshare_fbcp/build
sudo cmake -DSPI_BUS_CLOCK_DIVISOR=20 -DWAVESHARE_2INCH_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 ..
sudo make -j
if [ -x "/usr/local/bin/fbcp" ]; then
sudo rm -rf /usr/local/bin/fbcp
fi
sudo cp ./fbcp /usr/local/bin/fbcp
echo "The system is configured."
echo "The system will restart."
sudo reboot
else
echo "The shell only works with RaspberryPi"
fi
I change the sudo cmake line as below, it include the TX & RX changes:
sudo cmake -DSPI_BUS_CLOCK_DIVISOR=6 -DWAVESHARE_2INCH_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 -DDMA_TX_CHANNEL=10 -DDMA_RX_CHANNEL=5 -DARMV8A=ON ..
I add -DSPI_BUS_CLOCK_DIVISOR=6 and -DARMV8A=ON, this will increase the bandwidth, make the frame more smooth.
according to the fbcp github README:
the final Waveshare_fbcp/shell/waveshare-2inch will look like this, include all I changed:
j=$(uname -n)
b=$(getconf LONG_BIT)
echo "The operating system :$j $b bit"
if test "$j" = "raspberrypi";then
if [ -d "/home/pi/Waveshare_fbcp/build" ]; then
sudo rm -rf /home/pi/Waveshare_fbcp/build
fi
mkdir /home/pi/Waveshare_fbcp/build
sudo apt update
sudo apt install cmake -y
sudo apt install unzip -y
if test "$b" = "32";then
sudo cp /home/pi/Waveshare_fbcp/shell/boot/32/waveshare-2inch.txt /boot/config.txt
else
sudo cp /home/pi/Waveshare_fbcp/shell/boot/64/waveshare-2inch.txt /boot/config.txt
fi
sudo cp /home/pi/Waveshare_fbcp/shell/etc/rc.local /etc/rc.local
cd /home/pi/Waveshare_fbcp/build
sudo cmake -DSPI_BUS_CLOCK_DIVISOR=6 -DWAVESHARE_2INCH_LCD=ON -DBACKLIGHT_CONTROL=ON -DSTATISTICS=0 -DDMA_TX_CHANNEL=10 -DDMA_RX_CHANNEL=5 -DARMV8A=ON ..
sudo make -j
if [ -x "/usr/local/bin/fbcp" ]; then
sudo rm -rf /usr/local/bin/fbcp
fi
sudo cp ./fbcp /usr/local/bin/fbcp
echo "The system is configured."
echo "The system will restart."
sudo reboot
else
echo "The shell only works with RaspberryPi"
fi