From: Paul Hänsch Date: Mon, 5 Oct 2020 15:24:43 +0000 (+0200) Subject: support for waveshare 4inch display (rev A) X-Git-Url: http://git.plutz.net/?p=blast;a=commitdiff_plain;h=92db7feab8d6bfdae2ba3f37fe57d54e4e2d0040 support for waveshare 4inch display (rev A) --- diff --git a/modules/display_wsLCD4.mk b/modules/display_wsLCD4.mk new file mode 100644 index 0000000..7c32cf5 --- /dev/null +++ b/modules/display_wsLCD4.mk @@ -0,0 +1,77 @@ +PACKAGES += xserver-xorg-input-evdev xinput xinput-calibrator + +define RPICONFIG += + +### Waveshare 4 Inch Display ### +hdmi_force_hotplug=1 +dtparam=i2c_arm=on +dtparam=spi=on +enable_uart=1 +dtoverlay=waveshare35a +# 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 +hdmi_group=2 +hdmi_mode=1 +hdmi_mode=87 +hdmi_cvt 430 320 60 6 0 0 0 +hdmi_drive=2 +display_rotate=0 +endef + +export display_wsLCD4_cfg display_wsLCD4_rotation + +define display_wsLCD4_cfg := +Section "InputClass" + Identifier "calibration" + MatchProduct "ADS7846 Touchscreen" + Option "Calibration" "3950 172 3871 194" + Option "SwapAxes" "1" + Option "EmulateThirdButton" "1" + Option "EmulateThirdButtonTimeout" "1000" + Option "EmulateThirdButtonMoveThreshold" "300" + + # Identifier "evdev touchscreen catchall" + # MatchIsTouchscreen "on" + # Option "Calibration" "200 3950 250 4000" + # MatchDevicePath "/dev/input/event*" + # Driver "evdev" +EndSection +endef + +define display_wsLCD4_rotation := +# Keep touch matrix rotated in accordance with screen rotation +while sleep 3; do + oldrotate="$${rotate}" + rotate="$$(xrandr |grep primary)" + rotate="$${rotate#*+0+0 }" + rotate="$${rotate% (*}" + + [ "$${oldrotate}" = "$${rotate}" ] || case $$rotate in + left) xinput set-prop 'ADS7846 Touchscreen' 'Coordinate Transformation Matrix' 0 -1 1 1 0 0 0 0 1;; + right) xinput set-prop 'ADS7846 Touchscreen' 'Coordinate Transformation Matrix' 0 1 0 -1 0 1 0 0 1;; + inverted) xinput set-prop 'ADS7846 Touchscreen' 'Coordinate Transformation Matrix' -1 0 1 0 -1 1 0 0 1;; + *) xinput set-prop 'ADS7846 Touchscreen' 'Coordinate Transformation Matrix' 1 0 0 0 1 0 0 0 1;; + esac +done & +endef + +.PHONY: _display_wsLCD4 +_config: _display_wsLCD5 ${CFGROOT}/boot/waveshare35a.dtbo +_display_wsLCD4: ${CFGROOT} _copy _mount + # Rough touch calibration + mkdir -p "$${CFGROOT}/usr/share/X11/xorg.conf.d/" + printf '%s\n' "$${display_wsLCD4_cfg}" >"$${CFGROOT}/usr/share/X11/xorg.conf.d/45-evdev.conf" + # Resolution / Rotation stuff + mkdir -p "$${CFGROOT}/etc/X11/Xsession.d/" + printf 'xrandr --size 480x320\n' >"$${CFGROOT}/etc/X11/Xsession.d/10display_resolution" + printf '%s\n' "$$display_wsLCD4_rotation" >"$${CFGROOT}/etc/X11/Xsession.d/20touch_rotation" + # Correct DPI scaling, although application support is mediocre + mkdir -p "$${CFGROOT}/etc/X11/Xresources/" + printf 'Xft.dpi: 144\n' >"$${CFGROOT}/etc/X11/Xresources/dpi_resolution" + # Workaround for applications that do not handle DPI scaling correctly + -sed -i 's;^Exec=;Exec=env GDK_DPI_SCALE=.5 ;' \ + $${CFGROOT}/usr/share/applications/chromium*.desktop \ + $${CFGROOT}/usr/share/applications/firefox*.desktop \ + $${CFGROOT}/usr/share/applications/exo-web-browser.desktop + +${CFGROOT}/boot/waveshare35a.dtbo: modules/waveshare35a-overlay.dtb + cp "$<" "$@" diff --git a/modules/waveshare35a-overlay.dtb b/modules/waveshare35a-overlay.dtb new file mode 100644 index 0000000..9f082e4 Binary files /dev/null and b/modules/waveshare35a-overlay.dtb differ