Setting up an LCD display for the Raspberry Pi using the Yocto Project

There exist a number of different LCD displays for the Raspberry Pi. Among the most popular are the official Raspberry Pi 7 touchscreen and the PiTFT displays (often called PiTFT Hats, since they are suitable to mount on top of the Raspberry Pi). For now, we will focus on the Raspberry Pi 7 touchscreen and the PiTFT models.

In this section, we will go through how to boot a standard Yocto Project image, containing a window system and a working touchscreen.

The Raspberry Pi 7 touchscreen

Getting started with the Raspberry Pi 7 touchscreen using an image based on the Yocto Project requires quite a few configurations. First, we need to ensure we are using a 4.1+ kernel. Starting from the jethro release of meta-raspberrypi, 4.1 is the default version. Currently, meta-raspberrypi lacks full support for the Raspberry Pi 7 touchscreen, so we need to perform some small modifications before booting our image.

Note

Build instructions for the Raspberry Pi 7 touchscreen can be found at https://www.adafruit.com/images/product-files/2718/2718build.jpg . The display will work with Raspberry Pi A/B boards; however, the mounting holes on the back of the display will only line up with A+, B+, and Raspberry Pi 2/3.

If using the default meta-raspberrypi settings, we will have a supported kernel with all the required configuration options enabled by default. To be extra safe, you can go through the previous part of this chapter to ensure that the kernel is correctly configured for your display. With this in mind, we can start by creating a new project:

$ source /path/to/poky/oe-init-build-env my_project

Next, we can continue with the normal procedure and add external layers required for building Raspberry Pi images with Yocto:

$ cat local/bblayers.conf
# LAYER_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
LCONF_VERSION = "6"
BBPATH = "${TOPDIR}"
BBFILES ?= ""
BBLAYERS ?= " 
  /path/to/poky/meta 
  /path/to/poky/meta-yocto 
  /path/to/poky/meta-yocto-bsp 
  /path/to/meta-raspberrypi 
  /path/to/meta-openembedded/meta-oe 
  /path/to/meta-openembedded/meta-multimedia 
"
BBLAYERS_NON_REMOVABLE ?= " 
  /path/to/poky/meta 
  /path/to/poky/meta-yocto 

Note

If you haven't cloned the openembedded layers for the earlier examples in the book, it can be done with this command: $ git clone git://git.openembedded.org/meta-openembedded

We also need to make some modifications to local.conf:

$ echo "MACHINE = "raspberrypi"" >> conf/local.conf (Or MACHINE=raspberrypi2)
$ echo "LICENSE_FLAGS_WHITELIST = "commercial"" >> conf/local.conf

After this, we are ready to start a new build. By default, meta-raspberrypi will ensure that, for example, input devices for the touchscreen, together with appropriate udev rules, are set up for the touchscreen. These settings will be applied seamlessly during the build:

$ bitbake core-image-sato

Once the SD card has been prepared with the new image, we also need to ensure that all required drivers are loaded for the touchscreen. This can be done by adding this line to the end of config.txt, which is located in the boot partition of the SD card:

$ echo "dtoverlay=rpi-ft5406" >> /path/to/sdcard/boot/config.txt

Now, you're ready to rock and will be able to boot a window system with touch support using your Raspberry Pi 7 touchscreen.

The Raspberry Pi 7 touchscreen
A Raspberry Pi 7 touchscreen running core-image-sato

The PiTFT 2.8 resistive touchscreen

Native support for PiTFT displays in meta-raspberrypi is fairly new. Check whether your PiTFT model is supported by looking at the readme file for meta-raspberrypi, under the Enable PiTFT support section"".

PiTFT support is configurable for any existing (or customized) Raspberry Pi image using the Yocto Project. The support has been added as MACHINE_FEATURES in meta-raspberrypi. The MACHINE_FEATURES variable is a standard Yocto Project feature, which can be used to add hardware features for the target your are building for. There exists a set of predefined MACHINE_FEATURES features in the Yocto Project, which includes Wi-Fi, keyboard, Alsa, and Bluetooth, among others. In the Raspberry Pi BSP layer, a couple of these are enabled by default:

$ grep "MACHINE_FEATURES " conf/machine/include/rpi-base.inc
MACHINE_FEATURES += "kernel26 apm usbhost keyboard vfat ext2 screen touchscreen alsa bluetooth wifi sdio"

PiTFT support will require two new MACHINE_FEATURES features: a generic one called pitft and a model-specific version. In this example, we will be using pitft28r, which corresponds to the PiTFT 2.8 resistive touchscreen. The simplest way to add the new MACHINE_FEATURES features is by adding them to the local configuration file within your project:

$ cd /path/to/my/rpi/project
$ echo "MACHINE_FEATURES += "pitft pitft28r"" >> conf/local.conf

This will add support for either running a console-based image or a window-system image. The pitft feature will, under the hood, ensure that SPI and i2c are enabled. It will also configure the framebuffer for handling the PiTFT display (change from /dev/fb0 to /dev/fb1). The model-specific machine feature (pitft28r in this example) will add the model-specific device tree overlay to config.txt, set up proper configurations for the screen (such as orientation and speed), and ensure that the stmpe module needed for the touch functionality is loaded. It will also add some default calibration data for the touchscreen. When the MACHINE_FEATURES features are set up, we can build our image, load it on the SD card, and boot:

$ bitbake core-image-sato

The PiTFT 2.8 resistive touchscreen
The PiTFT 2.8 resistive touchscreen running core-image-sato

When you boot your Raspberry Pi, the LCD will turn white at first. After a short while, it should turn black again-this means that the kernel has recognized the screen. Shortly after, you should be up and running with a window system. The "2.8" screen is quite small, but it's possible to use the virtual keyboard in order to write, for example, simple commands in the terminal. The touchscreen has been calibrated for you using default values, suitable for your screen and rotation. If you find the default calibration insufficient, for example, if you wish to change the display orientation (90 degrees by default), you can recalibrate it using, for example, ts_calibrate.

Note

ts_calibrate is part of the tslib recipe in Poky. It's included by default when building core-image-sato, and it can easily be added to a custom image by specifying MACHINE_FEATURES += "touchscreen"

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.28.50