Fbtft with Beaglebone Black

From eLinux.org
Jump to: navigation, search

fbtft is 'Linux Framebuffer drivers for small TFT LCD display modules.' which supports several small LCDs which are driven by SPI bus.This page describes how to use this device driver.

Hardware Configuration

As an example, we use this LCD which is driven by ST7735R lcd driver. Please connect the LCD with BBB as following table:

LCD BBB
NAME PIN#
LED 3.3V P9_03
SCK SCLK P9_22
SDA MOSI P9_18
A0 GPIO1_28 P9_12
RESET GPIO1_16 P9_15
CS CS P9_17
GND GND P9_01
VCC 5V P9_05


BSP Build & Install

This page shows very detailed description of how to build and install BSP for BBB including U-boot, Linux kernel and distributions. Build & install all of them!

You should fully understand how to build and install the things, especially for the Linux kernel to continue.

Device Tree Description

In this example, we don't use device tree overlay. Instead, we append what we need to the device tree source that will be loaded at boot time.

Please edit the bb-kernel/KERNEL/arch/arm/boot/dts/am335x-boneblack.dts like followings:

PINMUX description for SPI0

Append following code to pinmuxing section:

1 spi0_pins:spi0_pins{
2 	pinctrl-single,pins = <
3 		AM33XX_IOPAD(0x95c, PIN_OUTPUT_PULLUP | MUX_MODE0)			/* P9_17, 87, SPI0_CS0 */
4 		AM33XX_IOPAD(0x950, PIN_INPUT_PULLUP | MUX_MODE0)			/* P9_22, 84, SPI0_CLK */
5 		AM33XX_IOPAD(0x954, PIN_INPUT_PULLUP | MUX_MODE0)       	/* P9_21, 85, SPI0_MISO */
6 		AM33XX_IOPAD(0x958, PIN_OUTPUT_PULLUP | MUX_MODE0)	        /* P9_18, 86, SPI0_MOSI */
7 	>;
8 };

You can understand the meaning of this pin muxing by comparing this code with this table :)

SPI Enabling

Append following code to the end of the source code:

1 &spi0 {
2 	status="okay";
3 	pinctrl-names = "default";
4 	pinctrl-0 = <&spi0_pins>;
5 };

Because fbtft driver doesn't take advantage of the device tree, there is no need to describe the peripheral under the SPI bus. Just enable the SPI driver.

Full source code

You can see the full source code of the modified dts file at this link.

Build & Install

If you fully understand how to build the dts and copy dtb to the BBB, it is very easy. If not, just type this code:

1 # Mount sdcard to the /media/rootfs */
2 $) cd bb-kernel
3 $) tools/rebuild.sh
4 $) cd ..
5 $) sudo tar xfv ./bb-kernel/deploy/${kernel_version}-dtbs.tar.gz -C /media/rootfs/boot/dtbs/${kernel_version}/

Enabling fbtft

Fortunately, fbtft is already in the BBB kernel so we don't need to build and install it. Just boot the BBB and type following to enable the fbtft :

1 $) sudo modprobe fbtft_device busnum=1 name=adafruit18 debug=7 verbose=3 gpios=dc:60,reset:48

Parameters for this device driver means:

  1. busnum = 1 : We want to use SPI0 bus. (SPI0 is exported to the kernel as SPI 1)
  2. name=adafruit18 : We want to use adafruit18 LCD driver in the fbtft source code tree, which is compatible with our LCD.
  3. gpios=dc : 60, reset:48 : GPIO 60 means GPIO1_28(32*1 + 28 = 60) and GPIO 48 means GPIO1_16(32 * 1 + 16 = 48). As we configured, we want use these GPIO pins.

Working Correctly?

When booted without loading the fbtft module, LCD just shows white screen, and when the driver is working correctly, LCD should change to the black screen.

Also, new file named /dev/fb1 should be created.

Testing It

$) cat /dev/urandom /dev/fb1

Then you should be able to see random-colored dots in the screen.

Some Examples

This page introduces some useful examples to use the fbtft.

This example is my favorite one :)

1 $) sudo apt-get install fbset
2 # Map console 1 to framebuffer 1, login screen will show up on the display
3 $) con2fbmap 1 1