]> git.plutz.net Git - blast/blob - modules/display_wsLCD4.mk
support for waveshare 4inch display (rev A)
[blast] / modules / display_wsLCD4.mk
1 PACKAGES += xserver-xorg-input-evdev xinput xinput-calibrator
2
3 define RPICONFIG +=
4
5 ### Waveshare 4 Inch Display ###
6 hdmi_force_hotplug=1
7 dtparam=i2c_arm=on
8 dtparam=spi=on
9 enable_uart=1
10 dtoverlay=waveshare35a
11 # dtoverlay=ads7846,cs=1,penirq=25,penirq_pull=2,speed=50000,keep_vref_on=0,swapxy=0,pmax=255,xohms=150,xmin=200,xmax=3900,ymin=200,ymax=3900
12 hdmi_group=2
13 hdmi_mode=1
14 hdmi_mode=87
15 hdmi_cvt 430 320 60 6 0 0 0
16 hdmi_drive=2
17 display_rotate=0
18 endef
19
20 export display_wsLCD4_cfg display_wsLCD4_rotation
21
22 define display_wsLCD4_cfg :=
23 Section "InputClass"
24         Identifier      "calibration"
25         MatchProduct    "ADS7846 Touchscreen"
26         Option  "Calibration"   "3950 172 3871 194"
27         Option  "SwapAxes"      "1"
28         Option  "EmulateThirdButton"    "1"
29         Option  "EmulateThirdButtonTimeout"     "1000"
30         Option  "EmulateThirdButtonMoveThreshold"       "300"
31
32         # Identifier "evdev touchscreen catchall"
33         # MatchIsTouchscreen "on"
34         # Option  "Calibration"   "200 3950 250 4000"
35         # MatchDevicePath "/dev/input/event*"
36         # Driver "evdev"
37 EndSection
38 endef
39
40 define display_wsLCD4_rotation :=
41 # Keep touch matrix rotated in accordance with screen rotation
42 while sleep 3; do
43   oldrotate="$${rotate}"
44   rotate="$$(xrandr |grep primary)"
45   rotate="$${rotate#*+0+0 }"
46   rotate="$${rotate% (*}"
47
48   [ "$${oldrotate}" = "$${rotate}" ] || case $$rotate in
49     left)     xinput set-prop 'ADS7846 Touchscreen' 'Coordinate Transformation Matrix' 0 -1 1  1 0 0  0 0 1;;
50     right)    xinput set-prop 'ADS7846 Touchscreen' 'Coordinate Transformation Matrix' 0 1 0  -1 0 1  0 0 1;;
51     inverted) xinput set-prop 'ADS7846 Touchscreen' 'Coordinate Transformation Matrix' -1 0 1  0 -1 1  0 0 1;;
52     *)        xinput set-prop 'ADS7846 Touchscreen' 'Coordinate Transformation Matrix' 1 0 0  0 1 0  0 0 1;;
53   esac
54 done &
55 endef
56
57 .PHONY: _display_wsLCD4
58 _config: _display_wsLCD5 ${CFGROOT}/boot/waveshare35a.dtbo
59 _display_wsLCD4: ${CFGROOT} _copy _mount
60         # Rough touch calibration
61         mkdir -p "$${CFGROOT}/usr/share/X11/xorg.conf.d/"
62         printf '%s\n' "$${display_wsLCD4_cfg}" >"$${CFGROOT}/usr/share/X11/xorg.conf.d/45-evdev.conf"
63         # Resolution / Rotation stuff
64         mkdir -p "$${CFGROOT}/etc/X11/Xsession.d/"
65         printf 'xrandr --size 480x320\n' >"$${CFGROOT}/etc/X11/Xsession.d/10display_resolution"
66         printf '%s\n' "$$display_wsLCD4_rotation" >"$${CFGROOT}/etc/X11/Xsession.d/20touch_rotation"
67         # Correct DPI scaling, although application support is mediocre
68         mkdir -p "$${CFGROOT}/etc/X11/Xresources/"
69         printf 'Xft.dpi: 144\n' >"$${CFGROOT}/etc/X11/Xresources/dpi_resolution"
70         # Workaround for applications that do not handle DPI scaling correctly
71         -sed -i 's;^Exec=;Exec=env GDK_DPI_SCALE=.5 ;' \
72           $${CFGROOT}/usr/share/applications/chromium*.desktop \
73           $${CFGROOT}/usr/share/applications/firefox*.desktop \
74           $${CFGROOT}/usr/share/applications/exo-web-browser.desktop
75
76 ${CFGROOT}/boot/waveshare35a.dtbo: modules/waveshare35a-overlay.dtb
77         cp "$<" "$@"