Project

General

Profile

Actions

Feature #839

closed

Integrate TFT-3.5inch Display

Added by Hammel about 3 years ago. Updated almost 3 years ago.

Status:
Closed
Priority:
Immediate
Assignee:
Category:
Systems
Target version:
Start date:
23 Apr 2021
Due date:
% Done:

100%

Estimated time:
Severity:
01 - Critical

Description

This is for PiFile.
See

This display has only a 480x320 display area. I can scale icons to fit this but should expect that, because I'm not using EGL as a Cairo backend (yet) that things might be a little slow.

Actions #1

Updated by Hammel almost 3 years ago

  • Severity changed from 02 - High to 01 - Critical
Actions #2

Updated by Hammel almost 3 years ago

  • Status changed from New to In Progress
  • % Done changed from 0 to 20

Looks like the model they sent me was actually an LCD-35, not an MHS-35.

Meta build created: lcdshow (not pushed yet).
Package available for testing.

Actions #3

Updated by Hammel almost 3 years ago

  • Description updated (diff)
Actions #4

Updated by Hammel almost 3 years ago

The build seems to work on the dev platform if I use the following command from a terminal window.

FRAMEBUFFER=/dev/fb1 startx

This is with the HDMI plugged in and acting as the default display. Touchscreen works but might be rotated incorrectly - the display is in landscape mode but touchscreen appears to be in portrait mode. I'll deal with the touchscreen later.

So now I need to see how I can force the TFT to be used at boot. I might need to use fbcon on the cmdline or con2fbmap 1 1. But mostly I just need to find out if there are one or two fb devices when HDMI is not plugged in, then set the X.org startup to use the correct device. This could be done, potentially, by using different xorg.conf files and specifying the TFT device conf like so.

Section "Device" 
        Identifier      "Allwinner A10/A13/A20 FBDEV" 
        Driver          "fbturbo" 
        Option          "fbdev" "/dev/fb1" 

        Option          "SwapbuffersWait" "true" 
EndSection
Actions #5

Updated by Hammel almost 3 years ago

  • Description updated (diff)
Actions #6

Updated by Hammel almost 3 years ago

Oh look - someone else is doing exactly what I'm doing. This could be really helpful.

Actions #7

Updated by Hammel almost 3 years ago

I have scripts to switch from HDMI to TFT and back, but they're hacks that just rerun startx. Exiting the xterm that gets started from that drops me back to the last startx. So running pibox-tft puts me on the TFT and exiting that puts me back on the HDMI.

That's good enough for testing purposes to get the rest of the display working but not a production method of swapping. I need either fbcp or con2fbmap apparently.

The current problem is the display size. Setting the framebuffer wxh did squeeze the width but not the height.

I need to review the following links and gather information on how to complete this project:
  1. https://github.com/notro/fbtft/wiki
  2. https://learn.watterott.com/hats/rpi-display/fbtft-install/
  3. https://learn.watterott.com/hats/rpi-display/faq/
  4. http://www.willprice.dev/2017/09/16/adventures-with-tft-screens-for-raspberry-pi.html
  5. https://www.raspberrypi.org/forums/viewtopic.php?t=111817#p1041032
  6. https://philipp-weissmann.de/touch-display-auf-raspberry-pi-mit-arch-linux/ (German)
  7. https://forum.armbian.com/topic/13221-fbtft-with-device-tree-overlay-on-mainline/ (DTS info) #
Actions #8

Updated by Hammel almost 3 years ago

Turns out the display is working just fine. All I need to do is add

FRAMEBUFFER=/dev/fb1
export FRAMEBUFFER

to /etc/init.d/S99UI and the UI starts on the small display. Running pibox-hdmi on there will launch the HDMI display, albeit at the width of the TFT display.

Now I need to test the touchscreen. I should use xinput-calibrate and ts-calibrate for this. I can also do:

TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/event0 ts_test
TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/event0 ts_calibrate

An initial attempt at ts_test locked up the screen. I'll need to write some simplified scripts to make this easier to rerun since there is no shell history to rerun commands in the dev platform.

For xinput-calibrate I should be able copy the output from the following into an xorg.conf file.

DISPLAY=:0.0 xinput_calibrator

This doesn't work either. I just get "No calibratable devices found". Might need to set an environment variable to find the correct input event file.

Actions #9

Updated by Hammel almost 3 years ago

  • Subject changed from Integrate MHS-3.5inch RPi Display to Integrate TFT-3.5inch Display
Actions #10

Updated by Hammel almost 3 years ago

The touchscreen is on event4, which I can see by running evtest with no arguments which gives me a list of events with associated names. I need a way to identify the event file in a script - evtest is interactive (at least without arguments).

To get the names of the devices you need an ioctl, which is not easy to call via a shell script. evtest.c has the scan_list() function that I could add to piboxlib/ptools/<new tool> to handle this.

Actions #11

Updated by Hammel almost 3 years ago

Added pbeventlist to piboxlib. Needs to be tested on hardware, then used with the TBD scripts that I can use to test the touchscreen.

Actions #12

Updated by Hammel almost 3 years ago

Preparing to test I found I wanted to switch back and forth between the TFT and HDMI. LCDShow-hdmi does this for LCDShow, but it's much simpler than that.

To go from TFT (after lcdshow package is installed) to HDMI
  1. Edit config.txt
    1. Comment out framebuffer_<width,height>
    2. Comment out dtparam=i2c_arm=on
    3. Comment out dtparam-spi=on
    4. Comment out dtoverlay=tft35a:rotate=90
  2. Edit /etc/init.d/functions
    1. Change FRAMEBUFFER=/dev/fb1 to FRAMEBUFFER=/dev/fb0
  3. Reboot

That FRAMEBUFFER change also requires using that variable in /etc/init.d/S99UI.

I need to edit pibox-hdmi to comment these out or uncomment to go back to TFT and then do the reboot.

It's annoying that a reboot is required, but at least I can edit directly on the device for testing purposes. Editing with the TFT is very difficult due to the very small display, which requires very small fonts to get enough visible to be useful.

Actions #13

Updated by Hammel almost 3 years ago

  • % Done changed from 20 to 60

Getting closer. S99UI calls xinit directly instead of using startx. The latter honors the FRAMEBUFFER setting. The former is not. I need to find out why.

Actions #14

Updated by Hammel almost 3 years ago

FRAMEBUFFER would need to be used to manually edit the xorg.conf file, which needs a Device section like so:

Section "Device" 
        Identifier      "Allwinner A10/A13/A20 FBDEV" 
        Driver          "fbturbo" 
        Option          "fbdev" "/dev/fb1" 

        Option          "SwapbuffersWait" "true" 
EndSection

So I can either have a copy of this that is edited by the pibox-hdmi script or I can have two copies with ".hdmi" and ".tft" suffices which the script chooses to symlink to the real xorg.conf.

Actions #15

Updated by Hammel almost 3 years ago

  • % Done changed from 60 to 80

This now works. The lcdshow package will handle support for switching to TFT displays, while the default in the dev platform is to always assume we're in HDMI mode (unless it's a touchscreen, which is still HDMI but a different xorg.conf).

I removed cruft from S99UI in the dev platform that was originally intended to handle TFT displays but it wasn't really doing anything and nothing was using what it did try to setup so it was useless. The updated init script is much simnpler.

Tested on the tft display with a small 5" hdmi display. The pibox-hdmi script handles switching back and forth just fine now.

Still need to test these changes on a PiBox Media System build and a kiosk build to make sure those work out-of-the-box.

Verified working on kiosk build.
Verified working on media system build.

Also: need to run calibration tests - see above comment (#829-8). I already have a script for this: pibox-touchtest. It should be in the rootfs already (after lcdshow package is installed).

Actions #16

Updated by Hammel almost 3 years ago

  • Status changed from In Progress to Closed
  • % Done changed from 80 to 100

This is now working (except xinput-calibrator, which won't work with PiBox but we don't care because we use tslib directly anyway). All changes have been tested on hardware, committed and pushed.

Closing issue.

Actions

Also available in: Atom PDF