Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempted fix for Pi 3 Buster touch weirdness #37

Merged
merged 7 commits into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,46 @@ These drivers are for Raspberry Pi models before the Pi 3B+.

## Installing / Uninstalling

First, clone this GitHub repository branch to your Pi:
1. Make sure you're running Raspbian Buster or Raspbian Stretch.

2. Update your Pi with `sudo apt update` and `sudo apt upgrade`.

3. Clone this GitHub repository to your Pi:

```
git clone https://github.com/pimoroni/hyperpixel4 -b pi3
```

Then run the installer to install:
4. Then run the installer to install:

```
cd hyperpixel4
sudo ./install.sh
```

## Rotation

To keep your touchscreen rotated with the display, you should rotate HyperPixel4 using the `hyperpixel4-rotate` command rather than "Screen Configuration."

This command will update your touch settings and screen configuration settings to match, and you can rotate between four modes: left, right, normal, inverted.

* `hyperpixel4-rotate left` - landscape, power/HDMI on bottom
* `hyperpixel4-rotate right` - landscape, power/HDMI on top
* `hyperpixel4-rotate normal` - portrait, USB ports on top
* `hyperpixel4-rotate inverted` - portrait, USB ports on bottom

This command changes the `display_rotate` parameter in `/boot/config.txt` and changes the touchscreen calibration dropped into `/etc/udev/rules.d/`.

## Touch rotation

If you're having trouble with your touch being 180 degrees rotated to your screen, or need to rotate the touch for other reasons you can use some additional arguments for the dtoverlay in config.txt, these are:

* `touchscreen-inverted-x`
* `touchscreen-inverted-y`
* `touchscreen-swapped-x-y`

For example, to rotate touch 180 degrees you want to invert both the x and y axis, by changing the `dtoverlay=hyperpixel4` line in your `/boot/config.txt` to:

```
dtoverlay=hyperpixel4,touchscreen-inverted-x,touchscreen-inverted-y
```
Binary file modified dist/hyperpixel4-init
Binary file not shown.
51 changes: 51 additions & 0 deletions dist/hyperpixel4-rotate
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

ORIENTATION=$1
DEVICE="pointer:Goodix Capacitive TouchScreen"
UDEV_FILE="/etc/udev/rules.d/98-hyperpixel4-calibration.rules"
CONFIG_FILE="/boot/config.txt"

function set_matrix {
printf "Setting matrix: $1 $2 $3 $4 $5 $6\n";
DISPLAY=:0.0 xinput set-prop "$DEVICE" "libinput Calibration Matrix" $1 $2 $3 $4 $5 $6 0 0 1

printf "Saving touch settings to $UDEV_FILE\n";
echo "ATTRS{name}==\"Goodix Capacitive TouchScreen\", ENV{LIBINPUT_CALIBRATION_MATRIX}=\"$1 $2 $3 $4 $5 $6\"" | sudo tee $UDEV_FILE > /dev/null

printf "Please reboot for changes to take effect!\n";
}

function set_display {
printf "Rotating display\n";
if [[ -f "$CONFIG_FILE" ]]; then
sudo sed -i "s/display_rotate=[0-3]/display_rotate=$1/" $CONFIG_FILE
sudo sed -i "s/#display_rotate=$1/display_rotate=$1/" $CONFIG_FILE
fi
}

if [ "$ORIENTATION" == "right" ]; then
set_display 1
set_matrix 0 1 0 -1 0 1
exit 0
fi

if [ "$ORIENTATION" == "left" ]; then
set_display 3
set_matrix 0 -1 1 1 0 0
exit 0
fi

if [ "$ORIENTATION" == "inverted" ]; then
set_display 2
set_matrix -1 0 1 0 -1 1
exit 0
fi

if [ "$ORIENTATION" == "normal" ]; then
set_display 0
set_matrix 1 0 0 0 1 0
exit 0
fi

printf "Unsupported orientation: $ORIENTATION\n";
printf "Try one of: left, right, normal, inverted\n";
16 changes: 12 additions & 4 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
SERVICE_NAME="hyperpixel4-init.service"
SERVICE_PATH="/etc/systemd/system"
BINARY_NAME="hyperpixel4-init"
ROTATE_NAME="hyperpixel4-rotate"
BINARY_PATH="/usr/bin"
OVERLAY_PATH="/boot/overlays"
OVERLAY_NAME="hyperpixel4.dtbo"
Expand All @@ -16,14 +17,12 @@ CONFIG_LINES=(
"overscan_right=0"
"overscan_top=0"
"overscan_bottom=0"
"framebuffer_width=800"
"framebuffer_height=480"
"enable_dpi_lcd=1"
"display_default_lcd=1"
"display_rotate=0"
"dpi_group=2"
"dpi_mode=87"
"dpi_output_format=0x7f216"
"display_rotate=3"
"hdmi_timings=480 0 10 16 59 800 0 15 113 15 0 0 0 60 0 32000000 6"
)

Expand Down Expand Up @@ -53,6 +52,11 @@ else
printf "Warning: cannot find $SERVICE_PATH for $SERVICE_NAME\n"
fi

if [ -d "$BINARY_PATH" ]; then
cp dist/$ROTATE_NAME $BINARY_PATH
printf "Installed: $BINARY_PATH/$ROTATE_NAME\n"
fi

if [ -d "$OVERLAY_PATH" ]; then
cp dist/$OVERLAY_NAME $OVERLAY_PATH
printf "Installed: $OVERLAY_PATH/$OVERLAY_NAME\n"
Expand Down Expand Up @@ -92,4 +96,8 @@ else
printf "Please add $OVERLAY_CONFIG to your config.txt\n"
fi


printf "\nBefore rebooting, use 'hyperpixel4-rotate left/right/normal/inverted' to rotate your display!\n\n"
printf " left - Landscape, power/HDMI on bottom\n"
printf " right - Landscape, power/HDMI on top\n"
printf " normal - Portrait, USB ports on top\n"
printf " inverted - Portrait, USB ports on bottom\n\n"
112 changes: 0 additions & 112 deletions src/hyperpixel4-init.c

This file was deleted.

57 changes: 32 additions & 25 deletions src/hyperpixel4.dts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,34 @@
/ {
compatible = "brcm,bcm2708";
fragment@0 {
target = <0xdeadbeef>;
target = <&fb>;
__overlay__ {
pinctrl-names = "default";
pinctrl-0 = <0x1>;
};
};
fragment@1 {
target = <0xdeadbeef>;
target = <&gpio>;
__overlay__ {
dpi18_pins {
// brcm,pins = <0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa 0xb 0xc 0xd 0xe 0xf 0x10 0x11 0x12 0x13 0x14 0x15>;
brcm,pins = <0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xc 0xd 0xe 0xf 0x10 0x11 0x14 0x15 0x16 0x17 0x18 0x19>;
brcm,pins = <0 1 2 3 4 5 6 7 8 9 12 13 14 15 16 17 20 21 22 23 24 25>;
brcm,function = <0x6>;
brcm,pull = <0x0>;
phandle = <0x1>;
};
};
};
fragment@2 {
target-path = "/";
__overlay__ {
rpi_backlight: rpi_backlight {
compatible = "gpio-backlight";
gpios = <&gpio 19 0>;
default-on;
};
};
};
fragment@3 {
target-path = "/";
__overlay__ {
i2c_gpio: i2c@0 {
Expand All @@ -35,7 +44,7 @@
};
};
};
fragment@3 {
fragment@4 {
target = <&i2c_gpio>;
__overlay__ {
/* needed to avoid dtc warning */
Expand All @@ -46,28 +55,29 @@
reg = <0x5d>;
interrupt-parent = <&gpio>;
interrupts = <27 2>;
touchscreen-size-x = <800>;
touchscreen-size-y = <480>;
touchscreen-x-mm = <85>;
touchscreen-y-mm = <51>;
touchscreen-size-x = <480>;
touchscreen-size-y = <800>;
touchscreen-x-mm = <51>;
touchscreen-y-mm = <85>;
};
};
};
fragment@4 {
target-path = "/";
fragment@5 {
target = <&ft6236>;
__overlay__ {
rpi_backlight: rpi_backlight {
compatible = "gpio-backlight";
gpios = <&gpio 19 0>;
default-on;
};
touchscreen-swapped-x-y;
};
};
fragment@5 {
fragment@6 {
target = <&ft6236>;
__dormant__ {
touchscreen-inverted-x;
};
};
fragment@7 {
target = <&ft6236>;
__overlay__ {
touchscreen-inverted-x = <1>;
touchscreen-inverted-y = <1>;
touchscreen-inverted-y;
};
};
__symbols__ {
Expand All @@ -80,12 +90,9 @@
};
};
};
__fixups__ {
leds = "/fragment@0:target:0";
gpio = "/fragment@1:target:0";
};
__overrides__ {
rotate = <0>,"-5";
touchscreen-inverted-x = <0>,"+6";
touchscreen-inverted-y = <0>,"-7";
touchscreen-swapped-x-y = <0>,"-5";
};
};