-
Notifications
You must be signed in to change notification settings - Fork 495
fbtft_device
fbtft_device is a kernel module for registering FBTFT devices.
To understand the need for this module we need to know a little bit about the Linux kernel. For the kernel to operate some device like a keyboard or a screen, it needs to know how to do it. This is what a device driver provides, it's a piece of code. But there is one piece missing, and that is something informing the kernel about the presence of the keyboard or screen. This is what the device provides. A device is a data structure that contains information about the device, like which bus it is connected to (SPI, PCI, USB), IO addresses and other device spesific information. When the kernel has a driver that supports a device, it hands control of the device to the driver (binding.txt).
Some ways a Linux device can be created:
- In the platform or board file
When the information changes, the kernel has to be rebuilt. -
Device Tree
Not supported in Raspian. - A bus driver detects a new hardware device on the bus, and creates a matching Linux device.
A bus like SPI, doesn't have enumeration capabilities. The same goes for GPIOs. - A kernel module
The displays that FBTFT supports uses SPI and/or GPIO. These busses can't find out what is connected to them, so we must tell the kernel about them. To be able to provide a prebuilt kernel for all displays, we need a kernel module that can provide that information.
fbtft_device does this. It has device information for all the displays it supports, with default values. These values can be changed with module parameters.
There is one required module parameter, and that is name. It specifies which display (device) to register.
modprobe fbtft_device name=adafruit22fb
fbtft_device prints information to the kernel log
$ dmesg
fbtft_device: SPI devices registered:
fbtft_device: spidev spi0.0 500kHz 8 bits mode=0x00
fbtft_device: spidev spi0.1 500kHz 8 bits mode=0x00
fbtft_device: 'fb' Platform devices registered:
fbtft_device: bcm2708_fb id=-1 pdata? no
fbtft_device: Deleting spi0.0
fbtft_device: GPIOS used by 'adafruit22fb':
fbtft_device: 'reset' = GPIO25
fbtft_device: 'led' = GPIO23
fbtft_device: SPI devices registered:
fbtft_device: spidev spi0.1 500kHz 8 bits mode=0x00
fbtft_device: adafruit22fb spi0.0 32000kHz 8 bits mode=0x00
First it tells which SPI devices and devices starting with 'fb' (framebuffer) that was registered before the module was loaded.
Then it deletes the device connected to spi0.0 (spidev) so we can register a new one.
Next it tells which GPIOs that is associated with this display.
Lastly it lists which SPI devices that are currently registered (spi0.0 means SPI busnum.chipselect).
For SPI displays, these parameters affect the SPI bus setup
-
busnum
SPI bus number (default=0) -
cs
SPI chip select (default=0) -
speed
SPI speed in Hz (default varies among displays) -
mode
SPI mode (default SPI_MODE_0)
Example: spi0.1 @ 16 MHz
modprobe fbtft_device name=sainsmart18fb cs=1 speed=16000000
Most displays needs GPIOs for signaling. To simplify configuration, pins with the same functionality has been given names:
- reset - Hardware reset
- dc - Data/Command (sometimes called RC)
- led - Backlight
GPIO only displays
- db00-15 - Databus
- cs - Chip Select
- wr - Write strobe
fbtft_device contains default values for these pin names. The values can be changed with the gpios parameter. This is a comma separated array of pin/signal names and GPIO numbers. gpios=pin_name:gpio_number[,pin_name:gpio_number]
When overriding the defaults using gpios, all gpios must be specified.
Example showing the default gpio values of itdb28fb
modprobe fbtft_device name=itdb28fb gpios=reset:17,dc:1,wr:0,cs:21,db00:9,db01:11,db02:18,db03:23,db04:24,db05:25,db06:8,db07:7,led:4
Frames per second (default 20)
In effect this states how long the driver will wait after video memory has been changed until display update transfer is started.
See Debug for a way to show how long the actual transfer takes.
Length of the FBTFT transmit buffer.
This buffer is used on Little Endian architectures like on the Raspberry Pi. The 2 bytes in the 16-bit pixel value has to be swapped before transfer.
When FBTFT is compiled on Little Endian, it used a default buffer of 4096 bytes. txbuflen can be used to change this.
txbuflen has a special value -1 which makes the buffer the same size as video memory.
This parameter controls how much information fbtft_device writes to the kernel log
- 0 - silent
- 1 - show gpios used
- 2 - and show devices after registration
- 3 - and show devices before registration (default)
The special name list will write the supported devices to the kernel log.
modprobe fbtft_device name=list
ERROR: could not insert 'fbtft_device': Operation canceled
# Show output
dmesg
fbtft_device: Supported drivers:
fbtft_device: spidev
fbtft_device: flexfb
fbtft_device: ili9341fb
fbtft_device: r61505ufb
fbtft_device: adafruit22fb
fbtft_device: adafruit18fb
fbtft_device: adafruit18greenfb
fbtft_device: sainsmart18fb
fbtft_device: nokia3310fb
fbtft_device: itdb28fb
fbtft_device: flexpfb
Register adafruit22fb device with default values:
modprobe fbtft_device name=adafruit22fb
dmesg
fbtft_device: SPI devices registered:
fbtft_device: spidev spi0.0 500kHz 8 bits mode=0x00
fbtft_device: spidev spi0.1 500kHz 8 bits mode=0x00
fbtft_device: 'fb' Platform devices registered:
fbtft_device: bcm2708_fb id=-1 pdata? no
fbtft_device: Deleting spi0.0
fbtft_device: GPIOS used by 'adafruit22fb':
fbtft_device: 'reset' = GPIO25
fbtft_device: 'led' = GPIO23
fbtft_device: SPI devices registered:
fbtft_device: spidev spi0.1 500kHz 8 bits mode=0x00
fbtft_device: adafruit22fb spi0.0 32000kHz 8 bits mode=0x00
Register sainsmart18fb with changes
SPI: spi0.1 at 16MHz
GPIOs: reset=18 (when overriding, all must be mentioned)
modprobe fbtft_device name=sainsmart18fb cs=1 speed=16000000 gpios=reset:18,dc:24
dmesg
fbtft_device: SPI devices registered:
fbtft_device: spidev spi0.1 500kHz 8 bits mode=0x00
fbtft_device: 'fb' Platform devices registered:
fbtft_device: bcm2708_fb id=-1 pdata? no
fbtft_device: Deleting spi0.1
fbtft_device: GPIOS used by 'sainsmart18fb':
fbtft_device: 'reset' = GPIO18
fbtft_device: 'dc' = GPIO24
fbtft_device: SPI devices registered:
fbtft_device: sainsmart18fb spi0.1 16000kHz 8 bits mode=0x00
When loading a driver, it's init() function is called and the device(s) it supports is made known to the kernel.
If the device it supports is registered in the kernel, the drivers probe() function is called with the device as an argument.
So, loading a driver when the device is not present, will just sit there. It is loaded, but it won't do anything before the supported device is present.
A driver can support more than one device.