Raspbian and mcufriend ili9325 tft cape
Posted at 2015-11-05.
I have an old raspi model B and on a whim I once bought a screen for it. Some say it's ILI9325, some ILI9488. Mine actually says 9327 in the flex cable. It's a type that plugs in on the top and turns out only worked with a shady old card image from somewhere. These displays are common in stores in Aliexpress and probably EBay. Often sold as 4.0 inch LCD module Pi TFT or some other random size between 3 and 4 inches. There might be different models.
More recently I noticed some devs had been getting output on ili9325, so I thought I'd give it a try.
Preparations
I used Raspbian (2015-09-24-raspbian-jessie.img) that I stripped down enough to fit on a 2GB microSD card that I had sitting around.
The pi has been attached to a piece of board and heatsinked in some old project. Nothing but power, network, and the screen are plugged in.
Starting up
(I did poke around before, so here's a cooked demo instead.)
When powered on, the backlight comes on immediately.
It might be directly wired to power.
If not, there might even be a way to adjust it.
First up, the device fb0
gets taken by the Broadcom chip (Composite by
default, IIRC).
At this point, fb1
does not exist.
$ fbset -i -fb /dev/fb0
mode "656x416"
geometry 656 416 656 416 16
timings 0 0 0 0 0 0 0
rgba 5/11,6/5,5/0,0/16
endmode
Frame buffer device information:
Name : BCM2708 FB
Address : 0x1eb75000
Size : 545792
Type : PACKED PIXELS
Visual : TRUECOLOR
XPanStep : 1
YPanStep : 1
YWrapStep : 0
LineLength : 1312
Accelerator : No
pi@oldpi ~ $ fbset -i -fb /dev/fb1
open /dev/fb1: No such file or directory
I run a script with the startup commands from berryelectronics' comment in the discussion. Wiki page for flexfb says it's obsolete. There might (some day?) be a way to run a particular driver instead.
$ ./starttft.sh
Load modules
fbtft and setup
insmod /lib/modules/4.1.7+/kernel/drivers/video/fbdev/core/sysimgblt.ko
insmod /lib/modules/4.1.7+/kernel/drivers/video/fbdev/core/sysfillrect.ko
insmod /lib/modules/4.1.7+/kernel/drivers/video/fbdev/core/syscopyarea.ko
insmod /lib/modules/4.1.7+/kernel/drivers/video/fbdev/core/fb_sys_fops.ko
insmod /lib/modules/4.1.7+/kernel/drivers/staging/fbtft/fbtft.ko
insmod /lib/modules/4.1.7+/kernel/drivers/staging/fbtft/fbtft_device.ko name=flexpfb rotate=180 fps=60 gpios=dc:18,reset:7,wr:17,cs:4,db00:22,db01:23,db02:24,db03:10,db04:25,db05:9,db06:11,db07:8
flexfb and init
insmod /lib/modules/4.1.7+/kernel/drivers/staging/fbtft/flexfb.ko width=240 height=432 buswidth=8 init=-1,0xE9,0x20,-1,0x11,-2,100,-1,0x3A,0x55,-1,0xD1,0x00,0x6B,0x19,-1,0xD0,0x07,0x07,0x80,-1,0x36,0x48,-1,0xC1,0x10,0x10,0x02,0x02,-1,0xC0,0x00,0x35,0x00,0x00,0x01,0x02,-1,0xC5,0x01,-1,0xD2,0x01,0x22,-1,0xC8,0x01,0x52,0x37,0x10,0x0D,0x01,0x04,0x51,0x77,0x01,0x01,0x0d,0x08,0x80,0x00,-1,0xEA,0x80,-1,0x29,-3
done
$ sudo dmesg -c
[ 244.604545] fbtft: module is from the staging directory, the quality is unknown, you have been warned.
[ 244.621058] fbtft_device: module is from the staging directory, the quality is unknown, you have been warned.
[ 244.622870] fbtft_device: SPI devices registered:
[ 244.622912] fbtft_device: spidev spi0.0 500kHz 8 bits mode=0x00
[ 244.622933] fbtft_device: spidev spi0.1 500kHz 8 bits mode=0x00
[ 244.622946] fbtft_device: 'fb' Platform devices registered:
[ 244.622993] fbtft_device: soc:fb id=-1 pdata? no
[ 244.623274] fbtft_device: GPIOS used by 'flexpfb':
[ 244.623297] fbtft_device: 'dc' = GPIO18
[ 244.623312] fbtft_device: 'reset' = GPIO7
[ 244.623324] fbtft_device: 'wr' = GPIO17
[ 244.623337] fbtft_device: 'cs' = GPIO4
[ 244.623349] fbtft_device: 'db00' = GPIO22
[ 244.623361] fbtft_device: 'db01' = GPIO23
[ 244.623372] fbtft_device: 'db02' = GPIO24
[ 244.623384] fbtft_device: 'db03' = GPIO10
[ 244.623395] fbtft_device: 'db04' = GPIO25
[ 244.623406] fbtft_device: 'db05' = GPIO9
[ 244.623418] fbtft_device: 'db06' = GPIO11
[ 244.623429] fbtft_device: 'db07' = GPIO8
[ 244.623439] fbtft_device: 'fb' Platform devices registered:
[ 244.623480] fbtft_device: soc:fb id=-1 pdata? no
[ 244.623541] fbtft_device: flexpfb id=0 pdata? yes
[ 244.818688] flexfb: module is from the staging directory, the quality is unknown, you have been warned.
[ 245.326872] graphics fb1: flexfb frame buffer, 240x432, 202 KiB video memory, 4 KiB DMA buffer memory, fps=100
At this point the screen has turned blank (black) and I presume it's operational.
A new framebuffer device, fb1
, appears as well.
$ fbset -i -fb /dev/fb1
mode "240x432"
geometry 240 432 240 432 16
timings 0 0 0 0 0 0 0
nonstd 1
rgba 5/11,6/5,5/0,0/0
endmode
Frame buffer device information:
Name : flexfb
Address : 0
Size : 207360
Type : PACKED PIXELS
Visual : TRUECOLOR
XPanStep : 0
YPanStep : 0
YWrapStep : 0
LineLength : 480
Accelerator : No
A crude way to put something on the screen is to just cat /dev/urandom >
/dev/fb1
.
Of course many programs can quickly display something nicer.
I picked up a logo for Tarlab and used sudo fbi -d
/dev/fb1 -T 1 -a tarlab-transparent.png
to put it up.
Not pretty, but it works.
For some reason, fbi
wants access to a console and not just the fb device.
Hence the sudo since I'm going in remotely.
I should look into that or use a smarter program, but this was on the
Framebuffer use
wiki page.
I don't see options for rotation or background either.
Nothing seems to be in /sys/class/backlight/
.
There might be a GPIO for it, though.
Or there might not.
It might even be controlled by talking to the IC.
Plans
That script can be replaced by putting modules and arguments into config files to be autoloaded on boot.
I should probably make something that comes up on boot and shows interesting stuff on the screen.
I don't actually recommend running on a 2G card if you want to install ready software. It does get pretty cramped quick.
One useful thing might be boot messages.